|
|
|
@ -12,8 +12,8 @@ import android.widget.Toast;
|
|
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
|
|
|
|
|
import com.fox2code.foxcompat.FoxActivity;
|
|
|
|
|
import com.fox2code.foxcompat.FoxDisplay;
|
|
|
|
|
import com.fox2code.foxcompat.app.FoxActivity;
|
|
|
|
|
import com.fox2code.foxcompat.view.FoxDisplay;
|
|
|
|
|
import com.fox2code.mmm.MainApplication;
|
|
|
|
|
import com.fox2code.mmm.R;
|
|
|
|
|
import com.fox2code.mmm.androidacy.AndroidacyUtil;
|
|
|
|
@ -41,36 +41,22 @@ public enum ActionButtonType {
|
|
|
|
|
public void doAction(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
String notesUrl = moduleHolder.repoModule.notesUrl;
|
|
|
|
|
if (AndroidacyUtil.isAndroidacyLink(notesUrl)) {
|
|
|
|
|
IntentHelper.openUrlAndroidacy(button.getContext(), notesUrl, false,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.name,
|
|
|
|
|
moduleHolder.getMainModuleConfig());
|
|
|
|
|
IntentHelper.openUrlAndroidacy(button.getContext(), notesUrl, false, moduleHolder.repoModule.moduleInfo.name, moduleHolder.getMainModuleConfig());
|
|
|
|
|
} else {
|
|
|
|
|
IntentHelper.openMarkdown(button.getContext(), notesUrl,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.name,
|
|
|
|
|
moduleHolder.getMainModuleConfig(),
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.changeBoot,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.needRamdisk,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.minMagisk,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.minApi,
|
|
|
|
|
moduleHolder.repoModule.moduleInfo.maxApi
|
|
|
|
|
);
|
|
|
|
|
IntentHelper.openMarkdown(button.getContext(), notesUrl, moduleHolder.repoModule.moduleInfo.name, moduleHolder.getMainModuleConfig(), moduleHolder.repoModule.moduleInfo.changeBoot, moduleHolder.repoModule.moduleInfo.needRamdisk, moduleHolder.repoModule.moduleInfo.minMagisk, moduleHolder.repoModule.moduleInfo.minApi, moduleHolder.repoModule.moduleInfo.maxApi);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean doActionLong(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
Context context = button.getContext();
|
|
|
|
|
Toast.makeText(context, context.getString(R.string.module_id_prefix) +
|
|
|
|
|
moduleHolder.moduleId, Toast.LENGTH_SHORT).show();
|
|
|
|
|
Toast.makeText(context, context.getString(R.string.module_id_prefix) + moduleHolder.moduleId, Toast.LENGTH_SHORT).show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
UPDATE_INSTALL() {
|
|
|
|
|
}, UPDATE_INSTALL() {
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
int icon = moduleHolder.hasUpdate() ?
|
|
|
|
|
R.drawable.ic_baseline_update_24 :
|
|
|
|
|
R.drawable.ic_baseline_system_update_24;
|
|
|
|
|
int icon = moduleHolder.hasUpdate() ? R.drawable.ic_baseline_update_24 : R.drawable.ic_baseline_system_update_24;
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(icon));
|
|
|
|
|
if (moduleHolder.hasUpdate()) {
|
|
|
|
|
button.setText(R.string.update);
|
|
|
|
@ -82,22 +68,19 @@ public enum ActionButtonType {
|
|
|
|
|
@Override
|
|
|
|
|
public void doAction(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();
|
|
|
|
|
if (moduleInfo == null) return;
|
|
|
|
|
if (moduleInfo == null)
|
|
|
|
|
return;
|
|
|
|
|
String updateZipUrl = moduleHolder.getUpdateZipUrl();
|
|
|
|
|
if (updateZipUrl == null) return;
|
|
|
|
|
if (updateZipUrl == null)
|
|
|
|
|
return;
|
|
|
|
|
// Androidacy manage the selection between download and install
|
|
|
|
|
if (AndroidacyUtil.isAndroidacyLink(updateZipUrl)) {
|
|
|
|
|
IntentHelper.openUrlAndroidacy(
|
|
|
|
|
button.getContext(), updateZipUrl, true,
|
|
|
|
|
moduleInfo.name, moduleInfo.config);
|
|
|
|
|
IntentHelper.openUrlAndroidacy(button.getContext(), updateZipUrl, true, moduleInfo.name, moduleInfo.config);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
boolean hasRoot = InstallerInitializer.peekMagiskPath() != null
|
|
|
|
|
&& !MainApplication.isShowcaseMode();
|
|
|
|
|
MaterialAlertDialogBuilder builder =
|
|
|
|
|
new MaterialAlertDialogBuilder(button.getContext());
|
|
|
|
|
builder.setTitle(moduleInfo.name).setCancelable(true)
|
|
|
|
|
.setIcon(R.drawable.ic_baseline_extension_24);
|
|
|
|
|
boolean hasRoot = InstallerInitializer.peekMagiskPath() != null && !MainApplication.isShowcaseMode();
|
|
|
|
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(button.getContext());
|
|
|
|
|
builder.setTitle(moduleInfo.name).setCancelable(true).setIcon(R.drawable.ic_baseline_extension_24);
|
|
|
|
|
CharSequence desc = moduleInfo.description;
|
|
|
|
|
Markwon markwon = null;
|
|
|
|
|
LocalModuleInfo localModuleInfo = moduleHolder.moduleInfo;
|
|
|
|
@ -113,20 +96,14 @@ public enum ActionButtonType {
|
|
|
|
|
builder.setMessage(desc);
|
|
|
|
|
}
|
|
|
|
|
Log.i("Test", "URL: " + updateZipUrl);
|
|
|
|
|
builder.setNegativeButton(R.string.download_module, (x, y) -> {
|
|
|
|
|
IntentHelper.openCustomTab(button.getContext(), updateZipUrl);
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(R.string.download_module, (x, y) -> IntentHelper.openCustomTab(button.getContext(), updateZipUrl));
|
|
|
|
|
if (hasRoot) {
|
|
|
|
|
builder.setPositiveButton(moduleHolder.hasUpdate() ?
|
|
|
|
|
R.string.update_module : R.string.install_module, (x, y) -> {
|
|
|
|
|
builder.setPositiveButton(moduleHolder.hasUpdate() ? R.string.update_module : R.string.install_module, (x, y) -> {
|
|
|
|
|
String updateZipChecksum = moduleHolder.getUpdateZipChecksum();
|
|
|
|
|
IntentHelper.openInstaller(button.getContext(), updateZipUrl,
|
|
|
|
|
moduleInfo.name, moduleInfo.config, updateZipChecksum,
|
|
|
|
|
moduleInfo.mmtReborn);
|
|
|
|
|
IntentHelper.openInstaller(button.getContext(), updateZipUrl, moduleInfo.name, moduleInfo.config, updateZipChecksum, moduleInfo.mmtReborn);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ExternalHelper.INSTANCE.injectButton(builder,
|
|
|
|
|
() -> Uri.parse(updateZipUrl), moduleHolder.getUpdateZipRepo());
|
|
|
|
|
ExternalHelper.INSTANCE.injectButton(builder, () -> Uri.parse(updateZipUrl), moduleHolder.getUpdateZipRepo());
|
|
|
|
|
int dim5dp = FoxDisplay.dpToPixel(5);
|
|
|
|
|
builder.setBackgroundInsetStart(dim5dp).setBackgroundInsetEnd(dim5dp);
|
|
|
|
|
AlertDialog alertDialog = builder.show();
|
|
|
|
@ -137,36 +114,26 @@ public enum ActionButtonType {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (markwon != null) {
|
|
|
|
|
TextView messageView = alertDialog.getWindow()
|
|
|
|
|
.findViewById(android.R.id.message);
|
|
|
|
|
TextView messageView = alertDialog.getWindow().findViewById(android.R.id.message);
|
|
|
|
|
markwon.setParsedMarkdown(messageView, (Spanned) desc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
UNINSTALL() {
|
|
|
|
|
}, UNINSTALL() {
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
int icon = moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING) ?
|
|
|
|
|
R.drawable.ic_baseline_delete_outline_24 : (
|
|
|
|
|
!moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING) ||
|
|
|
|
|
moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) ?
|
|
|
|
|
R.drawable.ic_baseline_delete_24 :
|
|
|
|
|
R.drawable.ic_baseline_delete_forever_24;
|
|
|
|
|
int icon = moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING) ? R.drawable.ic_baseline_delete_outline_24 : (!moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING) || moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) ? R.drawable.ic_baseline_delete_24 : R.drawable.ic_baseline_delete_forever_24;
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(icon));
|
|
|
|
|
button.setText(R.string.uninstall);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doAction(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
if (!moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE |
|
|
|
|
|
ModuleInfo.FLAG_MODULE_UNINSTALLING) &&
|
|
|
|
|
moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING)) {
|
|
|
|
|
if (!moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE | ModuleInfo.FLAG_MODULE_UNINSTALLING) && moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING)) {
|
|
|
|
|
doActionLong(button, moduleHolder);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Log.i("ActionButtonType", Integer.toHexString(moduleHolder.moduleInfo.flags));
|
|
|
|
|
if (!ModuleManager.getINSTANCE().setUninstallState(moduleHolder.moduleInfo,
|
|
|
|
|
!moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING))) {
|
|
|
|
|
if (!ModuleManager.getINSTANCE().setUninstallState(moduleHolder.moduleInfo, !moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UNINSTALLING))) {
|
|
|
|
|
Log.e("ActionButtonType", "Failed to switch uninstalled state!");
|
|
|
|
|
}
|
|
|
|
|
update(button, moduleHolder);
|
|
|
|
@ -177,23 +144,20 @@ public enum ActionButtonType {
|
|
|
|
|
// Actually a module having mount is the only issue when deleting module
|
|
|
|
|
if (moduleHolder.moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_HAS_ACTIVE_MOUNT))
|
|
|
|
|
return false; // We can't trust active flag on first boot
|
|
|
|
|
new AlertDialog.Builder(button.getContext()).setTitle(R.string.master_delete)
|
|
|
|
|
.setPositiveButton(R.string.master_delete_yes, (v, i) -> {
|
|
|
|
|
String moduleId = moduleHolder.moduleInfo.id;
|
|
|
|
|
if (!ModuleManager.getINSTANCE().masterClear(moduleHolder.moduleInfo)) {
|
|
|
|
|
Toast.makeText(button.getContext(), R.string.master_delete_fail,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
} else {
|
|
|
|
|
moduleHolder.moduleInfo = null;
|
|
|
|
|
FoxActivity.getFoxActivity(button).refreshUI();
|
|
|
|
|
Log.e("ActionButtonType", "Cleared: " + moduleId);
|
|
|
|
|
}
|
|
|
|
|
}).setNegativeButton(R.string.master_delete_no, (v, i) -> {
|
|
|
|
|
}).create().show();
|
|
|
|
|
new AlertDialog.Builder(button.getContext()).setTitle(R.string.master_delete).setPositiveButton(R.string.master_delete_yes, (v, i) -> {
|
|
|
|
|
String moduleId = moduleHolder.moduleInfo.id;
|
|
|
|
|
if (!ModuleManager.getINSTANCE().masterClear(moduleHolder.moduleInfo)) {
|
|
|
|
|
Toast.makeText(button.getContext(), R.string.master_delete_fail, Toast.LENGTH_SHORT).show();
|
|
|
|
|
} else {
|
|
|
|
|
moduleHolder.moduleInfo = null;
|
|
|
|
|
FoxActivity.getFoxActivity(button).refreshUI();
|
|
|
|
|
Log.e("ActionButtonType", "Cleared: " + moduleId);
|
|
|
|
|
}
|
|
|
|
|
}).setNegativeButton(R.string.master_delete_no, (v, i) -> {
|
|
|
|
|
}).create().show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
CONFIG() {
|
|
|
|
|
}, CONFIG() {
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(R.drawable.ic_baseline_app_settings_alt_24));
|
|
|
|
@ -203,35 +167,31 @@ public enum ActionButtonType {
|
|
|
|
|
@Override
|
|
|
|
|
public void doAction(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
String config = moduleHolder.getMainModuleConfig();
|
|
|
|
|
if (config == null) return;
|
|
|
|
|
if (config == null)
|
|
|
|
|
return;
|
|
|
|
|
if (AndroidacyUtil.isAndroidacyLink(config)) {
|
|
|
|
|
IntentHelper.openUrlAndroidacy(button.getContext(), config, true);
|
|
|
|
|
} else {
|
|
|
|
|
IntentHelper.openConfig(button.getContext(), config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
SUPPORT() {
|
|
|
|
|
}, SUPPORT() {
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(
|
|
|
|
|
supportIconForUrl(moduleInfo.support)));
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(supportIconForUrl(moduleInfo.support)));
|
|
|
|
|
button.setText(R.string.support);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void doAction(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
IntentHelper.openUrl(button.getContext(),
|
|
|
|
|
moduleHolder.getMainModuleInfo().support);
|
|
|
|
|
IntentHelper.openUrl(button.getContext(), moduleHolder.getMainModuleInfo().support);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
DONATE() {
|
|
|
|
|
}, DONATE() {
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(
|
|
|
|
|
donateIconForUrl(moduleInfo.donate)));
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(donateIconForUrl(moduleInfo.donate)));
|
|
|
|
|
button.setText(R.string.donate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -241,6 +201,18 @@ public enum ActionButtonType {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@DrawableRes
|
|
|
|
|
private final int iconId;
|
|
|
|
|
|
|
|
|
|
ActionButtonType() {
|
|
|
|
|
this.iconId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
ActionButtonType(int iconId) {
|
|
|
|
|
this.iconId = iconId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DrawableRes
|
|
|
|
|
public static int supportIconForUrl(String url) {
|
|
|
|
|
int icon = R.drawable.ic_baseline_support_24;
|
|
|
|
@ -248,8 +220,7 @@ public enum ActionButtonType {
|
|
|
|
|
return icon;
|
|
|
|
|
} else if (url.startsWith("https://t.me/")) {
|
|
|
|
|
icon = R.drawable.ic_baseline_telegram_24;
|
|
|
|
|
} else if (url.startsWith("https://discord.gg/") ||
|
|
|
|
|
url.startsWith("https://discord.com/invite/")) {
|
|
|
|
|
} else if (url.startsWith("https://discord.gg/") || url.startsWith("https://discord.com/invite/")) {
|
|
|
|
|
icon = R.drawable.ic_baseline_discord_24;
|
|
|
|
|
} else if (url.startsWith("https://github.com/")) {
|
|
|
|
|
icon = R.drawable.ic_github;
|
|
|
|
@ -266,28 +237,14 @@ public enum ActionButtonType {
|
|
|
|
|
int icon = R.drawable.ic_baseline_monetization_on_24;
|
|
|
|
|
if (url == null) {
|
|
|
|
|
return icon;
|
|
|
|
|
} else if (url.startsWith("https://www.paypal.me/") ||
|
|
|
|
|
url.startsWith("https://www.paypal.com/paypalme/") ||
|
|
|
|
|
url.startsWith("https://www.paypal.com/donate/")) {
|
|
|
|
|
} else if (url.startsWith("https://www.paypal.me/") || url.startsWith("https://www.paypal.com/paypalme/") || url.startsWith("https://www.paypal.com/donate/")) {
|
|
|
|
|
icon = R.drawable.ic_baseline_paypal_24;
|
|
|
|
|
} else if (url.startsWith("https://patreon.com/") ||
|
|
|
|
|
url.startsWith("https://www.patreon.com/")) {
|
|
|
|
|
} else if (url.startsWith("https://patreon.com/") || url.startsWith("https://www.patreon.com/")) {
|
|
|
|
|
icon = R.drawable.ic_patreon;
|
|
|
|
|
}
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DrawableRes
|
|
|
|
|
private final int iconId;
|
|
|
|
|
|
|
|
|
|
ActionButtonType() {
|
|
|
|
|
this.iconId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActionButtonType(int iconId) {
|
|
|
|
|
this.iconId = iconId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void update(Chip button, ModuleHolder moduleHolder) {
|
|
|
|
|
button.setChipIcon(button.getContext().getDrawable(this.iconId));
|
|
|
|
|
}
|
|
|
|
|