Skip to content

Commit

Permalink
Made the client handle nation-less games (future mustering status gam…
Browse files Browse the repository at this point in the history
…es).
  • Loading branch information
zond committed May 20, 2020
1 parent 6d5f8ba commit a301233
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
21 changes: 14 additions & 7 deletions app/src/main/java/se/oort/diplicity/MemberTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void setPhaseStates(Game game, PhaseMeta phaseMeta, List<PhaseState> phas
}
public void setMembers(final RetrofitActivity retrofitActivity, Game game, final List<Member> members) {
removeAllViews();
boolean fakeFoundPhaseState = false;
for (final Member member : members) {
boolean rowOK = true;
TableRow tableRow = new TableRow(retrofitActivity);
Expand All @@ -71,12 +72,14 @@ public void setMembers(final RetrofitActivity retrofitActivity, Game game, final
userView.setMember(retrofitActivity, game, member, member.User, this.phaseStates == null);
tableRow.addView(userView);

if (member.Nation != null && !member.Nation.equals("")) {
TextView nation = new TextView(retrofitActivity);
nation.setLayoutParams(wrapContentParams);
nation.setText(member.Nation);
tableRow.addView(nation);
String nationName = member.Nation;
if (nationName == null || nationName.equals("")) {
nationName = "TBD";
}
TextView nation = new TextView(retrofitActivity);
nation.setLayoutParams(wrapContentParams);
nation.setText(nationName);
tableRow.addView(nation);
if (this.scores != null) {
GameScore foundScore = null;
for (GameScore score : scores) {
Expand Down Expand Up @@ -104,14 +107,18 @@ public void setMembers(final RetrofitActivity retrofitActivity, Game game, final
break;
}
}
if (foundState == null && this.phaseStates.size() == 1 && !fakeFoundPhaseState) {
foundState = this.phaseStates.get(0);
fakeFoundPhaseState = true;
}
if (foundState != null) {
final PhaseState finalFoundState = foundState;
final CheckBox onProbation = new CheckBox(retrofitActivity);
final CheckBox readyToResolve = new CheckBox(retrofitActivity);
readyToResolve.setText(R.string.rdy);
readyToResolve.setLayoutParams(wrapContentParams);
readyToResolve.setChecked(finalFoundState.ReadyToResolve);
if (!foundState.NoOrders && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
if ((!foundState.NoOrders || fakeFoundPhaseState) && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
final Game finalGame = game;
readyToResolve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand Down Expand Up @@ -150,7 +157,7 @@ public void send(Object o) {
wantsDIAS.setText(R.string.DRAW);
wantsDIAS.setLayoutParams(wrapContentParams);
wantsDIAS.setChecked(finalFoundState.WantsDIAS);
if (!foundState.Eliminated && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
if (!fakeFoundPhaseState && !foundState.Eliminated && !phaseMeta.Resolved && retrofitActivity.getLoggedInUser().Id.equals(member.User.Id)) {
wantsDIAS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/se/oort/diplicity/RetrofitActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -556,7 +557,13 @@ public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
}

public Member getLoggedInMember(Game game) {
return App.getMemberByUser(game, getLoggedInUser().Id);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String fakeID = prefs.getString(getResources().getString(R.string.local_development_mode_fake_id_pref_key), "");
if (fakeID.equals("")) {
return App.getMemberByUser(game, getLoggedInUser().Id);
} else {
return App.getMemberByUser(game, fakeID);
}
}

public String getLocalDevelopmentModeFakeID() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/se/oort/diplicity/game/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void draw() {
addInfo();

FrameLayout rdyButtonFrame = (FrameLayout) findViewById(R.id.rdy_button_frame);
if (member != null && !phaseMeta.Properties.Resolved && !member.NewestPhaseState.NoOrders) {
if (member != null && !phaseMeta.Properties.Resolved && (member.Nation.equals("") || !member.NewestPhaseState.NoOrders)) {
final TextView rdyButtonText = (TextView) findViewById(R.id.rdy_button_text);
rdyButtonFrame.setVisibility(View.VISIBLE);
if (member.NewestPhaseState.ReadyToResolve) {
Expand Down

0 comments on commit a301233

Please sign in to comment.