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

Commit 7cca863

Browse files
committed
Update 0.2.0-pre3
1 parent 5f2f43c commit 7cca863

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.fox2code.mmm"
1111
minSdk 21
1212
targetSdk 30
13-
versionCode 7
14-
versionName "0.2.0-pre2"
13+
versionCode 8
14+
versionName "0.2.0-pre3"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.view.View;
1515
import android.view.inputmethod.EditorInfo;
1616
import android.widget.LinearLayout;
17+
import android.widget.TextView;
1718

1819
import com.fox2code.mmm.compat.CompatActivity;
1920
import com.fox2code.mmm.installer.InstallerInitializer;
@@ -32,7 +33,6 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
3233
private ModuleViewAdapter moduleViewAdapter;
3334
private SwipeRefreshLayout swipeRefreshLayout;
3435
private RecyclerView moduleList;
35-
private LinearLayout searchContainer;
3636
private CardView searchCard;
3737
private SearchView searchView;
3838
private boolean initMode;
@@ -55,7 +55,6 @@ protected void onCreate(Bundle savedInstanceState) {
5555
this.progressIndicator = findViewById(R.id.progress_bar);
5656
this.swipeRefreshLayout = findViewById(R.id.swipe_refresh);
5757
this.moduleList = findViewById(R.id.module_list);
58-
this.searchContainer = findViewById(R.id.search_container);
5958
this.searchCard = findViewById(R.id.search_card);
6059
this.searchView = findViewById(R.id.search_bar);
6160
this.moduleViewAdapter = new ModuleViewAdapter();
@@ -134,7 +133,6 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
134133
}
135134

136135
private void cardIconifyUpdate() {
137-
this.moduleViewListBuilder.setFooterPx(this.searchContainer.getHeight());
138136
boolean iconified = this.searchView.isIconified();
139137
int backgroundAttr = iconified ?
140138
R.attr.colorSecondary : R.attr.colorPrimarySurface;
@@ -201,7 +199,6 @@ public void onRefresh() {
201199
}
202200
this.progressIndicator.setVisibility(View.VISIBLE);
203201
this.progressIndicator.setProgressCompat(0, false);
204-
this.moduleViewListBuilder.setFooterPx(this.searchContainer.getHeight());
205202
// this.swipeRefreshLayout.setRefreshing(true); ??
206203
new Thread(() -> {
207204
RepoManager.getINSTANCE().update(value -> runOnUiThread(() ->

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.pm.PackageManager;
55
import android.util.Log;
66

7+
import androidx.annotation.NonNull;
78
import androidx.annotation.StringRes;
89

910
import com.fox2code.mmm.installer.InstallerInitializer;
@@ -54,7 +55,7 @@ public ModuleHolder(int footerPx) {
5455
}
5556

5657
public boolean isModuleHolder() {
57-
return this.notificationType == null && this.separator == null;
58+
return this.notificationType == null && this.separator == null && this.footerPx == 0;
5859
}
5960

6061
public ModuleInfo getMainModuleInfo() {
@@ -124,7 +125,7 @@ public Type getCompareType(Type type) {
124125

125126
public boolean shouldRemove() {
126127
return this.notificationType != null ? this.notificationType.shouldRemove() :
127-
this.moduleInfo == null && (this.repoModule == null);
128+
this.footerPx == 0 && this.moduleInfo == null && this.repoModule == null;
128129
}
129130

130131
public void getButtons(Context context, List<ActionButtonType> buttonTypeList, boolean showcaseMode) {
@@ -230,6 +231,7 @@ public int compare(ModuleHolder o1, ModuleHolder o2) {
230231
}
231232
}
232233

234+
@NonNull
233235
@Override
234236
public String toString() {
235237
return "ModuleHolder{" +

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class ModuleViewListBuilder {
2929
private final Activity activity;
3030
@NonNull
3131
private String query = "";
32-
private int footerPx;
3332
private boolean noUpdate;
3433

3534
public ModuleViewListBuilder(Activity activity) {
@@ -142,9 +141,6 @@ public void applyTo(RecyclerView moduleList, ModuleViewAdapter moduleViewAdapter
142141
this.activity.runOnUiThread(() -> {
143142
final EnumSet<NotificationType> oldNotifications =
144143
EnumSet.noneOf(NotificationType.class);
145-
if (this.footerPx != 0) {
146-
moduleHolders.add(new ModuleHolder(this.footerPx));
147-
}
148144
boolean isTop = !moduleList.canScrollVertically(-1);
149145
boolean isBottom = !isTop && !moduleList.canScrollVertically(1);
150146
int oldNotificationsLen = 0;
@@ -194,10 +190,6 @@ public void applyTo(RecyclerView moduleList, ModuleViewAdapter moduleViewAdapter
194190
});
195191
}
196192

197-
public void setFooterPx(int footerPx) {
198-
this.footerPx = Math.max(footerPx, 0);
199-
}
200-
201193
private boolean matchFilter(ModuleHolder moduleHolder) {
202194
if (this.query.isEmpty()) return true;
203195
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();

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

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import java.io.IOException;
1212
import java.io.InputStream;
1313
import java.net.InetAddress;
14+
import java.net.Proxy;
1415
import java.net.UnknownHostException;
16+
import java.util.Arrays;
1517
import java.util.Collections;
1618
import java.util.HashMap;
1719
import java.util.Iterator;
@@ -22,6 +24,7 @@
2224
import okhttp3.Cache;
2325
import okhttp3.Cookie;
2426
import okhttp3.CookieJar;
27+
import okhttp3.Dns;
2528
import okhttp3.HttpUrl;
2629
import okhttp3.OkHttpClient;
2730
import okhttp3.Request;
@@ -31,40 +34,54 @@
3134

3235
public class Http {
3336
private static final OkHttpClient httpClient;
34-
private static final OkHttpClient httpClientCachable;
37+
private static final OkHttpClient httpClientWithCache;
3538

3639
static {
3740
OkHttpClient.Builder httpclientBuilder = new OkHttpClient.Builder();
38-
httpclientBuilder.connectTimeout(11, TimeUnit.SECONDS);
41+
// Default is 10, extend it a bit for slow mobile connections.
42+
httpclientBuilder.connectTimeout(15, TimeUnit.SECONDS);
43+
httpclientBuilder.writeTimeout(15, TimeUnit.SECONDS);
44+
httpclientBuilder.readTimeout(15, TimeUnit.SECONDS);
45+
httpclientBuilder.proxy(Proxy.NO_PROXY); // Do not use system proxy
46+
Dns dns = Dns.SYSTEM;
3947
try {
48+
InetAddress[] cloudflareBootstrap = new InetAddress[] {
49+
InetAddress.getByName("162.159.36.1"),
50+
InetAddress.getByName("162.159.46.1"),
51+
InetAddress.getByName("1.1.1.1"),
52+
InetAddress.getByName("1.0.0.1"),
53+
InetAddress.getByName("162.159.132.53"),
54+
InetAddress.getByName("2606:4700:4700::1111"),
55+
InetAddress.getByName("2606:4700:4700::1001"),
56+
InetAddress.getByName("2606:4700:4700::0064"),
57+
InetAddress.getByName("2606:4700:4700::6400")
58+
};
59+
dns = s -> {
60+
if ("cloudflare-dns.com".equals(s)) {
61+
return Arrays.asList(cloudflareBootstrap);
62+
}
63+
return Dns.SYSTEM.lookup(s);
64+
};
65+
httpclientBuilder.dns(dns);
4066
httpclientBuilder.cookieJar(new CDNCookieJar());
41-
httpclientBuilder.dns(new DnsOverHttps.Builder().client(httpclientBuilder.build()).url(
67+
dns = new DnsOverHttps.Builder().client(httpclientBuilder.build()).url(
4268
Objects.requireNonNull(HttpUrl.parse("https://cloudflare-dns.com/dns-query")))
43-
.bootstrapDnsHosts(
44-
InetAddress.getByName("162.159.36.1"),
45-
InetAddress.getByName("162.159.46.1"),
46-
InetAddress.getByName("1.1.1.1"),
47-
InetAddress.getByName("1.0.0.1"),
48-
InetAddress.getByName("162.159.132.53"),
49-
InetAddress.getByName("2606:4700:4700::1111"),
50-
InetAddress.getByName("2606:4700:4700::1001"),
51-
InetAddress.getByName("2606:4700:4700::0064"),
52-
InetAddress.getByName("2606:4700:4700::6400")
53-
).resolvePrivateAddresses(true).build());
69+
.bootstrapDnsHosts(cloudflareBootstrap).resolvePrivateAddresses(true).build();
5470
} catch (UnknownHostException|RuntimeException e) {
5571
Log.e("Http", "Failed to init DoH", e);
5672
}
5773
httpclientBuilder.cookieJar(CookieJar.NO_COOKIES);
74+
httpclientBuilder.dns(dns);
5875
httpClient = httpclientBuilder.build();
5976
MainApplication mainApplication = MainApplication.getINSTANCE();
6077
if (mainApplication != null) {
6178
httpclientBuilder.cache(new Cache(
6279
new File(mainApplication.getCacheDir(), "http_cache"),
6380
2L * 1024L * 1024L)); // 2Mib of cache
6481
httpclientBuilder.cookieJar(new CDNCookieJar());
65-
httpClientCachable = httpclientBuilder.build();
82+
httpClientWithCache = httpclientBuilder.build();
6683
} else {
67-
httpClientCachable = httpClient;
84+
httpClientWithCache = httpClient;
6885
}
6986
}
7087

@@ -73,7 +90,7 @@ public static OkHttpClient getHttpclientNoCache() {
7390
}
7491

7592
public static OkHttpClient getHttpclientWithCache() {
76-
return httpClientCachable;
93+
return httpClientWithCache;
7794
}
7895

7996
private static Request.Builder makeRequestBuilder() {
@@ -82,7 +99,7 @@ private static Request.Builder makeRequestBuilder() {
8299
}
83100

84101
public static byte[] doHttpGet(String url,boolean allowCache) throws IOException {
85-
Response response = (allowCache ? httpClientCachable : httpClient).newCall(
102+
Response response = (allowCache ? httpClientWithCache : httpClient).newCall(
86103
makeRequestBuilder().url(url).get().build()
87104
).execute();
88105
// 200 == success, 304 == cache valid

0 commit comments

Comments
 (0)