Skip to content

Commit 3cdabf9

Browse files
committed
Option to redownload module
1 parent 62e29fe commit 3cdabf9

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
package com.topjohnwu.magisk.dialog
3+
4+
import android.R as AndroidR
5+
import com.topjohnwu.magisk.core.R as CoreR
6+
import com.topjohnwu.magisk.core.model.module.OnlineModule
7+
import com.topjohnwu.magisk.events.DialogBuilder
8+
import com.topjohnwu.magisk.ui.module.ModuleViewModel
9+
import com.topjohnwu.magisk.view.MagiskDialog
10+
11+
class ReinstallConfirmationDialog(
12+
private val viewModel: ModuleViewModel,
13+
private val item: OnlineModule
14+
) : DialogBuilder {
15+
override fun build(dialog: MagiskDialog) {
16+
dialog.apply {
17+
setTitle(CoreR.string.module_reinstall_title)
18+
setMessage(CoreR.string.module_reinstall_message)
19+
setButton(MagiskDialog.ButtonType.POSITIVE) {
20+
text = CoreR.string.module_reinstall
21+
onClick { viewModel.downloadPressed(item) }
22+
}
23+
setButton(MagiskDialog.ButtonType.NEGATIVE) {
24+
text = AndroidR.string.cancel
25+
}
26+
setCancelable(true)
27+
}
28+
}
29+
}

app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.topjohnwu.magisk.databinding.diffList
1919
import com.topjohnwu.magisk.databinding.set
2020
import com.topjohnwu.magisk.dialog.LocalModuleInstallDialog
2121
import com.topjohnwu.magisk.dialog.OnlineModuleInstallDialog
22+
import com.topjohnwu.magisk.dialog.ReinstallConfirmationDialog
2223
import com.topjohnwu.magisk.events.GetContentEvent
2324
import com.topjohnwu.magisk.events.SnackbarEvent
2425
import kotlinx.coroutines.Dispatchers
@@ -91,6 +92,15 @@ class ModuleViewModel : AsyncLoadViewModel() {
9192
LocalModuleInstallDialog(this, uri, displayName).show()
9293
}
9394

95+
fun onUpdateClicked(item: LocalModuleRvItem) {
96+
val updateInfo = item.item.updateInfo ?: return
97+
if (item.updateReady) {
98+
downloadPressed(updateInfo)
99+
} else {
100+
ReinstallConfirmationDialog(this, updateInfo).show()
101+
}
102+
}
103+
94104
@Parcelize
95105
class UriCallback : ContentResultCallback {
96106
override fun onActivityResult(result: Uri) {

app/apk/src/main/res/layout/item_module_md2.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@
132132

133133
<Button
134134
android:id="@+id/module_update"
135-
style="@style/WidgetFoundation.Button.Text"
135+
style="@style/Widget.Foundation.Button.Text"
136136
goneUnless="@{item.showUpdate}"
137137
android:layout_width="wrap_content"
138138
android:layout_height="wrap_content"
139139
android:clickable="true"
140-
android:enabled="@{item.updateReady}"
140+
android:enabled="true"
141141
android:focusable="true"
142-
android:onClick="@{() -> viewModel.downloadPressed(item.item.updateInfo)}"
142+
android:alpha="@{item.updateReady ? 1.0f : 0.38f}"
143+
android:onClick="@{() -> viewModel.onUpdateClicked(item)}"
143144
android:text="@string/update"
144145
android:textAllCaps="false"
145146
app:icon="@drawable/ic_update_md2"

app/core/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
<string name="module_empty">No module installed</string>
117117
<string name="confirm_install">Install module %1$s?</string>
118118
<string name="confirm_install_title">Install confirmation</string>
119+
<string name="module_reinstall_title">Reinstall Module</string>
120+
<string name="module_reinstall_message">This module is already up-to-date. Do you want to redownload and reinstall it?</string>
121+
<string name="module_reinstall">Reinstall</string>
119122

120123
<!--Settings-->
121124
<string name="settings_dark_mode_title">Theme mode</string>

0 commit comments

Comments
 (0)