Dynamically update selected navigation tab.

This commit is contained in:
Pierre HUBERT 2018-08-21 12:30:58 +02:00
parent 3923e2b704
commit 52a9c15290
10 changed files with 32 additions and 1 deletions

View File

@ -280,7 +280,20 @@ public class MainActivity extends AppCompatActivity implements
return true; 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);
}

View File

@ -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.models.UserInfo;
import org.communiquons.android.comunic.client.data.runnables.ConversationRefreshRunnable; import org.communiquons.android.comunic.client.data.runnables.ConversationRefreshRunnable;
import org.communiquons.android.comunic.client.data.utils.AccountUtils; 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.adapters.ConversationMessageAdapter;
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener; import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
import org.communiquons.android.comunic.client.ui.utils.BitmapUtils; import org.communiquons.android.comunic.client.ui.utils.BitmapUtils;
@ -307,6 +308,7 @@ public class ConversationFragment extends Fragment
//Update conversation title //Update conversation title
getActivity().setTitle(R.string.fragment_conversation_title); getActivity().setTitle(R.string.fragment_conversation_title);
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations);
//Check for conversation information //Check for conversation information

View File

@ -153,6 +153,7 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
//Update activity title //Update activity title
getActivity().setTitle(R.string.fragment_conversationslist_title); getActivity().setTitle(R.string.fragment_conversationslist_title);
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations);
} }
/** /**

View File

@ -166,6 +166,7 @@ public class FriendsListFragment extends Fragment
//Update the title of the application //Update the title of the application
getActivity().setTitle(R.string.fragment_friendslist_title); getActivity().setTitle(R.string.fragment_friendslist_title);
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_friendslist);
//Refresh the friends list //Refresh the friends list
refresh_friend_list(); refresh_friend_list();

View File

@ -109,6 +109,7 @@ public class LatestPostsFragment extends Fragment
//Update dock and activity title //Update dock and activity title
getActivity().setTitle(R.string.fragment_latestposts_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 the list of posts of the user
refresh_posts_list(); refresh_posts_list();

View File

@ -142,6 +142,7 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
//Update the title of the application //Update the title of the application
getActivity().setTitle(R.string.fragment_notifications_title); getActivity().setTitle(R.string.fragment_notifications_title);
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_notifications);
//Get user page opener //Get user page opener
mUserPageOpener = (onOpenUsersPageListener) getActivity(); mUserPageOpener = (onOpenUsersPageListener) getActivity();

View File

@ -235,6 +235,7 @@ public class UpdateConversationFragment extends Fragment {
getActivity().setTitle(R.string.fragment_update_conversation_title_create); getActivity().setTitle(R.string.fragment_update_conversation_title_create);
else else
getActivity().setTitle(R.string.fragment_update_conversation_title_update); getActivity().setTitle(R.string.fragment_update_conversation_title_update);
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_conversations);
} }
/** /**

View File

@ -115,6 +115,8 @@ public class UserPageFragment extends Fragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
MainActivity.SetNavbarSelectedOption(getActivity(), R.id.action_personal_page);
//Check if we got information about the user //Check if we got information about the user
if(userInfo == null || mTabLayout.getTabCount() < 2){ if(userInfo == null || mTabLayout.getTabCount() < 2){

View File

@ -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) { public void setOnNavigationItemSelectedListener(OnNavigationItemSelectedListener onNavigationItemSelectedListener) {
this.mOnNavigationItemSelectedListener = onNavigationItemSelectedListener; this.mOnNavigationItemSelectedListener = onNavigationItemSelectedListener;
} }

View File

@ -65,7 +65,7 @@
<string name="fragment_friendslist_title">Friends</string> <string name="fragment_friendslist_title">Friends</string>
<string name="fragment_conversationslist_title">Conversations</string> <string name="fragment_conversationslist_title">Conversations</string>
<string name="fragment_userinfos_title">About me</string> <string name="fragment_userinfos_title">About me</string>
<string name="fragment_conversation_title">Title</string> <string name="fragment_conversation_title">Conversation</string>
<string name="fragment_conversation_err_getconvinfos">Could not get information about the conversation !</string> <string name="fragment_conversation_err_getconvinfos">Could not get information about the conversation !</string>
<string name="action_conversation_delete">Delete</string> <string name="action_conversation_delete">Delete</string>
<string name="action_conversation_update">Update</string> <string name="action_conversation_update">Update</string>