From c5a162ecfb95a198fdb037532aa69d4f2d398001 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 13 Jan 2018 18:56:18 +0100 Subject: [PATCH] Linked friends list with users page --- .../android/comunic/client/MainActivity.java | 7 +++-- .../client/data/friendsList/FriendUser.java | 10 ++++++++ .../client/fragments/FriendsListFragment.java | 24 ++++++++++++++++-- .../client/fragments/UserPageFragment.java | 14 ++++++++++ .../res/drawable/perm_group_personal_info.png | Bin 0 -> 1137 bytes .../main/res/menu/main_bottom_navigation.xml | 6 +++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/perm_group_personal_info.png diff --git a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java index 40145d0..1c236a7 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/MainActivity.java @@ -19,6 +19,7 @@ import org.communiquons.android.comunic.client.api.APIRequest; import org.communiquons.android.comunic.client.data.Account.Account; import org.communiquons.android.comunic.client.data.Account.AccountUtils; import org.communiquons.android.comunic.client.data.DatabaseHelper; +import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersHelper; import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper; import org.communiquons.android.comunic.client.data.friendsList.FriendRefreshLoopRunnable; import org.communiquons.android.comunic.client.data.utils.UiUtils; @@ -37,7 +38,8 @@ import org.communiquons.android.comunic.client.fragments.UserPageFragment; */ public class MainActivity extends AppCompatActivity implements ConversationsListHelper.openConversationListener, - ConversationsListHelper.updateConversationListener { + ConversationsListHelper.updateConversationListener, + GetUsersHelper.onOpenUsersPageListener { /** * Debug tag @@ -272,7 +274,8 @@ public class MainActivity extends AppCompatActivity * * @param userID The ID of the user to open */ - void openUserPage(int userID){ + @Override + public void openUserPage(int userID){ //Prepare arguments Bundle args = new Bundle(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/friendsList/FriendUser.java b/app/src/main/java/org/communiquons/android/comunic/client/data/friendsList/FriendUser.java index 2c6e9f7..1813961 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/friendsList/FriendUser.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/friendsList/FriendUser.java @@ -66,4 +66,14 @@ public class FriendUser { public void setFriend(Friend friend) { this.friend = friend; } + + + /*** + * Get the ID of the user + * + * @return The id of the user + */ + public int get_user_id(){ + return userInfo.getId(); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java index c1d76f6..068a745 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/FriendsListFragment.java @@ -39,7 +39,8 @@ import java.util.ArrayList; * Created by pierre on 11/11/17. */ -public class FriendsListFragment extends Fragment { +public class FriendsListFragment extends Fragment + implements AdapterView.OnItemClickListener{ /** * Debug tag @@ -81,6 +82,11 @@ public class FriendsListFragment extends Fragment { */ private ConversationsListHelper.openConversationListener convOpener; + /** + * Users page opener + */ + private GetUsersHelper.onOpenUsersPageListener usersPageOpener; + /** * Friend adapter */ @@ -105,11 +111,13 @@ public class FriendsListFragment extends Fragment { //Cast activity to convOpener try { convOpener = (ConversationsListHelper.openConversationListener) getActivity(); + usersPageOpener = (GetUsersHelper.onOpenUsersPageListener) getActivity(); } catch (ClassCastException e){ e.printStackTrace(); throw new RuntimeException(getActivity().getClass().getName() + " must implement" + - "ConversationsListHelper.openConversationListener !"); + "ConversationsListHelper.openConversationListener " + + "and GetUsersHelper.onOpenUsersPageListener !"); } } @@ -214,6 +222,8 @@ public class FriendsListFragment extends Fragment { //Register the view for the context menu registerForContextMenu(listView); + + listView.setOnItemClickListener(this); } @Override @@ -366,4 +376,14 @@ public class FriendsListFragment extends Fragment { } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + + //Get clicked user ID + int userID = friendsList.get(position).get_user_id(); + + //Open user page + usersPageOpener.openUserPage(userID); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserPageFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserPageFragment.java index 82f6314..57dadd1 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserPageFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/UserPageFragment.java @@ -12,7 +12,9 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import org.communiquons.android.comunic.client.MainActivity; import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.Account.AccountUtils; import org.communiquons.android.comunic.client.data.DatabaseHelper; import org.communiquons.android.comunic.client.data.ImageLoad.ImageLoadManager; import org.communiquons.android.comunic.client.data.UsersInfo.AdvancedUserInfo; @@ -152,9 +154,21 @@ public class UserPageFragment extends Fragment { //Save user informations userInfo = info; + //Set activity title + getActivity().setTitle(userInfo.getDisplayFullName()); + + //Update activity menu dock + if(AccountUtils.getID(getActivity()) == userID) + ((MainActivity) getActivity()).setSelectedNavigationItem( + R.id.main_bottom_navigation_me_view); + else + ((MainActivity) getActivity()).setSelectedNavigationItem( + R.id.main_bottom_navigation_users_view); + //Update user name and account image user_name.setText(userInfo.getDisplayFullName()); ImageLoadManager.remove(user_image); ImageLoadManager.load(getActivity(), userInfo.getAcountImageURL(), user_image); + } } diff --git a/app/src/main/res/drawable/perm_group_personal_info.png b/app/src/main/res/drawable/perm_group_personal_info.png new file mode 100644 index 0000000000000000000000000000000000000000..13505a665dd74644397443acd46c4aa0f4850b2a GIT binary patch literal 1137 zcmV-%1djWOP)fgvwHFO>lmFfuTFyT-uCz`($8S=Z6U$(4aLz?xi8RKmc( zaDahL4HwUNoooM z0|V3!1_lNOUYGn51^2|vJOv{IRR$`9h{z}f2n!KD2r&dmE-fm92PFf80D}U90fPfW z07D`}J;MTqqYQ5t#Ti`~OBq)%-eVGD3SyeTbb(ozIg)uH^BWdRmJXI%ta_}itoPU~ z*`~35V-IKF&7s86#qotRk@EtVBi9ygP3{FeQan?6g?K0N3G+?km*HP5pd+wD&{gn? zP^!=m;a(9Hk-ehfqF=-&i5rPuk*JWAlRPGsFD)&7LZ(bsUG|n-pS+9wABC-og-Uu# zZwxwoom5>bJwd%!`bP{F7}gra7~7i2n=+feG`nEF z(_)F`1gkphT$?!CKs#4^YX@UT9VazsB^L!(c{c@jWe;^vT`v=F8y|PyV7~z2$~& zn@l!u*=n+F`wpv}`**wUIlC`x|AT`$hkhPuKPG;B#YyW^=guUb{dIoQMeR#RuOwdm zcYV%Hn_GA9)ZbISf8t@@W3eaupJl!fd3o@4{#*HX7d|w7GX4DO>w@p$KLviB`qTQ) z@&A7S4FC@``j+us00002VoOIv0RM-N%)bBt010qNS#tmY3ljhU3ljkVnw%H_000Mc zNliru;sFg28y{ha?rZ=60NzPNK~#9!?U~UPgD?!lI0j_cF4#`M!wC*P7ij=0#UBuN z+W-In007{vXvIUnpOYUu8U&oluZqx<@+%_rynb$iD)ciGRHL7lpep^Wgq`=m^!ew^ zfC=0=|BM;5p8x>_5I_I{1Q5X2C==jD)_el(FZDACW^0wv1jEJFNP_8VF&1IH+`Woe zv0euNfOo^EMD>M6HR^d8s#MR&P`&!S4Ee~Q$%S0eklV00000002{dI$Ane1%U`F00000NkvXXu0mjf DuLtIa literal 0 HcmV?d00001 diff --git a/app/src/main/res/menu/main_bottom_navigation.xml b/app/src/main/res/menu/main_bottom_navigation.xml index 0e86601..9b94b8e 100644 --- a/app/src/main/res/menu/main_bottom_navigation.xml +++ b/app/src/main/res/menu/main_bottom_navigation.xml @@ -6,6 +6,12 @@ android:icon="@drawable/ic_menu_allfriends" /> + + Private conversation Could not get a private conversation ! Loading… + User