Commit 60091ca3 authored by rakam's avatar rakam
Browse files

available courts

parent ba4def1e
...@@ -16,11 +16,11 @@ import java.util.ArrayList; ...@@ -16,11 +16,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import fr.istic.masteru.android.R; import fr.istic.masteru.android.R;
import fr.istic.masteru.android.fragments.CourtIdFragment;
import fr.istic.masteru.android.fragments.FirstServiceFragment; import fr.istic.masteru.android.fragments.FirstServiceFragment;
import fr.istic.masteru.android.fragments.InitialSideFragment; import fr.istic.masteru.android.fragments.InitialSideFragment;
import fr.istic.masteru.android.fragments.RefereeingTypeFragment; import fr.istic.masteru.android.fragments.RefereeingTypeFragment;
import fr.istic.masteru.android.fragments.ResultFragment; import fr.istic.masteru.android.fragments.ResultFragment;
import fr.istic.masteru.android.fragments.SelectCourtFragment;
import fr.istic.masteru.android.fragments.SelectMatchFragment; import fr.istic.masteru.android.fragments.SelectMatchFragment;
import fr.istic.masteru.android.fragments.SelectPlayersFragment; import fr.istic.masteru.android.fragments.SelectPlayersFragment;
import fr.istic.masteru.android.fragments.SetupFragment; import fr.istic.masteru.android.fragments.SetupFragment;
...@@ -57,7 +57,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe ...@@ -57,7 +57,7 @@ public class MatchSetupActivity extends Activity implements OnMatchSelectedListe
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.match_setup_activity); setContentView(R.layout.match_setup_activity);
flow.add(SelectMatchFragment.class.getName()); flow.add(SelectMatchFragment.class.getName());
flow.add(CourtIdFragment.class.getName()); flow.add(SelectCourtFragment.class.getName());
flow.add(SelectPlayersFragment.class.getName()); flow.add(SelectPlayersFragment.class.getName());
flow.add(FirstServiceFragment.class.getName()); flow.add(FirstServiceFragment.class.getName());
flow.add(InitialSideFragment.class.getName()); flow.add(InitialSideFragment.class.getName());
......
package fr.istic.masteru.android.fragments; package fr.istic.masteru.android.fragments;
import android.app.Activity; import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import fr.istic.masteru.android.R; import fr.istic.masteru.android.R;
import fr.istic.masteru.android.activities.MatchSetupActivity; import fr.istic.masteru.android.activities.MatchSetupActivity;
import fr.istic.masteru.android.utils.API_URLS;
import fr.istic.masteru.android.utils.Constants; import fr.istic.masteru.android.utils.Constants;
public class CourtIdFragment extends SetupFragment { public class SelectCourtFragment extends SetupFragment {
MatchSetupActivity matchSetupActivity; MatchSetupActivity matchSetupActivity;
private int lightGrey; private List<View> buttons = new ArrayList<>();
private List<View> buttons = new ArrayList<View>(); private View nextButton;
private View progressBar;
private View refreshButton;
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
...@@ -33,7 +40,6 @@ public class CourtIdFragment extends SetupFragment { ...@@ -33,7 +40,6 @@ public class CourtIdFragment extends SetupFragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
lightGrey = matchSetupActivity.getResources().getColor(R.color.light_grey);
View root = inflater.inflate(R.layout.court_id_fragment, container, false); View root = inflater.inflate(R.layout.court_id_fragment, container, false);
root.findViewById(R.id.previousButton).setOnClickListener(new View.OnClickListener() { root.findViewById(R.id.previousButton).setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -42,7 +48,9 @@ public class CourtIdFragment extends SetupFragment { ...@@ -42,7 +48,9 @@ public class CourtIdFragment extends SetupFragment {
matchSetupActivity.previous(); matchSetupActivity.previous();
} }
}); });
final View nextButton = root.findViewById(R.id.nextButton); nextButton = root.findViewById(R.id.nextButton);
progressBar = root.findViewById(R.id.progressBar);
refreshButton = root.findViewById(R.id.refreshButton);
nextButton.setOnClickListener(new View.OnClickListener() { nextButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -63,17 +71,66 @@ public class CourtIdFragment extends SetupFragment { ...@@ -63,17 +71,66 @@ public class CourtIdFragment extends SetupFragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
for (View button : buttons) { for (View button : buttons) {
button.setBackgroundColor(lightGrey); if (button.isEnabled())
button.setSelected(false);
} }
button.setBackgroundColor(Color.RED); button.setSelected(true);
matchSetupActivity.onSelectedCourtChange(idCourt); matchSetupActivity.onSelectedCourtChange(idCourt);
nextButton.setVisibility(View.VISIBLE); nextButton.setVisibility(View.VISIBLE);
} }
}); });
} }
refreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadAvailableCourts();
}
});
loadAvailableCourts();
return root; return root;
} }
private void loadAvailableCourts() {
setRefreshing(true);
Ion.with(matchSetupActivity)
.load("GET", API_URLS.AVAILABLE_COURTS)
.setTimeout(1000 * 6)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
setRefreshing(false);
if (e != null || result != null && result.get("code").getAsInt() != 0) {
loadAvailableCourts();
return;
}
nextButton.setVisibility(View.INVISIBLE);
matchSetupActivity.onSelectedCourtChange(Constants.UNDEFINED);
for (View button : buttons) {
button.setEnabled(false);
button.setSelected(false);
}
// progressBar.setVisibility(View.GONE);
JsonArray courtsArray = result.getAsJsonArray("courts");
for (int i = 0; i < courtsArray.size(); i++) {
int courtId = courtsArray.get(i).getAsInt();
buttons.get(courtId - 1).setEnabled(true);
}
buttons.get(3).setEnabled(false);
}
});
}
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 @Override
public void cancel() { public void cancel() {
matchSetupActivity.onSelectedCourtChange(Constants.UNDEFINED); matchSetupActivity.onSelectedCourtChange(Constants.UNDEFINED);
......
...@@ -8,6 +8,7 @@ public class API_URLS { ...@@ -8,6 +8,7 @@ public class API_URLS {
public static final String MATCH_WINNER = BASE_URL + "/match/finMatch"; public static final String MATCH_WINNER = BASE_URL + "/match/finMatch";
public static final String MATCHS = BASE_URL + "/matches"; public static final String MATCHS = BASE_URL + "/matches";
public static final String INFO_MATCH = BASE_URL + "/match/info/"; // + idMatch public static final String INFO_MATCH = BASE_URL + "/match/info/"; // + idMatch
public static final String AVAILABLE_COURTS = BASE_URL + "/courts/available";
public static String TEAM_PLAYERS(String teamId, String gender) { public static String TEAM_PLAYERS(String teamId, String gender) {
return BASE_URL + "/teams/" + teamId + "/players?gender=" + (gender == null ? "X" : gender); return BASE_URL + "/teams/" + teamId + "/players?gender=" + (gender == null ? "X" : gender);
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/grey_button_disabled" android:state_enabled="false"/>
<item android:drawable="@android:color/holo_red_dark" android:state_selected="true"/>
<item android:drawable="@color/grey_button" android:state_checked="true"/>
<item android:drawable="@color/grey_button" android:state_pressed="true"/>
<item android:drawable="@color/light_grey_button"/>
</selector>
\ No newline at end of file
...@@ -18,6 +18,28 @@ ...@@ -18,6 +18,28 @@
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold"/> 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"/>
<Button <Button
android:id="@+id/previousButton" android:id="@+id/previousButton"
style="@android:style/Widget.Holo.Button.Borderless" style="@android:style/Widget.Holo.Button.Borderless"
...@@ -77,8 +99,9 @@ ...@@ -77,8 +99,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court Central" android:text="Court Central"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -88,8 +111,9 @@ ...@@ -88,8 +111,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 1" android:text="Court 1"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -99,8 +123,9 @@ ...@@ -99,8 +123,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 2" android:text="Court 2"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -110,8 +135,9 @@ ...@@ -110,8 +135,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 3" android:text="Court 3"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -133,8 +159,9 @@ ...@@ -133,8 +159,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 4" android:text="Court 4"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -144,8 +171,9 @@ ...@@ -144,8 +171,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 5" android:text="Court 5"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
...@@ -155,8 +183,9 @@ ...@@ -155,8 +183,9 @@
android:layout_height="0px" android:layout_height="0px"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_weight="25" android:layout_weight="25"
android:background="@color/light_grey" android:background="@drawable/checkable_button"
android:text="Court 6" android:text="Court 6"
android:enabled="false"
android:textColor="#444" android:textColor="#444"
android:textSize="22sp"/> android:textSize="22sp"/>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<color name="light_grey">#dddddd</color> <color name="light_grey">#dddddd</color>
<color name="light_grey_button">#cccccc</color> <color name="light_grey_button">#cccccc</color>
<color name="grey_button">#bbbbbb</color> <color name="grey_button">#bbbbbb</color>
<color name="grey_button_disabled">#888</color>
<color name="white">#fefefe</color> <color name="white">#fefefe</color>
<color name="dark_grey">#303030</color> <color name="dark_grey">#303030</color>
<color name="darker_grey">#222222</color> <color name="darker_grey">#222222</color>
......
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