From 282dc59a30a2c065122bdd64aea1261a72f8aee4 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 22 Dec 2018 16:03:27 +0100 Subject: [PATCH] Fix account change --- .../mastodon/activities/BaseMainActivity.java | 15 ++++--------- .../asynctasks/RetrieveFeedsAsyncTask.java | 3 ++- .../gouv/etalab/mastodon/helper/Helper.java | 21 +++++++------------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index e3b0466cf..885529a9e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -148,7 +148,6 @@ import static fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask.action.G import static fr.gouv.etalab.mastodon.helper.Helper.ADD_USER_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.BACKUP_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.BACK_TO_SETTINGS; -import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_USER_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE; import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.INSTANCE_NAME; @@ -708,7 +707,9 @@ public abstract class BaseMainActivity extends BaseActivity tabLayout.addTab(tabHome); tabLayout.addTab(tabNotif); tabPosition.put("home",0); + typePosition.put(0, RetrieveFeedsAsyncTask.Type.HOME); tabPosition.put("notifications",1); + typePosition.put(1, RetrieveFeedsAsyncTask.Type.NOTIFICATION); int i = 2; if( display_direct) { tabLayout.addTab(tabDirect); @@ -1790,14 +1791,6 @@ public abstract class BaseMainActivity extends BaseActivity navigationView.setCheckedItem(R.id.nav_settings); navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0); toolbarTitle.setText(R.string.settings); - }else if( extras.getInt(INTENT_ACTION) == CHANGE_USER_INTENT){ - unCheckAllMenuItems(navigationView); - if( tabLayout.getTabAt(0) != null) - //noinspection ConstantConditions - tabLayout.getTabAt(0).select(); - if( !toolbar_search.isIconified() ) { - toolbar_search.setIconified(true); - } }else if (extras.getInt(INTENT_ACTION) == ADD_USER_INTENT){ this.recreate(); }else if( extras.getInt(INTENT_ACTION) == BACKUP_INTENT){ @@ -2407,8 +2400,8 @@ public abstract class BaseMainActivity extends BaseActivity return notificationsFragment; }else { statusFragment = new DisplayStatusFragment(); - bundle.putSerializable("type", Helper.timelineType(position)); - if( Helper.timelineType(position) == RetrieveFeedsAsyncTask.Type.TAG){ + bundle.putSerializable("type", typePosition.get(position)); + if( typePosition.get(position) == RetrieveFeedsAsyncTask.Type.TAG){ if( tabLayout.getTabAt(position) != null && tabLayout.getTabAt(position).getText() != null) { bundle.putString("tag", tabLayout.getTabAt(position).getText().toString()); tagFragment.put(tabLayout.getTabAt(position).getText().toString(), statusFragment); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index 3539b7992..c7ba3c25e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -74,7 +74,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { CACHE_BOOKMARKS_PEERTUBE, CACHE_STATUS, REMOTE_INSTANCE, - ART + ART, + NOTIFICATION } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 1899265f3..185930e68 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -1263,12 +1263,11 @@ public class Helper { editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim()); editor.commit(); - activity.recreate(); - if( checkItem ) { - Intent intent = new Intent(activity, MainActivity.class); - intent.putExtra(INTENT_ACTION, CHANGE_USER_INTENT); - activity.startActivity(intent); - } + Intent changeAccount = new Intent(activity, MainActivity.class); + changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.finish(); + activity.startActivity(changeAccount); + } @@ -2638,9 +2637,12 @@ public class Helper { allTabCount -=1; } } + int i = countInitialTab; if( searches != null) { for (String search : searches) { addTab(tableLayout, pagerAdapter, search); + BaseMainActivity.typePosition.put(i, RetrieveFeedsAsyncTask.Type.TAG); + i++; } if( searches.size() > 0 ){ tableLayout.setTabGravity(TabLayout.GRAVITY_FILL); @@ -3089,13 +3091,6 @@ public class Helper { } } - public static RetrieveFeedsAsyncTask.Type timelineType(int position){ - if(MainActivity.typePosition.size() > position) - return MainActivity.typePosition.get(position); - else - return RetrieveFeedsAsyncTask.Type.TAG; - } - public static boolean containsCaseInsensitive(String s, List l){ for (String string : l){ if (string.equalsIgnoreCase(s)){