Rework markdown activity, make module chip nicer and translatable!

This commit is contained in:
Fox2Code 2022-06-03 19:07:51 +02:00
parent 7b60a514fe
commit fed16d049b
7 changed files with 128 additions and 115 deletions

View File

@ -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);

View File

@ -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);
@Override
public void refreshUI() {
super.refreshUI();
this.updateScreenInsets();
this.updateBlurState();
}
private void addChip(MarkdownChip markdownChip) {
this.makeChip(this.getString(markdownChip.title),
markdownChip.desc == 0 ? null : this.getString(markdownChip.desc));
}
private void addChip(MarkdownChip markdownChip, String extra) {
String title = this.getString(markdownChip.title);
if (title.contains("%s")) {
title = title.replace("%s", extra);
} else {
this.chipHolder.setBlurEnabled(false);
this.chipHolder.setOverlayColor(Color.TRANSPARENT);
this.anyBarBackground.setColor(colorBackground);
this.actionBarBlur.setBlurEnabled(false);
this.actionBarBlur.setOverlayColor(Color.TRANSPARENT);
}
}
private void setChip(boolean bool, String title, String message) {
if (bool) {
this.makeChip(title, message);
}
}
private void setChip(int i, String title, String message) {
if (i != 0) {
this.makeChip(title, message);
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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -8,7 +8,7 @@
app:fitsSystemWindowsInsets="left|right"
tools:context=".markdown.MarkdownActivity">
<ScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
@ -24,6 +24,12 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/markdownHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/markdownView"
android:layout_width="match_parent"
@ -31,13 +37,25 @@
android:layout_margin="@dimen/markdown_border_content"
android:text="@string/loading" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="8dp"
app:singleLine="true">
<!-- Dynamically added -->
</com.google.android.material.chip.ChipGroup>
<TextView
android:id="@+id/markdownFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
</androidx.core.widget.NestedScrollView>
<eightbitlab.com.blurview.BlurView
android:id="@+id/markdown_action_bar_blur"
@ -52,30 +70,4 @@
android:layout_height="wrap_content" />
</eightbitlab.com.blurview.BlurView>
<eightbitlab.com.blurview.BlurView
android:id="@+id/chip_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/scrollView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="8dp"
app:singleLine="true">
<!-- Dynamically added -->
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
</eightbitlab.com.blurview.BlurView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -44,7 +44,12 @@
<string name="module_downloads">Downloads:</string>
<string name="module_stars">Stars:</string>
<string name="module_needs_ramdisk">Needs ramdisk</string>
<string name="module_needs_ramdisk_desc">This module need boot ramdisk to be installed</string>
<string name="module_can_change_boot">Can change boot</string>
<string name="module_can_change_boot_desc">This module may change the boot image</string>
<string name="module_min_magisk_chip">This module may change the boot image</string>
<string name="module_min_sdk_chip">This module may change the boot image</string>
<string name="module_max_sdk_chip">This module may change the boot image</string>
<!-- Preference Titles -->
<!-- Note: Lockdown mode used to be called showcase mode -->

View File

@ -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" />
<Preference
app:key="pref_magisk_alt_repo_website"
@ -27,7 +27,7 @@
app:key="pref_androidacy_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" />
<Preference
app:key="pref_androidacy_repo_website"