Page encrypted logs with cursors
This commit is contained in:
@@ -19,6 +19,7 @@ import android.widget.TextView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import se.ajpanton.notificationlog.data.EncryptedImageStore
|
||||
import se.ajpanton.notificationlog.data.EncryptedNotificationLogStore
|
||||
import se.ajpanton.notificationlog.data.NewestLogCursor
|
||||
import se.ajpanton.notificationlog.databinding.FragmentViewLogsBinding
|
||||
import se.ajpanton.notificationlog.model.NotificationAction
|
||||
import se.ajpanton.notificationlog.model.NotificationLogEntry
|
||||
@@ -37,7 +38,7 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
private var binding: FragmentViewLogsBinding? = null
|
||||
private val expandedIds = mutableSetOf<String>()
|
||||
private val rows = mutableListOf<LogRow>()
|
||||
private var loadedEntries = 0
|
||||
private var nextCursor: NewestLogCursor? = null
|
||||
private var loading = false
|
||||
private var noMoreRows = false
|
||||
private var loadGeneration = 0
|
||||
@@ -75,7 +76,7 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
val context = requireContext().applicationContext
|
||||
if (reset) {
|
||||
rows.clear()
|
||||
loadedEntries = 0
|
||||
nextCursor = null
|
||||
noMoreRows = false
|
||||
loadGeneration++
|
||||
}
|
||||
@@ -83,12 +84,12 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
||||
loading = true
|
||||
binding?.logsRefresh?.isRefreshing = true
|
||||
Thread {
|
||||
val entries = EncryptedNotificationLogStore(context).readNewest(loadedEntries, PAGE_SIZE)
|
||||
val page = EncryptedNotificationLogStore(context).readNewest(nextCursor, PAGE_SIZE)
|
||||
activity?.runOnUiThread {
|
||||
if (generation == loadGeneration) {
|
||||
loadedEntries += entries.size
|
||||
noMoreRows = entries.size < PAGE_SIZE
|
||||
val addedRows = entries.map(::LogRow)
|
||||
nextCursor = page.nextCursor
|
||||
noMoreRows = nextCursor == null
|
||||
val addedRows = page.entries.map(::LogRow)
|
||||
rows += addedRows
|
||||
binding?.let(::render)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user