Persist log view preferences
This commit is contained in:
@@ -8,6 +8,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import se.ajpanton.notificationlog.data.EncryptedNotificationLogStore
|
||||
import se.ajpanton.notificationlog.databinding.FragmentViewLogsBinding
|
||||
import se.ajpanton.notificationlog.model.NotificationLogEntry
|
||||
import se.ajpanton.notificationlog.settings.LogField
|
||||
import se.ajpanton.notificationlog.settings.LogViewSettingsStore
|
||||
import se.ajpanton.notificationlog.settings.TimestampZone
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
@@ -44,16 +47,24 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
private fun render(view: FragmentViewLogsBinding, entries: List<NotificationLogEntry>) {
|
||||
view.logRows.removeAllViews()
|
||||
view.emptyView.visibility = if (entries.isEmpty()) View.VISIBLE else View.GONE
|
||||
val settings = LogViewSettingsStore(requireContext()).load()
|
||||
entries.forEach { entry ->
|
||||
view.logRows.addView(TextView(requireContext()).apply {
|
||||
text = listOfNotNull(
|
||||
DateFormat.getDateTimeInstance().format(Date(entry.recordedAtEpochMillis)),
|
||||
entry.appName,
|
||||
entry.action.name.lowercase().replace('_', ' '),
|
||||
entry.contents,
|
||||
).joinToString(" · ")
|
||||
text = settings.order.filter { it in settings.visibleFields }.mapNotNull { field -> when (field) {
|
||||
LogField.TIMESTAMP -> timestamp(entry.recordedAtEpochMillis, settings.timestampZone)
|
||||
LogField.APP_NAME -> entry.appName
|
||||
LogField.PACKAGE_NAME -> entry.packageName
|
||||
LogField.ACTION -> entry.action.name.lowercase().replace('_', ' ')
|
||||
LogField.CONTENTS -> entry.contents
|
||||
} }.joinToString(" · ")
|
||||
setPadding(0, 12, 0, 12)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun timestamp(value: Long, zone: TimestampZone): String {
|
||||
val format = DateFormat.getDateTimeInstance()
|
||||
if (zone == TimestampZone.UTC) format.timeZone = java.util.TimeZone.getTimeZone("UTC")
|
||||
return format.format(Date(value))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user