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

Commit f8183bd

Browse files
committed
Fix WebView uri handling, and fix top inset.
1 parent 52d22fe commit f8183bd

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
applicationId "com.fox2code.mmm"
1111
minSdk 21
1212
targetSdk 32
13-
versionCode 30
13+
versionCode 31
1414
versionName "0.3.2"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private void updateScreenInsets(Configuration configuration) {
244244
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
245245
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
246246
this.moduleViewListBuilder.setHeaderPx(
247-
actionBarHeight + CompatDisplay.dpToPixel(4));
247+
actionBarHeight + CompatDisplay.dpToPixel(8));
248248
this.moduleViewListBuilder.setFooterPx(
249249
bottomInset + this.searchCard.getHeight());
250250
this.searchCard.setRadius(this.searchCard.getHeight() / 2F);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
120120
public boolean shouldOverrideUrlLoading(
121121
@NonNull WebView view, @NonNull WebResourceRequest request) {
122122
// Don't open non Androidacy urls inside WebView
123-
if (request.isForMainFrame() && !(request.getUrl().getScheme().equals("intent") ||
124-
AndroidacyUtil.isAndroidacyLink(request.getUrl()))) {
125-
IntentHelper.openUrl(view.getContext(), request.getUrl().toString());
123+
if (request.isForMainFrame() &&
124+
!AndroidacyUtil.isAndroidacyLink(request.getUrl())) {
125+
IntentHelper.openUri(view.getContext(), request.getUrl().toString());
126126
return true;
127127
}
128128
return false;

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,21 @@
3030
import java.io.FileOutputStream;
3131
import java.io.InputStream;
3232
import java.io.OutputStream;
33+
import java.net.URISyntaxException;
3334

3435
public class IntentHelper {
36+
private static final String TAG = "IntentHelper";
37+
38+
public static void openUri(Context context, String uri) {
39+
if (uri.startsWith("intent://")) {
40+
try {
41+
startActivity(context, Intent.parseUri(uri, Intent.URI_INTENT_SCHEME), false);
42+
} catch (URISyntaxException | ActivityNotFoundException e) {
43+
Log.e(TAG, "Failed launch of " + uri, e);
44+
}
45+
} else openUrl(context, uri);
46+
}
47+
3548
public static void openUrl(Context context, String url) {
3649
openUrl(context, url, false);
3750
}
@@ -227,7 +240,7 @@ public static void openFileTo(CompatActivity compatActivity, File destination,
227240
callback.onReceived(destination, null, RESPONSE_ERROR);
228241
return;
229242
}
230-
Log.d("IntentHelper", "FilePicker returned " + uri);
243+
Log.d(TAG, "FilePicker returned " + uri);
231244
if ("http".equals(uri.getScheme()) ||
232245
"https".equals(uri.getScheme())) {
233246
callback.onReceived(destination, uri, RESPONSE_URL);
@@ -259,15 +272,15 @@ public static void openFileTo(CompatActivity compatActivity, File destination,
259272
Files.copy(inputStream, outputStream);
260273
success = true;
261274
} catch (Exception e) {
262-
Log.e("IntentHelper", "failed copy of " + uri, e);
275+
Log.e(TAG, "failed copy of " + uri, e);
263276
Toast.makeText(compatActivity,
264277
R.string.file_picker_failure,
265278
Toast.LENGTH_SHORT).show();
266279
} finally {
267280
Files.closeSilently(inputStream);
268281
Files.closeSilently(outputStream);
269282
if (!success && destination.exists() && !destination.delete())
270-
Log.e("IntentHelper", "Failed to delete artefact!");
283+
Log.e(TAG, "Failed to delete artefact!");
271284
}
272285
callback.onReceived(destination, uri, success ? RESPONSE_FILE : RESPONSE_ERROR);
273286
});

0 commit comments

Comments
 (0)