mirror of
https://github.com/gsantner/dandelion
synced 2024-12-22 19:08:03 +01:00
Moved BroadcastReceiver for CustomTabs in own class
This commit is contained in:
parent
40592ffae8
commit
dc8349a4e8
3 changed files with 61 additions and 27 deletions
|
@ -79,6 +79,7 @@ import com.github.dfa.diaspora_android.R;
|
|||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
||||
import com.github.dfa.diaspora_android.receivers.OpenExternalLinkReceiver;
|
||||
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
||||
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
|
||||
|
@ -135,6 +136,7 @@ public class MainActivity extends AppCompatActivity
|
|||
private PodUserProfile podUserProfile;
|
||||
private final Handler uiHandler = new Handler();
|
||||
private CustomWebViewClient webViewClient;
|
||||
private OpenExternalLinkReceiver brOpenExternalLink;
|
||||
private Snackbar snackbarExitApp;
|
||||
private Snackbar snackbarNewNotification;
|
||||
private Snackbar snackbarNoInternet;
|
||||
|
@ -204,10 +206,19 @@ public class MainActivity extends AppCompatActivity
|
|||
} else if (appSettings.wasProxyEnabled()) {
|
||||
resetProxy();
|
||||
}
|
||||
|
||||
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
||||
}
|
||||
|
||||
private void setupUI(Bundle savedInstanceState) {
|
||||
Log.i(App.TAG, "MainActivity.setupUI()");
|
||||
ButterKnife.bind(this);
|
||||
if (webviewPlaceholder.getChildCount() != 0) {
|
||||
Log.v(App.TAG, "remove child views from webViewPlaceholder");
|
||||
webviewPlaceholder.removeAllViews();
|
||||
} else {
|
||||
Log.v(App.TAG, "webViewPlaceholder had no child views");
|
||||
}
|
||||
boolean newWebView = (webView == null);
|
||||
if(newWebView) {
|
||||
Log.v(App.TAG, "WebView was null. Create new one.");
|
||||
|
@ -218,10 +229,7 @@ public class MainActivity extends AppCompatActivity
|
|||
} else {
|
||||
Log.v(App.TAG, "Reuse old WebView to avoid reloading page");
|
||||
}
|
||||
ButterKnife.bind(this);
|
||||
if (webviewPlaceholder.getChildCount() != 0) {
|
||||
webviewPlaceholder.removeAllViews();
|
||||
}
|
||||
|
||||
Log.v(App.TAG, "Add WebView to placeholder");
|
||||
webviewPlaceholder.addView(webView);
|
||||
// Setup toolbar
|
||||
|
@ -734,27 +742,6 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver brOpenExternalLink = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String url = intent.getStringExtra(EXTRA_URL);
|
||||
if(url != null) {
|
||||
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
|
||||
if(Build.VERSION.SDK_INT >= 23) {
|
||||
intentBuilder.setToolbarColor(getResources().getColor(R.color.colorPrimary, getTheme()));
|
||||
} else {
|
||||
intentBuilder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
|
||||
}
|
||||
intentBuilder.setStartAnimations(MainActivity.this, android.R.anim.slide_in_left, android.R.anim.fade_out);
|
||||
intentBuilder.setExitAnimations(MainActivity.this, android.R.anim.fade_in, android.R.anim.slide_out_right);
|
||||
Bitmap backButtonIcon = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.ic_arrow_back_white_24px);
|
||||
intentBuilder.setCloseButtonIcon(backButtonIcon);
|
||||
CustomTabActivityHelper.openCustomTab(MainActivity.this, intentBuilder.build(), Uri.parse(url), new BrowserFallback());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package com.github.dfa.diaspora_android.receivers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
|
||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
||||
|
||||
/**
|
||||
* BroadcastReceiver that opens
|
||||
* Created by vanitas on 11.09.16.
|
||||
*/
|
||||
public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
||||
private final Activity parent;
|
||||
|
||||
public OpenExternalLinkReceiver(Activity parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String url = intent.getStringExtra(MainActivity.EXTRA_URL);
|
||||
if(url != null) {
|
||||
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
|
||||
if(Build.VERSION.SDK_INT >= 23) {
|
||||
intentBuilder.setToolbarColor(parent.getResources().getColor(R.color.colorPrimary, parent.getTheme()));
|
||||
} else {
|
||||
intentBuilder.setToolbarColor(parent.getResources().getColor(R.color.colorPrimary));
|
||||
}
|
||||
intentBuilder.setStartAnimations(parent, android.R.anim.slide_in_left, android.R.anim.fade_out);
|
||||
intentBuilder.setExitAnimations(parent, android.R.anim.fade_in, android.R.anim.slide_out_right);
|
||||
Bitmap backButtonIcon = BitmapFactory.decodeResource(parent.getResources(),
|
||||
R.drawable.ic_arrow_back_white_24px);
|
||||
intentBuilder.setCloseButtonIcon(backButtonIcon);
|
||||
CustomTabActivityHelper.openCustomTab(parent, intentBuilder.build(), Uri.parse(url), new BrowserFallback());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:orientation="vertical" android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
Loading…
Reference in a new issue