mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Fixes #117 - Reset NavHeader on change account, reset web profile
This commit is contained in:
parent
9e0c6b1741
commit
c461ff5b7c
4 changed files with 21 additions and 23 deletions
|
@ -81,6 +81,9 @@ public class App extends Application {
|
||||||
// Clear preferences__master
|
// Clear preferences__master
|
||||||
appSettings.clearPodSettings();
|
appSettings.clearPodSettings();
|
||||||
|
|
||||||
|
// Clear User profile - reload empty AppSettings data
|
||||||
|
diasporaUserProfile.loadFromAppSettings();
|
||||||
|
|
||||||
// Clear cookies
|
// Clear cookies
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
cookieManager.removeAllCookie();
|
cookieManager.removeAllCookie();
|
||||||
|
|
|
@ -167,10 +167,9 @@ public class MainActivity extends ThemedActivity
|
||||||
setContentView(R.layout.main__activity);
|
setContentView(R.layout.main__activity);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
if ((app = (App) getApplication()) == null) AppLog.e(this, "App is null!");
|
app = (App) getApplication();
|
||||||
if ((appSettings = app.getSettings()) == null) AppLog.e(this, "AppSettings is null!");
|
appSettings = app.getSettings();
|
||||||
if ((diasporaUserProfile = app.getDiasporaUserProfile()) == null)
|
diasporaUserProfile = app.getDiasporaUserProfile();
|
||||||
AppLog.e(this, "DiasporaUserProfile is null!");
|
|
||||||
diasporaUserProfile.setCallbackHandler(uiHandler);
|
diasporaUserProfile.setCallbackHandler(uiHandler);
|
||||||
diasporaUserProfile.setListener(this);
|
diasporaUserProfile.setListener(this);
|
||||||
urls = new DiasporaUrlHelper(appSettings);
|
urls = new DiasporaUrlHelper(appSettings);
|
||||||
|
@ -183,15 +182,13 @@ public class MainActivity extends ThemedActivity
|
||||||
|
|
||||||
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
||||||
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
|
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
|
||||||
@Override
|
public void setTitle(int resId) {
|
||||||
public void setTitle(int rId) {
|
|
||||||
CustomFragment top = getTopFragment();
|
CustomFragment top = getTopFragment();
|
||||||
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
||||||
MainActivity.this.setTitle(rId);
|
MainActivity.this.setTitle(resId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
CustomFragment top = getTopFragment();
|
CustomFragment top = getTopFragment();
|
||||||
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
||||||
|
@ -226,7 +223,7 @@ public class MainActivity extends ThemedActivity
|
||||||
// Setup toolbar
|
// Setup toolbar
|
||||||
setSupportActionBar(toolbarTop);
|
setSupportActionBar(toolbarTop);
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if(actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
|
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
|
||||||
|
@ -347,13 +344,10 @@ public class MainActivity extends ThemedActivity
|
||||||
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
|
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
|
||||||
//Handle clicks on profile picture
|
//Handle clicks on profile picture
|
||||||
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
|
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
navDrawer.closeDrawer(GravityCompat.START);
|
navDrawer.closeDrawer(GravityCompat.START);
|
||||||
if (WebHelper.isOnline(MainActivity.this)) {
|
if (!appSettings.getProfileId().equals("")) {
|
||||||
openDiasporaUrl(urls.getProfileUrl());
|
openDiasporaUrl(urls.getProfileUrl());
|
||||||
} else {
|
|
||||||
snackbarNoInternet.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -416,12 +410,13 @@ public class MainActivity extends ThemedActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open Stream when clicked on top toolbar AND preference stream shortcut is true
|
* Open Stream when clicked on top toolbar AND preference stream shortcut is true
|
||||||
|
*
|
||||||
* @param view selected view
|
* @param view selected view
|
||||||
*/
|
*/
|
||||||
@OnClick(R.id.main__topbar)
|
@OnClick(R.id.main__topbar)
|
||||||
public void onToolBarClicked(View view) {
|
public void onToolBarClicked(View view) {
|
||||||
AppLog.i(this, "onToolBarClicked()");
|
AppLog.i(this, "onToolBarClicked()");
|
||||||
if(appSettings.isTopbarStreamShortcutEnabled() && appSettings.hasPod()) {
|
if (appSettings.isTopbarStreamShortcutEnabled() && appSettings.hasPod()) {
|
||||||
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,8 +465,10 @@ public class MainActivity extends ThemedActivity
|
||||||
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
||||||
appSettings.setPod(null);
|
appSettings.setPod(null);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
navheaderTitle.setText(R.string.app_name);
|
||||||
|
navheaderDescription.setText(R.string.app_subtitle);
|
||||||
|
navheaderImage.setImageResource(R.drawable.ic_launcher);
|
||||||
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
|
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -479,7 +476,6 @@ public class MainActivity extends ThemedActivity
|
||||||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||||
AppLog.v(this, "Clear WebView cache");
|
AppLog.v(this, "Clear WebView cache");
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
|
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
|
||||||
if (wv != null) {
|
if (wv != null) {
|
||||||
|
@ -989,10 +985,8 @@ public class MainActivity extends ThemedActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_profile: {
|
case R.id.nav_profile: {
|
||||||
if (WebHelper.isOnline(MainActivity.this)) {
|
if (!appSettings.getProfileId().equals("")) {
|
||||||
openDiasporaUrl(urls.getProfileUrl());
|
openDiasporaUrl(urls.getProfileUrl());
|
||||||
} else {
|
|
||||||
snackbarNoInternet.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1002,7 +996,6 @@ public class MainActivity extends ThemedActivity
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//TODO: Replace with fragment
|
|
||||||
case R.id.nav_aspects: {
|
case R.id.nav_aspects: {
|
||||||
showFragment(getFragment(AspectListFragment.TAG));
|
showFragment(getFragment(AspectListFragment.TAG));
|
||||||
}
|
}
|
||||||
|
@ -1062,7 +1055,7 @@ public class MainActivity extends ThemedActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_reports: {
|
case R.id.nav_reports: {
|
||||||
if(WebHelper.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
openDiasporaUrl(urls.getReportsUrl());
|
openDiasporaUrl(urls.getReportsUrl());
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
|
|
@ -56,7 +56,10 @@ public class DiasporaUserProfile {
|
||||||
public DiasporaUserProfile(App app) {
|
public DiasporaUserProfile(App app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
appSettings = app.getSettings();
|
appSettings = app.getSettings();
|
||||||
|
loadFromAppSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFromAppSettings(){
|
||||||
avatarUrl = appSettings.getAvatarUrl();
|
avatarUrl = appSettings.getAvatarUrl();
|
||||||
guid = appSettings.getProfileId();
|
guid = appSettings.getProfileId();
|
||||||
name = appSettings.getName();
|
name = appSettings.getName();
|
||||||
|
|
|
@ -91,8 +91,7 @@ public class UpdateTitleReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TitleCallback {
|
public interface TitleCallback {
|
||||||
void setTitle(int Rid);
|
void setTitle(int resId);
|
||||||
|
|
||||||
void setTitle(String title);
|
void setTitle(String title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue