Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 1969e05

Browse files
committed
Improve full clear button, don't require reboot for just installed modules. (Fix #51)
1 parent 781020e commit 1969e05

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

app/src/main/java/com/fox2code/mmm/ActionButtonType.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,23 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
122122
public void update(ImageButton button, ModuleHolder moduleHolder) {
123123
int icon = moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING) ?
124124
R.drawable.ic_baseline_delete_outline_24 : (
125-
// We can't trust active flag on first boot
126-
MainApplication.isFirstBoot() ||
127-
moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_ACTIVE)) ?
125+
!moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING) ||
126+
moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) ?
128127
R.drawable.ic_baseline_delete_24 :
129128
R.drawable.ic_baseline_delete_forever_24;
130129
button.setImageResource(icon);
131130
}
132131

133132
@Override
134133
public void doAction(ImageButton button, ModuleHolder moduleHolder) {
134+
if (!moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE |
135+
ModuleInfo.FLAG_MODULE_UNINSTALLING) &&
136+
moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING)) {
137+
doActionLong(button, moduleHolder);
138+
return;
139+
}
135140
if (!ModuleManager.getINSTANCE().setUninstallState(moduleHolder.moduleInfo,
136-
!moduleHolder.moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING))) {
141+
!moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING))) {
137142
Log.e("ActionButtonType", "Failed to switch uninstalled state!");
138143
}
139144
update(button, moduleHolder);
@@ -142,8 +147,7 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
142147
@Override
143148
public boolean doActionLong(ImageButton button, ModuleHolder moduleHolder) {
144149
// We can't trust active flag on first boot
145-
if (moduleHolder.moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_ACTIVE)
146-
|| MainApplication.isFirstBoot()) return false;
150+
if (moduleHolder.moduleInfo.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) return false;
147151
new AlertDialog.Builder(button.getContext()).setTitle(R.string.master_delete)
148152
.setPositiveButton(R.string.master_delete_yes, (v, i) -> {
149153
if (!ModuleManager.getINSTANCE().masterClear(moduleHolder.moduleInfo)) {

app/src/main/java/com/fox2code/mmm/manager/ModuleInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class ModuleInfo {
1111
public static final int FLAG_MODULE_ACTIVE = 0x04;
1212
public static final int FLAG_MODULE_UNINSTALLING = 0x08;
1313
public static final int FLAG_MODULE_UPDATING_ONLY = 0x10;
14+
public static final int FLAG_MODULE_MAYBE_ACTIVE = 0x20;
15+
16+
public static final int FLAGS_MODULE_ACTIVE =
17+
FLAG_MODULE_ACTIVE | FLAG_MODULE_MAYBE_ACTIVE;
1418

1519
public static final int FLAG_METADATA_INVALID = 0x80000000;
1620

app/src/main/java/com/fox2code/mmm/manager/ModuleManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public final void runAfterScan(Runnable runnable) {
7272
}
7373

7474
private void scanInternal() {
75+
boolean firstBoot = MainApplication.isFirstBoot();
7576
boolean firstScan = this.bootPrefs.getBoolean("mm_first_scan", true);
7677
SharedPreferences.Editor editor = firstScan ? this.bootPrefs.edit() : null;
7778
for (ModuleInfo v : this.moduleInfos.values()) {
@@ -102,11 +103,16 @@ private void scanInternal() {
102103
"/data/adb/modules/" + module + "/disable").exists();
103104
if (disabled) {
104105
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_DISABLED;
106+
if (firstBoot && firstScan) {
107+
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
108+
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE;
109+
}
105110
} else {
106111
if (firstScan) {
107112
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
108113
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
109-
} else if (bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false)) {
114+
} else if (!moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE) &&
115+
bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false)) {
110116
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
111117
}
112118
}
@@ -221,7 +227,7 @@ public boolean setUninstallState(ModuleInfo moduleInfo, boolean checked) {
221227
}
222228

223229
public boolean masterClear(ModuleInfo moduleInfo) {
224-
if (moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_ACTIVE)) return false;
230+
if (moduleInfo.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) return false;
225231
String escapedId = moduleInfo.id.replace("\\", "\\\\")
226232
.replace("\"", "\\\"").replace(" ", "\\ ");
227233
try { // Check for module that declare having file outside their own folder.

app/src/main/res/drawable/ic_baseline_delete_forever_24.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:height="24dp"
44
android:viewportWidth="24"
55
android:viewportHeight="24"
6-
android:tint="?attr/colorControlNormal">
6+
android:tint="?attr/colorError">
77
<path
88
android:fillColor="@android:color/white"
99
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8.46,11.88l1.41,-1.41L12,12.59l2.12,-2.12 1.41,1.41L13.41,14l2.12,2.12 -1.41,1.41L12,15.41l-2.12,2.12 -1.41,-1.41L10.59,14l-2.13,-2.12zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z"/>

0 commit comments

Comments
 (0)