mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Fix loading non-pod links outside customtab/external browser
This commit is contained in:
parent
618f3eaaba
commit
b48dc5dcac
11 changed files with 51 additions and 33 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -325,21 +325,30 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
|||
@SuppressWarnings("unused")
|
||||
@JavascriptInterface
|
||||
public void setUserProfile(final String webMessage) throws JSONException {
|
||||
App app = ((App) getActivity().getApplication());
|
||||
final DiasporaUserProfile pup = app.getDiasporaUserProfile();
|
||||
if (pup.isRefreshNeeded()) {
|
||||
try {
|
||||
// Try to very fail-safe check if user information gets really loaded from correct pod
|
||||
if (!webView.getUrl().startsWith(app.getSettings().getPod().getPodUrl().getBaseUrl())) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
||||
pup.parseJson(webMessage);
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pup.analyzeUrl(webView.getUrl());
|
||||
App app = ((App) activity.getApplication());
|
||||
final DiasporaUserProfile pup = app.getDiasporaUserProfile();
|
||||
if (pup.isRefreshNeeded()) {
|
||||
try {
|
||||
// Try to very fail-safe check if user information gets really loaded from correct pod
|
||||
if (!webView.getUrl().startsWith(app.getSettings().getPod().getPodUrl().getBaseUrl())) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
return;
|
||||
}
|
||||
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
||||
pup.parseJson(webMessage);
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
pup.analyzeUrl(webView.getUrl());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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()");
|
||||
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
||||
showFragment(streamFragment);
|
||||
showLastVisitedTimestampMessageIfNeeded(url);
|
||||
streamFragment.loadUrl(url);
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue