From 2af59a19edeb786dc69a9492d8f4efe297bd5353 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 25 Dec 2017 18:29:39 +0100 Subject: [PATCH] Add progressbar to conversations list fragment --- .../fragments/ConversationsListFragment.java | 22 ++++++++++ .../client/fragments/FriendsListFragment.java | 41 +++++++++---------- .../res/layout/fragment_conversationslist.xml | 8 ++++ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java index ea30fc3..1df3c78 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/fragments/ConversationsListFragment.java @@ -13,6 +13,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.Toast; import org.communiquons.android.comunic.client.MainActivity; @@ -74,6 +75,11 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O */ private ConversationsListAdapter conversationsListAdapter; + /** + * Loading progress bar + */ + private ProgressBar progressBar; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { @@ -96,6 +102,9 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O //Get the conversation target list view conversationsListView = view.findViewById(R.id.fragment_conversationslist_list); + //Get progress bar wheel + progressBar = view.findViewById(R.id.fragment_conversationslist_progressbar); + //Get the list of conversations new AsyncTask>(){ @Override @@ -243,7 +252,11 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O //Attach it to the view conversationsListView.setAdapter(conversationsListAdapter); + //Add click listener conversationsListView.setOnItemClickListener(this); + + //Remove progress bar + display_progress_bar(false); } /** @@ -261,4 +274,13 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O openConvListener.openConversation(conv.getID()); } + + /** + * Display (or hide) the progress bar + * + * @param show Set wether the progress bar should be shown or not + */ + private void display_progress_bar(boolean show){ + progressBar.setVisibility(show ? View.VISIBLE : View.GONE); + } } 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 039c549..eaa3d2e 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 @@ -8,7 +8,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; import android.util.ArrayMap; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuInflater; @@ -148,26 +147,26 @@ public class FriendsListFragment extends Fragment { } new GetUsersInfos(mContext, mDbHelper). - getMultiple(FriendsUtils.getFriendsIDs(friendsList), new GetUsersInfos.getMultipleUserInfosCallback() { - @Override - public void callback(ArrayMap info) { - //Check for errors - if (info == null) { - Toast.makeText(mContext, R.string.fragment_friendslist_err_get_userinfos, - Toast.LENGTH_SHORT).show(); - return; + getMultiple(FriendsUtils.getFriendsIDs(friendsList), new GetUsersInfos.getMultipleUserInfosCallback() { + @Override + public void callback(ArrayMap info) { + //Check for errors + if (info == null) { + Toast.makeText(mContext, R.string.fragment_friendslist_err_get_userinfos, + Toast.LENGTH_SHORT).show(); + return; + } + + //Merge the user informations list and friends List into FriendInfo list + ArrayList friendsUserList = FriendsUtils.merge_friends_user_infos_list( + friendsList, + info + ); + + //Refresh friends list + apply_friends_list(friendsUserList); } - - //Merge the user informations list and friends List into FriendInfo list - ArrayList friendsUserList = FriendsUtils.merge_friends_user_infos_list( - friendsList, - info - ); - - //Refresh friends list - apply_friends_list(friendsUserList); - } - }); + }); } @@ -231,7 +230,7 @@ public class FriendsListFragment extends Fragment { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.popup_deletefriend_title) .setMessage(R.string.popup_deletefriend_message); - + builder.setPositiveButton(R.string.popup_deletefriend_button_confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/app/src/main/res/layout/fragment_conversationslist.xml b/app/src/main/res/layout/fragment_conversationslist.xml index 8370081..b3f9fd3 100644 --- a/app/src/main/res/layout/fragment_conversationslist.xml +++ b/app/src/main/res/layout/fragment_conversationslist.xml @@ -3,6 +3,14 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> + + +