Improve notification capture fidelity and documentation
This commit is contained in:
@@ -12,6 +12,9 @@ import se.ajpanton.notificationlog.databinding.FragmentEventSettingsBinding
|
||||
import se.ajpanton.notificationlog.settings.AppRuleMode
|
||||
import se.ajpanton.notificationlog.settings.LoggingRuleStore
|
||||
import se.ajpanton.notificationlog.settings.LoggingType
|
||||
import se.ajpanton.notificationlog.settings.AppListItem
|
||||
import se.ajpanton.notificationlog.settings.AppListOrdering
|
||||
import se.ajpanton.notificationlog.settings.ListedApp
|
||||
import se.ajpanton.notificationlog.capture.SeenApps
|
||||
|
||||
class EventSettingsFragment : Fragment(R.layout.fragment_event_settings) {
|
||||
@@ -99,31 +102,19 @@ class EventSettingsFragment : Fragment(R.layout.fragment_event_settings) {
|
||||
val seen = SeenApps.snapshot()
|
||||
val apps = requireContext().packageManager.getInstalledApplications(0)
|
||||
.map { info ->
|
||||
AppRow(
|
||||
ListedApp(
|
||||
label = requireContext().packageManager.getApplicationLabel(info).toString(),
|
||||
packageName = info.packageName,
|
||||
seen = info.packageName in seen,
|
||||
selected = info.packageName in rule.selectedPackages,
|
||||
)
|
||||
}
|
||||
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.label })
|
||||
val shown = if (rule.onlySeenApps) apps.filter { it.seen || it.selected } else apps
|
||||
val seenRows = shown.filter { it.seen }
|
||||
val otherRows = shown.filterNot { it.seen }
|
||||
if (!rule.onlySeenApps && rule.seenAppsFirst && seenRows.isNotEmpty()) {
|
||||
seenRows.forEach { container.addView(appView(it)) }
|
||||
if (otherRows.isNotEmpty()) container.addView(separator())
|
||||
otherRows.forEach { container.addView(appView(it)) }
|
||||
} else if (rule.onlySeenApps && seenRows.isNotEmpty() && otherRows.isNotEmpty()) {
|
||||
seenRows.forEach { container.addView(appView(it)) }
|
||||
container.addView(separator())
|
||||
otherRows.forEach { container.addView(appView(it)) }
|
||||
} else {
|
||||
shown.forEach { container.addView(appView(it)) }
|
||||
AppListOrdering.items(apps, rule.onlySeenApps, rule.seenAppsFirst).forEach { item ->
|
||||
container.addView(if (item is AppListItem.App) appView(item.value) else separator())
|
||||
}
|
||||
}
|
||||
|
||||
private fun appView(row: AppRow): View = LinearLayout(requireContext()).apply {
|
||||
private fun appView(row: ListedApp): View = LinearLayout(requireContext()).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
val checkbox = CheckBox(context).apply { isChecked = row.selected }
|
||||
checkbox.setOnCheckedChangeListener { _, checked ->
|
||||
@@ -148,8 +139,6 @@ class EventSettingsFragment : Fragment(R.layout.fragment_event_settings) {
|
||||
setBackgroundColor(0x33000000)
|
||||
}
|
||||
|
||||
private data class AppRow(val label: String, val packageName: String, val seen: Boolean, val selected: Boolean)
|
||||
|
||||
companion object {
|
||||
private const val ARG_TITLE = "title"
|
||||
private const val ARG_TYPE = "type"
|
||||
|
||||
Reference in New Issue
Block a user