Fix WebView uri handling, and fix top inset.

pull/27/head
Fox2Code 3 years ago
parent 52d22fe487
commit f8183bd2dc

@ -10,7 +10,7 @@ android {
applicationId "com.fox2code.mmm" applicationId "com.fox2code.mmm"
minSdk 21 minSdk 21
targetSdk 32 targetSdk 32
versionCode 30 versionCode 31
versionName "0.3.2" versionName "0.3.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

@ -244,7 +244,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
swipeRefreshLayoutOrigStartOffset + combinedBarsHeight, swipeRefreshLayoutOrigStartOffset + combinedBarsHeight,
swipeRefreshLayoutOrigEndOffset + combinedBarsHeight); swipeRefreshLayoutOrigEndOffset + combinedBarsHeight);
this.moduleViewListBuilder.setHeaderPx( this.moduleViewListBuilder.setHeaderPx(
actionBarHeight + CompatDisplay.dpToPixel(4)); actionBarHeight + CompatDisplay.dpToPixel(8));
this.moduleViewListBuilder.setFooterPx( this.moduleViewListBuilder.setFooterPx(
bottomInset + this.searchCard.getHeight()); bottomInset + this.searchCard.getHeight());
this.searchCard.setRadius(this.searchCard.getHeight() / 2F); this.searchCard.setRadius(this.searchCard.getHeight() / 2F);

@ -120,9 +120,9 @@ public class AndroidacyActivity extends CompatActivity {
public boolean shouldOverrideUrlLoading( public boolean shouldOverrideUrlLoading(
@NonNull WebView view, @NonNull WebResourceRequest request) { @NonNull WebView view, @NonNull WebResourceRequest request) {
// Don't open non Androidacy urls inside WebView // Don't open non Androidacy urls inside WebView
if (request.isForMainFrame() && !(request.getUrl().getScheme().equals("intent") || if (request.isForMainFrame() &&
AndroidacyUtil.isAndroidacyLink(request.getUrl()))) { !AndroidacyUtil.isAndroidacyLink(request.getUrl())) {
IntentHelper.openUrl(view.getContext(), request.getUrl().toString()); IntentHelper.openUri(view.getContext(), request.getUrl().toString());
return true; return true;
} }
return false; return false;

@ -30,8 +30,21 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URISyntaxException;
public class IntentHelper { public class IntentHelper {
private static final String TAG = "IntentHelper";
public static void openUri(Context context, String uri) {
if (uri.startsWith("intent://")) {
try {
startActivity(context, Intent.parseUri(uri, Intent.URI_INTENT_SCHEME), false);
} catch (URISyntaxException | ActivityNotFoundException e) {
Log.e(TAG, "Failed launch of " + uri, e);
}
} else openUrl(context, uri);
}
public static void openUrl(Context context, String url) { public static void openUrl(Context context, String url) {
openUrl(context, url, false); openUrl(context, url, false);
} }
@ -227,7 +240,7 @@ public class IntentHelper {
callback.onReceived(destination, null, RESPONSE_ERROR); callback.onReceived(destination, null, RESPONSE_ERROR);
return; return;
} }
Log.d("IntentHelper", "FilePicker returned " + uri); Log.d(TAG, "FilePicker returned " + uri);
if ("http".equals(uri.getScheme()) || if ("http".equals(uri.getScheme()) ||
"https".equals(uri.getScheme())) { "https".equals(uri.getScheme())) {
callback.onReceived(destination, uri, RESPONSE_URL); callback.onReceived(destination, uri, RESPONSE_URL);
@ -259,7 +272,7 @@ public class IntentHelper {
Files.copy(inputStream, outputStream); Files.copy(inputStream, outputStream);
success = true; success = true;
} catch (Exception e) { } catch (Exception e) {
Log.e("IntentHelper", "failed copy of " + uri, e); Log.e(TAG, "failed copy of " + uri, e);
Toast.makeText(compatActivity, Toast.makeText(compatActivity,
R.string.file_picker_failure, R.string.file_picker_failure,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
@ -267,7 +280,7 @@ public class IntentHelper {
Files.closeSilently(inputStream); Files.closeSilently(inputStream);
Files.closeSilently(outputStream); Files.closeSilently(outputStream);
if (!success && destination.exists() && !destination.delete()) if (!success && destination.exists() && !destination.delete())
Log.e("IntentHelper", "Failed to delete artefact!"); Log.e(TAG, "Failed to delete artefact!");
} }
callback.onReceived(destination, uri, success ? RESPONSE_FILE : RESPONSE_ERROR); callback.onReceived(destination, uri, success ? RESPONSE_FILE : RESPONSE_ERROR);
}); });

Loading…
Cancel
Save