diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index 0f94d4d..1a5d921 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -126,11 +126,6 @@ public class MainApplication extends CompatApplication { getSharedPreferences().getBoolean("pref_enable_blur", false); } - public static boolean isChipsDisabled() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - getSharedPreferences().getBoolean("pref_disable_chips", false); - } - public static boolean isDeveloper() { return BuildConfig.DEBUG || getSharedPreferences().getBoolean("developer", false); diff --git a/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java index 96adedc..12f96ad 100644 --- a/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java +++ b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java @@ -55,12 +55,11 @@ public class MarkdownActivity extends CompatActivity { private static final String[] variants = new String[]{ "readme.md", "README.MD", ".github/README.md" }; - private BlurView chipHolder; private TextView actionBarPadding; + private ColorDrawable actionBarBackground; private BlurView actionBarBlur; - private ColorDrawable anyBarBackground; - private ScrollView scrollView; - private LinearLayout md_layout; + private TextView header; + private TextView footer; private static byte[] getRawMarkdown(String url) throws IOException { String newUrl = redirects.get(url); @@ -138,40 +137,23 @@ public class MarkdownActivity extends CompatActivity { setContentView(R.layout.markdown_view); final ViewGroup markdownBackground = findViewById(R.id.markdownBackground); final TextView textView = findViewById(R.id.markdownView); - this.chipHolder = findViewById(R.id.chip_holder); - this.anyBarBackground = new ColorDrawable(Color.TRANSPARENT); this.actionBarPadding = findViewById(R.id.markdown_action_bar_padding); + this.actionBarBackground = new ColorDrawable(Color.TRANSPARENT); this.actionBarBlur = findViewById(R.id.markdown_action_bar_blur); - this.scrollView = findViewById(R.id.scrollView2); - this.md_layout = findViewById(R.id.md_layout); - final TextView footer = findViewById(R.id.markdownFooter); - UiThreadHandler.handler.postDelayed(() -> // Fix footer height - footer.setMinHeight(this.getNavigationBarHeight()), 1L); - this.actionBarBlur.setBackground(this.anyBarBackground); - this.setupBlurView(this.chipHolder, markdownBackground, this.anyBarBackground); - this.setupBlurView(this.actionBarBlur, markdownBackground, this.anyBarBackground); - this.updateScreenInsets(); - this.updateUI(); + this.header = findViewById(R.id.markdownHeader); + this.footer = findViewById(R.id.markdownFooter); + this.actionBarBlur.setBackground(this.actionBarBackground); + this.setupBlurView(this.actionBarBlur, markdownBackground); + UiThreadHandler.handler.post(() -> // Fix header/footer height + this.updateScreenInsets(this.getResources().getConfiguration())); // Really bad created (MSG by Der_Googler) - if (MainApplication.isChipsDisabled()) { - this.chipHolder.setVisibility(View.GONE); - } else { - this.chipHolder.setPadding(0,0,0,this.getNavigationBarHeight()); - // set "message" to null to disable dialog - this.setChip(change_boot, - getString(R.string.module_can_change_boot), - "This module may change the boot image"); - this.setChip(needs_ramdisk, - getString(R.string.module_needs_ramdisk), - "This module need boot ramdisk to be installed"); - this.setChip(min_magisk, "Min. Magisk \"" + min_magisk + "\"", - null); - this.setChip(min_api, "Min. Android " + min_api, - null); - this.setChip(max_api, "Max. Android " + max_api, - null); - } + // set "message" to null to disable dialog + if (change_boot) this.addChip(MarkdownChip.CHANGE_BOOT); + if (needs_ramdisk) this.addChip(MarkdownChip.NEED_RAMDISK); + if (min_magisk != 0) this.addChip(MarkdownChip.MIN_MAGISK, String.valueOf(min_magisk)); + if (min_api != 0) this.addChip(MarkdownChip.MIN_SDK, parseAndroidVersion(min_api)); + if (max_api != 0) this.addChip(MarkdownChip.MAX_SDK, parseAndroidVersion(max_api)); new Thread(() -> { try { @@ -201,15 +183,37 @@ public class MarkdownActivity extends CompatActivity { }, "Markdown load thread").start(); } - private void setupBlurView(BlurView view, ViewGroup setupWith, ColorDrawable background) { - view.setBackground(background); + private void setupBlurView(BlurView view, ViewGroup setupWith) { view.setupWith(setupWith).setFrameClearDrawable( this.getWindow().getDecorView().getBackground()) .setBlurAlgorithm(new RenderScriptBlur(this)) .setBlurRadius(4F).setBlurAutoUpdate(true) .setHasFixedTransformationMatrix(true); + this.updateBlurState(); } + private void updateBlurState() { + boolean isLightMode = this.isLightTheme(); + int colorBackground; + try { + colorBackground = this.getColorCompat( + android.R.attr.windowBackground); + } catch (Resources.NotFoundException e) { + colorBackground = this.getColorCompat(isLightMode ? + R.color.white : R.color.black); + } + if (MainApplication.isBlurEnabled()) { + this.actionBarBlur.setBlurEnabled(true); + this.actionBarBackground.setColor(ColorUtils + .setAlphaComponent(colorBackground, 0x02)); + this.actionBarBackground.setColor(Color.TRANSPARENT); + } else { + this.actionBarBlur.setBlurEnabled(false); + this.actionBarBlur.setOverlayColor(Color.TRANSPARENT); + this.actionBarBackground.setColor(colorBackground); + } + } + private void updateScreenInsets() { this.runOnUiThread(() -> this.updateScreenInsets( this.getResources().getConfiguration())); @@ -223,46 +227,33 @@ public class MarkdownActivity extends CompatActivity { int actionBarHeight = getActionBarHeight(); int combinedBarsHeight = statusBarHeight + actionBarHeight; this.actionBarPadding.setMinHeight(combinedBarsHeight); + this.header.setMinHeight(combinedBarsHeight); + this.footer.setMinHeight(bottomInset); //this.actionBarBlur.invalidate(); } - private void updateUI() { - boolean isLightMode = this.isLightTheme(); - int colorBackground; - try { - colorBackground = this.getColorCompat( - android.R.attr.windowBackground); - } catch (Resources.NotFoundException e) { - colorBackground = this.getColorCompat(isLightMode ? - R.color.white : R.color.black); - } - this.md_layout.setPadding(0,this.getActionBarHeight(this) + this.getStatusBarHeight(),0,this.getNavigationBarHeight() + 56); - if (MainApplication.isBlurEnabled()) { - this.actionBarBlur.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, this.getActionBarHeight(this) + this.getStatusBarHeight())); - this.chipHolder.setBlurEnabled(true); - this.anyBarBackground.setColor(ColorUtils - .setAlphaComponent(colorBackground, 0x02)); - this.anyBarBackground.setColor(Color.TRANSPARENT); - this.actionBarBlur.setBlurEnabled(true); - } else { - this.chipHolder.setBlurEnabled(false); - this.chipHolder.setOverlayColor(Color.TRANSPARENT); - this.anyBarBackground.setColor(colorBackground); - this.actionBarBlur.setBlurEnabled(false); - this.actionBarBlur.setOverlayColor(Color.TRANSPARENT); - } + @Override + public void refreshUI() { + super.refreshUI(); + this.updateScreenInsets(); + this.updateBlurState(); } - private void setChip(boolean bool, String title, String message) { - if (bool) { - this.makeChip(title, message); - } + + private void addChip(MarkdownChip markdownChip) { + this.makeChip(this.getString(markdownChip.title), + markdownChip.desc == 0 ? null : this.getString(markdownChip.desc)); } - private void setChip(int i, String title, String message) { - if (i != 0) { - this.makeChip(title, message); + private void addChip(MarkdownChip markdownChip, String extra) { + String title = this.getString(markdownChip.title); + if (title.contains("%s")) { + title = title.replace("%s", extra); + } else { + title = title + " " + extra; } + this.makeChip(title, markdownChip.desc == 0 ? + null : this.getString(markdownChip.desc)); } private void makeChip(String title, String message) { @@ -288,22 +279,32 @@ public class MarkdownActivity extends CompatActivity { private String parseAndroidVersion(int version) { switch (version) { + case Build.VERSION_CODES.JELLY_BEAN: + return "4.1 JellyBean"; + case Build.VERSION_CODES.JELLY_BEAN_MR1: + return "4.2 JellyBean"; + case Build.VERSION_CODES.JELLY_BEAN_MR2: + return "4.3 JellyBean"; + case Build.VERSION_CODES.KITKAT: + return "4.4 KitKat"; + case Build.VERSION_CODES.KITKAT_WATCH: + return "4.4 KitKat Watch"; case Build.VERSION_CODES.LOLLIPOP: - return "5.0"; + return "5.0 Lollipop"; case Build.VERSION_CODES.LOLLIPOP_MR1: - return "5.1"; + return "5.1 Lollipop"; case Build.VERSION_CODES.M: - return "6.0"; + return "6.0 Marshmallow"; case Build.VERSION_CODES.N: - return "7.0"; + return "7.0 Nougat"; case Build.VERSION_CODES.N_MR1: - return "7.1"; + return "7.1 Nougat"; case Build.VERSION_CODES.O: - return "8.0"; + return "8.0 Oreo"; case Build.VERSION_CODES.O_MR1: - return "8.1"; + return "8.1 Oreo"; case Build.VERSION_CODES.P: - return "9.0 (P)"; + return "9.0 Pie"; case Build.VERSION_CODES.Q: return "10 (Q)"; case Build.VERSION_CODES.R: @@ -313,7 +314,7 @@ public class MarkdownActivity extends CompatActivity { case Build.VERSION_CODES.S_V2: return "12L"; default: - return "false"; + return "Sdk: " + version; } } diff --git a/app/src/main/java/com/fox2code/mmm/markdown/MarkdownChip.java b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownChip.java new file mode 100644 index 0000000..5665c8f --- /dev/null +++ b/app/src/main/java/com/fox2code/mmm/markdown/MarkdownChip.java @@ -0,0 +1,19 @@ +package com.fox2code.mmm.markdown; + +import androidx.annotation.StringRes; + +import com.fox2code.mmm.R; + +public enum MarkdownChip { + CHANGE_BOOT(R.string.module_can_change_boot, R.string.module_can_change_boot_desc), + NEED_RAMDISK(R.string.module_needs_ramdisk, R.string.module_needs_ramdisk_desc), + MIN_MAGISK(R.string.module_min_magisk_chip, 0), + MIN_SDK(R.string.module_min_sdk_chip, 0), + MAX_SDK(R.string.module_max_sdk_chip, 0); + @StringRes public final int title, desc; + + MarkdownChip(@StringRes int title,@StringRes int desc) { + this.title = title; + this.desc = desc; + } +} diff --git a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java index 15d1e4c..5236263 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java @@ -53,6 +53,7 @@ public class PropUtils { moduleConfigsFallbacks.put("xposed", "de.robv.android.xposed.installer"); moduleConfigsFallbacks.put("substratum", "projekt.substratum"); // minApi is the minimum android version required to use the module + moduleMinApiFallbacks.put("HideNavBar", Build.VERSION_CODES.Q); moduleMinApiFallbacks.put("riru_ifw_enhance", Build.VERSION_CODES.O); moduleMinApiFallbacks.put("zygisk_ifw_enhance", Build.VERSION_CODES.O); moduleMinApiFallbacks.put("riru_edxposed", Build.VERSION_CODES.O); diff --git a/app/src/main/res/layout/markdown_view.xml b/app/src/main/res/layout/markdown_view.xml index a0aef44..87eb600 100644 --- a/app/src/main/res/layout/markdown_view.xml +++ b/app/src/main/res/layout/markdown_view.xml @@ -8,7 +8,7 @@ app:fitsSystemWindowsInsets="left|right" tools:context=".markdown.MarkdownActivity"> - + + + + + + + + - + - - - - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd99036..ae3cca6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,7 +44,12 @@ Downloads: Stars: Needs ramdisk + This module need boot ramdisk to be installed Can change boot + This module may change the boot image + This module may change the boot image + This module may change the boot image + This module may change the boot image diff --git a/app/src/main/res/xml/repo_preferences.xml b/app/src/main/res/xml/repo_preferences.xml index 9bed0d6..5fb37de 100644 --- a/app/src/main/res/xml/repo_preferences.xml +++ b/app/src/main/res/xml/repo_preferences.xml @@ -7,7 +7,7 @@ app:key="pref_magisk_alt_repo_enabled" app:icon="@drawable/ic_baseline_extension_24" app:switchTextOn="@string/repo_enabled" - app:switchTextOff="@string/repo_enabled" + app:switchTextOff="@string/repo_disabled" app:singleLineTitle="false" />