Display a notice on friends fragment when the user does not have any friend.

This commit is contained in:
Pierre 2018-04-14 17:41:24 +02:00
parent 636c74bc98
commit 2074792212
3 changed files with 31 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.communiquons.android.comunic.client.ui.activities.MainActivity; import org.communiquons.android.comunic.client.ui.activities.MainActivity;
@ -93,6 +94,11 @@ public class FriendsListFragment extends Fragment
*/ */
private FriendsAdapter fAdapter; private FriendsAdapter fAdapter;
/**
* No friend notice
*/
private TextView mNoFriendNotice;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -135,6 +141,10 @@ public class FriendsListFragment extends Fragment
rootView = view; rootView = view;
//Get the no friend notice
mNoFriendNotice = view.findViewById(R.id.no_friend_notice);
mNoFriendNotice.setVisibility(View.GONE);
//Retain the fragment //Retain the fragment
//setRetainInstance(true); //setRetainInstance(true);
@ -218,10 +228,12 @@ public class FriendsListFragment extends Fragment
return; return;
} }
//Save the list of friends //Save the list of friends
this.friendsList = friendsList; this.friendsList = friendsList;
//Update the visibility of the no friend notice
updateNoFriendNoticeVisibility();
//Set the adapter //Set the adapter
fAdapter = new FriendsAdapter(this, getActivity(), friendsList); fAdapter = new FriendsAdapter(this, getActivity(), friendsList);
ListView listView = rootView.findViewById(R.id.fragment_friendslist_listview); ListView listView = rootView.findViewById(R.id.fragment_friendslist_listview);
@ -384,6 +396,14 @@ public class FriendsListFragment extends Fragment
} }
/**
* Update the visibility of the no friend notice
*/
private void updateNoFriendNoticeVisibility(){
if(friendsList != null)
mNoFriendNotice.setVisibility(friendsList.size() == 0 ? View.VISIBLE : View.GONE);
}
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

View File

@ -10,6 +10,15 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" /> android:layout_centerHorizontal="true" />
<!-- No friend notice -->
<TextView
android:id="@+id/no_friend_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/notice_no_friend"
android:textAlignment="center"
android:layout_marginTop="50dp"/>
<ListView <ListView
android:id="@+id/fragment_friendslist_listview" android:id="@+id/fragment_friendslist_listview"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -176,4 +176,5 @@
<string name="notice_no_notification">You do not have any notification yet.</string> <string name="notice_no_notification">You do not have any notification yet.</string>
<string name="notice_no_post_user_page">There is not any post on this page yet.</string> <string name="notice_no_post_user_page">There is not any post on this page yet.</string>
<string name="notice_no_conversation">You do not have any conversation yet.</string> <string name="notice_no_conversation">You do not have any conversation yet.</string>
<string name="notice_no_friend">You do not have any friend yet.</string>
</resources> </resources>