From 52a9c152904c53168329c66d37e0da2306f3b682 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 21 Aug 2018 12:30:58 +0200 Subject: [PATCH] Dynamically update selected navigation tab. --- .../comunic/client/ui/activities/MainActivity.java | 13 +++++++++++++ .../client/ui/fragments/ConversationFragment.java | 2 ++ .../ui/fragments/ConversationsListFragment.java | 1 + .../client/ui/fragments/FriendsListFragment.java | 1 + .../client/ui/fragments/LatestPostsFragment.java | 1 + .../client/ui/fragments/NotificationsFragment.java | 1 + .../ui/fragments/UpdateConversationFragment.java | 1 + .../client/ui/fragments/UserPageFragment.java | 2 ++ .../comunic/client/ui/views/NavigationBar.java | 9 +++++++++ app/src/main/res/values/strings.xml | 2 +- 10 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index 9afb0fb..1f8330e 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -280,7 +280,20 @@ public class MainActivity extends AppCompatActivity implements return true; } + /** + * Specify what is the selected + * + * @param activity An instance of {@link MainActivity} + * @param id The identifier of the menu to choose + */ + public static void SetNavbarSelectedOption(@NonNull Activity activity, int id){ + if(!(activity instanceof MainActivity)) + throw new RuntimeException("Specified activity is not an instance of activity!"); + + ((MainActivity)activity).mNavBar.setIdentifierSelected(id); + + } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index 84ca59b..2d522c3 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -34,6 +34,7 @@ import org.communiquons.android.comunic.client.data.models.ConversationsInfo; import org.communiquons.android.comunic.client.data.models.UserInfo; import org.communiquons.android.comunic.client.data.runnables.ConversationRefreshRunnable; import org.communiquons.android.comunic.client.data.utils.AccountUtils; +import org.communiquons.android.comunic.client.ui.activities.MainActivity; import org.communiquons.android.comunic.client.ui.adapters.ConversationMessageAdapter; import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener; import org.communiquons.android.comunic.client.ui.utils.BitmapUtils; @@ -307,6 +308,7 @@ public class ConversationFragment extends Fragment //Update conversation title getActivity().setTitle(R.string.fragment_conversation_title); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations); //Check for conversation information diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java index e6ee028..2d7caf4 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationsListFragment.java @@ -153,6 +153,7 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O //Update activity title getActivity().setTitle(R.string.fragment_conversationslist_title); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations); } /** diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/FriendsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/FriendsListFragment.java index 8beb3bb..c0a2483 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/FriendsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/FriendsListFragment.java @@ -166,6 +166,7 @@ public class FriendsListFragment extends Fragment //Update the title of the application getActivity().setTitle(R.string.fragment_friendslist_title); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_friendslist); //Refresh the friends list refresh_friend_list(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/LatestPostsFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/LatestPostsFragment.java index ef1b4e0..16ecf56 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/LatestPostsFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/LatestPostsFragment.java @@ -109,6 +109,7 @@ public class LatestPostsFragment extends Fragment //Update dock and activity title getActivity().setTitle(R.string.fragment_latestposts_title); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_latest_posts); //Refresh the list of posts of the user refresh_posts_list(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/NotificationsFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/NotificationsFragment.java index 4f9b204..6954b8c 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/NotificationsFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/NotificationsFragment.java @@ -142,6 +142,7 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont //Update the title of the application getActivity().setTitle(R.string.fragment_notifications_title); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_notifications); //Get user page opener mUserPageOpener = (onOpenUsersPageListener) getActivity(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java index 6e29647..929e252 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UpdateConversationFragment.java @@ -235,6 +235,7 @@ public class UpdateConversationFragment extends Fragment { getActivity().setTitle(R.string.fragment_update_conversation_title_create); else getActivity().setTitle(R.string.fragment_update_conversation_title_update); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations); } /** diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java index a7f0eb2..575da9a 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java @@ -115,6 +115,8 @@ public class UserPageFragment extends Fragment { public void onResume() { super.onResume(); + MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_personal_page); + //Check if we got information about the user if(userInfo == null || mTabLayout.getTabCount() < 2){ diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/NavigationBar.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/NavigationBar.java index b5c7b85..a68aa41 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/NavigationBar.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/NavigationBar.java @@ -107,6 +107,15 @@ public class NavigationBar extends BaseFrameLayoutView implements NavigationBarI } + /** + * Set the currently selected item by its identifier in the list + * + * @param id The index of the item to mark as selected + */ + public void setIdentifierSelected(int id){ + setIndexSelected(MenuUtils.MenuIdentifierToIndex(mMenu, id)); + } + public void setOnNavigationItemSelectedListener(OnNavigationItemSelectedListener onNavigationItemSelectedListener) { this.mOnNavigationItemSelectedListener = onNavigationItemSelectedListener; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1d518b5..9dccfc9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,7 +65,7 @@ Friends Conversations About me - Title + Conversation Could not get information about the conversation ! Delete Update