From 236ad576082af0a28a8f9c1f8ee9578feb0d2666 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 20 Oct 2019 12:40:50 +0200 Subject: [PATCH] Added showing download progress in the home ui --- .../magisk/redesign/home/HomeFragment.kt | 16 ++++++++++-- .../magisk/redesign/home/HomeViewModel.kt | 3 +++ .../res/drawable/progress_determinate.xml | 26 +++++++++++++++++++ app/src/main/res/layout/fragment_home_md2.xml | 17 +++++++++++- app/src/main/res/values/attrs.xml | 4 +++ app/src/main/res/values/styles_md2.xml | 4 +++ app/src/main/res/values/styles_md2_impl.xml | 12 +++++++++ 7 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/progress_determinate.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeFragment.kt index 3bf76be98..674ee0fdf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeFragment.kt @@ -1,10 +1,15 @@ package com.topjohnwu.magisk.redesign.home import android.graphics.Insets +import androidx.lifecycle.Observer import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.FragmentHomeMd2Binding +import com.topjohnwu.magisk.model.download.RemoteFileService +import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.redesign.compat.CompatFragment import org.koin.androidx.viewmodel.ext.android.viewModel +import timber.log.Timber +import kotlin.math.roundToInt class HomeFragment : CompatFragment() { @@ -15,8 +20,15 @@ class HomeFragment : CompatFragment() { override fun onStart() { super.onStart() - + RemoteFileService.progressBroadcast.observe(this, Observer { + when (it.second) { + is DownloadSubject.Magisk.Download, + is DownloadSubject.Magisk.Flash -> viewModel.stateMagiskProgress.value = + it.first.times(100f).roundToInt().also { Timber.i("Progress: $it") } + is DownloadSubject.Manager -> viewModel.stateManagerProgress.value = + it.first.times(100f).roundToInt().also { Timber.i("Progress: $it") } + } + }) activity.title = resources.getString(R.string.section_home) } - } \ No newline at end of file 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 20ca3e50b..e37b0dbed 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 @@ -50,6 +50,9 @@ class HomeViewModel( val stateVersionUpdateMagisk = KObservableField("") val stateVersionUpdateManager = KObservableField("") + val stateMagiskProgress = KObservableField(0) + val stateManagerProgress = KObservableField(0) + val stateHideManagerName = R.string.manager.res().let { if (!statePackageOriginal) { it.replaceRandomWithSpecial(3) diff --git a/app/src/main/res/drawable/progress_determinate.xml b/app/src/main/res/drawable/progress_determinate.xml new file mode 100644 index 000000000..95b275b5d --- /dev/null +++ b/app/src/main/res/drawable/progress_determinate.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index 73a80790b..c9db30fb8 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -148,6 +148,14 @@ + + - + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 4d9d21dce..637df5635 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -44,6 +44,10 @@ + + + + diff --git a/app/src/main/res/values/styles_md2.xml b/app/src/main/res/values/styles_md2.xml index e3a69cd08..0a26fa01b 100644 --- a/app/src/main/res/values/styles_md2.xml +++ b/app/src/main/res/values/styles_md2.xml @@ -53,6 +53,10 @@ @style/WidgetFoundation.Checkbox + @style/WidgetFoundation.ProgressBar + @style/WidgetFoundation.ProgressBar.Indeterminate + + @style/AppearanceFoundation.Display diff --git a/app/src/main/res/values/styles_md2_impl.xml b/app/src/main/res/values/styles_md2_impl.xml index 106ea8370..1ecc8dca5 100644 --- a/app/src/main/res/values/styles_md2_impl.xml +++ b/app/src/main/res/values/styles_md2_impl.xml @@ -131,4 +131,16 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml. ?colorPrimary + + + + \ No newline at end of file