Simplify UI code for Magisk logs

We have all texts, no need to go through recyclerview
This commit is contained in:
topjohnwu
2020-06-29 05:22:16 -07:00
parent ddc2f317ab
commit 89e9e7c176
3 changed files with 41 additions and 32 deletions

View File

@@ -15,8 +15,22 @@ class LogRepository(
fun fetchLogs() = logDao.fetchAll()
fun fetchMagiskLogs() = Single.fromCallable {
Shell.su("tail -n 5000 ${Const.MAGISK_LOG}").exec().out
}.flattenAsFlowable { it }.filter { it.isNotEmpty() }
val list = object : AbstractMutableList<String>() {
val buf = StringBuilder()
override val size get() = 0
override fun get(index: Int): String = ""
override fun removeAt(index: Int): String = ""
override fun set(index: Int, element: String): String = ""
override fun add(index: Int, element: String) {
if (element.isNotEmpty()) {
buf.append(element)
buf.append('\n')
}
}
}
Shell.su("cat ${Const.MAGISK_LOG}").to(list).exec()
list.buf.toString()
}
fun clearLogs() = logDao.deleteAll()

View File

@@ -6,14 +6,13 @@ import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.data.repository.LogRepository
import com.topjohnwu.magisk.extensions.subscribeK
import com.topjohnwu.magisk.model.binding.BindingAdapter
import com.topjohnwu.magisk.model.entity.recycler.ConsoleItem
import com.topjohnwu.magisk.model.entity.recycler.LogItem
import com.topjohnwu.magisk.model.entity.recycler.TextItem
import com.topjohnwu.magisk.model.events.SnackbarEvent
import com.topjohnwu.magisk.ui.base.BaseViewModel
import com.topjohnwu.magisk.ui.base.diffListOf
import com.topjohnwu.magisk.ui.base.itemBindingOf
import com.topjohnwu.magisk.utils.KObservableField
import com.topjohnwu.superuser.Shell
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
@@ -32,18 +31,16 @@ class LogViewModel(
val itemEmpty = TextItem(R.string.log_data_none)
val itemMagiskEmpty = TextItem(R.string.log_data_magisk_none)
// --- main view
// --- su log
val items = diffListOf<LogItem>()
val itemBinding = itemBindingOf<LogItem> {
it.bindExtra(BR.viewModel, this)
}
// --- console
// --- magisk log
val consoleAdapter = BindingAdapter<ConsoleItem>()
val itemsConsole = diffListOf<ConsoleItem>()
val itemConsoleBinding = itemBindingOf<ConsoleItem>()
val consoleText = KObservableField(" ")
override fun refresh(): Disposable {
val logs = repo.fetchLogs()
@@ -63,12 +60,7 @@ class LogViewModel(
.ignoreElement()
val console = repo.fetchMagiskLogs()
.map { ConsoleItem(it) }
.toList()
.observeOn(Schedulers.computation())
.map { it to itemsConsole.calculateDiff(it) }
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess { itemsConsole.update(it.first, it.second) }
.doOnSuccess { consoleText.value = it }
.ignoreElement()
return Completable.merge(listOf(logs, console)).subscribeK()