mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 13:52:08 +01:00
Moved TitleUpdateReceiver in own class and added some debug logs
This commit is contained in:
parent
dc8349a4e8
commit
1261d93a17
3 changed files with 102 additions and 47 deletions
|
@ -80,6 +80,7 @@ import com.github.dfa.diaspora_android.data.AppSettings;
|
||||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||||
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
||||||
import com.github.dfa.diaspora_android.receivers.OpenExternalLinkReceiver;
|
import com.github.dfa.diaspora_android.receivers.OpenExternalLinkReceiver;
|
||||||
|
import com.github.dfa.diaspora_android.receivers.UpdateTitleReceiver;
|
||||||
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
||||||
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
||||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
|
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
|
||||||
|
@ -137,6 +138,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private final Handler uiHandler = new Handler();
|
private final Handler uiHandler = new Handler();
|
||||||
private CustomWebViewClient webViewClient;
|
private CustomWebViewClient webViewClient;
|
||||||
private OpenExternalLinkReceiver brOpenExternalLink;
|
private OpenExternalLinkReceiver brOpenExternalLink;
|
||||||
|
private BroadcastReceiver brSetTitle;
|
||||||
private Snackbar snackbarExitApp;
|
private Snackbar snackbarExitApp;
|
||||||
private Snackbar snackbarNewNotification;
|
private Snackbar snackbarNewNotification;
|
||||||
private Snackbar snackbarNoInternet;
|
private Snackbar snackbarNoInternet;
|
||||||
|
@ -208,6 +210,17 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
||||||
|
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
|
||||||
|
@Override
|
||||||
|
public void setTitle(int rId) {
|
||||||
|
MainActivity.this.setTitle(rId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTitle(String title) {
|
||||||
|
MainActivity.this.setTitle(title);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUI(Bundle savedInstanceState) {
|
private void setupUI(Bundle savedInstanceState) {
|
||||||
|
@ -219,6 +232,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
} else {
|
} else {
|
||||||
Log.v(App.TAG, "webViewPlaceholder had no child views");
|
Log.v(App.TAG, "webViewPlaceholder had no child views");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean newWebView = (webView == null);
|
boolean newWebView = (webView == null);
|
||||||
if(newWebView) {
|
if(newWebView) {
|
||||||
Log.v(App.TAG, "WebView was null. Create new one.");
|
Log.v(App.TAG, "WebView was null. Create new one.");
|
||||||
|
@ -701,47 +715,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* BroadcastReceiver that updates the title of the activity based on which url is currently loaded
|
|
||||||
*/
|
|
||||||
private final BroadcastReceiver brSetTitle = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String url = intent.getStringExtra(EXTRA_URL);
|
|
||||||
if (url != null && url.startsWith(urls.getPodUrl())) {
|
|
||||||
String subUrl = url.substring((urls.getPodUrl()).length());
|
|
||||||
Log.v(App.TAG, "MainActivity.brSetTitle.onReceive(): Set title for subUrl "+subUrl);
|
|
||||||
if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) {
|
|
||||||
setTitle(R.string.nav_stream);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) {
|
|
||||||
setTitle(R.string.diaspora);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NOTIFICATIONS)) {
|
|
||||||
setTitle(R.string.notifications);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_CONVERSATIONS)) {
|
|
||||||
setTitle(R.string.conversations);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NEW_POST)) {
|
|
||||||
setTitle(R.string.new_post);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PEOPLE + appSettings.getProfileId())) {
|
|
||||||
setTitle(R.string.nav_profile);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_ACTIVITY)) {
|
|
||||||
setTitle(R.string.nav_activities);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_LIKED)) {
|
|
||||||
setTitle(R.string.nav_liked);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_COMMENTED)) {
|
|
||||||
setTitle(R.string.nav_commented);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_MENTIONS)) {
|
|
||||||
setTitle(R.string.nav_mentions);
|
|
||||||
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) {
|
|
||||||
setTitle(R.string.public_);
|
|
||||||
} else if (urls.isAspectUrl(url)){
|
|
||||||
setTitle(urls.getAspectNameFromUrl(url, app));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.w(App.TAG, "MainActivity.brSetTitle.onReceive(): Invalid url: "+url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
|
@ -10,13 +10,15 @@ import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.customtabs.CustomTabsIntent;
|
import android.support.customtabs.CustomTabsIntent;
|
||||||
|
|
||||||
|
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.activity.MainActivity;
|
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.BrowserFallback;
|
||||||
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
||||||
|
import com.github.dfa.diaspora_android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BroadcastReceiver that opens
|
* BroadcastReceiver that opens links in a Chrome CustomTab
|
||||||
* Created by vanitas on 11.09.16.
|
* Created by vanitas on 11.09.16.
|
||||||
*/
|
*/
|
||||||
public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
||||||
|
@ -29,16 +31,17 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String url = intent.getStringExtra(MainActivity.EXTRA_URL);
|
String url = intent.getStringExtra(MainActivity.EXTRA_URL);
|
||||||
|
Log.v(App.TAG, "OpenExternalLinkReceiver.onReceive(): url");
|
||||||
if(url != null) {
|
if(url != null) {
|
||||||
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
|
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
|
||||||
if(Build.VERSION.SDK_INT >= 23) {
|
if(Build.VERSION.SDK_INT >= 23) {
|
||||||
intentBuilder.setToolbarColor(parent.getResources().getColor(R.color.colorPrimary, parent.getTheme()));
|
intentBuilder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary, context.getTheme()));
|
||||||
} else {
|
} else {
|
||||||
intentBuilder.setToolbarColor(parent.getResources().getColor(R.color.colorPrimary));
|
intentBuilder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary));
|
||||||
}
|
}
|
||||||
intentBuilder.setStartAnimations(parent, android.R.anim.slide_in_left, android.R.anim.fade_out);
|
intentBuilder.setStartAnimations(context, 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);
|
intentBuilder.setExitAnimations(context, android.R.anim.fade_in, android.R.anim.slide_out_right);
|
||||||
Bitmap backButtonIcon = BitmapFactory.decodeResource(parent.getResources(),
|
Bitmap backButtonIcon = BitmapFactory.decodeResource(context.getResources(),
|
||||||
R.drawable.ic_arrow_back_white_24px);
|
R.drawable.ic_arrow_back_white_24px);
|
||||||
intentBuilder.setCloseButtonIcon(backButtonIcon);
|
intentBuilder.setCloseButtonIcon(backButtonIcon);
|
||||||
CustomTabActivityHelper.openCustomTab(parent, intentBuilder.build(), Uri.parse(url), new BrowserFallback());
|
CustomTabActivityHelper.openCustomTab(parent, intentBuilder.build(), Uri.parse(url), new BrowserFallback());
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.github.dfa.diaspora_android.receivers;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.App;
|
||||||
|
import com.github.dfa.diaspora_android.R;
|
||||||
|
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||||
|
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||||
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
import com.github.dfa.diaspora_android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BroadcastReceiver used to update the title of the MainActivity depending on the url of the webview
|
||||||
|
* Created by vanitas on 11.09.16.
|
||||||
|
*/
|
||||||
|
public class UpdateTitleReceiver extends BroadcastReceiver {
|
||||||
|
private DiasporaUrlHelper urls;
|
||||||
|
private AppSettings appSettings;
|
||||||
|
private App app;
|
||||||
|
private TitleCallback callback;
|
||||||
|
|
||||||
|
public UpdateTitleReceiver(App app, DiasporaUrlHelper urls, TitleCallback callback) {
|
||||||
|
this.urls = urls;
|
||||||
|
this.app = app;
|
||||||
|
this.appSettings = app.getSettings();
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String url = intent.getStringExtra(MainActivity.EXTRA_URL);
|
||||||
|
if (url != null && url.startsWith(urls.getPodUrl())) {
|
||||||
|
String subUrl = url.substring((urls.getPodUrl()).length());
|
||||||
|
Log.v(App.TAG, "UpdateTitleReceiver.onReceive(): Set title for subUrl "+subUrl);
|
||||||
|
if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) {
|
||||||
|
setTitle(R.string.nav_stream);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) {
|
||||||
|
setTitle(R.string.diaspora);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NOTIFICATIONS)) {
|
||||||
|
setTitle(R.string.notifications);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_CONVERSATIONS)) {
|
||||||
|
setTitle(R.string.conversations);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NEW_POST)) {
|
||||||
|
setTitle(R.string.new_post);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PEOPLE + appSettings.getProfileId())) {
|
||||||
|
setTitle(R.string.nav_profile);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_ACTIVITY)) {
|
||||||
|
setTitle(R.string.nav_activities);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_LIKED)) {
|
||||||
|
setTitle(R.string.nav_liked);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_COMMENTED)) {
|
||||||
|
setTitle(R.string.nav_commented);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_MENTIONS)) {
|
||||||
|
setTitle(R.string.nav_mentions);
|
||||||
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) {
|
||||||
|
setTitle(R.string.public_);
|
||||||
|
} else if (urls.isAspectUrl(url)){
|
||||||
|
setTitle(urls.getAspectNameFromUrl(url, app));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(App.TAG, "UpdateTitleReceiver.onReceive(): Invalid url: "+url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTitle(int rId) {
|
||||||
|
callback.setTitle(rId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTitle(String title) {
|
||||||
|
callback.setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface TitleCallback {
|
||||||
|
void setTitle(int Rid);
|
||||||
|
void setTitle(String title);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue