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.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
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.data.DiasporaAspect;
|
||||||
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
|
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
|
||||||
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
|
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.AppSettings;
|
||||||
import com.github.dfa.diaspora_android.util.ContextUtils;
|
import com.github.dfa.diaspora_android.util.ContextUtils;
|
||||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
|
@ -325,7 +325,12 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void setUserProfile(final String webMessage) throws JSONException {
|
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();
|
final DiasporaUserProfile pup = app.getDiasporaUserProfile();
|
||||||
if (pup.isRefreshNeeded()) {
|
if (pup.isRefreshNeeded()) {
|
||||||
try {
|
try {
|
||||||
|
@ -334,6 +339,7 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
||||||
pup.parseJson(webMessage);
|
pup.parseJson(webMessage);
|
||||||
|
@ -344,6 +350,9 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
|
|
|
@ -338,12 +338,23 @@ public class MainActivity extends ThemedActivity
|
||||||
*
|
*
|
||||||
* @param url URL to load in the DiasporaStreamFragment
|
* @param url URL to load in the DiasporaStreamFragment
|
||||||
*/
|
*/
|
||||||
public void openDiasporaUrl(String url) {
|
public void openDiasporaUrl(final String url) {
|
||||||
AppLog.v(this, "openDiasporaUrl()");
|
AppLog.v(this, "openDiasporaUrl()");
|
||||||
|
if (url.startsWith(_appSettings.getPod().getPodUrl().getBaseUrl()) && !url.startsWith("https://dia.so/")) {
|
||||||
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
||||||
showFragment(streamFragment);
|
showFragment(streamFragment);
|
||||||
showLastVisitedTimestampMessageIfNeeded(url);
|
showLastVisitedTimestampMessageIfNeeded(url);
|
||||||
streamFragment.loadUrl(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) {
|
public void showLastVisitedTimestampMessageIfNeeded(String url) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.widget.AppCompatButton;
|
import android.support.v7.widget.AppCompatButton;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
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.PodSelectionDialog;
|
||||||
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
|
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
|
||||||
import com.github.dfa.diaspora_android.util.ActivityUtils;
|
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.AppSettings;
|
||||||
import com.github.dfa.diaspora_android.util.ContextUtils;
|
import com.github.dfa.diaspora_android.util.ContextUtils;
|
||||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
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.R;
|
||||||
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
|
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener;
|
||||||
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
|
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.AppSettings;
|
||||||
import com.github.dfa.diaspora_android.util.ContextUtils;
|
import com.github.dfa.diaspora_android.util.ContextUtils;
|
||||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
|
@ -19,10 +19,7 @@
|
||||||
package com.github.dfa.diaspora_android.ui.theme;
|
package com.github.dfa.diaspora_android.ui.theme;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class ActivityUtils extends net.gsantner.opoc.util.ActivityUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates file sharing uri by using FileProvider
|
* This method creates file sharing uri by using FileProvider
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Uri getFileSharingUri(Context context, File file) {
|
public static Uri getFileSharingUri(Context context, File file) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class AppSettings extends SharedPreferencesPropertyBackend {
|
||||||
return new AppSettings(App.get());
|
return new AppSettings(App.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppSettings(Context context) {
|
public AppSettings(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
_prefPod = _context.getSharedPreferences("pod0", Context.MODE_PRIVATE);
|
_prefPod = _context.getSharedPreferences("pod0", Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class CustomTabsHelper {
|
||||||
static final String BETA_PACKAGE = "com.chrome.beta";
|
static final String BETA_PACKAGE = "com.chrome.beta";
|
||||||
static final String DEV_PACKAGE = "com.chrome.dev";
|
static final String DEV_PACKAGE = "com.chrome.dev";
|
||||||
static final String LOCAL_PACKAGE = "com.google.android.apps.chrome";
|
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 =
|
private static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE =
|
||||||
"android.support.customtabs.extra.KEEP_ALIVE";
|
"android.support.customtabs.extra.KEEP_ALIVE";
|
||||||
|
|
||||||
|
@ -101,6 +103,10 @@ public class CustomTabsHelper {
|
||||||
sPackageNameToUse = DEV_PACKAGE;
|
sPackageNameToUse = DEV_PACKAGE;
|
||||||
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
|
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
|
||||||
sPackageNameToUse = LOCAL_PACKAGE;
|
sPackageNameToUse = LOCAL_PACKAGE;
|
||||||
|
} else if (packagesSupportingCustomTabs.contains(CHROMIUM)) {
|
||||||
|
sPackageNameToUse = CHROMIUM;
|
||||||
|
} else if (packagesSupportingCustomTabs.contains(FENNEC)) {
|
||||||
|
sPackageNameToUse = FENNEC;
|
||||||
}
|
}
|
||||||
return sPackageNameToUse;
|
return sPackageNameToUse;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +143,6 @@ public class CustomTabsHelper {
|
||||||
* @return All possible chrome package names that provide custom tabs feature.
|
* @return All possible chrome package names that provide custom tabs feature.
|
||||||
*/
|
*/
|
||||||
public static String[] getPackages() {
|
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