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

Commit fed16d0

Browse files
committed
Rework markdown activity, make module chip nicer and translatable!
1 parent 7b60a51 commit fed16d0

File tree

7 files changed

+125
-112
lines changed

7 files changed

+125
-112
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ public static boolean isBlurEnabled() {
126126
getSharedPreferences().getBoolean("pref_enable_blur", false);
127127
}
128128

129-
public static boolean isChipsDisabled() {
130-
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
131-
getSharedPreferences().getBoolean("pref_disable_chips", false);
132-
}
133-
134129
public static boolean isDeveloper() {
135130
return BuildConfig.DEBUG ||
136131
getSharedPreferences().getBoolean("developer", false);

app/src/main/java/com/fox2code/mmm/markdown/MarkdownActivity.java

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ public class MarkdownActivity extends CompatActivity {
5555
private static final String[] variants = new String[]{
5656
"readme.md", "README.MD", ".github/README.md"
5757
};
58-
private BlurView chipHolder;
5958
private TextView actionBarPadding;
59+
private ColorDrawable actionBarBackground;
6060
private BlurView actionBarBlur;
61-
private ColorDrawable anyBarBackground;
62-
private ScrollView scrollView;
63-
private LinearLayout md_layout;
61+
private TextView header;
62+
private TextView footer;
6463

6564
private static byte[] getRawMarkdown(String url) throws IOException {
6665
String newUrl = redirects.get(url);
@@ -138,40 +137,23 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
138137
setContentView(R.layout.markdown_view);
139138
final ViewGroup markdownBackground = findViewById(R.id.markdownBackground);
140139
final TextView textView = findViewById(R.id.markdownView);
141-
this.chipHolder = findViewById(R.id.chip_holder);
142-
this.anyBarBackground = new ColorDrawable(Color.TRANSPARENT);
143140
this.actionBarPadding = findViewById(R.id.markdown_action_bar_padding);
141+
this.actionBarBackground = new ColorDrawable(Color.TRANSPARENT);
144142
this.actionBarBlur = findViewById(R.id.markdown_action_bar_blur);
145-
this.scrollView = findViewById(R.id.scrollView2);
146-
this.md_layout = findViewById(R.id.md_layout);
147-
final TextView footer = findViewById(R.id.markdownFooter);
148-
UiThreadHandler.handler.postDelayed(() -> // Fix footer height
149-
footer.setMinHeight(this.getNavigationBarHeight()), 1L);
150-
this.actionBarBlur.setBackground(this.anyBarBackground);
151-
this.setupBlurView(this.chipHolder, markdownBackground, this.anyBarBackground);
152-
this.setupBlurView(this.actionBarBlur, markdownBackground, this.anyBarBackground);
153-
this.updateScreenInsets();
154-
this.updateUI();
143+
this.header = findViewById(R.id.markdownHeader);
144+
this.footer = findViewById(R.id.markdownFooter);
145+
this.actionBarBlur.setBackground(this.actionBarBackground);
146+
this.setupBlurView(this.actionBarBlur, markdownBackground);
147+
UiThreadHandler.handler.post(() -> // Fix header/footer height
148+
this.updateScreenInsets(this.getResources().getConfiguration()));
155149

156150
// Really bad created (MSG by Der_Googler)
157-
if (MainApplication.isChipsDisabled()) {
158-
this.chipHolder.setVisibility(View.GONE);
159-
} else {
160-
this.chipHolder.setPadding(0,0,0,this.getNavigationBarHeight());
161-
// set "message" to null to disable dialog
162-
this.setChip(change_boot,
163-
getString(R.string.module_can_change_boot),
164-
"This module may change the boot image");
165-
this.setChip(needs_ramdisk,
166-
getString(R.string.module_needs_ramdisk),
167-
"This module need boot ramdisk to be installed");
168-
this.setChip(min_magisk, "Min. Magisk \"" + min_magisk + "\"",
169-
null);
170-
this.setChip(min_api, "Min. Android " + min_api,
171-
null);
172-
this.setChip(max_api, "Max. Android " + max_api,
173-
null);
174-
}
151+
// set "message" to null to disable dialog
152+
if (change_boot) this.addChip(MarkdownChip.CHANGE_BOOT);
153+
if (needs_ramdisk) this.addChip(MarkdownChip.NEED_RAMDISK);
154+
if (min_magisk != 0) this.addChip(MarkdownChip.MIN_MAGISK, String.valueOf(min_magisk));
155+
if (min_api != 0) this.addChip(MarkdownChip.MIN_SDK, parseAndroidVersion(min_api));
156+
if (max_api != 0) this.addChip(MarkdownChip.MAX_SDK, parseAndroidVersion(max_api));
175157

176158
new Thread(() -> {
177159
try {
@@ -201,15 +183,37 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
201183
}, "Markdown load thread").start();
202184
}
203185

204-
private void setupBlurView(BlurView view, ViewGroup setupWith, ColorDrawable background) {
205-
view.setBackground(background);
186+
private void setupBlurView(BlurView view, ViewGroup setupWith) {
206187
view.setupWith(setupWith).setFrameClearDrawable(
207188
this.getWindow().getDecorView().getBackground())
208189
.setBlurAlgorithm(new RenderScriptBlur(this))
209190
.setBlurRadius(4F).setBlurAutoUpdate(true)
210191
.setHasFixedTransformationMatrix(true);
192+
this.updateBlurState();
211193
}
212194

195+
private void updateBlurState() {
196+
boolean isLightMode = this.isLightTheme();
197+
int colorBackground;
198+
try {
199+
colorBackground = this.getColorCompat(
200+
android.R.attr.windowBackground);
201+
} catch (Resources.NotFoundException e) {
202+
colorBackground = this.getColorCompat(isLightMode ?
203+
R.color.white : R.color.black);
204+
}
205+
if (MainApplication.isBlurEnabled()) {
206+
this.actionBarBlur.setBlurEnabled(true);
207+
this.actionBarBackground.setColor(ColorUtils
208+
.setAlphaComponent(colorBackground, 0x02));
209+
this.actionBarBackground.setColor(Color.TRANSPARENT);
210+
} else {
211+
this.actionBarBlur.setBlurEnabled(false);
212+
this.actionBarBlur.setOverlayColor(Color.TRANSPARENT);
213+
this.actionBarBackground.setColor(colorBackground);
214+
}
215+
}
216+
213217
private void updateScreenInsets() {
214218
this.runOnUiThread(() -> this.updateScreenInsets(
215219
this.getResources().getConfiguration()));
@@ -223,46 +227,33 @@ private void updateScreenInsets(Configuration configuration) {
223227
int actionBarHeight = getActionBarHeight();
224228
int combinedBarsHeight = statusBarHeight + actionBarHeight;
225229
this.actionBarPadding.setMinHeight(combinedBarsHeight);
230+
this.header.setMinHeight(combinedBarsHeight);
231+
this.footer.setMinHeight(bottomInset);
226232
//this.actionBarBlur.invalidate();
227233
}
228234

229-
private void updateUI() {
230-
boolean isLightMode = this.isLightTheme();
231-
int colorBackground;
232-
try {
233-
colorBackground = this.getColorCompat(
234-
android.R.attr.windowBackground);
235-
} catch (Resources.NotFoundException e) {
236-
colorBackground = this.getColorCompat(isLightMode ?
237-
R.color.white : R.color.black);
238-
}
239-
this.md_layout.setPadding(0,this.getActionBarHeight(this) + this.getStatusBarHeight(),0,this.getNavigationBarHeight() + 56);
240-
if (MainApplication.isBlurEnabled()) {
241-
this.actionBarBlur.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, this.getActionBarHeight(this) + this.getStatusBarHeight()));
242-
this.chipHolder.setBlurEnabled(true);
243-
this.anyBarBackground.setColor(ColorUtils
244-
.setAlphaComponent(colorBackground, 0x02));
245-
this.anyBarBackground.setColor(Color.TRANSPARENT);
246-
this.actionBarBlur.setBlurEnabled(true);
247-
} else {
248-
this.chipHolder.setBlurEnabled(false);
249-
this.chipHolder.setOverlayColor(Color.TRANSPARENT);
250-
this.anyBarBackground.setColor(colorBackground);
251-
this.actionBarBlur.setBlurEnabled(false);
252-
this.actionBarBlur.setOverlayColor(Color.TRANSPARENT);
253-
}
235+
@Override
236+
public void refreshUI() {
237+
super.refreshUI();
238+
this.updateScreenInsets();
239+
this.updateBlurState();
254240
}
255241

256-
private void setChip(boolean bool, String title, String message) {
257-
if (bool) {
258-
this.makeChip(title, message);
259-
}
242+
243+
private void addChip(MarkdownChip markdownChip) {
244+
this.makeChip(this.getString(markdownChip.title),
245+
markdownChip.desc == 0 ? null : this.getString(markdownChip.desc));
260246
}
261247

262-
private void setChip(int i, String title, String message) {
263-
if (i != 0) {
264-
this.makeChip(title, message);
248+
private void addChip(MarkdownChip markdownChip, String extra) {
249+
String title = this.getString(markdownChip.title);
250+
if (title.contains("%s")) {
251+
title = title.replace("%s", extra);
252+
} else {
253+
title = title + " " + extra;
265254
}
255+
this.makeChip(title, markdownChip.desc == 0 ?
256+
null : this.getString(markdownChip.desc));
266257
}
267258

268259
private void makeChip(String title, String message) {
@@ -288,22 +279,32 @@ private void makeChip(String title, String message) {
288279

289280
private String parseAndroidVersion(int version) {
290281
switch (version) {
282+
case Build.VERSION_CODES.JELLY_BEAN:
283+
return "4.1 JellyBean";
284+
case Build.VERSION_CODES.JELLY_BEAN_MR1:
285+
return "4.2 JellyBean";
286+
case Build.VERSION_CODES.JELLY_BEAN_MR2:
287+
return "4.3 JellyBean";
288+
case Build.VERSION_CODES.KITKAT:
289+
return "4.4 KitKat";
290+
case Build.VERSION_CODES.KITKAT_WATCH:
291+
return "4.4 KitKat Watch";
291292
case Build.VERSION_CODES.LOLLIPOP:
292-
return "5.0";
293+
return "5.0 Lollipop";
293294
case Build.VERSION_CODES.LOLLIPOP_MR1:
294-
return "5.1";
295+
return "5.1 Lollipop";
295296
case Build.VERSION_CODES.M:
296-
return "6.0";
297+
return "6.0 Marshmallow";
297298
case Build.VERSION_CODES.N:
298-
return "7.0";
299+
return "7.0 Nougat";
299300
case Build.VERSION_CODES.N_MR1:
300-
return "7.1";
301+
return "7.1 Nougat";
301302
case Build.VERSION_CODES.O:
302-
return "8.0";
303+
return "8.0 Oreo";
303304
case Build.VERSION_CODES.O_MR1:
304-
return "8.1";
305+
return "8.1 Oreo";
305306
case Build.VERSION_CODES.P:
306-
return "9.0 (P)";
307+
return "9.0 Pie";
307308
case Build.VERSION_CODES.Q:
308309
return "10 (Q)";
309310
case Build.VERSION_CODES.R:
@@ -313,7 +314,7 @@ private String parseAndroidVersion(int version) {
313314
case Build.VERSION_CODES.S_V2:
314315
return "12L";
315316
default:
316-
return "false";
317+
return "Sdk: " + version;
317318
}
318319
}
319320

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fox2code.mmm.markdown;
2+
3+
import androidx.annotation.StringRes;
4+
5+
import com.fox2code.mmm.R;
6+
7+
public enum MarkdownChip {
8+
CHANGE_BOOT(R.string.module_can_change_boot, R.string.module_can_change_boot_desc),
9+
NEED_RAMDISK(R.string.module_needs_ramdisk, R.string.module_needs_ramdisk_desc),
10+
MIN_MAGISK(R.string.module_min_magisk_chip, 0),
11+
MIN_SDK(R.string.module_min_sdk_chip, 0),
12+
MAX_SDK(R.string.module_max_sdk_chip, 0);
13+
@StringRes public final int title, desc;
14+
15+
MarkdownChip(@StringRes int title,@StringRes int desc) {
16+
this.title = title;
17+
this.desc = desc;
18+
}
19+
}

app/src/main/java/com/fox2code/mmm/utils/PropUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class PropUtils {
5353
moduleConfigsFallbacks.put("xposed", "de.robv.android.xposed.installer");
5454
moduleConfigsFallbacks.put("substratum", "projekt.substratum");
5555
// minApi is the minimum android version required to use the module
56+
moduleMinApiFallbacks.put("HideNavBar", Build.VERSION_CODES.Q);
5657
moduleMinApiFallbacks.put("riru_ifw_enhance", Build.VERSION_CODES.O);
5758
moduleMinApiFallbacks.put("zygisk_ifw_enhance", Build.VERSION_CODES.O);
5859
moduleMinApiFallbacks.put("riru_edxposed", Build.VERSION_CODES.O);

app/src/main/res/layout/markdown_view.xml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
app:fitsSystemWindowsInsets="left|right"
99
tools:context=".markdown.MarkdownActivity">
1010

11-
<ScrollView
11+
<androidx.core.widget.NestedScrollView
1212
android:id="@+id/scrollView2"
1313
android:layout_width="0dp"
1414
android:layout_height="0dp"
@@ -24,20 +24,38 @@
2424
android:layout_height="wrap_content"
2525
android:orientation="vertical">
2626

27+
<TextView
28+
android:id="@+id/markdownHeader"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:text="" />
32+
2733
<TextView
2834
android:id="@+id/markdownView"
2935
android:layout_width="match_parent"
3036
android:layout_height="wrap_content"
3137
android:layout_margin="@dimen/markdown_border_content"
3238
android:text="@string/loading" />
3339

40+
<com.google.android.material.chip.ChipGroup
41+
android:id="@+id/chip_group_holder"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:layout_gravity="end"
45+
android:padding="8dp"
46+
app:singleLine="true">
47+
48+
<!-- Dynamically added -->
49+
50+
</com.google.android.material.chip.ChipGroup>
51+
3452
<TextView
3553
android:id="@+id/markdownFooter"
3654
android:layout_width="match_parent"
3755
android:layout_height="wrap_content"
3856
android:text="" />
3957
</LinearLayout>
40-
</ScrollView>
58+
</androidx.core.widget.NestedScrollView>
4159

4260
<eightbitlab.com.blurview.BlurView
4361
android:id="@+id/markdown_action_bar_blur"
@@ -52,30 +70,4 @@
5270
android:layout_height="wrap_content" />
5371
</eightbitlab.com.blurview.BlurView>
5472

55-
<eightbitlab.com.blurview.BlurView
56-
android:id="@+id/chip_holder"
57-
android:layout_width="0dp"
58-
android:layout_height="wrap_content"
59-
app:layout_constraintBottom_toBottomOf="@id/scrollView2"
60-
app:layout_constraintEnd_toEndOf="parent"
61-
app:layout_constraintStart_toStartOf="parent">
62-
63-
<HorizontalScrollView
64-
android:layout_width="match_parent"
65-
android:layout_height="wrap_content">
66-
67-
<com.google.android.material.chip.ChipGroup
68-
android:id="@+id/chip_group_holder"
69-
android:layout_width="wrap_content"
70-
android:layout_height="wrap_content"
71-
android:layout_gravity="end"
72-
android:padding="8dp"
73-
app:singleLine="true">
74-
75-
<!-- Dynamically added -->
76-
77-
</com.google.android.material.chip.ChipGroup>
78-
</HorizontalScrollView>
79-
</eightbitlab.com.blurview.BlurView>
80-
8173
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
<string name="module_downloads">Downloads:</string>
4545
<string name="module_stars">Stars:</string>
4646
<string name="module_needs_ramdisk">Needs ramdisk</string>
47+
<string name="module_needs_ramdisk_desc">This module need boot ramdisk to be installed</string>
4748
<string name="module_can_change_boot">Can change boot</string>
49+
<string name="module_can_change_boot_desc">This module may change the boot image</string>
50+
<string name="module_min_magisk_chip">This module may change the boot image</string>
51+
<string name="module_min_sdk_chip">This module may change the boot image</string>
52+
<string name="module_max_sdk_chip">This module may change the boot image</string>
4853

4954
<!-- Preference Titles -->
5055
<!-- Note: Lockdown mode used to be called showcase mode -->

app/src/main/res/xml/repo_preferences.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
app:key="pref_magisk_alt_repo_enabled"
88
app:icon="@drawable/ic_baseline_extension_24"
99
app:switchTextOn="@string/repo_enabled"
10-
app:switchTextOff="@string/repo_enabled"
10+
app:switchTextOff="@string/repo_disabled"
1111
app:singleLineTitle="false" />
1212
<Preference
1313
app:key="pref_magisk_alt_repo_website"
@@ -27,7 +27,7 @@
2727
app:key="pref_androidacy_repo_enabled"
2828
app:icon="@drawable/ic_baseline_extension_24"
2929
app:switchTextOn="@string/repo_enabled"
30-
app:switchTextOff="@string/repo_enabled"
30+
app:switchTextOff="@string/repo_disabled"
3131
app:singleLineTitle="false" />
3232
<Preference
3333
app:key="pref_androidacy_repo_website"

0 commit comments

Comments
 (0)