Request listener rebind on startup
This commit is contained in:
@@ -2,6 +2,8 @@ package se.ajpanton.notificationlog
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.content.ComponentName
|
||||
import android.app.NotificationManager
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
@@ -18,6 +20,7 @@ import se.ajpanton.notificationlog.settings.LogViewSettings
|
||||
import se.ajpanton.notificationlog.settings.LogViewSettingsStore
|
||||
import se.ajpanton.notificationlog.settings.TimestampZone
|
||||
import se.ajpanton.notificationlog.settings.DisplayEvent
|
||||
import se.ajpanton.notificationlog.capture.NotificationCaptureService
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -91,6 +94,11 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
private fun render(view: FragmentViewLogsBinding, addedRows: List<LogRow>, reset: Boolean) {
|
||||
if (reset) view.logRows.removeAllViews()
|
||||
view.emptyView.visibility = if (rows.isEmpty()) View.VISIBLE else View.GONE
|
||||
view.emptyView.text = if (hasNotificationAccess()) {
|
||||
"No logs yet."
|
||||
} else {
|
||||
"Notification access is disabled. Enable it in Settings."
|
||||
}
|
||||
val settings = LogViewSettingsStore(requireContext()).load()
|
||||
addedRows.filter { eventFor(it.entry.action) in settings.visibleEvents }
|
||||
.forEach { row -> view.logRows.addView(logRowView(row, settings)) }
|
||||
@@ -264,6 +272,10 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
else -> DisplayEvent.DISAPPEARING
|
||||
}
|
||||
|
||||
private fun hasNotificationAccess(): Boolean = requireContext()
|
||||
.getSystemService(NotificationManager::class.java)
|
||||
.isNotificationListenerAccessGranted(ComponentName(requireContext(), NotificationCaptureService::class.java))
|
||||
|
||||
private fun timestamp(value: Long, zone: TimestampZone, eventTimeZoneId: String?): String = DateFormat.getDateTimeInstance().apply {
|
||||
timeZone = when (zone) {
|
||||
TimestampZone.UTC -> java.util.TimeZone.getTimeZone("UTC")
|
||||
|
||||
Reference in New Issue
Block a user