Added showing download progress in the home ui

This commit is contained in:
Viktor De Pasquale 2019-10-20 12:40:50 +02:00
parent 6d03798314
commit 236ad57608
7 changed files with 79 additions and 3 deletions

View File

@ -1,10 +1,15 @@
package com.topjohnwu.magisk.redesign.home package com.topjohnwu.magisk.redesign.home
import android.graphics.Insets import android.graphics.Insets
import androidx.lifecycle.Observer
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentHomeMd2Binding 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 com.topjohnwu.magisk.redesign.compat.CompatFragment
import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.androidx.viewmodel.ext.android.viewModel
import timber.log.Timber
import kotlin.math.roundToInt
class HomeFragment : CompatFragment<HomeViewModel, FragmentHomeMd2Binding>() { class HomeFragment : CompatFragment<HomeViewModel, FragmentHomeMd2Binding>() {
@ -15,8 +20,15 @@ class HomeFragment : CompatFragment<HomeViewModel, FragmentHomeMd2Binding>() {
override fun onStart() { override fun onStart() {
super.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) activity.title = resources.getString(R.string.section_home)
} }
} }

View File

@ -50,6 +50,9 @@ class HomeViewModel(
val stateVersionUpdateMagisk = KObservableField("") val stateVersionUpdateMagisk = KObservableField("")
val stateVersionUpdateManager = KObservableField("") val stateVersionUpdateManager = KObservableField("")
val stateMagiskProgress = KObservableField(0)
val stateManagerProgress = KObservableField(0)
val stateHideManagerName = R.string.manager.res().let { val stateHideManagerName = R.string.manager.res().let {
if (!statePackageOriginal) { if (!statePackageOriginal) {
it.replaceRandomWithSpecial(3) it.replaceRandomWithSpecial(3)

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="?colorSecondary" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="?colorPrimary" />
</shape>
</clip>
</item>
</layer-list>

View File

@ -148,6 +148,14 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<ProgressBar
style="?styleProgressDeterminate"
gone="@{viewModel.stateMagiskProgress == 0 || viewModel.stateMagiskProgress == 100}"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:max="100"
android:progress="@{viewModel.stateMagiskProgress}" />
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
@ -252,8 +260,15 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> <ProgressBar
style="?styleProgressDeterminate"
gone="@{viewModel.stateManagerProgress == 0 || viewModel.stateManagerProgress == 100}"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:max="100"
android:progress="@{viewModel.stateManagerProgress}" />
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -44,6 +44,10 @@
<!--Checkbox--> <!--Checkbox-->
<attr name="styleCheckboxNormal" format="reference" /> <attr name="styleCheckboxNormal" format="reference" />
<!--Progress-->
<attr name="styleProgressDeterminate" format="reference" />
<attr name="styleProgressIndeterminate" format="reference" />
<!--endregion--> <!--endregion-->
<!--region Texts--> <!--region Texts-->

View File

@ -53,6 +53,10 @@
<item name="styleCheckboxNormal">@style/WidgetFoundation.Checkbox</item> <item name="styleCheckboxNormal">@style/WidgetFoundation.Checkbox</item>
<item name="styleProgressDeterminate">@style/WidgetFoundation.ProgressBar</item>
<item name="styleProgressIndeterminate">@style/WidgetFoundation.ProgressBar.Indeterminate
</item>
<!--///--> <!--///-->
<item name="appearanceTextDisplayNormal">@style/AppearanceFoundation.Display</item> <item name="appearanceTextDisplayNormal">@style/AppearanceFoundation.Display</item>

View File

@ -131,4 +131,16 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml.
<item name="tint">?colorPrimary</item> <item name="tint">?colorPrimary</item>
</style> </style>
<style name="WidgetFoundation.ProgressBar" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:indeterminate">false</item>
<item name="android:layout_height">4dp</item>
<item name="android:progressDrawable">@drawable/progress_determinate</item>
</style>
<style name="WidgetFoundation.ProgressBar.Indeterminate" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:indeterminate">true</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">100dp</item>
</style>
</resources> </resources>