From 3cc5cb31239c615842a80f93f68bd62e8f18bc9f Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 25 Oct 2019 19:13:54 +0200 Subject: [PATCH] Updated the install flow Now the binary is downloaded after user selects a method. It also shows download progress as the file's being downloaded --- .../com/topjohnwu/magisk/di/RedesignModule.kt | 2 +- .../model/download/RemoteFileService.kt | 4 + .../magisk/model/navigation/Navigation.kt | 2 +- .../magisk/redesign/compat/CompatViewModel.kt | 4 +- .../magisk/redesign/home/HomeViewModel.kt | 2 +- .../install/InstallFragment.kt | 2 +- .../install/InstallViewModel.kt | 22 +- .../res/drawable/avd_circle_from_filled.xml | 70 ++++ .../res/drawable/avd_circle_to_filled.xml | 71 ++++ app/src/main/res/drawable/ic_forth_md2.xml | 17 + .../res/drawable/ic_radio_check_button.xml | 55 +++ .../main/res/layout/fragment_install_md2.xml | 367 +++++++++++------- app/src/main/res/values/styles_md2_impl.xml | 2 + 13 files changed, 461 insertions(+), 159 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/{ui => redesign}/install/InstallFragment.kt (95%) rename app/src/main/java/com/topjohnwu/magisk/{ui => redesign}/install/InstallViewModel.kt (67%) create mode 100644 app/src/main/res/drawable/avd_circle_from_filled.xml create mode 100644 app/src/main/res/drawable/avd_circle_to_filled.xml create mode 100644 app/src/main/res/drawable/ic_forth_md2.xml create mode 100644 app/src/main/res/drawable/ic_radio_check_button.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt index 4edd025e0..b4f3bac25 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/RedesignModule.kt @@ -4,6 +4,7 @@ import com.topjohnwu.magisk.redesign.MainViewModel import com.topjohnwu.magisk.redesign.flash.FlashViewModel import com.topjohnwu.magisk.redesign.hide.HideViewModel import com.topjohnwu.magisk.redesign.home.HomeViewModel +import com.topjohnwu.magisk.redesign.install.InstallViewModel import com.topjohnwu.magisk.redesign.log.LogViewModel import com.topjohnwu.magisk.redesign.module.ModuleViewModel import com.topjohnwu.magisk.redesign.request.RequestViewModel @@ -11,7 +12,6 @@ import com.topjohnwu.magisk.redesign.safetynet.SafetynetViewModel import com.topjohnwu.magisk.redesign.settings.SettingsViewModel import com.topjohnwu.magisk.redesign.superuser.SuperuserViewModel import com.topjohnwu.magisk.redesign.theme.ThemeViewModel -import com.topjohnwu.magisk.ui.install.InstallViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt index 402266d63..53e5d0ed4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt @@ -128,6 +128,10 @@ abstract class RemoteFileService : NotificationService() { fun send(progress: Float, subject: DownloadSubject) { internalProgressBroadcast.postValue(progress to subject) } + + fun reset() { + internalProgressBroadcast.value = null + } } } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt index 5099a6b7f..bf7b3c0ed 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/navigation/Navigation.kt @@ -6,11 +6,11 @@ import android.os.Build import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Const +import com.topjohnwu.magisk.redesign.install.InstallFragment import com.topjohnwu.magisk.redesign.safetynet.SafetynetFragment import com.topjohnwu.magisk.ui.MainActivity import com.topjohnwu.magisk.ui.hide.MagiskHideFragment import com.topjohnwu.magisk.ui.home.HomeFragment -import com.topjohnwu.magisk.ui.install.InstallFragment import com.topjohnwu.magisk.ui.log.LogFragment import com.topjohnwu.magisk.ui.module.ModulesFragment import com.topjohnwu.magisk.ui.module.ReposFragment diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt index 8721cca2a..ecdd19044 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt @@ -8,7 +8,9 @@ import com.topjohnwu.magisk.utils.KObservableField import io.reactivex.disposables.Disposable import org.koin.core.KoinComponent -abstract class CompatViewModel : BaseViewModel(), KoinComponent { +abstract class CompatViewModel( + initialState: State = State.LOADING +) : BaseViewModel(initialState), KoinComponent { val insets = KObservableField(Insets.NONE) diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt index b8cfc0935..71c0c7e7d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt @@ -81,7 +81,7 @@ class HomeViewModel( init { RemoteFileService.progressBroadcast.observeForever { - when (it.second) { + when (it?.second) { is Magisk.Download, is Magisk.Flash -> stateMagiskProgress.value = it.first.times(100f).roundToInt() is Manager -> stateManagerProgress.value = it.first.times(100f).roundToInt() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallFragment.kt similarity index 95% rename from app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt rename to app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallFragment.kt index 9690f3282..feff14bf4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallFragment.kt @@ -1,4 +1,4 @@ -package com.topjohnwu.magisk.ui.install +package com.topjohnwu.magisk.redesign.install import android.content.Intent import android.graphics.Insets diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallViewModel.kt similarity index 67% rename from app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt rename to app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallViewModel.kt index 9fc061e67..25150c36e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/install/InstallViewModel.kt @@ -1,9 +1,10 @@ -package com.topjohnwu.magisk.ui.install +package com.topjohnwu.magisk.redesign.install import android.net.Uri import com.topjohnwu.magisk.R import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback import com.topjohnwu.magisk.model.download.DownloadService +import com.topjohnwu.magisk.model.download.RemoteFileService import com.topjohnwu.magisk.model.entity.internal.Configuration import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.events.RequestFileEvent @@ -12,8 +13,9 @@ import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.ShellUtils import org.koin.core.get +import kotlin.math.roundToInt -class InstallViewModel : CompatViewModel() { +class InstallViewModel : CompatViewModel(State.LOADED) { val isRooted = Shell.rootAccess() val isAB = isABDevice() @@ -21,9 +23,23 @@ class InstallViewModel : CompatViewModel() { val step = KObservableField(0) val method = KObservableField(-1) + val progress = KObservableField(0) + var data = KObservableField(null) init { + RemoteFileService.reset() + RemoteFileService.progressBroadcast.observeForever { + val (progress, subject) = it ?: return@observeForever + if (subject !is DownloadSubject.Magisk) { + return@observeForever + } + this.progress.value = progress.times(100).roundToInt() + if (this.progress.value >= 100) { + // this might cause issues if the flash activity launches on top of this sooner + back() + } + } method.addOnPropertyChangedCallback { if (method.value == R.id.method_patch) { RequestFileEvent().publish() @@ -37,7 +53,7 @@ class InstallViewModel : CompatViewModel() { fun install() = DownloadService(get()) { subject = DownloadSubject.Magisk(resolveConfiguration()) - } + }.also { state = State.LOADING } // --- diff --git a/app/src/main/res/drawable/avd_circle_from_filled.xml b/app/src/main/res/drawable/avd_circle_from_filled.xml new file mode 100644 index 000000000..7038cbba7 --- /dev/null +++ b/app/src/main/res/drawable/avd_circle_from_filled.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/avd_circle_to_filled.xml b/app/src/main/res/drawable/avd_circle_to_filled.xml new file mode 100644 index 000000000..5c248fbce --- /dev/null +++ b/app/src/main/res/drawable/avd_circle_to_filled.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_forth_md2.xml b/app/src/main/res/drawable/ic_forth_md2.xml new file mode 100644 index 000000000..261bcc7b3 --- /dev/null +++ b/app/src/main/res/drawable/ic_forth_md2.xml @@ -0,0 +1,17 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_radio_check_button.xml b/app/src/main/res/drawable/ic_radio_check_button.xml new file mode 100644 index 000000000..9c6c7ef92 --- /dev/null +++ b/app/src/main/res/drawable/ic_radio_check_button.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_install_md2.xml b/app/src/main/res/layout/fragment_install_md2.xml index 0d279e7c4..34df5d9ad 100644 --- a/app/src/main/res/layout/fragment_install_md2.xml +++ b/app/src/main/res/layout/fragment_install_md2.xml @@ -7,7 +7,7 @@ + type="com.topjohnwu.magisk.redesign.install.InstallViewModel" /> @@ -20,194 +20,259 @@ android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l2}" tools:paddingTop="24dp"> - + android:layout_height="wrap_content"> - + android:layout_height="match_parent" + android:clipToPadding="false" + android:orientation="vertical" + android:paddingTop="@dimen/l1"> - + android:layout_marginStart="@dimen/l1" + android:layout_marginEnd="@dimen/l1" + app:cardCornerRadius="@dimen/l1" + app:cardElevation="@{viewModel.step != 0 ? 0f : @dimen/l_25}"> - + android:orientation="vertical"> - - - + android:minHeight="?listPreferredItemHeightSmall"> - + + + + + + + + - - - - - - + android:layout_height="wrap_content"> - + - + - + - + - + android:layout_marginStart="@dimen/l1" + android:layout_marginTop="@dimen/l1" + android:layout_marginEnd="@dimen/l1" + app:cardCornerRadius="@dimen/l1" + app:cardElevation="@{viewModel.step != 1 ? 0f : @dimen/l_25}"> - + android:orientation="vertical"> - - - + android:minHeight="?listPreferredItemHeightSmall"> - + + + + + + + + - - - - - - + android:layout_marginStart="@dimen/l1" + android:layout_marginTop="@dimen/l_50" + android:layout_marginEnd="@dimen/l1" + android:layout_marginBottom="@dimen/l_50" + android:checkedButton="@={viewModel.method}"> - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/styles_md2_impl.xml b/app/src/main/res/values/styles_md2_impl.xml index 85dca6b1f..fc3377237 100644 --- a/app/src/main/res/values/styles_md2_impl.xml +++ b/app/src/main/res/values/styles_md2_impl.xml @@ -136,6 +136,7 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml. @dimen/l1 @dimen/l1 ?colorPrimary + @drawable/ic_radio_check_button