Commit aab91ef8 authored by rakam's avatar rakam

Adds refresh button in SelectMatchesFragment

parent 02ec9b4a
......@@ -133,6 +133,12 @@ public class MatchAdapter extends BaseAdapter {
viewHolder._separator.setTextColor(normalTextColor);
}
public void resetSelection() {
selectedItem = -1;
onMatchSelectedListener.onMatchSelected(null);
notifyDataSetChanged();
}
static class ViewHolder {
ImageView drapeauA, drapeauB;
TextView paysA, paysB;
......
......@@ -7,7 +7,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.gson.JsonArray;
......@@ -33,7 +32,8 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
private List<Match> matches = new ArrayList<Match>();
private MatchAdapter matchAdapter;
private Button nextButton;
private ProgressBar progressBar;
private View progressBar;
private View refreshButton;
private TextView messageTV;
@Override
......@@ -49,13 +49,20 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.select_match_fragment, container, false);
nextButton = (Button) root.findViewById(R.id.nextButton);
progressBar = root.findViewById(R.id.progressBar);
refreshButton = root.findViewById(R.id.refreshButton);
refreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadMatches();
}
});
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
matchSetupActivity.next();
}
});
progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
messageTV = (TextView) root.findViewById(R.id.messageTV);
ListView matchListView = (ListView) root.findViewById(R.id.matchListView);
matchListView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height));
......@@ -68,6 +75,7 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
}
private void loadMatches() {
setRefreshing(true);
Ion.with(matchSetupActivity)
.load("GET", API_URLS.MATCHS + "?round=CURRENT")
.setTimeout(1000 * 10)
......@@ -75,6 +83,7 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
setRefreshing(false);
if (e != null || result != null && result.get("code").getAsInt() != 0) {
if (result.get("code").getAsInt() == -3)
displayMessage(matchSetupActivity.getString(R.string.no_match_setting_up));
......@@ -82,7 +91,8 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
loadMatches();
return;
}
progressBar.setVisibility(View.GONE);
matches.clear();
matchAdapter.resetSelection();
JsonArray matchesArray = result.getAsJsonArray("matches");
for (int i = 0; i < matchesArray.size(); i++) {
JsonObject o = matchesArray.get(i).getAsJsonObject();
......@@ -119,6 +129,16 @@ public class SelectMatchFragment extends SetupFragment implements OnMatchSelecte
messageTV.setText(message);
}
private void setRefreshing(boolean refreshing) {
if (refreshing) {
progressBar.setVisibility(View.VISIBLE);
refreshButton.setVisibility(View.GONE);
} else {
progressBar.setVisibility(View.INVISIBLE);
refreshButton.setVisibility(View.VISIBLE);
}
}
@Override
public void onMatchSelected(Match match) {
if (match == null) {
......
......@@ -11,44 +11,48 @@
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textColor="#444"
android:textSize="14sp"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
<fr.istic.masteru.android.views.RobotoTextView
android:id="@+id/categorie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/court"
android:layout_centerHorizontal="true"
android:textColor="#444"
android:textSize="14sp"/>
android:textStyle="italic"
android:textSize="16sp"/>
<TextView
<fr.istic.masteru.android.views.RobotoTextView
android:id="@+id/tableau"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/categorie"
android:layout_centerHorizontal="true"
android:textColor="#444"
android:textSize="14sp"/>
android:textStyle="italic"
android:textSize="16sp"/>
<TextView
<fr.istic.masteru.android.views.RobotoTextView
android:id="@+id/refereeingType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tableau"
android:layout_centerHorizontal="true"
android:textColor="#444"
android:textSize="14sp"
android:textSize="16sp"
android:textStyle="italic"
android:visibility="gone"/>
<TextView
<fr.istic.masteru.android.views.RobotoTextView
android:id="@+id/fsfButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/refereeingType"
android:layout_centerHorizontal="true"
android:textColor="#444"
android:textStyle="italic"
android:textSize="14sp"/>
<LinearLayout
......
......@@ -16,6 +16,28 @@
android:textSize="20sp"
android:textStyle="bold"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/_title"
android:layout_alignBottom="@id/_title"
android:layout_alignParentRight="true"
android:indeterminate="true"/>
<ImageButton
android:id="@+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/_title"
android:layout_alignBottom="@id/_title"
android:layout_alignLeft="@id/progressBar"
android:layout_alignRight="@id/progressBar"
android:layout_alignParentRight="true"
android:src="@android:drawable/stat_notify_sync"
android:background="@android:color/transparent"
android:visibility="invisible"/>
<fr.istic.masteru.android.views.RobotoButton
android:id="@+id/nextButton"
style="@android:style/Widget.Holo.Button.Borderless"
......@@ -32,12 +54,6 @@
android:textStyle="italic"
android:visibility="invisible"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<TextView
android:id="@+id/messageTV"
android:layout_width="wrap_content"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment