Display encrypted notification logs
This commit is contained in:
@@ -95,8 +95,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||||||
supportFragmentManager.commit {
|
supportFragmentManager.commit {
|
||||||
replace(
|
replace(
|
||||||
R.id.content_frame,
|
R.id.content_frame,
|
||||||
page.loggingType?.let { EventSettingsFragment.newInstance(page.titleRes, it) }
|
when {
|
||||||
?: PageFragment.newInstance(page.titleRes),
|
page == Page.VIEW_LOGS -> ViewLogsFragment()
|
||||||
|
page.loggingType != null -> EventSettingsFragment.newInstance(page.titleRes, page.loggingType)
|
||||||
|
else -> PageFragment.newInstance(page.titleRes)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
runOnCommit(::applyPageTitleVisibility)
|
runOnCommit(::applyPageTitleVisibility)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package se.ajpanton.notificationlog
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
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 java.text.DateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||||
|
private var binding: FragmentViewLogsBinding? = null
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
binding = FragmentViewLogsBinding.bind(view)
|
||||||
|
binding!!.clearLogs.setOnClickListener {
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle("Clear logs?")
|
||||||
|
.setMessage("This permanently removes every stored notification log.")
|
||||||
|
.setNegativeButton("Cancel", null)
|
||||||
|
.setPositiveButton("Clear") { _, _ ->
|
||||||
|
EncryptedNotificationLogStore(requireContext()).clear()
|
||||||
|
loadLogs()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
loadLogs()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() { binding = null; super.onDestroyView() }
|
||||||
|
|
||||||
|
private fun loadLogs() {
|
||||||
|
val context = requireContext().applicationContext
|
||||||
|
Thread {
|
||||||
|
val entries = EncryptedNotificationLogStore(context).readAll().sortedByDescending { it.recordedAtEpochMillis }
|
||||||
|
activity?.runOnUiThread { binding?.let { render(it, entries) } }
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun render(view: FragmentViewLogsBinding, entries: List<NotificationLogEntry>) {
|
||||||
|
view.logRows.removeAllViews()
|
||||||
|
view.emptyView.visibility = if (entries.isEmpty()) View.VISIBLE else View.GONE
|
||||||
|
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(" · ")
|
||||||
|
setPadding(0, 12, 0, 12)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="@dimen/page_padding">
|
||||||
|
<Button android:id="@+id/clear_logs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Clear logs" />
|
||||||
|
<ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1">
|
||||||
|
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
|
||||||
|
<TextView android:id="@+id/empty_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="No logs yet." />
|
||||||
|
<LinearLayout android:id="@+id/log_rows" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" />
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user