1
0
Fork 0
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:
Gregor Santner 2016-12-16 05:24:03 +01:00
parent 9e0c6b1741
commit c461ff5b7c
No known key found for this signature in database
GPG key ID: 2AEB822A5CF48C9F
4 changed files with 21 additions and 23 deletions

View file

@ -81,6 +81,9 @@ public class App extends Application {
// Clear preferences__master
appSettings.clearPodSettings();
// Clear User profile - reload empty AppSettings data
diasporaUserProfile.loadFromAppSettings();
// Clear cookies
//noinspection deprecation
cookieManager.removeAllCookie();

View file

@ -167,10 +167,9 @@ public class MainActivity extends ThemedActivity
setContentView(R.layout.main__activity);
ButterKnife.bind(this);
if ((app = (App) getApplication()) == null) AppLog.e(this, "App is null!");
if ((appSettings = app.getSettings()) == null) AppLog.e(this, "AppSettings is null!");
if ((diasporaUserProfile = app.getDiasporaUserProfile()) == null)
AppLog.e(this, "DiasporaUserProfile is null!");
app = (App) getApplication();
appSettings = app.getSettings();
diasporaUserProfile = app.getDiasporaUserProfile();
diasporaUserProfile.setCallbackHandler(uiHandler);
diasporaUserProfile.setListener(this);
urls = new DiasporaUrlHelper(appSettings);
@ -183,15 +182,13 @@ public class MainActivity extends ThemedActivity
brOpenExternalLink = new OpenExternalLinkReceiver(this);
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
@Override
public void setTitle(int rId) {
public void setTitle(int resId) {
CustomFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
MainActivity.this.setTitle(rId);
MainActivity.this.setTitle(resId);
}
}
@Override
public void setTitle(String title) {
CustomFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
@ -347,13 +344,10 @@ public class MainActivity extends ThemedActivity
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
//Handle clicks on profile picture
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navDrawer.closeDrawer(GravityCompat.START);
if (WebHelper.isOnline(MainActivity.this)) {
if (!appSettings.getProfileId().equals("")) {
openDiasporaUrl(urls.getProfileUrl());
} else {
snackbarNoInternet.show();
}
}
});
@ -416,6 +410,7 @@ public class MainActivity extends ThemedActivity
/**
* Open Stream when clicked on top toolbar AND preference stream shortcut is true
*
* @param view selected view
*/
@OnClick(R.id.main__topbar)
@ -470,8 +465,10 @@ public class MainActivity extends ThemedActivity
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
appSettings.setPod(null);
runOnUiThread(new Runnable() {
@Override
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());
}
});
@ -479,7 +476,6 @@ public class MainActivity extends ThemedActivity
} else if (ACTION_CLEAR_CACHE.equals(action)) {
AppLog.v(this, "Clear WebView cache");
runOnUiThread(new Runnable() {
@Override
public void run() {
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
if (wv != null) {
@ -989,10 +985,8 @@ public class MainActivity extends ThemedActivity
break;
case R.id.nav_profile: {
if (WebHelper.isOnline(MainActivity.this)) {
if (!appSettings.getProfileId().equals("")) {
openDiasporaUrl(urls.getProfileUrl());
} else {
snackbarNoInternet.show();
}
}
break;
@ -1002,7 +996,6 @@ public class MainActivity extends ThemedActivity
}
break;
//TODO: Replace with fragment
case R.id.nav_aspects: {
showFragment(getFragment(AspectListFragment.TAG));
}

View file

@ -56,7 +56,10 @@ public class DiasporaUserProfile {
public DiasporaUserProfile(App app) {
this.app = app;
appSettings = app.getSettings();
loadFromAppSettings();
}
public void loadFromAppSettings(){
avatarUrl = appSettings.getAvatarUrl();
guid = appSettings.getProfileId();
name = appSettings.getName();

View file

@ -91,8 +91,7 @@ public class UpdateTitleReceiver extends BroadcastReceiver {
}
public interface TitleCallback {
void setTitle(int Rid);
void setTitle(int resId);
void setTitle(String title);
}
}