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.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import org.communiquons.android.comunic.client.MainActivity; import org.communiquons.android.comunic.client.MainActivity;
@ -74,6 +75,11 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
*/ */
private ConversationsListAdapter conversationsListAdapter; private ConversationsListAdapter conversationsListAdapter;
/**
* Loading progress bar
*/
private ProgressBar progressBar;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 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 //Get the conversation target list view
conversationsListView = view.findViewById(R.id.fragment_conversationslist_list); 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 //Get the list of conversations
new AsyncTask<Void, Void, ArrayList<ConversationsInfo>>(){ new AsyncTask<Void, Void, ArrayList<ConversationsInfo>>(){
@Override @Override
@ -243,7 +252,11 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
//Attach it to the view //Attach it to the view
conversationsListView.setAdapter(conversationsListAdapter); conversationsListView.setAdapter(conversationsListAdapter);
//Add click listener
conversationsListView.setOnItemClickListener(this); 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()); 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.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuInflater; import android.view.MenuInflater;

View File

@ -3,6 +3,14 @@
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="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 --> <!-- List of the conversations -->
<ListView <ListView
android:id="@+id/fragment_conversationslist_list" android:id="@+id/fragment_conversationslist_list"