Commit 89e9e7c1 authored by topjohnwu's avatar topjohnwu

Simplify UI code for Magisk logs

We have all texts, no need to go through recyclerview
parent ddc2f317
...@@ -15,8 +15,22 @@ class LogRepository( ...@@ -15,8 +15,22 @@ class LogRepository(
fun fetchLogs() = logDao.fetchAll() fun fetchLogs() = logDao.fetchAll()
fun fetchMagiskLogs() = Single.fromCallable { fun fetchMagiskLogs() = Single.fromCallable {
Shell.su("tail -n 5000 ${Const.MAGISK_LOG}").exec().out val list = object : AbstractMutableList<String>() {
}.flattenAsFlowable { it }.filter { it.isNotEmpty() } 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() fun clearLogs() = logDao.deleteAll()
......
...@@ -6,14 +6,13 @@ import com.topjohnwu.magisk.core.Config ...@@ -6,14 +6,13 @@ import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.data.repository.LogRepository import com.topjohnwu.magisk.data.repository.LogRepository
import com.topjohnwu.magisk.extensions.subscribeK 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.LogItem
import com.topjohnwu.magisk.model.entity.recycler.TextItem import com.topjohnwu.magisk.model.entity.recycler.TextItem
import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.model.events.SnackbarEvent
import com.topjohnwu.magisk.ui.base.BaseViewModel import com.topjohnwu.magisk.ui.base.BaseViewModel
import com.topjohnwu.magisk.ui.base.diffListOf import com.topjohnwu.magisk.ui.base.diffListOf
import com.topjohnwu.magisk.ui.base.itemBindingOf import com.topjohnwu.magisk.ui.base.itemBindingOf
import com.topjohnwu.magisk.utils.KObservableField
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
...@@ -32,18 +31,16 @@ class LogViewModel( ...@@ -32,18 +31,16 @@ class LogViewModel(
val itemEmpty = TextItem(R.string.log_data_none) val itemEmpty = TextItem(R.string.log_data_none)
val itemMagiskEmpty = TextItem(R.string.log_data_magisk_none) val itemMagiskEmpty = TextItem(R.string.log_data_magisk_none)
// --- main view // --- su log
val items = diffListOf<LogItem>() val items = diffListOf<LogItem>()
val itemBinding = itemBindingOf<LogItem> { val itemBinding = itemBindingOf<LogItem> {
it.bindExtra(BR.viewModel, this) it.bindExtra(BR.viewModel, this)
} }
// --- console // --- magisk log
val consoleAdapter = BindingAdapter<ConsoleItem>() val consoleText = KObservableField(" ")
val itemsConsole = diffListOf<ConsoleItem>()
val itemConsoleBinding = itemBindingOf<ConsoleItem>()
override fun refresh(): Disposable { override fun refresh(): Disposable {
val logs = repo.fetchLogs() val logs = repo.fetchLogs()
...@@ -63,12 +60,7 @@ class LogViewModel( ...@@ -63,12 +60,7 @@ class LogViewModel(
.ignoreElement() .ignoreElement()
val console = repo.fetchMagiskLogs() val console = repo.fetchMagiskLogs()
.map { ConsoleItem(it) } .doOnSuccess { consoleText.value = it }
.toList()
.observeOn(Schedulers.computation())
.map { it to itemsConsole.calculateDiff(it) }
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess { itemsConsole.update(it.first, it.second) }
.ignoreElement() .ignoreElement()
return Completable.merge(listOf(logs, console)).subscribeK() return Completable.merge(listOf(logs, console)).subscribeK()
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
...@@ -15,28 +14,32 @@ ...@@ -15,28 +14,32 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<HorizontalScrollView <ScrollView
gone="@{viewModel.consoleText.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <HorizontalScrollView
adapter="@{viewModel.consoleAdapter}" android:layout_width="match_parent"
itemBinding="@{viewModel.itemConsoleBinding}" android:layout_height="wrap_content">
items="@{viewModel.itemsConsole}"
android:layout_width="wrap_content" <TextView
android:layout_height="match_parent" android:layout_width="wrap_content"
android:clipToPadding="false" android:layout_height="wrap_content"
android:orientation="vertical" android:fontFamily="monospace"
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size}" android:text="@{viewModel.consoleText}"
android:paddingBottom="@{viewModel.insets.bottom}" android:textAppearance="@style/AppearanceFoundation.Caption"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" android:textSize="10sp"
tools:listitem="@layout/item_console_md2" android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size}"
tools:paddingTop="24dp" /> android:paddingBottom="@{viewModel.insets.bottom}"
tools:text="@tools:sample/lorem/random" />
</HorizontalScrollView>
</HorizontalScrollView>
</ScrollView>
<FrameLayout <FrameLayout
gone="@{!viewModel.itemsConsole.empty}" gone="@{!viewModel.consoleText.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"> android:layout_gravity="center">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment