1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 21:32:07 +01:00

Fix loading non-pod links outside customtab/external browser

This commit is contained in:
Gregor Santner 2018-03-30 02:46:44 +02:00
parent 618f3eaaba
commit b48dc5dcac
No known key found for this signature in database
GPG key ID: 7E83A7834AECB009
11 changed files with 51 additions and 33 deletions

View file

@ -20,7 +20,6 @@ package com.github.dfa.diaspora_android.activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

View file

@ -37,7 +37,6 @@ import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.DiasporaAspect;
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;

View file

@ -325,7 +325,12 @@ public class DiasporaStreamFragment extends BrowserFragment {
@SuppressWarnings("unused")
@JavascriptInterface
public void setUserProfile(final String webMessage) throws JSONException {
App app = ((App) getActivity().getApplication());
final Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
App app = ((App) activity.getApplication());
final DiasporaUserProfile pup = app.getDiasporaUserProfile();
if (pup.isRefreshNeeded()) {
try {
@ -334,6 +339,7 @@ public class DiasporaStreamFragment extends BrowserFragment {
return;
}
} catch (Exception ignored) {
return;
}
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
pup.parseJson(webMessage);
@ -344,6 +350,9 @@ public class DiasporaStreamFragment extends BrowserFragment {
});
}
}
});
}
}
@SuppressWarnings("unused")
@JavascriptInterface

View file

@ -338,12 +338,23 @@ public class MainActivity extends ThemedActivity
*
* @param url URL to load in the DiasporaStreamFragment
*/
public void openDiasporaUrl(String url) {
public void openDiasporaUrl(final String url) {
AppLog.v(this, "openDiasporaUrl()");
if (url.startsWith(_appSettings.getPod().getPodUrl().getBaseUrl()) && !url.startsWith("https://dia.so/")) {
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
showFragment(streamFragment);
showLastVisitedTimestampMessageIfNeeded(url);
streamFragment.loadUrl(url);
} else {
toolbarTop.postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(ACTION_OPEN_EXTERNAL_URL);
i.putExtra(EXTRA_URL, url);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
}
}, 1000);
}
}
public void showLastVisitedTimestampMessageIfNeeded(String url) {

View file

@ -32,7 +32,6 @@ import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.SearchView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -53,7 +52,6 @@ import com.github.dfa.diaspora_android.service.FetchPodsService;
import com.github.dfa.diaspora_android.ui.PodSelectionDialog;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.ActivityUtils;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;

View file

@ -35,7 +35,6 @@ import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;

View file

@ -19,10 +19,7 @@
package com.github.dfa.diaspora_android.ui.theme;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;

View file

@ -77,10 +77,11 @@ public class ActivityUtils extends net.gsantner.opoc.util.ActivityUtils {
/**
* This method creates file sharing uri by using FileProvider
*
* @return
*/
public static Uri getFileSharingUri(Context context,File file) {
public static Uri getFileSharingUri(Context context, File file) {
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID,file);
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
}
}

View file

@ -46,7 +46,7 @@ public class AppSettings extends SharedPreferencesPropertyBackend {
return new AppSettings(App.get());
}
private AppSettings(Context context) {
public AppSettings(Context context) {
super(context);
_prefPod = _context.getSharedPreferences("pod0", Context.MODE_PRIVATE);
}

View file

@ -30,7 +30,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
@ -222,7 +221,7 @@ public class BrowserFragment extends ThemedFragment {
// Only show share intent when Action Share Screenshot was selected
if (hasToShareScreenshot) {
Uri bmpUri = ActivityUtils.getFileSharingUri(getContext(),new File(fileSaveDirectory, fileSaveName));
Uri bmpUri = ActivityUtils.getFileSharingUri(getContext(), new File(fileSaveDirectory, fileSaveName));
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");

View file

@ -41,6 +41,8 @@ public class CustomTabsHelper {
static final String BETA_PACKAGE = "com.chrome.beta";
static final String DEV_PACKAGE = "com.chrome.dev";
static final String LOCAL_PACKAGE = "com.google.android.apps.chrome";
static final String CHROMIUM = "org.chromium.chrome";
static final String FENNEC = "org.mozilla.fennec_fdroid";
private static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE =
"android.support.customtabs.extra.KEEP_ALIVE";
@ -101,6 +103,10 @@ public class CustomTabsHelper {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(CHROMIUM)) {
sPackageNameToUse = CHROMIUM;
} else if (packagesSupportingCustomTabs.contains(FENNEC)) {
sPackageNameToUse = FENNEC;
}
return sPackageNameToUse;
}
@ -137,6 +143,6 @@ public class CustomTabsHelper {
* @return All possible chrome package names that provide custom tabs feature.
*/
public static String[] getPackages() {
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE};
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE, CHROMIUM, FENNEC};
}
}