Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Jun 9, 2021
1 parent 0f09866 commit 0a71dd6
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import java.io.File

internal class LumberjackViewerActivity : AppCompatActivity() {

private var loading: Boolean = true
private lateinit var binding: ActivityLumberjackViewerBinding
private lateinit var adapter: LogAdapter
private var adapter: LogAdapter? = null
private lateinit var logs: List<LogAdapter.Item>
private var filterJob: Job? = null

Expand Down Expand Up @@ -64,7 +63,6 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
logs = allLogs

adapter = LogAdapter(this@LumberjackViewerActivity, logs, "")
loading = false
withContext(Dispatchers.Main) {
binding.rvLogs.adapter = adapter
updateFilter(true)
Expand Down Expand Up @@ -121,6 +119,7 @@ internal class LumberjackViewerActivity : AppCompatActivity() {

private fun updateFilter(init: Boolean) {

val loading = adapter == null
val filter = binding.etFilter.text?.toString() ?: ""
val level = binding.spLevel.selectedItemPosition.takeIf { it > 0 }
?.let { LogAdapter.Item.Level.values()[it - 1] }
Expand All @@ -136,7 +135,7 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
filterJob?.cancel()

if (!filterIsActive) {
adapter.update(logs, filter)
adapter!!.update(logs, filter)
updateInfos()
return
}
Expand All @@ -148,13 +147,15 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
(level == null || it.level.level >= level.level)
}
withContext(Dispatchers.Main) {
adapter.update(filtered, filter)
adapter!!.update(filtered, filter)
updateInfos()
}
}
}

private fun updateInfos() {
binding.tvInfos.text = "${adapter.items.size} / ${logs.size}"
binding.tvInfos.text = adapter?.let {
"${it.items.size} / ${logs.size}"
} ?: ""
}
}

0 comments on commit 0a71dd6

Please sign in to comment.