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

Commit b9b75b0

Browse files
authored
Merge branch 'Fox2Code:master' into master
2 parents b8c1063 + 6442735 commit b9b75b0

26 files changed

+354
-49
lines changed

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ android {
3535
lint {
3636
disable 'MissingTranslation'
3737
}
38+
namespace 'com.fox2code.mmm'
3839
}
3940

4041
aboutLibraries {
@@ -48,8 +49,8 @@ configurations {
4849
dependencies {
4950
// UI
5051
implementation 'androidx.appcompat:appcompat:1.4.1'
51-
implementation 'androidx.emoji2:emoji2:1.0.1'
52-
implementation 'androidx.emoji2:emoji2-views-helper:1.0.1'
52+
implementation 'androidx.emoji2:emoji2:1.1.0'
53+
implementation 'androidx.emoji2:emoji2-views-helper:1.1.0'
5354
implementation 'androidx.preference:preference:1.2.0'
5455
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
5556
implementation 'androidx.recyclerview:recyclerview:1.2.1'

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.fox2code.mmm"
54
tools:ignore="QueryAllPackagesPermission">
65

76
<!-- Wifi is not the only way to get an internet connection -->

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import androidx.annotation.NonNull;
44
import androidx.appcompat.widget.SearchView;
55
import androidx.cardview.widget.CardView;
6+
import androidx.core.content.ContextCompat;
67
import androidx.recyclerview.widget.LinearLayoutManager;
78
import androidx.recyclerview.widget.RecyclerView;
89
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
910

1011
import android.content.res.Configuration;
1112
import android.content.res.Resources;
13+
import android.graphics.Color;
14+
import android.graphics.drawable.ColorDrawable;
1215
import android.os.Build;
1316
import android.os.Bundle;
1417
import android.util.Log;
@@ -47,6 +50,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
4750
private int overScrollInsetBottom;
4851
private TextView actionBarPadding;
4952
private BlurView actionBarBlur;
53+
private ColorDrawable actionBarBackground;
5054
private RecyclerView moduleList;
5155
private CardView searchCard;
5256
private SearchView searchView;
@@ -81,6 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
8185
}
8286
this.actionBarPadding = findViewById(R.id.action_bar_padding);
8387
this.actionBarBlur = findViewById(R.id.action_bar_blur);
88+
this.actionBarBackground = new ColorDrawable(Color.TRANSPARENT);
8489
this.progressIndicator = findViewById(R.id.progress_bar);
8590
this.swipeRefreshLayout = findViewById(R.id.swipe_refresh);
8691
this.swipeRefreshLayoutOrigStartOffset =
@@ -97,11 +102,13 @@ protected void onCreate(Bundle savedInstanceState) {
97102
this.moduleList.setItemViewCacheSize(4); // Default is 2
98103
OverScrollManager.install(this.moduleList, this);
99104
this.swipeRefreshLayout.setOnRefreshListener(this);
105+
this.actionBarBlur.setBackground(this.actionBarBackground);
100106
this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable(
101107
this.getWindow().getDecorView().getBackground())
102108
.setBlurAlgorithm(new RenderScriptBlur(this))
103109
.setBlurRadius(5F).setBlurAutoUpdate(true)
104110
.setHasFixedTransformationMatrix(true);
111+
this.updateBlurState();
105112
this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
106113
@Override
107114
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
@@ -223,6 +230,7 @@ private void updateScreenInsets() {
223230
private void updateScreenInsets(Configuration configuration) {
224231
boolean landscape = configuration.orientation ==
225232
Configuration.ORIENTATION_LANDSCAPE;
233+
int bottomInset = (landscape ? 0 : this.getNavigationBarHeight());
226234
int statusBarHeight = getStatusBarHeight();
227235
int actionBarHeight = getActionBarHeight();
228236
int combinedBarsHeight = statusBarHeight + actionBarHeight;
@@ -231,7 +239,6 @@ private void updateScreenInsets(Configuration configuration) {
231239
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
232240
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
233241
this.moduleViewListBuilder.setHeaderPx(actionBarHeight);
234-
int bottomInset = (landscape ? 0 : this.getNavigationBarHeight());
235242
this.moduleViewListBuilder.setFooterPx(
236243
bottomInset + this.searchCard.getHeight());
237244
this.moduleViewListBuilder.updateInsets();
@@ -240,6 +247,26 @@ private void updateScreenInsets(Configuration configuration) {
240247
this.overScrollInsetBottom = bottomInset;
241248
}
242249

250+
private void updateBlurState() {
251+
if (MainApplication.isBlurEnabled()) {
252+
this.actionBarBlur.setBlurEnabled(true);
253+
int transparent = this.getColorCompat(R.color.transparent);
254+
this.actionBarBackground.setColor(transparent);
255+
} else {
256+
this.actionBarBlur.setBlurEnabled(false);
257+
boolean isLightMode = this.isLightTheme();
258+
int colorOpaque;
259+
try {
260+
colorOpaque = this.getColorCompat(
261+
android.R.attr.windowBackground);
262+
} catch (Resources.NotFoundException e) {
263+
colorOpaque = this.getColorCompat(isLightMode ?
264+
R.color.white : R.color.black);
265+
}
266+
this.actionBarBackground.setColor(colorOpaque);
267+
}
268+
}
269+
243270
@Override
244271
public void refreshUI() {
245272
super.refreshUI();
@@ -251,6 +278,7 @@ public void refreshUI() {
251278
this.searchView.setIconified(true);
252279
this.cardIconifyUpdate();
253280
this.updateScreenInsets();
281+
this.updateBlurState();
254282
this.moduleViewListBuilder.setQuery(null);
255283
Log.i(TAG, "Item After");
256284
this.moduleViewListBuilder.refreshNotificationsUI(this.moduleViewAdapter);

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.res.Configuration;
88
import android.content.res.Resources;
99
import android.graphics.Color;
10+
import android.os.Build;
1011
import android.os.SystemClock;
1112
import android.text.SpannableStringBuilder;
1213
import android.util.Log;
@@ -18,6 +19,7 @@
1819
import androidx.emoji2.text.FontRequestEmojiCompatConfig;
1920

2021
import com.fox2code.mmm.compat.CompatActivity;
22+
import com.fox2code.mmm.compat.CompatApplication;
2123
import com.fox2code.mmm.compat.CompatThemeWrapper;
2224
import com.fox2code.mmm.installer.InstallerInitializer;
2325
import com.fox2code.mmm.utils.GMSProviderInstaller;
@@ -44,7 +46,7 @@
4446
includeAll = true,
4547
grammarLocatorClassName = ".Prism4jGrammarLocator"
4648
)
47-
public class MainApplication extends Application implements CompatActivity.ApplicationCallbacks {
49+
public class MainApplication extends CompatApplication {
4850
private static final String timeFormatString = "dd MMM yyyy"; // Example: 13 july 2001
4951
private static Locale timeFormatLocale =
5052
Resources.getSystem().getConfiguration().locale;
@@ -110,6 +112,11 @@ public static boolean isDohEnabled() {
110112
return getSharedPreferences().getBoolean("pref_dns_over_https", true);
111113
}
112114

115+
public static boolean isBlurEnabled() {
116+
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
117+
getSharedPreferences().getBoolean("pref_enable_blur", false);
118+
}
119+
113120
public static boolean isDeveloper() {
114121
return BuildConfig.DEBUG ||
115122
getSharedPreferences().getBoolean("developer", false);
@@ -164,7 +171,6 @@ public static String formatTime(long timeStamp) {
164171

165172
@StyleRes
166173
private int managerThemeResId = R.style.Theme_MagiskModuleManager;
167-
private Boolean nightModeOverride = null;
168174
private CompatThemeWrapper markwonThemeContext;
169175
private Markwon markwon;
170176

@@ -217,20 +223,7 @@ public void apply(@NonNull String language, @NonNull Prism4j.Syntax syntax,
217223
@SuppressLint("NonConstantResourceId")
218224
public void setManagerThemeResId(@StyleRes int resId) {
219225
this.managerThemeResId = resId;
220-
switch (this.managerThemeResId) {
221-
case R.style.Theme_MagiskModuleManager:
222-
this.nightModeOverride = null;
223-
break;
224-
case R.style.Theme_MagiskModuleManager_Light:
225-
this.nightModeOverride = Boolean.FALSE;
226-
break;
227-
case R.style.Theme_MagiskModuleManager_Dark:
228-
this.nightModeOverride = Boolean.TRUE;
229-
break;
230-
default:
231-
}
232226
if (this.markwonThemeContext != null) {
233-
this.markwonThemeContext.setNightModeOverride(this.nightModeOverride);
234227
this.markwonThemeContext.setTheme(resId);
235228
}
236229
this.markwon = null;
@@ -317,15 +310,15 @@ public void onCreate() {
317310

318311
@Override
319312
public void onCreateCompatActivity(CompatActivity compatActivity) {
320-
compatActivity.setNightModeOverride(this.nightModeOverride);
321-
compatActivity.setForceEnglish(isForceEnglish());
313+
this.setForceEnglish(isForceEnglish());
314+
super.onCreateCompatActivity(compatActivity);
322315
compatActivity.setTheme(this.managerThemeResId);
323316
}
324317

325318
@Override
326319
public void onRefreshUI(CompatActivity compatActivity) {
327-
compatActivity.setNightModeOverride(this.nightModeOverride);
328-
compatActivity.setForceEnglish(isForceEnglish());
320+
this.setForceEnglish(isForceEnglish());
321+
super.onRefreshUI(compatActivity);
329322
compatActivity.setThemeRecreate(this.managerThemeResId);
330323
}
331324

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
105105
webSettings.setUserAgentString(Http.getAndroidacyUA());
106106
webSettings.setDomStorageEnabled(true);
107107
webSettings.setJavaScriptEnabled(true);
108+
webSettings.setAllowFileAccess(false);
108109
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // Make website follow app theme
109110
webSettings.setForceDark(MainApplication.getINSTANCE().isLightTheme() ?
110111
WebSettings.FORCE_DARK_OFF : WebSettings.FORCE_DARK_ON);

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.webkit.JavascriptInterface;
77
import android.widget.Toast;
88

9+
import androidx.annotation.Keep;
10+
911
import com.fox2code.mmm.BuildConfig;
1012
import com.fox2code.mmm.MainApplication;
1113
import com.fox2code.mmm.installer.InstallerInitializer;
@@ -20,6 +22,7 @@
2022
import java.io.IOException;
2123
import java.nio.charset.StandardCharsets;
2224

25+
@Keep
2326
public class AndroidacyWebAPI {
2427
private static final String TAG = "AndroidacyWebAPI";
2528
private final AndroidacyActivity activity;
@@ -106,7 +109,9 @@ public void install(String moduleUrl, String installTitle,String checksum) {
106109
return;
107110
}
108111
if (checksum != null) checksum = checksum.trim();
109-
if (!Hashes.checkSumValid(checksum)) {
112+
if (checksum == null || checksum.isEmpty()) {
113+
Log.w(TAG, "Androidacy WebView didn't provided a checksum!");
114+
} else if (!Hashes.checkSumValid(checksum)) {
110115
this.forceQuitRaw("Androidacy didn't provided a valid checksum");
111116
return;
112117
}

app/src/main/java/com/fox2code/mmm/compat/CompatActivity.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import android.os.Build;
1212
import android.os.Bundle;
1313
import android.util.Log;
14+
import android.util.TypedValue;
1415
import android.view.Menu;
1516
import android.view.MenuItem;
1617
import android.view.View;
1718

19+
import androidx.annotation.AttrRes;
1820
import androidx.annotation.CallSuper;
21+
import androidx.annotation.ColorInt;
22+
import androidx.annotation.ColorRes;
1923
import androidx.annotation.Dimension;
2024
import androidx.annotation.DrawableRes;
2125
import androidx.annotation.NonNull;
@@ -24,12 +28,15 @@
2428
import androidx.annotation.StringRes;
2529
import androidx.annotation.StyleRes;
2630
import androidx.appcompat.app.AppCompatActivity;
31+
import androidx.core.content.ContextCompat;
32+
import androidx.core.graphics.ColorUtils;
2733
import androidx.core.view.WindowInsetsCompat;
2834
import androidx.fragment.app.Fragment;
2935

3036
import com.fox2code.mmm.Constants;
3137
import com.fox2code.mmm.R;
3238

39+
import java.lang.ref.WeakReference;
3340
import java.util.Locale;
3441
import java.util.Objects;
3542

@@ -51,6 +58,7 @@ public boolean onBackPressed(CompatActivity compatActivity) {
5158
}
5259
};
5360

61+
final WeakReference<CompatActivity> selfReference;
5462
private final CompatConfigHelper compatConfigHelper = new CompatConfigHelper(this);
5563
private CompatActivity.OnActivityResultCallback onActivityResultCallback;
5664
private CompatActivity.OnBackPressedCallback onBackPressedCallback;
@@ -65,6 +73,10 @@ public boolean onBackPressed(CompatActivity compatActivity) {
6573
private boolean forceEnglish;
6674
private Boolean nightModeOverride;
6775

76+
public CompatActivity() {
77+
this.selfReference = new WeakReference<>(this);
78+
}
79+
6880
@Override
6981
protected void onCreate(@Nullable Bundle savedInstanceState) {
7082
if (!this.onCreateCalled) {
@@ -326,7 +338,7 @@ protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean fi
326338

327339
@Override
328340
public void onConfigurationChanged(@NonNull Configuration newConfig) {
329-
this.compatConfigHelper.checkResourcesOverrides(this.getTheme(),
341+
this.compatConfigHelper.checkResourcesOverrides(newConfig,
330342
this.forceEnglish, this.nightModeOverride);
331343
super.onConfigurationChanged(newConfig);
332344
}
@@ -409,11 +421,51 @@ public void setNightModeOverride(Boolean nightModeOverride) {
409421
this.checkResourcesOverrides(this.forceEnglish, nightModeOverride);
410422
}
411423

424+
void propagateResourcesOverride(boolean forceEnglish, Boolean nightModeOverride) {
425+
if (this.forceEnglish == forceEnglish &&
426+
this.nightModeOverride == nightModeOverride) return;
427+
this.forceEnglish = forceEnglish;
428+
this.nightModeOverride = nightModeOverride;
429+
this.checkResourcesOverrides(forceEnglish, nightModeOverride);
430+
}
431+
412432
private void checkResourcesOverrides(boolean forceEnglish,Boolean nightModeOverride) {
413433
if (this.isRefreshUi || !this.onCreateCalled) return; // Wait before reload
414434
this.compatConfigHelper.checkResourcesOverrides(forceEnglish, nightModeOverride);
415435
}
416436

437+
public boolean isLightTheme() {
438+
Resources.Theme theme = this.getTheme();
439+
TypedValue typedValue = new TypedValue();
440+
theme.resolveAttribute(R.attr.isLightTheme, typedValue, true);
441+
if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) {
442+
return typedValue.data != 0;
443+
}
444+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
445+
theme.resolveAttribute(android.R.attr.isLightTheme, typedValue, true);
446+
if (typedValue.type == TypedValue.TYPE_INT_BOOLEAN) {
447+
return typedValue.data != 0;
448+
}
449+
}
450+
theme.resolveAttribute(android.R.attr.background, typedValue, true);
451+
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
452+
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
453+
return ColorUtils.calculateLuminance(typedValue.data) > 0.7D;
454+
}
455+
throw new IllegalStateException("Theme is not a valid theme!");
456+
}
457+
458+
@ColorInt
459+
public final int getColorCompat(@ColorRes @AttrRes int color) {
460+
TypedValue typedValue = new TypedValue();
461+
this.getTheme().resolveAttribute(color, typedValue, true);
462+
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
463+
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
464+
return typedValue.data;
465+
}
466+
return ContextCompat.getColor(this, color);
467+
}
468+
417469
public Locale getUserLocale() {
418470
return this.compatConfigHelper.getUserLocale();
419471
}
@@ -435,6 +487,10 @@ public static CompatActivity getCompatActivity(Context context) {
435487
return (CompatActivity) context;
436488
}
437489

490+
public WeakReference<CompatActivity> asWeakReference() {
491+
return this.selfReference;
492+
}
493+
438494
@FunctionalInterface
439495
public interface OnActivityResultCallback {
440496
void onActivityResult(int resultCode, @Nullable Intent data);

0 commit comments

Comments
 (0)