Skip to content

Commit

Permalink
Added build/disband help message for adjustment phases.
Browse files Browse the repository at this point in the history
Repaired some of the local dev mode settings that broke during last config refactoring.
Removed some debug logging.
  • Loading branch information
zond committed Jan 1, 2017
1 parent cc13d66 commit 0e75d1d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 18 deletions.
17 changes: 6 additions & 11 deletions app/src/main/java/se/oort/diplicity/PreferenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,34 @@ public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
}

final EditTextPreference fakeIDPref = (EditTextPreference) findPreference(getResources().getString(R.string.local_development_mode_fake_id_pref_key));
fakeIDPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
final Preference.OnPreferenceChangeListener fakeIDChanged = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
fakeIDPref.setSummary((String) o);
PreferenceManager.getDefaultSharedPreferences(retrofitActivity()).edit().putString(AUTH_TOKEN_PREF_KEY, "").apply();
retrofitActivity().performLogin();
return true;
}
});
};
fakeIDPref.setOnPreferenceChangeListener(fakeIDChanged);

final CheckBoxPreference localDevPreference = (CheckBoxPreference) findPreference(getResources().getString(R.string.local_development_mode_pref_key));
localDevPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
if ((Boolean) o) {
prefs.edit().putString(RetrofitActivity.API_URL_PREF_KEY, RetrofitActivity.LOCAL_DEVELOPMENT_URL).apply();
Log.d("Diplicity", "*** updated " + API_URL_PREF_KEY);
final EditTextPreference fakeIDPref = new EditTextPreference(getActivity());
fakeIDPref.setKey(getResources().getString(R.string.local_development_mode_fake_id_pref_key));
fakeIDPref.setTitle(getActivity().getResources().getString(R.string.local_development_fake_id));
fakeIDPref.setSummary(prefs.getString(getResources().getString(R.string.local_development_mode_fake_id_pref_key), ""));
fakeIDPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
fakeIDPref.setSummary((String) o);
return true;
}
});
fakeIDPref.setOnPreferenceChangeListener(fakeIDChanged);
((PreferenceCategory) findPreference("development_prefs")).addPreference(fakeIDPref);
} else {
prefs.edit().putString(RetrofitActivity.API_URL_PREF_KEY, RetrofitActivity.DEFAULT_URL).apply();
Log.d("Diplicity", "*** updated " + API_URL_PREF_KEY);
removeFakeIDPref();
}
retrofitActivity().performLogin();
return true;
}
});
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/se/oort/diplicity/RetrofitActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ public Object call(RootService.Root root, MultiContainer<VariantService.Variant>
SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(RetrofitActivity.this).edit();
Gson gson = new Gson();
prefs.putString(LOGGED_IN_USER_PREF_KEY, gson.toJson(root.Properties.User));
loggedInUser = root.Properties.User;
prefs.putString(VARIANTS_PREF_KEY, gson.toJson(variants));
variants = variants;
prefs.apply();
List<LoginSubscriber<?>> subscribersCopy;
synchronized (loginSubscribers) {
Expand Down Expand Up @@ -395,9 +397,7 @@ protected void onPostCreate(Bundle savedInstanceState) {
prefsListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
Log.d("Diplicity", "Prefs changed, " + s);
if (s.equals(API_URL_PREF_KEY)) {
Log.d("Diplicity", "Prefs changed, API URL");
recreateServices();
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/se/oort/diplicity/apigen/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Phase implements java.io.Serializable {
public String UnitsJSON;
public String SCsJSON;
public String GameID;
public java.util.List<Unit> Units;
public java.util.List<UnitWrapper> Units;
public java.util.List<SC> SCs;
public java.util.List<Dislodged> Dislodgeds;
public java.util.List<Dislodger> Dislodgers;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/se/oort/diplicity/apigen/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import retrofit2.http.*;

public class Unit implements java.io.Serializable {
public String Province;
public Unit Unit;
public String Type;
public String Nation;
}
8 changes: 8 additions & 0 deletions app/src/main/java/se/oort/diplicity/apigen/UnitWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package se.oort.diplicity.apigen;

import retrofit2.http.*;

public class UnitWrapper implements java.io.Serializable {
public String Province;
public Unit Unit;
}
36 changes: 34 additions & 2 deletions app/src/main/java/se/oort/diplicity/game/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import retrofit2.adapter.rxjava.HttpException;
import rx.functions.Func2;
import rx.functions.Func3;
import rx.observables.JoinObservable;
import se.oort.diplicity.App;
import se.oort.diplicity.ChannelService;
Expand All @@ -66,7 +67,10 @@
import se.oort.diplicity.apigen.PhaseResult;
import se.oort.diplicity.apigen.PhaseState;
import se.oort.diplicity.apigen.Resolution;
import se.oort.diplicity.apigen.SC;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.Unit;
import se.oort.diplicity.apigen.UnitWrapper;

public class GameActivity extends RetrofitActivity
implements NavigationView.OnNavigationItemSelectedListener {
Expand Down Expand Up @@ -896,9 +900,10 @@ public void send(String url) {
handleReq(JoinObservable.when(JoinObservable
.from(optionsService.GetOptions(game.ID, phaseMeta.PhaseOrdinal.toString()))
.and(orderService.ListOrders(game.ID, phaseMeta.PhaseOrdinal.toString()))
.then(new Func2<SingleContainer<Map<String, OptionsService.Option>>, MultiContainer<Order>, Object>() {
.and(phaseService.PhaseLoad(game.ID, phaseMeta.PhaseOrdinal.toString()))
.then(new Func3<SingleContainer<Map<String,OptionsService.Option>>, MultiContainer<Order>, SingleContainer<Phase>, Object>() {
@Override
public Object call(SingleContainer<Map<String, OptionsService.Option>> opts, MultiContainer<Order> ords) {
public Object call(SingleContainer<Map<String, OptionsService.Option>> opts, MultiContainer<Order> ords, SingleContainer<Phase> phase) {
options = opts.Properties;
orders.clear();
for (SingleContainer<Order> orderContainer : ords.Properties) {
Expand All @@ -908,6 +913,33 @@ public Object call(SingleContainer<Map<String, OptionsService.Option>> opts, Mul
}
orders.put(srcProvince, orderContainer.Properties);
}
boolean hasBuildOpts = false;
boolean hasDisbandOpts = false;
for (OptionsService.Option opt : options.values()) {
if (opt.Next.containsKey("Build")) {
hasBuildOpts = true;
}
if (opt.Next.containsKey("Disband")) {
hasDisbandOpts = true;
}
}
int units = 0;
int scs = 0;
for (UnitWrapper unit : phase.Properties.Units) {
if (unit.Unit.Nation.equals(member.Nation)) {
units++;
}
}
for (SC sc : phase.Properties.SCs) {
if (sc.Owner.equals(member.Nation)) {
scs++;
}
}
if (hasBuildOpts && units < scs) {
Toast.makeText(GameActivity.this, getResources().getString(R.string.you_can_build_n_this_phase, getResources().getQuantityString(R.plurals.unit, scs - units)), Toast.LENGTH_LONG).show();
} else if (hasDisbandOpts && scs < units) {
Toast.makeText(GameActivity.this, getResources().getString(R.string.you_have_to_disband_n_this_phase, getResources().getQuantityString(R.plurals.unit, units - scs)), Toast.LENGTH_LONG).show();
}
return null;
}
})).toObservable(), new Sendable<Object>() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/plurals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
<item quantity="one">1 msg</item>
<item quantity="other">%d msgs</item>
</plurals>
<plurals name="unit">
<item quantity="zero">0 units</item>
<item quantity="one">1 unit</item>
<item quantity="other">%d units</item>
</plurals>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@
<string name="email_notifications_pref_key">email_notifications_pref_key</string>
<string name="local_development_mode_pref_key">local_development_mode_pref_key</string>
<string name="local_development_mode_fake_id_pref_key">local_development_mode_fake_id_pref_key</string>
<string name="you_can_build_n_this_phase">You can build %s this phase.</string>
<string name="you_have_to_disband_n_this_phase">You have to disband %s this phase.</string>
</resources>

0 comments on commit 0e75d1d

Please sign in to comment.