You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Reverted removing UpdateRepos temporarily
This commit is contained in:
@@ -5,11 +5,15 @@ import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.skoumal.teanity.extensions.subscribeK
|
||||
import com.topjohnwu.magisk.*
|
||||
import com.topjohnwu.magisk.tasks.UpdateRepos
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.view.Notifications
|
||||
import com.topjohnwu.magisk.view.Shortcuts
|
||||
import com.topjohnwu.net.Networking
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import org.koin.android.ext.android.get
|
||||
|
||||
open class SplashActivity : AppCompatActivity() {
|
||||
|
||||
@@ -62,8 +66,9 @@ open class SplashActivity : AppCompatActivity() {
|
||||
// Load modules
|
||||
//Utils.loadModules(false)
|
||||
// Load repos
|
||||
//if (Networking.checkNetworkStatus(this))
|
||||
//UpdateRepos().exec()
|
||||
if (Networking.checkNetworkStatus(this)) {
|
||||
get<UpdateRepos>().exec().subscribeK()
|
||||
}
|
||||
}
|
||||
|
||||
val intent = Intent(this, ClassMap[MainActivity::class.java])
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.topjohnwu.magisk.App
|
||||
import com.topjohnwu.magisk.Config
|
||||
import com.topjohnwu.magisk.KConfig
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||
import com.topjohnwu.magisk.data.repository.ModuleRepository
|
||||
import com.topjohnwu.magisk.data.repository.SettingRepository
|
||||
import org.koin.android.ext.android.inject
|
||||
@@ -22,6 +23,7 @@ import org.koin.android.ext.android.inject
|
||||
abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
protected val repoDatabase: RepoDatabaseHelper by inject()
|
||||
protected val prefs: SharedPreferences by inject()
|
||||
protected val app: App by inject()
|
||||
protected val settingRepo: SettingRepository by inject()
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.database.Cursor
|
||||
import com.skoumal.teanity.databinding.ComparableRvItem
|
||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||
import com.skoumal.teanity.extensions.doOnSuccessUi
|
||||
import com.skoumal.teanity.extensions.subscribeK
|
||||
import com.skoumal.teanity.util.DiffObservableList
|
||||
import com.skoumal.teanity.util.KObservableField
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||
import com.topjohnwu.magisk.data.repository.ModuleRepository
|
||||
import com.topjohnwu.magisk.model.entity.Repo
|
||||
import com.topjohnwu.magisk.model.entity.recycler.ModuleRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.RepoRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.SectionRvItem
|
||||
import com.topjohnwu.magisk.model.events.InstallModuleEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenChangelogEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenFilePickerEvent
|
||||
import com.topjohnwu.magisk.tasks.UpdateRepos
|
||||
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||
import com.topjohnwu.magisk.utils.toSingle
|
||||
import com.topjohnwu.magisk.utils.update
|
||||
import com.topjohnwu.magisk.utils.zip
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
@@ -26,7 +32,9 @@ import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||
|
||||
class ModuleViewModel(
|
||||
private val resources: Resources,
|
||||
private val moduleRepo: ModuleRepository
|
||||
private val moduleRepo: ModuleRepository,
|
||||
private val repoDatabase: RepoDatabaseHelper,
|
||||
private val repoUpdater: UpdateRepos
|
||||
) : MagiskViewModel() {
|
||||
|
||||
val query = KObservableField("")
|
||||
@@ -54,7 +62,7 @@ class ModuleViewModel(
|
||||
fun repoPressed(item: RepoRvItem) = OpenChangelogEvent(item.item).publish()
|
||||
fun downloadPressed(item: RepoRvItem) = InstallModuleEvent(item.item).publish()
|
||||
|
||||
fun refresh(forceReload: Boolean) {
|
||||
fun refreshNew(forceReload: Boolean) {
|
||||
val updateInstalled = moduleRepo.fetchInstalledModules()
|
||||
.flattenAsFlowable { it }
|
||||
.map { ModuleRvItem(it) }
|
||||
@@ -79,6 +87,24 @@ class ModuleViewModel(
|
||||
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||
}
|
||||
|
||||
fun refresh/*Old*/(force: Boolean) {
|
||||
moduleRepo.fetchInstalledModules()
|
||||
.flattenAsFlowable { it }
|
||||
.map { ModuleRvItem(it) }
|
||||
.toList()
|
||||
.map { it to itemsInstalled.calculateDiff(it) }
|
||||
.doOnSuccessUi { itemsInstalled.update(it.first, it.second) }
|
||||
.flatMap { repoUpdater.exec() }
|
||||
.flatMap { Single.fromCallable { repoDatabase.repoCursor.toList { Repo(it) } } }
|
||||
.flattenAsFlowable { it }
|
||||
.map { RepoRvItem(it) }
|
||||
.toList()
|
||||
.doOnSuccess { allItems.update(it) }
|
||||
.flatMap { queryRaw() }
|
||||
.applyViewModel(this)
|
||||
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||
}
|
||||
|
||||
private fun query() = queryRaw()
|
||||
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||
|
||||
@@ -112,6 +138,12 @@ class ModuleViewModel(
|
||||
groupedItems.getOrElse(MODULE_REMOTE) { listOf() }.withTitle(R.string.not_installed)
|
||||
}
|
||||
|
||||
private fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
|
||||
val out = mutableListOf<Result>()
|
||||
while (moveToNext()) out.add(transformer(this))
|
||||
return out
|
||||
}
|
||||
|
||||
companion object {
|
||||
protected const val MODULE_INSTALLED = 0
|
||||
protected const val MODULE_REMOTE = 1
|
||||
|
||||
@@ -107,12 +107,12 @@ public final class SettingsFragment extends BasePreferenceFragment {
|
||||
DownloadApp.restore();
|
||||
return true;
|
||||
});
|
||||
Preference clear = findPreference("clear");
|
||||
clear.setOnPreferenceClickListener(pref -> {
|
||||
findPreference("clear").setOnPreferenceClickListener(pref -> {
|
||||
getPrefs().edit().remove(Config.Key.ETAG_KEY).apply();
|
||||
getModuleRepo().deleteAllCached().subscribeOn(Schedulers.io()).subscribe(() -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
getRepoDatabase().clearRepo();
|
||||
//getModuleRepo().deleteAllCached().subscribeOn(Schedulers.io()).subscribe(() -> {
|
||||
//}, throwable -> {
|
||||
//});
|
||||
Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user