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

Commit 5e2535e

Browse files
Merge pull request #107 from DerGoogler/f2c-merge-patch
Fix darkmode and make improvments
2 parents a825251 + ef616ea commit 5e2535e

19 files changed

+204
-112
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dependencies {
9797
// Utils
9898
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
9999
implementation 'com.squareup.okhttp3:okhttp-brotli:4.9.3'
100-
implementation 'com.github.topjohnwu.libsu:io:4.0.3'
100+
implementation 'com.github.topjohnwu.libsu:io:5.0.0'
101101

102102
// Markdown
103103
implementation "io.noties.markwon:core:4.6.2"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fox2code.mmm.manager.LocalModuleInfo;
1919
import com.fox2code.mmm.manager.ModuleInfo;
2020
import com.fox2code.mmm.manager.ModuleManager;
21+
import com.fox2code.mmm.module.ModuleHolder;
2122
import com.fox2code.mmm.utils.IntentHelper;
2223
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
2324

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020
import android.view.WindowManager;
2121
import android.view.inputmethod.EditorInfo;
2222
import android.widget.TextView;
23+
import android.widget.Toast;
2324

2425
import com.fox2code.mmm.compat.CompatActivity;
2526
import com.fox2code.mmm.compat.CompatDisplay;
2627
import com.fox2code.mmm.installer.InstallerInitializer;
2728
import com.fox2code.mmm.manager.LocalModuleInfo;
2829
import com.fox2code.mmm.manager.ModuleManager;
30+
import com.fox2code.mmm.module.ModuleViewAdapter;
31+
import com.fox2code.mmm.module.ModuleViewListBuilder;
2932
import com.fox2code.mmm.repo.RepoManager;
3033
import com.fox2code.mmm.settings.SettingsActivity;
3134
import com.fox2code.mmm.utils.Http;
3235
import com.fox2code.mmm.utils.IntentHelper;
36+
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
3337
import com.google.android.material.progressindicator.LinearProgressIndicator;
38+
import com.topjohnwu.superuser.Shell;
3439

3540
import eightbitlab.com.blurview.BlurView;
3641
import eightbitlab.com.blurview.RenderScriptBlur;
@@ -133,6 +138,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
133138
this.searchView.setEnabled(false); // Enabled later
134139
this.cardIconifyUpdate();
135140
this.updateScreenInsets(this.getResources().getConfiguration());
141+
136142
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
137143
@Override
138144
public void onPathReceived(String path) {
@@ -378,9 +384,7 @@ public boolean onQueryTextSubmit(final String query) {
378384
this.searchView.clearFocus();
379385
if (this.initMode) return false;
380386
if (this.moduleViewListBuilder.setQueryChange(query)) {
381-
new Thread(() -> {
382-
this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
383-
}, "Query update thread").start();
387+
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
384388
}
385389
return true;
386390
}
@@ -389,9 +393,7 @@ public boolean onQueryTextSubmit(final String query) {
389393
public boolean onQueryTextChange(String query) {
390394
if (this.initMode) return false;
391395
if (this.moduleViewListBuilder.setQueryChange(query)) {
392-
new Thread(() -> {
393-
this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
394-
}, "Query update thread").start();
396+
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
395397
}
396398
return false;
397399
}
@@ -400,9 +402,7 @@ public boolean onQueryTextChange(String query) {
400402
public boolean onClose() {
401403
if (this.initMode) return false;
402404
if (this.moduleViewListBuilder.setQueryChange(null)) {
403-
new Thread(() -> {
404-
this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
405-
}, "Query update thread").start();
405+
new Thread(() -> this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter), "Query update thread").start();
406406
}
407407
return false;
408408
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public static boolean isShowcaseMode() {
9191
return getSharedPreferences().getBoolean("pref_showcase_mode", false);
9292
}
9393

94+
public static boolean shouldPreventReboot() {
95+
return getSharedPreferences().getBoolean("pref_prevent_reboot", false);
96+
}
97+
9498
public static boolean isShowIncompatibleModules() {
9599
return getSharedPreferences().getBoolean("pref_show_incompatible", false);
96100
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public boolean shouldRemove() {
3333
}
3434
},
3535
NO_ROOT(R.string.fail_root_magisk, R.drawable.ic_baseline_numbers_24, v -> {
36-
IntentHelper.openUrl(v.getContext(), "https://github.com/topjohnwu/Magisk");
36+
IntentHelper.openUrl(v.getContext(), "https://github.com/topjohnwu/Magisk/blob/master/docs/install.md");
3737
}) {
3838
@Override
3939
public boolean shouldRemove() {
4040
return InstallerInitializer.peekMagiskPath() != null;
4141
}
4242
},
4343
MAGISK_OUTDATED(R.string.magisk_outdated, R.drawable.ic_baseline_update_24, v -> {
44-
IntentHelper.openUrl(v.getContext(), "https://github.com/topjohnwu/Magisk");
44+
IntentHelper.openUrl(v.getContext(), "https://github.com/topjohnwu/Magisk/releases");
4545
}) {
4646
@Override
4747
public boolean shouldRemove() {
@@ -120,7 +120,7 @@ public boolean shouldRemove() {
120120
InstallerInitializer.peekMagiskPath() == null);
121121
}
122122
});
123-
}, true) {
123+
}, false) {
124124
@Override
125125
public boolean shouldRemove() {
126126
return !BuildConfig.DEBUG &&

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.fox2code.mmm.utils.Http;
3030
import com.fox2code.mmm.utils.IntentHelper;
3131
import com.fox2code.mmm.utils.PropUtils;
32+
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
33+
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
3234
import com.google.android.material.progressindicator.LinearProgressIndicator;
3335
import com.topjohnwu.superuser.CallbackList;
3436
import com.topjohnwu.superuser.Shell;
@@ -50,6 +52,7 @@
5052
public class InstallerActivity extends CompatActivity {
5153
private static final String TAG = "InstallerActivity";
5254
public LinearProgressIndicator progressIndicator;
55+
public ExtendedFloatingActionButton rebootFloatingButton;
5356
public InstallerTerminal installerTerminal;
5457
private File moduleCache;
5558
private File toDelete;
@@ -113,6 +116,7 @@ protected void onCreate(Bundle savedInstanceState) {
113116
View horizontalScroller = findViewById(R.id.install_horizontal_scroller);
114117
RecyclerView installTerminal;
115118
this.progressIndicator = findViewById(R.id.progress_bar);
119+
this.rebootFloatingButton = findViewById(R.id.install_terminal_reboot_fab);
116120
this.installerTerminal = new InstallerTerminal(
117121
installTerminal = findViewById(R.id.install_terminal), foreground);
118122
(horizontalScroller != null ? horizontalScroller : installTerminal)
@@ -225,7 +229,7 @@ protected void onCreate(Bundle savedInstanceState) {
225229
}
226230

227231

228-
private void doInstall(File file,boolean noExtensions,boolean rootless) {
232+
private void doInstall(File file, boolean noExtensions, boolean rootless) {
229233
if (this.canceled) return;
230234
UiThreadHandler.runAndWait(() -> {
231235
this.setOnBackPressedCallback(DISABLE_BACK_BUTTON);
@@ -310,8 +314,9 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
310314
ZipEntry moduleProp = zipFile.getEntry("module.prop");
311315
magiskModule = moduleProp != null;
312316
moduleId = PropUtils.readModuleId(zipFile
313-
.getInputStream(moduleProp));
314-
} catch (IOException ignored) {}
317+
.getInputStream(zipFile.getEntry("module.prop")));
318+
} catch (IOException ignored) {
319+
}
315320
int compatFlags = AppUpdateManager.getFlagsForModule(moduleId);
316321
if ((compatFlags & AppUpdateManager.FLAG_COMPAT_NEED_32BIT) != 0)
317322
needs32bit = true;
@@ -396,7 +401,8 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
396401
}
397402
boolean success = installJob.exec().isSuccess();
398403
// Wait one UI cycle before disabling controller or processing results
399-
UiThreadHandler.runAndWait(() -> {}); // to avoid race conditions
404+
UiThreadHandler.runAndWait(() -> {
405+
}); // to avoid race conditions
400406
installerController.disable();
401407
String message = "- Install successful";
402408
if (!success) {
@@ -420,7 +426,7 @@ public static class InstallerController extends CallbackList<String> {
420426
private String supportLink = "";
421427

422428
private InstallerController(LinearProgressIndicator progressIndicator,
423-
InstallerTerminal terminal,File moduleFile,
429+
InstallerTerminal terminal, File moduleFile,
424430
boolean noExtension) {
425431
this.progressIndicator = progressIndicator;
426432
this.terminal = terminal;
@@ -503,7 +509,8 @@ private void processCommand(String rawCommand) {
503509
try {
504510
this.progressIndicator.setProgressCompat(
505511
Short.parseShort(arg), true);
506-
} catch (Exception ignored) {}
512+
} catch (Exception ignored) {
513+
}
507514
break;
508515
case "hideLoading":
509516
this.progressIndicator.setVisibility(View.GONE);
@@ -596,7 +603,7 @@ private File extractInstallScript(String script) {
596603
}
597604

598605
@SuppressWarnings("SameParameterValue")
599-
private void setInstallStateFinished(boolean success, String message,String optionalLink) {
606+
private void setInstallStateFinished(boolean success, String message, String optionalLink) {
600607
if (success && toDelete != null && !toDelete.delete()) {
601608
SuFile suFile = new SuFile(toDelete.getAbsolutePath());
602609
if (suFile.exists() && !suFile.delete())
@@ -608,14 +615,37 @@ private void setInstallStateFinished(boolean success, String message,String opti
608615
this.setOnBackPressedCallback(null);
609616
this.setDisplayHomeAsUpEnabled(true);
610617
this.progressIndicator.setVisibility(View.GONE);
618+
619+
// This should be improved ?
620+
String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot";
621+
rebootFloatingButton.setOnClickListener(_view -> {
622+
if (MainApplication.shouldPreventReboot()) {
623+
MaterialAlertDialogBuilder builder =
624+
new MaterialAlertDialogBuilder(this);
625+
626+
builder
627+
.setTitle(R.string.install_terminal_reboot_now)
628+
.setCancelable(false)
629+
.setIcon(R.drawable.ic_reboot_24)
630+
.setPositiveButton(R.string.yes, (x, y) -> {
631+
Shell.cmd(reboot_cmd).submit();
632+
})
633+
.setNegativeButton(R.string.no, (x, y) -> {
634+
x.dismiss();
635+
}).show();
636+
} else {
637+
Shell.cmd(reboot_cmd).submit();
638+
}
639+
});
640+
611641
if (message != null && !message.isEmpty())
612642
this.installerTerminal.addLine(message);
613643
if (!optionalLink.isEmpty()) {
614644
this.setActionBarExtraMenuButton(ActionButtonType.supportIconForUrl(optionalLink),
615645
menu -> {
616-
IntentHelper.openUrl(this, optionalLink);
617-
return true;
618-
});
646+
IntentHelper.openUrl(this, optionalLink);
647+
return true;
648+
});
619649
} else if (success) {
620650
final Intent intent = this.getIntent();
621651
final String config = MainApplication.checkSecret(intent) ?
@@ -628,6 +658,7 @@ private void setInstallStateFinished(boolean success, String message,String opti
628658
IntentHelper.openConfig(this, config);
629659
return true;
630660
});
661+
this.rebootFloatingButton.setVisibility(View.VISIBLE);
631662
} catch (PackageManager.NameNotFoundException e) {
632663
Log.w(TAG, "Config package \"" +
633664
configPkg + "\" missing for installer view");

app/src/main/java/com/fox2code/mmm/ModuleHolder.java renamed to app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fox2code.mmm;
1+
package com.fox2code.mmm.module;
22

33
import android.content.Context;
44
import android.content.pm.PackageManager;
@@ -8,6 +8,11 @@
88
import androidx.annotation.NonNull;
99
import androidx.annotation.StringRes;
1010

11+
import com.fox2code.mmm.ActionButtonType;
12+
import com.fox2code.mmm.MainApplication;
13+
import com.fox2code.mmm.NotificationType;
14+
import com.fox2code.mmm.R;
15+
import com.fox2code.mmm.XHooks;
1116
import com.fox2code.mmm.manager.LocalModuleInfo;
1217
import com.fox2code.mmm.manager.ModuleInfo;
1318
import com.fox2code.mmm.repo.RepoModule;

app/src/main/java/com/fox2code/mmm/ModuleSorter.java renamed to app/src/main/java/com/fox2code/mmm/module/ModuleSorter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package com.fox2code.mmm;
1+
package com.fox2code.mmm.module;
22

33
import androidx.annotation.DrawableRes;
44

5+
import com.fox2code.mmm.R;
6+
57
import java.util.Comparator;
68

79
public enum ModuleSorter implements Comparator<ModuleHolder> {

app/src/main/java/com/fox2code/mmm/ModuleViewAdapter.java renamed to app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fox2code.mmm;
1+
package com.fox2code.mmm.module;
22

33
import android.annotation.SuppressLint;
44
import android.content.res.Resources;
@@ -18,6 +18,10 @@
1818
import androidx.cardview.widget.CardView;
1919
import androidx.recyclerview.widget.RecyclerView;
2020

21+
import com.fox2code.mmm.ActionButtonType;
22+
import com.fox2code.mmm.MainApplication;
23+
import com.fox2code.mmm.NotificationType;
24+
import com.fox2code.mmm.R;
2125
import com.fox2code.mmm.manager.LocalModuleInfo;
2226
import com.fox2code.mmm.manager.ModuleInfo;
2327
import com.fox2code.mmm.manager.ModuleManager;
@@ -269,7 +273,7 @@ public boolean update(ModuleHolder moduleHolder) {
269273
this.descriptionText.setText(" ");
270274
this.switchMaterial.setEnabled(false);
271275
this.actionButtonsTypes.clear();
272-
for (ImageButton button:this.actionsButtons) {
276+
for (ImageButton button : this.actionsButtons) {
273277
button.setVisibility(View.GONE);
274278
button.setImportantForAccessibility(
275279
View.IMPORTANT_FOR_ACCESSIBILITY_NO);
@@ -320,7 +324,11 @@ public boolean update(ModuleHolder moduleHolder) {
320324
theme.resolveAttribute(foregroundAttr, value, true);
321325
@ColorInt int fgColor = value.data;
322326
// Fix card background being invisible on light theme
323-
if (bgColor == Color.WHITE) bgColor = 0xFFF8F8F8;
327+
if (bgColor == Color.WHITE) {
328+
bgColor = 0xFFF8F8F8;
329+
} else {
330+
bgColor = 0xFF1E1E1E;
331+
}
324332
this.titleText.setTextColor(fgColor);
325333
this.buttonAction.setColorFilter(fgColor);
326334
this.cardView.setCardBackgroundColor(bgColor);

app/src/main/java/com/fox2code/mmm/ModuleViewListBuilder.java renamed to app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fox2code.mmm;
1+
package com.fox2code.mmm.module;
22

33
import android.app.Activity;
44
import android.os.Build;
@@ -7,10 +7,16 @@
77
import androidx.annotation.NonNull;
88
import androidx.recyclerview.widget.RecyclerView;
99

10+
import com.fox2code.mmm.AppUpdateManager;
11+
import com.fox2code.mmm.MainApplication;
12+
import com.fox2code.mmm.NotificationType;
1013
import com.fox2code.mmm.installer.InstallerInitializer;
1114
import com.fox2code.mmm.manager.LocalModuleInfo;
1215
import com.fox2code.mmm.manager.ModuleInfo;
1316
import com.fox2code.mmm.manager.ModuleManager;
17+
import com.fox2code.mmm.module.ModuleHolder;
18+
import com.fox2code.mmm.module.ModuleSorter;
19+
import com.fox2code.mmm.module.ModuleViewAdapter;
1420
import com.fox2code.mmm.repo.RepoManager;
1521
import com.fox2code.mmm.repo.RepoModule;
1622

0 commit comments

Comments
 (0)