From a766c73af1e182c723d0b42a9a5a65fea4cbeeab Mon Sep 17 00:00:00 2001 From: DerGoogler Date: Sun, 15 May 2022 01:10:18 +0200 Subject: [PATCH] Rework cards, Initial Android 12 Monet support --- app/build.gradle | 2 +- .../java/com/fox2code/mmm/MainActivity.java | 20 +-- .../com/fox2code/mmm/MainApplication.java | 4 + .../fox2code/mmm/module/ActionButtonType.java | 79 ++++++---- .../mmm/module/ModuleViewAdapter.java | 16 +- .../mmm/settings/SettingsActivity.java | 6 + .../ic_baseline_design_services_24.xml | 6 + app/src/main/res/layout/module_entry.xml | 145 ++++++++++++++---- app/src/main/res/values-v31/colors.xml | 77 ++++++++++ app/src/main/res/values-v31/themes.xml | 37 +++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/themes.xml | 14 ++ app/src/main/res/xml/root_preferences.xml | 7 + build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 16 files changed, 344 insertions(+), 76 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_design_services_24.xml create mode 100644 app/src/main/res/values-v31/colors.xml create mode 100644 app/src/main/res/values-v31/themes.xml diff --git a/app/build.gradle b/app/build.gradle index e70951f..9aaa11c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -88,7 +88,7 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.webkit:webkit:1.4.0' - implementation 'com.google.android.material:material:1.5.0' + implementation 'com.google.android.material:material:1.6.0' implementation "com.mikepenz:aboutlibraries:${latestAboutLibsRelease}" implementation "dev.rikka.rikkax.layoutinflater:layoutinflater:1.2.0" implementation "dev.rikka.rikkax.insets:insets:1.2.0" diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index ac98aca..020278b 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -32,6 +32,8 @@ import com.fox2code.mmm.repo.RepoManager; import com.fox2code.mmm.settings.SettingsActivity; import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.IntentHelper; +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.progressindicator.LinearProgressIndicator; import eightbitlab.com.blurview.BlurView; @@ -68,10 +70,10 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O protected void onCreate(Bundle savedInstanceState) { this.initMode = true; super.onCreate(savedInstanceState); - this.setActionBarExtraMenuButton(R.drawable.ic_baseline_settings_24, v -> { + this.setActionBarExtraMenuButton(R.drawable.ic_baseline_settings_24, v -> { IntentHelper.startActivity(this, SettingsActivity.class); - return true; - }, R.string.pref_category_settings); + return true; + }, R.string.pref_category_settings); setContentView(R.layout.activity_main); this.setTitle(R.string.app_name); this.getWindow().setFlags( @@ -103,13 +105,13 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O this.moduleList.setItemViewCacheSize(4); // Default is 2 OverScrollManager.install(this.moduleList, this); this.swipeRefreshLayout.setOnRefreshListener(this); - this.actionBarBlur.setBackground(this.actionBarBackground); + this.actionBarBlur.setBackground(this.actionBarBackground);; this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable( this.getWindow().getDecorView().getBackground()) - .setBlurAlgorithm(new RenderScriptBlur(this)) - .setBlurRadius(4F).setBlurAutoUpdate(true) - .setHasFixedTransformationMatrix(true); - this.updateBlurState(); + .setBlurAlgorithm(new RenderScriptBlur(this)) + .setBlurRadius(4F).setBlurAutoUpdate(true) + .setHasFixedTransformationMatrix(true); + this.updateBlurState(); this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { @@ -255,7 +257,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O bottomInset + this.searchCard.getHeight()); this.searchCard.setRadius(this.searchCard.getHeight() / 2F); this.moduleViewListBuilder.updateInsets(); - this.actionBarBlur.invalidate(); + //this.actionBarBlur.invalidate(); this.overScrollInsetTop = combinedBarsHeight; this.overScrollInsetBottom = bottomInset; Log.d(TAG, "( " + bottomInset + ", " + diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index ef926b6..cc99d74 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -23,6 +23,7 @@ import com.fox2code.mmm.compat.CompatThemeWrapper; import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.utils.GMSProviderInstaller; import com.fox2code.mmm.utils.Http; +import com.google.android.material.color.DynamicColors; import com.topjohnwu.superuser.Shell; import java.text.SimpleDateFormat; @@ -280,6 +281,9 @@ public class MainApplication extends CompatApplication { @Override public void onCreate() { super.onCreate(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + DynamicColors.applyToActivitiesIfAvailable(this); + } SharedPreferences sharedPreferences = MainApplication.getSharedPreferences(); // We are only one process so it's ok to do this SharedPreferences bootPrefs = MainApplication.bootSharedPreferences = diff --git a/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java b/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java index 1c08978..551a61f 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java +++ b/app/src/main/java/com/fox2code/mmm/module/ActionButtonType.java @@ -10,6 +10,7 @@ import android.widget.Toast; import androidx.annotation.DrawableRes; import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.R; @@ -22,14 +23,21 @@ import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.manager.ModuleManager; import com.fox2code.mmm.module.ModuleHolder; import com.fox2code.mmm.utils.IntentHelper; +import com.google.android.material.chip.Chip; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import io.noties.markwon.Markwon; public enum ActionButtonType { - INFO(R.drawable.ic_baseline_info_24) { + INFO() { @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void update(Chip button, ModuleHolder moduleHolder) { + button.setChipIcon(button.getContext().getResources().getDrawable(R.drawable.ic_baseline_info_24)); + button.setText("Description"); + } + + @Override + public void doAction(Chip button, ModuleHolder moduleHolder) { String notesUrl = moduleHolder.repoModule.notesUrl; if (notesUrl.startsWith("https://api.androidacy.com/magisk/readme/?module=") || notesUrl.startsWith("https://www.androidacy.com/")) { @@ -46,31 +54,36 @@ public enum ActionButtonType { } @Override - public boolean doActionLong(ImageButton button, ModuleHolder moduleHolder) { + 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(); + moduleHolder.moduleId, Toast.LENGTH_SHORT).show(); return true; } }, UPDATE_INSTALL() { @Override - public void update(ImageButton button, ModuleHolder moduleHolder) { + public void update(Chip button, ModuleHolder moduleHolder) { int icon = moduleHolder.hasUpdate() ? R.drawable.ic_baseline_update_24 : R.drawable.ic_baseline_system_update_24; - button.setImageResource(icon); + button.setChipIcon(button.getContext().getResources().getDrawable(icon)); + if (moduleHolder.hasUpdate()) { + button.setText("Update"); + } else { + button.setText("Install"); + } } @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void doAction(Chip button, ModuleHolder moduleHolder) { ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo(); if (moduleInfo == null) return; String updateZipUrl = moduleHolder.getUpdateZipUrl(); if (updateZipUrl == null) return; // Androidacy manage the selection between download and install if (updateZipUrl.startsWith("https://www.androidacy.com/") || - updateZipUrl.startsWith("https://api.androidacy.com/magisk/info/?module=")) { + updateZipUrl.startsWith("https://api.androidacy.com/magisk/info/?module=")) { IntentHelper.openUrlAndroidacy( button.getContext(), updateZipUrl, true, moduleInfo.name, moduleInfo.config); @@ -127,18 +140,19 @@ public enum ActionButtonType { }, UNINSTALL() { @Override - public void update(ImageButton button, ModuleHolder moduleHolder) { + 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; - button.setImageResource(icon); + moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) ? + R.drawable.ic_baseline_delete_24 : + R.drawable.ic_baseline_delete_forever_24; + button.setChipIcon(button.getContext().getResources().getDrawable(icon)); + button.setText("Uninstall"); } @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void doAction(Chip button, ModuleHolder moduleHolder) { if (!moduleHolder.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE | ModuleInfo.FLAG_MODULE_UNINSTALLING) && moduleHolder.hasFlag(ModuleInfo.FLAG_MODULE_UPDATING)) { @@ -153,7 +167,7 @@ public enum ActionButtonType { } @Override - public boolean doActionLong(ImageButton button, ModuleHolder moduleHolder) { + public boolean doActionLong(Chip button, ModuleHolder moduleHolder) { // We can't trust active flag on first boot if (moduleHolder.moduleInfo.hasFlag(ModuleInfo.FLAGS_MODULE_ACTIVE)) return false; new AlertDialog.Builder(button.getContext()).setTitle(R.string.master_delete) @@ -165,13 +179,20 @@ public enum ActionButtonType { moduleHolder.moduleInfo = null; CompatActivity.getCompatActivity(button).refreshUI(); } - }).setNegativeButton(R.string.master_delete_no, (v, i) -> {}).create().show(); + }).setNegativeButton(R.string.master_delete_no, (v, i) -> { + }).create().show(); return true; } }, - CONFIG(R.drawable.ic_baseline_app_settings_alt_24) { + CONFIG() { + @Override + public void update(Chip button, ModuleHolder moduleHolder) { + button.setChipIcon(button.getContext().getResources().getDrawable(R.drawable.ic_baseline_app_settings_alt_24)); + button.setText("Config"); + } + @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void doAction(Chip button, ModuleHolder moduleHolder) { String config = moduleHolder.getMainModuleConfig(); if (config == null) return; if (AndroidacyUtil.isAndroidacyLink(config)) { @@ -183,19 +204,20 @@ public enum ActionButtonType { }, SUPPORT() { @Override - public void update(ImageButton button, ModuleHolder moduleHolder) { + public void update(Chip button, ModuleHolder moduleHolder) { ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo(); - button.setImageResource(supportIconForUrl(moduleInfo.support)); + button.setChipIcon(button.getContext().getResources().getDrawable(supportIconForUrl(moduleInfo.support))); + button.setText("Support"); } @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void doAction(Chip button, ModuleHolder moduleHolder) { IntentHelper.openUrl(button.getContext(), moduleHolder.getMainModuleInfo().support); } }, DONATE() { @Override - public void update(ImageButton button, ModuleHolder moduleHolder) { + public void update(Chip button, ModuleHolder moduleHolder) { ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo(); int icon = R.drawable.ic_baseline_monetization_on_24; if (moduleInfo.donate.startsWith("https://www.paypal.me/")) { @@ -203,11 +225,12 @@ public enum ActionButtonType { } else if (moduleInfo.donate.startsWith("https://www.patreon.com/")) { icon = R.drawable.ic_patreon; } - button.setImageResource(icon); + button.setChipIcon(button.getContext().getResources().getDrawable(icon)); + button.setText("Donate"); } @Override - public void doAction(ImageButton button, ModuleHolder moduleHolder) { + public void doAction(Chip button, ModuleHolder moduleHolder) { IntentHelper.openUrl(button.getContext(), moduleHolder.getMainModuleInfo().donate); } }; @@ -239,13 +262,13 @@ public enum ActionButtonType { this.iconId = iconId; } - public void update(ImageButton button, ModuleHolder moduleHolder) { - button.setImageResource(this.iconId); + public void update(Chip button, ModuleHolder moduleHolder) { + button.setChipIcon(button.getContext().getResources().getDrawable(this.iconId)); } - public abstract void doAction(ImageButton button, ModuleHolder moduleHolder); + public abstract void doAction(Chip button, ModuleHolder moduleHolder); - public boolean doActionLong(ImageButton button, ModuleHolder moduleHolder) { + public boolean doActionLong(Chip button, ModuleHolder moduleHolder) { return false; } } diff --git a/app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java b/app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java index 6331bf2..3791bb8 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java +++ b/app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java @@ -25,12 +25,14 @@ import com.fox2code.mmm.manager.LocalModuleInfo; import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.manager.ModuleManager; import com.fox2code.mmm.repo.RepoModule; +import com.google.android.material.chip.Chip; import com.google.android.material.switchmaterial.SwitchMaterial; import com.topjohnwu.superuser.internal.UiThreadHandler; import java.util.ArrayList; import java.util.Objects; + public final class ModuleViewAdapter extends RecyclerView.Adapter { private static final boolean DEBUG = false; public final ArrayList moduleHolders = new ArrayList<>(); @@ -70,7 +72,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter actionButtonsTypes; private boolean initState; public ModuleHolder moduleHolder; @@ -86,7 +88,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter { - if (this.initState) return; // Skip if non user + if (this.initState) return; // Skip if non user ModuleHolder moduleHolder = this.moduleHolder; if (moduleHolder != null && moduleHolder.moduleInfo != null) { ModuleInfo moduleInfo = moduleHolder.moduleInfo; @@ -128,7 +130,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter { CompatThemeWrapper compatThemeWrapper = diff --git a/app/src/main/res/drawable/ic_baseline_design_services_24.xml b/app/src/main/res/drawable/ic_baseline_design_services_24.xml new file mode 100644 index 0000000..872fcba --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_design_services_24.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/layout/module_entry.xml b/app/src/main/res/layout/module_entry.xml index 8881612..9566156 100644 --- a/app/src/main/res/layout/module_entry.xml +++ b/app/src/main/res/layout/module_entry.xml @@ -19,22 +19,25 @@ app:cardPreventCornerOverlap="true" app:cardElevation="0dp" app:strokeWidth="0dp"> + + android:layout_margin="8dp" + app:layout_constraintBottom_toBottomOf="@+id/description_text" + app:layout_constraintTop_toBottomOf="@+id/description_text"> @@ -44,60 +47,59 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="6dp" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintRight_toRightOf="parent" /> + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintTop_toBottomOf="@+id/description_text"> + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-v31/colors.xml b/app/src/main/res/values-v31/colors.xml new file mode 100644 index 0000000..3cfd695 --- /dev/null +++ b/app/src/main/res/values-v31/colors.xml @@ -0,0 +1,77 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + @android:color/system_neutral1_0 + @android:color/system_neutral1_10 + @android:color/system_neutral1_50 + @android:color/system_neutral1_100 + @android:color/system_neutral1_200 + @android:color/system_neutral1_300 + @android:color/system_neutral1_400 + @android:color/system_neutral1_500 + @android:color/system_neutral1_600 + @android:color/system_neutral1_700 + @android:color/system_neutral1_800 + @android:color/system_neutral1_900 + @android:color/system_neutral1_1000 + @android:color/system_neutral2_0 + @android:color/system_neutral2_10 + @android:color/system_neutral2_50 + @android:color/system_neutral2_100 + @android:color/system_neutral2_200 + @android:color/system_neutral2_300 + @android:color/system_neutral2_400 + @android:color/system_neutral2_500 + @android:color/system_neutral2_600 + @android:color/system_neutral2_700 + @android:color/system_neutral2_800 + @android:color/system_neutral2_900 + @android:color/system_neutral2_1000 + @android:color/system_accent1_0 + @android:color/system_accent1_10 + @android:color/system_accent1_50 + @android:color/system_accent1_100 + @android:color/system_accent1_200 + @android:color/system_accent1_300 + @android:color/system_accent1_400 + @android:color/system_accent1_500 + @android:color/system_accent1_600 + @android:color/system_accent1_700 + @android:color/system_accent1_800 + @android:color/system_accent1_900 + @android:color/system_accent1_1000 + @android:color/system_accent2_0 + @android:color/system_accent2_10 + @android:color/system_accent2_50 + @android:color/system_accent2_100 + @android:color/system_accent2_200 + @android:color/system_accent2_300 + @android:color/system_accent2_400 + @android:color/system_accent2_500 + @android:color/system_accent2_600 + @android:color/system_accent2_700 + @android:color/system_accent2_800 + @android:color/system_accent2_900 + @android:color/system_accent2_1000 + @android:color/system_accent3_0 + @android:color/system_accent3_10 + @android:color/system_accent3_50 + @android:color/system_accent3_100 + @android:color/system_accent3_200 + @android:color/system_accent3_300 + @android:color/system_accent3_400 + @android:color/system_accent3_500 + @android:color/system_accent3_600 + @android:color/system_accent3_700 + @android:color/system_accent3_800 + @android:color/system_accent3_900 + @android:color/system_accent3_1000 + @android:color/system_accent1_100 + @android:color/system_neutral2_700 + \ No newline at end of file diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml new file mode 100644 index 0000000..99a50b5 --- /dev/null +++ b/app/src/main/res/values-v31/themes.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 1f09259..4ad6e0b 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -71,6 +71,13 @@ app:title="@string/disable_chips_in_description" app:singleLineTitle="false" /> + +