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

Commit 6f7c403

Browse files
committed
Improve layout and top blur, fix light theme.
1 parent 63224b7 commit 6f7c403

File tree

14 files changed

+200
-40
lines changed

14 files changed

+200
-40
lines changed

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
import androidx.annotation.NonNull;
44
import androidx.appcompat.widget.SearchView;
55
import androidx.cardview.widget.CardView;
6-
import androidx.core.view.WindowInsetsCompat;
76
import androidx.recyclerview.widget.LinearLayoutManager;
87
import androidx.recyclerview.widget.RecyclerView;
98
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
109

1110
import android.content.res.Configuration;
1211
import android.content.res.Resources;
13-
import android.graphics.PixelFormat;
1412
import android.os.Build;
1513
import android.os.Bundle;
1614
import android.util.Log;
1715
import android.util.TypedValue;
1816
import android.view.View;
19-
import android.view.ViewGroup;
20-
import android.view.Window;
2117
import android.view.WindowManager;
2218
import android.view.inputmethod.EditorInfo;
2319
import android.widget.TextView;
@@ -36,7 +32,8 @@
3632
import eightbitlab.com.blurview.RenderScriptBlur;
3733

3834
public class MainActivity extends CompatActivity implements SwipeRefreshLayout.OnRefreshListener,
39-
SearchView.OnQueryTextListener, SearchView.OnCloseListener {
35+
SearchView.OnQueryTextListener, SearchView.OnCloseListener,
36+
OverScrollManager.OverScrollHelper {
4037
private static final String TAG = "MainActivity";
4138
private static final int PRECISION = 10000;
4239
public final ModuleViewListBuilder moduleViewListBuilder;
@@ -46,6 +43,8 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
4643
private int swipeRefreshLayoutOrigStartOffset;
4744
private int swipeRefreshLayoutOrigEndOffset;
4845
private long swipeRefreshBlocker = 0;
46+
private int overScrollInsetTop;
47+
private int overScrollInsetBottom;
4948
private TextView actionBarPadding;
5049
private BlurView actionBarBlur;
5150
private RecyclerView moduleList;
@@ -70,9 +69,10 @@ protected void onCreate(Bundle savedInstanceState) {
7069
this.setTitle(R.string.app_name);
7170
this.getWindow().setFlags(
7271
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
73-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
72+
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
7473
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
75-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
74+
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
75+
setActionBarBackground(null);
7676
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
7777
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
7878
layoutParams.layoutInDisplayCutoutMode = // Support cutout in Android 9
@@ -95,6 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {
9595
this.moduleList.setAdapter(this.moduleViewAdapter);
9696
this.moduleList.setLayoutManager(new LinearLayoutManager(this));
9797
this.moduleList.setItemViewCacheSize(4); // Default is 2
98+
OverScrollManager.install(this.moduleList, this);
9899
this.swipeRefreshLayout.setOnRefreshListener(this);
99100
this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable(
100101
this.getWindow().getDecorView().getBackground())
@@ -109,7 +110,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
109110
}
110111
});
111112
this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH |
112-
EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_FORCE_ASCII);
113+
EditorInfo.IME_FLAG_NO_FULLSCREEN);
113114
this.searchView.setOnQueryTextListener(this);
114115
this.searchView.setOnCloseListener(this);
115116
this.searchView.setOnQueryTextFocusChangeListener((v, h) -> {
@@ -230,10 +231,13 @@ private void updateScreenInsets(Configuration configuration) {
230231
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
231232
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
232233
this.moduleViewListBuilder.setHeaderPx(actionBarHeight);
233-
this.moduleViewListBuilder.setFooterPx((landscape ? 0 :
234-
this.getNavigationBarHeight()) + this.searchCard.getHeight());
234+
int bottomInset = (landscape ? 0 : this.getNavigationBarHeight());
235+
this.moduleViewListBuilder.setFooterPx(
236+
bottomInset + this.searchCard.getHeight());
235237
this.moduleViewListBuilder.updateInsets();
236238
this.actionBarBlur.invalidate();
239+
this.overScrollInsetTop = combinedBarsHeight;
240+
this.overScrollInsetBottom = bottomInset;
237241
}
238242

239243
@Override
@@ -360,4 +364,14 @@ public boolean onClose() {
360364
}
361365
return false;
362366
}
367+
368+
@Override
369+
public int getOverScrollInsetTop() {
370+
return this.overScrollInsetTop;
371+
}
372+
373+
@Override
374+
public int getOverScrollInsetBottom() {
375+
return this.overScrollInsetBottom;
376+
}
363377
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter module
103103
this.updating = true;
104104
final ArrayList<ModuleHolder> moduleHolders;
105105
final int newNotificationsLen;
106+
final boolean first;
106107
final ModuleHolder[] headerFooter = new ModuleHolder[2];
107108
try {
108109
synchronized (this.updateLock) {
@@ -120,6 +121,7 @@ public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter module
120121
moduleHolders.add(new ModuleHolder(notificationType));
121122
}
122123
}
124+
first = moduleViewAdapter.moduleHolders.isEmpty();
123125
newNotificationsLen = this.notifications.size() + 1 - special;
124126
EnumSet<ModuleHolder.Type> headerTypes = EnumSet.of(ModuleHolder.Type.SEPARATOR,
125127
ModuleHolder.Type.NOTIFICATION, ModuleHolder.Type.FOOTER);
@@ -170,9 +172,7 @@ public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter module
170172
this.updateInsets = RUNNABLE;
171173
final EnumSet<NotificationType> oldNotifications =
172174
EnumSet.noneOf(NotificationType.class);
173-
boolean isTop = // Force isTop if empty
174-
moduleViewAdapter.moduleHolders.isEmpty() ||
175-
!moduleList.canScrollVertically(-1);
175+
boolean isTop = first || !moduleList.canScrollVertically(-1);
176176
boolean isBottom = !isTop && !moduleList.canScrollVertically(1);
177177
int oldNotificationsLen = 0;
178178
int oldOfflineModulesLen = 0;
@@ -182,7 +182,8 @@ public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter module
182182
oldNotifications.add(notificationType);
183183
if (!notificationType.special)
184184
oldNotificationsLen++;
185-
} else if (moduleHolder.footerPx != -1)
185+
} else if (moduleHolder.footerPx != -1 &&
186+
moduleHolder.filterLevel == 1)
186187
oldNotificationsLen++; // Fix header
187188
if (moduleHolder.separator == ModuleHolder.Type.INSTALLABLE)
188189
break;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.fox2code.mmm;
2+
3+
import android.util.Log;
4+
import android.view.View;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.recyclerview.widget.RecyclerView;
8+
9+
import com.fox2code.mmm.compat.CompatDisplay;
10+
import com.mikepenz.aboutlibraries.LibsConfiguration;
11+
12+
public class OverScrollManager {
13+
private static final String TAG = "OverScrollManager";
14+
15+
public interface OverScrollHelper {
16+
int getOverScrollInsetTop();
17+
18+
int getOverScrollInsetBottom();
19+
}
20+
21+
public static class LibsOverScroll implements LibsConfiguration.LibsUIListener {
22+
private final OverScrollHelper overScrollHelper;
23+
24+
public LibsOverScroll() {
25+
this.overScrollHelper = null;
26+
}
27+
28+
public LibsOverScroll(OverScrollHelper overScrollHelper) {
29+
this.overScrollHelper = overScrollHelper;
30+
}
31+
32+
@NonNull
33+
@Override
34+
public View preOnCreateView(@NonNull View view) {
35+
return view;
36+
}
37+
38+
@NonNull
39+
@Override
40+
public View postOnCreateView(@NonNull View view) {
41+
OverScrollManager.install(
42+
view.findViewById(R.id.cardListView),
43+
this.overScrollHelper);
44+
return view;
45+
}
46+
}
47+
48+
public static void install(final RecyclerView recyclerView) {
49+
OverScrollManager.install(recyclerView, null);
50+
}
51+
52+
public static void install(final RecyclerView recyclerView,
53+
final OverScrollHelper overScrollHelper) {
54+
if (recyclerView == null) return;
55+
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
56+
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
57+
int prevState = -1, lastTranslation = 0;
58+
59+
@Override
60+
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
61+
if (newState == RecyclerView.SCROLL_STATE_IDLE && this.prevState != newState) {
62+
if (recyclerView.getOverScrollMode() != View.OVER_SCROLL_NEVER)
63+
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
64+
final int threshold = CompatDisplay.dpToPixel(16);
65+
final int lastTranslation = this.lastTranslation;
66+
if (lastTranslation < threshold) {
67+
this.prevState = newState;
68+
return;
69+
}
70+
final int insetTop;
71+
final int insetBottom;
72+
if (overScrollHelper == null) {
73+
insetTop = 0;
74+
insetBottom = 0;
75+
} else {
76+
insetTop = overScrollHelper.getOverScrollInsetTop();
77+
insetBottom = overScrollHelper.getOverScrollInsetBottom();
78+
}
79+
Log.d(TAG, "Overscroll: " + lastTranslation + " -> ("
80+
+ insetTop + ", " + insetBottom + ")");
81+
// TODO Overscroll effect for 5.0 (With settings toggle)
82+
}
83+
this.prevState = newState;
84+
}
85+
86+
@Override
87+
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
88+
this.lastTranslation = dy;
89+
}
90+
});
91+
}
92+
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
7878
String title = intent.getStringExtra(Constants.EXTRA_ANDROIDACY_ACTIONBAR_TITLE);
7979
String config = intent.getStringExtra(Constants.EXTRA_ANDROIDACY_ACTIONBAR_CONFIG);
8080
this.setContentView(R.layout.webview);
81+
setActionBarBackground(null);
82+
this.setDisplayHomeAsUpEnabled(true);
83+
if (title == null || title.isEmpty()) {
84+
this.setTitle(title);
85+
} else {
86+
this.setTitle("Androidacy");
87+
}
8188
if (allowInstall || title == null || title.isEmpty()) {
8289
this.hideActionBar();
8390
} else { // Only used for note section
84-
this.setTitle(title);
85-
this.setDisplayHomeAsUpEnabled(true);
8691
if (config != null && !config.isEmpty()) {
8792
String configPkg = IntentHelper.getPackageOfConfig(config);
8893
try {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Context;
66
import android.content.ContextWrapper;
77
import android.content.Intent;
8+
import android.content.res.Configuration;
89
import android.content.res.Resources;
910
import android.graphics.drawable.Drawable;
1011
import android.os.Build;
@@ -17,6 +18,7 @@
1718
import androidx.annotation.CallSuper;
1819
import androidx.annotation.Dimension;
1920
import androidx.annotation.DrawableRes;
21+
import androidx.annotation.NonNull;
2022
import androidx.annotation.Nullable;
2123
import androidx.annotation.Px;
2224
import androidx.annotation.StringRes;
@@ -322,6 +324,13 @@ protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean fi
322324
}
323325
}
324326

327+
@Override
328+
public void onConfigurationChanged(@NonNull Configuration newConfig) {
329+
this.compatConfigHelper.checkResourcesOverrides(this.getTheme(),
330+
this.forceEnglish, this.nightModeOverride);
331+
super.onConfigurationChanged(newConfig);
332+
}
333+
325334
public void setOnBackPressedCallback(OnBackPressedCallback onBackPressedCallback) {
326335
this.onBackPressedCallback = onBackPressedCallback;
327336
}

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
final class CompatConfigHelper {
1515
// ENGLISH like this is an unnatural local, as it doesn't precise the country
1616
// All english locales settable by the user precise the country (Ex: en-US)
17-
private static final Locale english = Locale.ENGLISH;
17+
private static final Locale englishLocale = Locale.ENGLISH;
18+
private static final Object englishLocales =
19+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
20+
new LocaleList(englishLocale) : null;
1821

1922
private final Context context;
23+
private Object userLocales;
2024
private Locale userLocale;
2125

2226
CompatConfigHelper(Context context) {
@@ -32,22 +36,35 @@ void checkResourcesOverrides(boolean forceEnglish,
3236

3337
void checkResourcesOverrides(Resources.Theme theme, boolean forceEnglish,
3438
Boolean nightModeOverride) {
35-
final Resources res = theme.getResources();
36-
final Configuration conf = res.getConfiguration();
39+
Resources res = theme.getResources();
40+
if (this.checkResourcesOverrides(res.getConfiguration(),
41+
forceEnglish, nightModeOverride)) {
42+
res.updateConfiguration(
43+
res.getConfiguration(),
44+
res.getDisplayMetrics());
45+
}
46+
}
47+
48+
boolean checkResourcesOverrides(Configuration conf, boolean forceEnglish,
49+
Boolean nightModeOverride) {
3750
Locale current = conf.locale;
3851
boolean didChange = false;
39-
if (forceEnglish != current.equals(english)) {
52+
boolean wasForceEnglish = englishLocale.equals(current);
53+
if (forceEnglish != wasForceEnglish) {
4054
didChange = true;
4155
if (forceEnglish) {
4256
this.userLocale = conf.locale;
43-
conf.locale = english;
4457
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
45-
conf.setLocales(LocaleList.getEmptyLocaleList());
58+
this.userLocales = conf.getLocales();
59+
}
60+
conf.locale = englishLocale;
61+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
62+
conf.setLocales((LocaleList) englishLocales);
4663
}
4764
} else {
4865
conf.locale = this.userLocale;
4966
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
50-
conf.setLocales(LocaleList.getAdjustedDefault());
67+
conf.setLocales((LocaleList) this.userLocales);
5168
}
5269
}
5370
}
@@ -62,15 +79,16 @@ void checkResourcesOverrides(Resources.Theme theme, boolean forceEnglish,
6279
Configuration.UI_MODE_NIGHT_YES : Configuration.UI_MODE_NIGHT_NO;
6380
conf.uiMode = nightMode | (conf.uiMode & ~Configuration.UI_MODE_NIGHT_MASK);
6481
}
65-
if (didChange) {
66-
res.updateConfiguration(conf, null);
67-
if (!forceEnglish) this.userLocale = null;
82+
if (!forceEnglish && !wasForceEnglish) {
83+
this.userLocale = null;
84+
this.userLocales = null;
6885
}
86+
return didChange;
6987
}
7088

7189
public Locale getUserLocale() {
7290
// Only use cached value if force english
7391
Locale locale = this.context.getResources().getConfiguration().locale;
74-
return english.equals(locale) ? this.userLocale : locale;
92+
return englishLocale.equals(locale) ? this.userLocale : locale;
7593
}
7694
}

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
5757
Log.e(TAG, "Failed to mkdir module cache dir!");
5858
super.onCreate(savedInstanceState);
5959
this.setDisplayHomeAsUpEnabled(true);
60+
setActionBarBackground(null);
6061
this.setOnBackPressedCallback(a -> {
6162
this.canceled = true; return false;
6263
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4343
String config = intent.getExtras()
4444
.getString(Constants.EXTRA_MARKDOWN_CONFIG);
4545
if (title != null && !title.isEmpty()) {
46-
setTitle(title);
46+
this.setTitle(title);
4747
}
48+
setActionBarBackground(null);
4849
this.getWindow().setFlags(
4950
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
5051
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

0 commit comments

Comments
 (0)