Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package com.topjohnwu.magisk.dialog

import android.R as AndroidR
import com.topjohnwu.magisk.core.R as CoreR
import com.topjohnwu.magisk.core.model.module.OnlineModule
import com.topjohnwu.magisk.events.DialogBuilder
import com.topjohnwu.magisk.ui.module.ModuleViewModel
import com.topjohnwu.magisk.view.MagiskDialog

class ReinstallConfirmationDialog(
private val viewModel: ModuleViewModel,
private val item: OnlineModule
) : DialogBuilder {
override fun build(dialog: MagiskDialog) {
dialog.apply {
setTitle(CoreR.string.module_reinstall_title)
setMessage(CoreR.string.module_reinstall_message)
setButton(MagiskDialog.ButtonType.POSITIVE) {
text = CoreR.string.module_reinstall
onClick { viewModel.downloadPressed(item) }
}
setButton(MagiskDialog.ButtonType.NEGATIVE) {
text = AndroidR.string.cancel
}
setCancelable(true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

package com.topjohnwu.magisk.ui.module

import android.widget.Button
import androidx.databinding.BindingAdapter
import com.google.android.material.R
import com.google.android.material.color.MaterialColors
import android.content.res.ColorStateList
import com.google.android.material.button.MaterialButton

@BindingAdapter("updateButtonAppearance")
fun setUpdateButtonAppearance(button: MaterialButton, isReady: Boolean) {
button.alpha = if (isReady) 1.0f else 0.38f
val colorAttr = if (isReady) R.attr.colorPrimary else R.attr.colorOnSurface
val color = MaterialColors.getColor(button, colorAttr)
button.setTextColor(color)
button.iconTint = ColorStateList.valueOf(color)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.topjohnwu.magisk.databinding.diffList
import com.topjohnwu.magisk.databinding.set
import com.topjohnwu.magisk.dialog.LocalModuleInstallDialog
import com.topjohnwu.magisk.dialog.OnlineModuleInstallDialog
import com.topjohnwu.magisk.dialog.ReinstallConfirmationDialog
import com.topjohnwu.magisk.events.GetContentEvent
import com.topjohnwu.magisk.events.SnackbarEvent
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -91,6 +92,15 @@ class ModuleViewModel : AsyncLoadViewModel() {
LocalModuleInstallDialog(this, uri, displayName).show()
}

fun onUpdateClicked(item: LocalModuleRvItem) {
val updateInfo = item.item.updateInfo ?: return
if (item.updateReady) {
downloadPressed(updateInfo)
} else {
ReinstallConfirmationDialog(this, updateInfo).show()
}
}

@Parcelize
class UriCallback : ContentResultCallback {
override fun onActivityResult(result: Uri) {
Expand Down
5 changes: 3 additions & 2 deletions app/apk/src/main/res/layout/item_module_md2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:enabled="@{item.updateReady}"
android:enabled="true"
android:focusable="true"
android:onClick="@{() -> viewModel.downloadPressed(item.item.updateInfo)}"
app:updateButtonAppearance="@{item.updateReady}"
android:onClick="@{() -> viewModel.onUpdateClicked(item)}"
android:text="@string/update"
android:textAllCaps="false"
app:icon="@drawable/ic_update_md2"
Expand Down
3 changes: 3 additions & 0 deletions app/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<string name="module_empty">No module installed</string>
<string name="confirm_install">Install module %1$s?</string>
<string name="confirm_install_title">Install confirmation</string>
<string name="module_reinstall_title">Reinstall Module</string>
<string name="module_reinstall_message">This module is already up-to-date. Do you want to redownload and reinstall it?</string>
<string name="module_reinstall">Reinstall</string>

<!--Settings-->
<string name="settings_dark_mode_title">Theme mode</string>
Expand Down
Loading