From a301233f90621ee5ff558be7a5365da8628cec90 Mon Sep 17 00:00:00 2001 From: Martin Bruse Date: Wed, 20 May 2020 22:34:40 +0200 Subject: [PATCH] Made the client handle nation-less games (future mustering status games). --- .../java/se/oort/diplicity/MemberTable.java | 21 ++++++++++++------- .../se/oort/diplicity/RetrofitActivity.java | 9 +++++++- .../java/se/oort/diplicity/game/MapView.java | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/se/oort/diplicity/MemberTable.java b/app/src/main/java/se/oort/diplicity/MemberTable.java index b2c3821..448b1f7 100644 --- a/app/src/main/java/se/oort/diplicity/MemberTable.java +++ b/app/src/main/java/se/oort/diplicity/MemberTable.java @@ -53,6 +53,7 @@ public void setPhaseStates(Game game, PhaseMeta phaseMeta, List phas } public void setMembers(final RetrofitActivity retrofitActivity, Game game, final List members) { removeAllViews(); + boolean fakeFoundPhaseState = false; for (final Member member : members) { boolean rowOK = true; TableRow tableRow = new TableRow(retrofitActivity); @@ -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) { @@ -104,6 +107,10 @@ 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); @@ -111,7 +118,7 @@ public void setMembers(final RetrofitActivity retrofitActivity, Game game, final 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 @@ -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) { diff --git a/app/src/main/java/se/oort/diplicity/RetrofitActivity.java b/app/src/main/java/se/oort/diplicity/RetrofitActivity.java index 013e62d..03bf02d 100644 --- a/app/src/main/java/se/oort/diplicity/RetrofitActivity.java +++ b/app/src/main/java/se/oort/diplicity/RetrofitActivity.java @@ -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; @@ -556,7 +557,13 @@ public void send(SingleContainer 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() { diff --git a/app/src/main/java/se/oort/diplicity/game/MapView.java b/app/src/main/java/se/oort/diplicity/game/MapView.java index d516a4f..48e79db 100644 --- a/app/src/main/java/se/oort/diplicity/game/MapView.java +++ b/app/src/main/java/se/oort/diplicity/game/MapView.java @@ -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) {