Add progressbar to conversations list fragment

This commit is contained in:
Pierre 2017-12-25 18:29:39 +01:00
parent 7e451d73a9
commit 2af59a19ed
3 changed files with 50 additions and 21 deletions

View File

@ -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<Void, Void, ArrayList<ConversationsInfo>>(){
@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);
}
}

View File

@ -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<Integer, UserInfo> 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<Integer, UserInfo> 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<FriendUser> 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<FriendUser> friendsUserList = FriendsUtils.merge_friends_user_infos_list(
friendsList,
info
);
//Refresh friends list
apply_friends_list(friendsUserList);
}
});
});
}

View File

@ -3,6 +3,14 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Loading progress bar -->
<ProgressBar
android:id="@+id/fragment_conversationslist_progressbar"
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<!-- List of the conversations -->
<ListView
android:id="@+id/fragment_conversationslist_list"