diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 941898c34..35026da39 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -21,8 +21,8 @@ import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.utils.refreshLocale import com.topjohnwu.magisk.core.utils.updateConfig import com.topjohnwu.magisk.extensions.forceGetDeclaredField -import com.topjohnwu.magisk.ui.surequest.SuRequestActivity import com.topjohnwu.magisk.ui.MainActivity +import com.topjohnwu.magisk.ui.surequest.SuRequestActivity fun AssetManager.addAssetPath(path: String) { DynAPK.addAssetPath(this, path) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index e036bd318..b268935a9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -1,12 +1,13 @@ package com.topjohnwu.magisk.core +import androidx.databinding.ObservableField import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork import com.topjohnwu.magisk.DynAPK import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.extensions.get import com.topjohnwu.magisk.extensions.subscribeK +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.utils.CachedValue -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.ShellUtils.fastCmd import java.io.FileInputStream @@ -35,7 +36,7 @@ object Info { @JvmStatic var ramdisk = false val isConnected by lazy { - KObservableField(false).also { field -> + ObservableField(false).also { field -> ReactiveNetwork.observeNetworkConnectivity(get()) .subscribeK { field.value = it.available() diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt index 7c79fef39..625c246c3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt @@ -5,7 +5,6 @@ import android.content.pm.PackageManager import android.util.Base64 import android.util.Base64OutputStream import com.topjohnwu.magisk.core.Config -import com.topjohnwu.magisk.core.utils.PatchAPK.ALPHANUM import com.topjohnwu.signing.CryptoUtils.readCertificate import com.topjohnwu.signing.CryptoUtils.readPrivateKey import org.bouncycastle.asn1.x500.X500Name diff --git a/app/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt b/app/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt index a86e4d267..cb9b0b58c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt @@ -11,7 +11,10 @@ import androidx.core.content.getSystemService import androidx.core.graphics.drawable.toAdaptiveIcon import androidx.core.graphics.drawable.toIcon import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.* +import com.topjohnwu.magisk.core.Const +import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.SplashActivity +import com.topjohnwu.magisk.core.intent import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.extensions.getBitmap diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/DataBinding.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/DataBinding.kt index f671815a1..45352929c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/DataBinding.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/DataBinding.kt @@ -54,4 +54,12 @@ inline fun ObservableField.updateNonNull(block: (T) -> Unit) { inline fun ObservableInt.update(block: (Int) -> Unit) { set(get().apply(block)) -} \ No newline at end of file +} + +inline var ObservableField.value + get() = get() as T + set(value) { + // Use Kotlin comparision (Any.equals) + if (value != get()) + set(value) + } diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt index 0d0ef1839..962ccb402 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt @@ -1,7 +1,6 @@ package com.topjohnwu.magisk.extensions import androidx.databinding.ObservableField -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.internal.UiThreadHandler import io.reactivex.* import io.reactivex.android.schedulers.AndroidSchedulers @@ -76,34 +75,6 @@ fun Completable.subscribeK( ) = applySchedulers() .subscribe(onComplete, onError) - -fun Observable.updateBy( - field: KObservableField -) = doOnNextUi { field.value = it } - .doOnErrorUi { field.value = null } - -fun Single.updateBy( - field: KObservableField -) = doOnSuccessUi { field.value = it } - .doOnErrorUi { field.value = null } - -fun Maybe.updateBy( - field: KObservableField -) = doOnSuccessUi { field.value = it } - .doOnErrorUi { field.value = null } - .doOnComplete { field.value = field.value } - -fun Flowable.updateBy( - field: KObservableField -) = doOnNextUi { field.value = it } - .doOnErrorUi { field.value = null } - -fun Completable.updateBy( - field: KObservableField -) = doOnCompleteUi { field.value = true } - .doOnErrorUi { field.value = false } - - fun Observable.doOnSubscribeUi(body: () -> Unit) = doOnSubscribe { UiThreadHandler.run { body() } } @@ -202,4 +173,4 @@ inline fun zip( t1: Single, t2: Single, crossinline zipper: (T1, T2) -> R -) = Single.zip(t1, t2, BiFunction { rt1, rt2 -> zipper(rt1, rt2) }) \ No newline at end of file +) = Single.zip(t1, t2, BiFunction { rt1, rt2 -> zipper(rt1, rt2) }) diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/XBinding.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/XBinding.kt index cb496a4fa..dec32e851 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/XBinding.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/XBinding.kt @@ -1,10 +1,10 @@ package com.topjohnwu.magisk.extensions +import androidx.databinding.ObservableField import androidx.databinding.ObservableList -import com.topjohnwu.magisk.utils.KObservableField -fun KObservableField.toggle() { +fun ObservableField.toggle() { value = !value } @@ -68,4 +68,4 @@ fun ObservableList.addOnListChangedCallback( itemCount ) } -}) \ No newline at end of file +}) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt index c6be0412e..11ba41d0d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt @@ -2,16 +2,17 @@ package com.topjohnwu.magisk.model.entity.recycler import android.view.View import android.view.ViewGroup +import androidx.databinding.ObservableField import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback import com.topjohnwu.magisk.extensions.startAnimations import com.topjohnwu.magisk.extensions.toggle +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.ProcessHideApp import com.topjohnwu.magisk.model.entity.StatefulProcess import com.topjohnwu.magisk.model.observer.Observer import com.topjohnwu.magisk.ui.hide.HideViewModel -import com.topjohnwu.magisk.utils.KObservableField import kotlin.math.roundToInt class HideItem(val item: ProcessHideApp) : ComparableRvItem() { @@ -21,8 +22,8 @@ class HideItem(val item: ProcessHideApp) : ComparableRvItem() { val packageName = item.info.info.packageName.orEmpty() val items = item.processes.map { HideProcessItem(it) } - val isExpanded = KObservableField(false) - val itemsChecked = KObservableField(0) + val isExpanded = ObservableField(false) + val itemsChecked = ObservableField(0) val itemsCheckedPercent = Observer(itemsChecked) { (itemsChecked.value.toFloat() / items.size * 100).roundToInt() } @@ -68,7 +69,7 @@ class HideProcessItem(val item: StatefulProcess) : ComparableRvItem() { override val layoutRes = R.layout.item_module_download @@ -65,7 +61,7 @@ class SectionTitle( sealed class RepoItem(val item: Repo) : ObservableItem() { override val layoutRes: Int = R.layout.item_repo_md2 - val progress = KObservableField(0) + val progress = ObservableField(0) var isUpdate = false @Bindable get protected set(value) { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt index 11403aa7e..0879e3b69 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt @@ -1,23 +1,24 @@ package com.topjohnwu.magisk.model.entity.recycler import android.graphics.drawable.Drawable +import androidx.databinding.ObservableField import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.StaggeredGridLayoutManager import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.model.MagiskPolicy import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.extensions.toggle +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.PolicyUpdateEvent import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel -import com.topjohnwu.magisk.utils.KObservableField class PolicyItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvItem() { override val layoutRes = R.layout.item_policy_md2 - val isExpanded = KObservableField(false) - val isEnabled = KObservableField(item.policy == MagiskPolicy.ALLOW) - val shouldNotify = KObservableField(item.notification) - val shouldLog = KObservableField(item.logging) + val isExpanded = ObservableField(false) + val isEnabled = ObservableField(item.policy == MagiskPolicy.ALLOW) + val shouldNotify = ObservableField(item.notification) + val shouldLog = ObservableField(item.logging) private val updatedPolicy get() = item.copy( diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 5107ee20a..3b822fffd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewTreeObserver import android.view.WindowManager import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.graphics.Insets import androidx.core.view.forEach import androidx.core.view.setPadding import androidx.core.view.updateLayoutParams @@ -138,10 +137,6 @@ open class MainActivity : BaseUIActivity( return true } - override fun peekSystemWindowInsets(insets: Insets) { - viewModel.insets.value = insets - } - fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) { binding.mainToolbar.startAnimations() when { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseUIActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseUIActivity.kt index c11267f8d..5b3268247 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseUIActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseUIActivity.kt @@ -20,6 +20,7 @@ import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.magisk.extensions.snackbar import com.topjohnwu.magisk.extensions.startAnimations +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.EventHandler import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.model.events.ViewEvent diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt index fac30fe78..05b17d9f0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/BaseViewModel.kt @@ -4,6 +4,7 @@ import android.Manifest import androidx.annotation.CallSuper import androidx.core.graphics.Insets import androidx.databinding.Bindable +import androidx.databinding.ObservableField import androidx.databinding.PropertyChangeRegistry import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -13,10 +14,10 @@ import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.magisk.extensions.doOnSubscribeUi +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.* import com.topjohnwu.magisk.model.navigation.NavigationWrapper import com.topjohnwu.magisk.model.observer.Observer -import com.topjohnwu.magisk.utils.KObservableField import io.reactivex.* import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable @@ -40,7 +41,7 @@ abstract class BaseViewModel( val isConnected = Observer(Info.isConnected) { Info.isConnected.value } val viewEvents: LiveData get() = _viewEvents - val insets = KObservableField(Insets.NONE) + val insets = ObservableField(Insets.NONE) var state: State = initialState set(value) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/CompatDelegate.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/CompatDelegate.kt index 97d1bc769..f6fad1265 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/CompatDelegate.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/CompatDelegate.kt @@ -5,6 +5,7 @@ import androidx.core.graphics.Insets import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.ActivityExecutor import com.topjohnwu.magisk.model.events.ContextExecutor import com.topjohnwu.magisk.model.events.FragmentExecutor diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt index 63717a0a1..13da8c7b3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt @@ -5,11 +5,7 @@ import android.content.Context import android.content.pm.ActivityInfo import android.net.Uri import android.os.Bundle -import android.view.KeyEvent -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem -import android.view.View +import android.view.* import androidx.core.net.toUri import androidx.navigation.NavDeepLinkBuilder import com.topjohnwu.magisk.R diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 097453665..f3d71b2e6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -5,6 +5,7 @@ import android.content.res.Resources import android.net.Uri import android.view.MenuItem import androidx.databinding.ObservableArrayList +import androidx.databinding.ObservableField import androidx.lifecycle.viewModelScope import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config @@ -19,7 +20,6 @@ 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 kotlinx.coroutines.launch import java.io.File @@ -30,8 +30,8 @@ class FlashViewModel( private val resources: Resources ) : BaseViewModel() { - val showReboot = KObservableField(Shell.rootAccess()) - val behaviorText = KObservableField(resources.getString(R.string.flashing)) + val showReboot = ObservableField(Shell.rootAccess()) + val behaviorText = ObservableField(resources.getString(R.string.flashing)) val adapter = BindingAdapter() val items = diffListOf() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt index e92797aec..7aa3fc040 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt @@ -2,11 +2,12 @@ package com.topjohnwu.magisk.ui.hide import android.content.pm.ApplicationInfo import androidx.databinding.Bindable +import androidx.databinding.ObservableField import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.extensions.subscribeK -import com.topjohnwu.magisk.extensions.toggle +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.HideAppInfo import com.topjohnwu.magisk.model.entity.HideTarget import com.topjohnwu.magisk.model.entity.ProcessHideApp @@ -17,7 +18,6 @@ import com.topjohnwu.magisk.ui.base.BaseViewModel import com.topjohnwu.magisk.ui.base.Queryable import com.topjohnwu.magisk.ui.base.filterableListOf import com.topjohnwu.magisk.ui.base.itemBindingOf -import com.topjohnwu.magisk.utils.KObservableField class HideViewModel( private val magiskRepo: MagiskRepository @@ -48,7 +48,7 @@ class HideViewModel( it.bindExtra(BR.viewModel, this) } - val isFilterExpanded = KObservableField(false) + val isFilterExpanded = ObservableField(false) override fun rxRefresh() = magiskRepo.fetchApps() .map { it to magiskRepo.fetchHideTargets().blockingGet() } @@ -101,8 +101,6 @@ class HideViewModel( fun toggleItem(item: HideProcessItem) = magiskRepo .toggleHide(item.isHidden.value, item.item.packageName, item.item.name) - fun toggle(item: KObservableField) = item.toggle() - fun resetQuery() { query = "" } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index cd07fe99b..7fe4a75be 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.ui.home import android.Manifest import android.os.Build +import androidx.databinding.ObservableField import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config @@ -24,7 +25,6 @@ import com.topjohnwu.magisk.model.events.dialog.ManagerInstallDialog import com.topjohnwu.magisk.model.events.dialog.UninstallDialog import com.topjohnwu.magisk.ui.base.BaseViewModel import com.topjohnwu.magisk.ui.base.itemBindingOf -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.Shell import me.tatarka.bindingcollectionadapter2.BR import kotlin.math.roundToInt @@ -37,22 +37,22 @@ class HomeViewModel( private val repoMagisk: MagiskRepository ) : BaseViewModel() { - val isNoticeVisible = KObservableField(Config.safetyNotice) + val isNoticeVisible = ObservableField(Config.safetyNotice) - val stateMagisk = KObservableField(MagiskState.LOADING) - val stateManager = KObservableField(MagiskState.LOADING) + val stateMagisk = ObservableField(MagiskState.LOADING) + val stateManager = ObservableField(MagiskState.LOADING) - val stateMagiskRemoteVersion = KObservableField(R.string.loading.res()) + val stateMagiskRemoteVersion = ObservableField(R.string.loading.res()) val stateMagiskInstalledVersion get() = "${Info.env.magiskVersionString} (${Info.env.magiskVersionCode})" val stateMagiskMode get() = R.string.home_status_normal.res() - val stateManagerRemoteVersion = KObservableField(R.string.loading.res()) + val stateManagerRemoteVersion = ObservableField(R.string.loading.res()) val stateManagerInstalledVersion = Info.stub?.let { "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}) (${it.version})" } ?: "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" val statePackageName = packageName - val stateManagerProgress = KObservableField(0) + val stateManagerProgress = ObservableField(0) val items = listOf(DeveloperItem.Mainline, DeveloperItem.App, DeveloperItem.Project) val itemBinding = itemBindingOf { @@ -116,8 +116,6 @@ class HomeViewModel( .subscribeK { HomeFragmentDirections.actionHomeFragmentToInstallFragment().publish() } .add() - fun toggle(kof: KObservableField) = kof.toggle() - fun hideNotice() { Config.safetyNotice = false isNoticeVisible.value = false diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt index 7da19034e..105f44d41 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.ui.install import android.content.Intent import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.RequestFileEvent import com.topjohnwu.magisk.ui.base.BaseUIFragment import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index a7ba76486..187ecda41 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -4,6 +4,7 @@ import android.net.Uri import android.text.SpannableString import android.text.Spanned import android.widget.Toast +import androidx.databinding.ObservableField import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.DownloadService @@ -12,12 +13,12 @@ import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.data.repository.StringRepository import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback import com.topjohnwu.magisk.extensions.subscribeK +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.internal.Configuration import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.events.RequestFileEvent import com.topjohnwu.magisk.model.events.dialog.SecondSlotWarningDialog import com.topjohnwu.magisk.ui.base.BaseViewModel -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.Shell import io.noties.markwon.Markwon import org.koin.core.get @@ -31,11 +32,11 @@ class InstallViewModel( val isRooted get() = Shell.rootAccess() val isAB get() = Info.isAB - val step = KObservableField(0) - val method = KObservableField(-1) - val progress = KObservableField(0) - val data = KObservableField(null) - val notes = KObservableField(SpannableString("")) + val step = ObservableField(0) + val method = ObservableField(-1) + val progress = ObservableField(0) + val data = ObservableField(null) + val notes = ObservableField(SpannableString("")) init { RemoteFileService.reset() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt index abcbef528..a2b7fb818 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt @@ -1,18 +1,19 @@ package com.topjohnwu.magisk.ui.log +import androidx.databinding.ObservableField import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R 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.extensions.value 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 @@ -40,7 +41,7 @@ class LogViewModel( // --- magisk log - val consoleText = KObservableField(" ") + val consoleText = ObservableField(" ") override fun rxRefresh(): Disposable { val logs = repo.fetchLogs() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 372295ad6..a162ce471 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.ui.module import androidx.databinding.Bindable import androidx.databinding.ObservableArrayList +import androidx.databinding.ObservableField import androidx.lifecycle.viewModelScope import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R @@ -15,6 +16,7 @@ import com.topjohnwu.magisk.data.database.RepoByUpdatedDao import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.extensions.addOnListChangedCallback import com.topjohnwu.magisk.extensions.reboot +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.recycler.* import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent @@ -23,7 +25,6 @@ import com.topjohnwu.magisk.model.events.SnackbarEvent import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.ui.base.* import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener -import com.topjohnwu.magisk.utils.KObservableField import kotlinx.coroutines.* import me.tatarka.bindingcollectionadapter2.collections.MergeObservableList import kotlin.math.roundToInt @@ -63,7 +64,7 @@ class ModuleViewModel( searchLoading.value = true } - val searchLoading = KObservableField(false) + val searchLoading = ObservableField(false) val itemsSearch = diffListOf() val itemSearchBinding = itemBindingOf { it.bindExtra(BR.viewModel, this) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt index 45d88a9aa..7346aeac6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt @@ -1,14 +1,15 @@ package com.topjohnwu.magisk.ui.safetynet import androidx.databinding.Bindable +import androidx.databinding.ObservableField import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.extensions.subscribeK +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.events.SafetyNetResult import com.topjohnwu.magisk.model.events.UpdateSafetyNetEvent import com.topjohnwu.magisk.ui.base.BaseViewModel import com.topjohnwu.magisk.ui.safetynet.SafetyNetState.* -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.magisk.utils.RxBus import org.json.JSONObject @@ -25,10 +26,10 @@ class SafetynetViewModel( field = value notifyStateChanged() } - val safetyNetTitle = KObservableField(R.string.empty) - val ctsState = KObservableField(false) - val basicIntegrityState = KObservableField(false) - val evalType = KObservableField("") + val safetyNetTitle = ObservableField(R.string.empty) + val ctsState = ObservableField(false) + val basicIntegrityState = ObservableField(false) + val evalType = ObservableField("") val isChecking @Bindable get() = currentState == LOADING val isFailed @Bindable get() = currentState == FAILED diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index b6d15a2e3..f5fb47c51 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -13,11 +13,12 @@ import com.topjohnwu.magisk.core.utils.PatchAPK import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.data.database.RepoDao import com.topjohnwu.magisk.extensions.subscribeK +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.internal.Configuration import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.recycler.SettingsItem -import com.topjohnwu.magisk.model.events.RxPermissionEvent import com.topjohnwu.magisk.model.events.RecreateEvent +import com.topjohnwu.magisk.model.events.RxPermissionEvent import com.topjohnwu.magisk.model.events.dialog.BiometricDialog import com.topjohnwu.magisk.ui.base.BaseViewModel import com.topjohnwu.magisk.ui.base.adapterOf diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index 47317892c..9e73e3bdb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -6,6 +6,7 @@ import android.content.pm.PackageManager import android.content.res.Resources import android.graphics.drawable.Drawable import android.os.CountDownTimer +import androidx.databinding.ObservableField import androidx.lifecycle.viewModelScope import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config @@ -14,10 +15,10 @@ import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.ALLOW import com.topjohnwu.magisk.core.model.MagiskPolicy.Companion.DENY import com.topjohnwu.magisk.core.su.SuRequestHandler import com.topjohnwu.magisk.core.utils.BiometricHelper +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.model.entity.recycler.SpinnerRvItem import com.topjohnwu.magisk.model.events.DieEvent import com.topjohnwu.magisk.ui.base.BaseViewModel -import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.internal.UiThreadHandler import kotlinx.coroutines.launch import me.tatarka.bindingcollectionadapter2.BindingListViewAdapter @@ -31,16 +32,16 @@ class SuRequestViewModel( private val res: Resources ) : BaseViewModel() { - val icon = KObservableField(null) - val title = KObservableField("") - val packageName = KObservableField("") + val icon = ObservableField(null) + val title = ObservableField("") + val packageName = ObservableField("") - val denyText = KObservableField(res.getString(R.string.deny)) - val warningText = KObservableField(res.getString(R.string.su_warning)) + val denyText = ObservableField(res.getString(R.string.deny)) + val warningText = ObservableField(res.getString(R.string.su_warning)) - val selectedItemPosition = KObservableField(0) + val selectedItemPosition = ObservableField(0) - val grantEnabled = KObservableField(false) + val grantEnabled = ObservableField(false) private val items = res.getStringArray(R.array.allow_timeout).map { SpinnerRvItem(it) } val adapter = BindingListViewAdapter(1).apply { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/KObservableField.kt b/app/src/main/java/com/topjohnwu/magisk/utils/KObservableField.kt deleted file mode 100644 index b9ae8f251..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/utils/KObservableField.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.topjohnwu.magisk.utils - -import androidx.databinding.Observable -import androidx.databinding.ObservableField -import com.topjohnwu.magisk.model.observer.Observer -import java.io.Serializable - -/** - * Kotlin version of [ObservableField]. - * You can define if wrapped type is Nullable or not. - * You can use kotlin get/set syntax for value - * - * ## Notes - * This stays final for fuck's sake. Too many things depend on it, so you just cannot go around and - * change it randomly. Even though you think you're improving the design, you might be fucking this - * up in unimaginable ways. So DON'T TOUCH THIS. - * - * In order to have value-less observer you need - you guessed it - **a fucking [Observer]**! - */ -class KObservableField : ObservableField, Serializable { - - var value: T - set(value) { - if (field != value) { - field = value - notifyChange() - } - } - - constructor(init: T) { - value = init - } - - constructor(init: T, vararg dependencies: Observable) : super(*dependencies) { - value = init - } - - @Deprecated( - message = "Needed for data binding, use KObservableField.value syntax from code", - replaceWith = ReplaceWith("value") - ) - override fun get(): T { - return value - } - - @Deprecated( - message = "Needed for data binding, use KObservableField.value = ... syntax from code", - replaceWith = ReplaceWith("value = newValue") - ) - override fun set(newValue: T) { - value = newValue - } - - override fun toString(): String { - return "KObservableField(value=$value)" - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt index 5f0ad783d..faae33fd3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/MagiskDialog.kt @@ -15,6 +15,7 @@ import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatDialog import androidx.core.view.ViewCompat import androidx.core.view.updatePadding +import androidx.databinding.ObservableField import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -22,8 +23,8 @@ import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.databinding.DialogMagiskBaseBinding +import com.topjohnwu.magisk.extensions.value import com.topjohnwu.magisk.ui.base.itemBindingOf -import com.topjohnwu.magisk.utils.KObservableField import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapters import me.tatarka.bindingcollectionadapter2.ItemBinding @@ -71,10 +72,10 @@ class MagiskDialog @JvmOverloads constructor( } inner class Data { - val icon = KObservableField(0) - val iconRaw = KObservableField(null) - val title = KObservableField("") - val message = KObservableField("") + val icon = ObservableField(0) + val iconRaw = ObservableField(null) + val title = ObservableField("") + val message = ObservableField("") val buttonPositive = Button() val buttonNeutral = Button() @@ -87,9 +88,9 @@ class MagiskDialog @JvmOverloads constructor( } inner class Button { - val icon = KObservableField(0) - val title = KObservableField("") - val isEnabled = KObservableField(true) + val icon = ObservableField(0) + val title = ObservableField("") + val isEnabled = ObservableField(true) var onClickAction: OnDialogButtonClickListener = {} var preventDismiss = false