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

Commit b8c1063

Browse files
authored
Merge branch 'Fox2Code:master' into master
2 parents 7136803 + 6f7c403 commit b8c1063

18 files changed

+378
-54
lines changed

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

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
import androidx.recyclerview.widget.RecyclerView;
88
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
99

10+
import android.content.res.Configuration;
1011
import android.content.res.Resources;
12+
import android.os.Build;
1113
import android.os.Bundle;
1214
import android.util.Log;
1315
import android.util.TypedValue;
1416
import android.view.View;
1517
import android.view.WindowManager;
1618
import android.view.inputmethod.EditorInfo;
19+
import android.widget.TextView;
1720

1821
import com.fox2code.mmm.compat.CompatActivity;
1922
import com.fox2code.mmm.installer.InstallerInitializer;
@@ -25,15 +28,25 @@
2528
import com.fox2code.mmm.utils.IntentHelper;
2629
import com.google.android.material.progressindicator.LinearProgressIndicator;
2730

31+
import eightbitlab.com.blurview.BlurView;
32+
import eightbitlab.com.blurview.RenderScriptBlur;
33+
2834
public class MainActivity extends CompatActivity implements SwipeRefreshLayout.OnRefreshListener,
29-
SearchView.OnQueryTextListener, SearchView.OnCloseListener {
35+
SearchView.OnQueryTextListener, SearchView.OnCloseListener,
36+
OverScrollManager.OverScrollHelper {
3037
private static final String TAG = "MainActivity";
3138
private static final int PRECISION = 10000;
3239
public final ModuleViewListBuilder moduleViewListBuilder;
3340
public LinearProgressIndicator progressIndicator;
3441
private ModuleViewAdapter moduleViewAdapter;
3542
private SwipeRefreshLayout swipeRefreshLayout;
43+
private int swipeRefreshLayoutOrigStartOffset;
44+
private int swipeRefreshLayoutOrigEndOffset;
3645
private long swipeRefreshBlocker = 0;
46+
private int overScrollInsetTop;
47+
private int overScrollInsetBottom;
48+
private TextView actionBarPadding;
49+
private BlurView actionBarBlur;
3750
private RecyclerView moduleList;
3851
private CardView searchCard;
3952
private SearchView searchView;
@@ -55,10 +68,25 @@ protected void onCreate(Bundle savedInstanceState) {
5568
setContentView(R.layout.activity_main);
5669
this.setTitle(R.string.app_name);
5770
this.getWindow().setFlags(
58-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
59-
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
71+
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
72+
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
73+
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION |
74+
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
75+
setActionBarBackground(null);
76+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
77+
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
78+
layoutParams.layoutInDisplayCutoutMode = // Support cutout in Android 9
79+
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
80+
this.getWindow().setAttributes(layoutParams);
81+
}
82+
this.actionBarPadding = findViewById(R.id.action_bar_padding);
83+
this.actionBarBlur = findViewById(R.id.action_bar_blur);
6084
this.progressIndicator = findViewById(R.id.progress_bar);
6185
this.swipeRefreshLayout = findViewById(R.id.swipe_refresh);
86+
this.swipeRefreshLayoutOrigStartOffset =
87+
this.swipeRefreshLayout.getProgressViewStartOffset();
88+
this.swipeRefreshLayoutOrigEndOffset =
89+
this.swipeRefreshLayout.getProgressViewEndOffset();
6290
this.swipeRefreshBlocker = Long.MAX_VALUE;
6391
this.moduleList = findViewById(R.id.module_list);
6492
this.searchCard = findViewById(R.id.search_card);
@@ -67,7 +95,13 @@ protected void onCreate(Bundle savedInstanceState) {
6795
this.moduleList.setAdapter(this.moduleViewAdapter);
6896
this.moduleList.setLayoutManager(new LinearLayoutManager(this));
6997
this.moduleList.setItemViewCacheSize(4); // Default is 2
98+
OverScrollManager.install(this.moduleList, this);
7099
this.swipeRefreshLayout.setOnRefreshListener(this);
100+
this.actionBarBlur.setupWith(this.moduleList).setFrameClearDrawable(
101+
this.getWindow().getDecorView().getBackground())
102+
.setBlurAlgorithm(new RenderScriptBlur(this))
103+
.setBlurRadius(5F).setBlurAutoUpdate(true)
104+
.setHasFixedTransformationMatrix(true);
71105
this.moduleList.addOnScrollListener(new RecyclerView.OnScrollListener() {
72106
@Override
73107
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
@@ -76,7 +110,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
76110
}
77111
});
78112
this.searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH |
79-
EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_FORCE_ASCII);
113+
EditorInfo.IME_FLAG_NO_FULLSCREEN);
80114
this.searchView.setOnQueryTextListener(this);
81115
this.searchView.setOnCloseListener(this);
82116
this.searchView.setOnQueryTextFocusChangeListener((v, h) -> {
@@ -121,6 +155,8 @@ public void commonNext() {
121155
runOnUiThread(() -> {
122156
progressIndicator.setIndeterminate(false);
123157
progressIndicator.setMax(PRECISION);
158+
// Fix insets not being accounted for correctly
159+
updateScreenInsets(getResources().getConfiguration());
124160
});
125161
Log.i(TAG, "Scanning for modules!");
126162
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
@@ -158,6 +194,7 @@ public void commonNext() {
158194
progressIndicator.setProgressCompat(PRECISION, true);
159195
progressIndicator.setVisibility(View.GONE);
160196
searchView.setEnabled(true);
197+
setActionBarBackground(null);
161198
});
162199
moduleViewListBuilder.appendRemoteModules();
163200
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
@@ -175,12 +212,32 @@ private void cardIconifyUpdate() {
175212
TypedValue value = new TypedValue();
176213
theme.resolveAttribute(backgroundAttr, value, true);
177214
this.searchCard.setCardBackgroundColor(value.data);
178-
this.searchCard.setAlpha(iconified ? 0.70F : 1F);
215+
this.searchCard.setAlpha(iconified ? 0.80F : 1F);
179216
}
180217

181218
private void updateScreenInsets() {
219+
this.runOnUiThread(() -> this.updateScreenInsets(
220+
this.getResources().getConfiguration()));
221+
}
222+
223+
private void updateScreenInsets(Configuration configuration) {
224+
boolean landscape = configuration.orientation ==
225+
Configuration.ORIENTATION_LANDSCAPE;
226+
int statusBarHeight = getStatusBarHeight();
227+
int actionBarHeight = getActionBarHeight();
228+
int combinedBarsHeight = statusBarHeight + actionBarHeight;
229+
this.actionBarPadding.setMinHeight(combinedBarsHeight);
230+
this.swipeRefreshLayout.setProgressViewOffset(false,
231+
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
232+
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
233+
this.moduleViewListBuilder.setHeaderPx(actionBarHeight);
234+
int bottomInset = (landscape ? 0 : this.getNavigationBarHeight());
182235
this.moduleViewListBuilder.setFooterPx(
183-
this.getNavigationBarHeight() + this.searchCard.getHeight());
236+
bottomInset + this.searchCard.getHeight());
237+
this.moduleViewListBuilder.updateInsets();
238+
this.actionBarBlur.invalidate();
239+
this.overScrollInsetTop = combinedBarsHeight;
240+
this.overScrollInsetBottom = bottomInset;
184241
}
185242

186243
@Override
@@ -234,6 +291,12 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
234291
this.initMode = false;
235292
}
236293

294+
@Override
295+
public void onConfigurationChanged(@NonNull Configuration newConfig) {
296+
this.updateScreenInsets(newConfig);
297+
super.onConfigurationChanged(newConfig);
298+
}
299+
237300
@Override
238301
public void onRefresh() {
239302
if (this.swipeRefreshBlocker > System.currentTimeMillis() ||
@@ -301,4 +364,14 @@ public boolean onClose() {
301364
}
302365
return false;
303366
}
367+
368+
@Override
369+
public int getOverScrollInsetTop() {
370+
return this.overScrollInsetTop;
371+
}
372+
373+
@Override
374+
public int getOverScrollInsetBottom() {
375+
return this.overScrollInsetBottom;
376+
}
304377
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class ModuleHolder implements Comparable<ModuleHolder> {
2424
public final String moduleId;
2525
public final NotificationType notificationType;
2626
public final Type separator;
27-
public final int footerPx;
27+
public int footerPx;
2828
public View.OnClickListener onClickListener;
2929
public LocalModuleInfo moduleInfo;
3030
public RepoModule repoModule;
@@ -34,32 +34,33 @@ public ModuleHolder(String moduleId) {
3434
this.moduleId = Objects.requireNonNull(moduleId);
3535
this.notificationType = null;
3636
this.separator = null;
37-
this.footerPx = 0;
37+
this.footerPx = -1;
3838
}
3939

4040
public ModuleHolder(NotificationType notificationType) {
4141
this.moduleId = "";
4242
this.notificationType = Objects.requireNonNull(notificationType);
4343
this.separator = null;
44-
this.footerPx = 0;
44+
this.footerPx = -1;
4545
}
4646

4747
public ModuleHolder(Type separator) {
4848
this.moduleId = "";
4949
this.notificationType = null;
5050
this.separator = separator;
51-
this.footerPx = 0;
51+
this.footerPx = -1;
5252
}
5353

54-
public ModuleHolder(int footerPx) {
54+
public ModuleHolder(int footerPx,boolean header) {
5555
this.moduleId = "";
5656
this.notificationType = null;
5757
this.separator = null;
5858
this.footerPx = footerPx;
59+
this.filterLevel = header ? 1 : 0;
5960
}
6061

6162
public boolean isModuleHolder() {
62-
return this.notificationType == null && this.separator == null && this.footerPx == 0;
63+
return this.notificationType == null && this.separator == null && this.footerPx == -1;
6364
}
6465

6566
public ModuleInfo getMainModuleInfo() {
@@ -115,7 +116,7 @@ public boolean hasFlag(int flag) {
115116
}
116117

117118
public Type getType() {
118-
if (this.footerPx != 0) {
119+
if (this.footerPx != -1) {
119120
return Type.FOOTER;
120121
} else if (this.separator != null) {
121122
return Type.SEPARATOR;
@@ -145,7 +146,7 @@ public Type getCompareType(Type type) {
145146

146147
public boolean shouldRemove() {
147148
return this.notificationType != null ? this.notificationType.shouldRemove() :
148-
this.footerPx == 0 && this.moduleInfo == null &&
149+
this.footerPx == -1 && this.moduleInfo == null &&
149150
(this.repoModule == null || !this.repoModule.repoData.isEnabled() ||
150151
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
151152
!MainApplication.isDisableLowQualityModuleFilter()));
@@ -207,6 +208,7 @@ public int compareTo(ModuleHolder o) {
207208
}
208209

209210
public enum Type implements Comparator<ModuleHolder> {
211+
HEADER(R.string.loading, false, false),
210212
SEPARATOR(R.string.loading, false, false) {
211213
@Override
212214
@SuppressWarnings("ConstantConditions")

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.topjohnwu.superuser.internal.UiThreadHandler;
2727

2828
import java.util.ArrayList;
29+
import java.util.Objects;
2930

3031
public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdapter.ViewHolder> {
3132
private static final boolean DEBUG = false;
@@ -182,14 +183,16 @@ public boolean update(ModuleHolder moduleHolder) {
182183
if (localModuleInfo == null || moduleInfo.versionCode >
183184
localModuleInfo.updateVersionCode) {
184185
this.creditText.setText((localModuleInfo == null ||
185-
moduleInfo.version.equals(localModuleInfo.version) ?
186+
Objects.equals(moduleInfo.version, localModuleInfo.version) ?
186187
moduleInfo.version : localModuleInfo.version + " (" +
187188
this.getString(R.string.module_last_update) +
188189
moduleInfo.version + ")") + " " +
189190
this.getString(R.string.module_by) + " " + moduleInfo.author);
190191
} else {
191192
this.creditText.setText(localModuleInfo.version + (
192-
localModuleInfo.version.equals(localModuleInfo.updateVersion) ?
193+
(localModuleInfo.updateVersion != null &&
194+
Objects.equals(localModuleInfo.version,
195+
localModuleInfo.updateVersion)) ?
193196
"" : " (" + this.getString(R.string.module_last_update) +
194197
localModuleInfo.updateVersion + ")") + " " +
195198
this.getString(R.string.module_by) + " " + localModuleInfo.author);

0 commit comments

Comments
 (0)