diff --git a/app/src/main/java/se/oort/diplicity/PreferenceActivity.java b/app/src/main/java/se/oort/diplicity/PreferenceActivity.java index c4f7495..6b8f549 100644 --- a/app/src/main/java/se/oort/diplicity/PreferenceActivity.java +++ b/app/src/main/java/se/oort/diplicity/PreferenceActivity.java @@ -136,14 +136,16 @@ public void send(SingleContainer 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() { @@ -151,24 +153,17 @@ public boolean onPreferenceChange(Preference preference, Object o) { 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; } }); diff --git a/app/src/main/java/se/oort/diplicity/RetrofitActivity.java b/app/src/main/java/se/oort/diplicity/RetrofitActivity.java index 9e21c37..637579e 100644 --- a/app/src/main/java/se/oort/diplicity/RetrofitActivity.java +++ b/app/src/main/java/se/oort/diplicity/RetrofitActivity.java @@ -261,7 +261,9 @@ public Object call(RootService.Root root, MultiContainer 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> subscribersCopy; synchronized (loginSubscribers) { @@ -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(); } } diff --git a/app/src/main/java/se/oort/diplicity/apigen/Phase.java b/app/src/main/java/se/oort/diplicity/apigen/Phase.java index d8e54d9..bf2f65c 100644 --- a/app/src/main/java/se/oort/diplicity/apigen/Phase.java +++ b/app/src/main/java/se/oort/diplicity/apigen/Phase.java @@ -13,7 +13,7 @@ public class Phase implements java.io.Serializable { public String UnitsJSON; public String SCsJSON; public String GameID; - public java.util.List Units; + public java.util.List Units; public java.util.List SCs; public java.util.List Dislodgeds; public java.util.List Dislodgers; diff --git a/app/src/main/java/se/oort/diplicity/apigen/Unit.java b/app/src/main/java/se/oort/diplicity/apigen/Unit.java index 96ba0a8..4b1828b 100644 --- a/app/src/main/java/se/oort/diplicity/apigen/Unit.java +++ b/app/src/main/java/se/oort/diplicity/apigen/Unit.java @@ -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; } \ No newline at end of file diff --git a/app/src/main/java/se/oort/diplicity/apigen/UnitWrapper.java b/app/src/main/java/se/oort/diplicity/apigen/UnitWrapper.java new file mode 100644 index 0000000..129de00 --- /dev/null +++ b/app/src/main/java/se/oort/diplicity/apigen/UnitWrapper.java @@ -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; +} \ No newline at end of file diff --git a/app/src/main/java/se/oort/diplicity/game/GameActivity.java b/app/src/main/java/se/oort/diplicity/game/GameActivity.java index a84725d..f262515 100644 --- a/app/src/main/java/se/oort/diplicity/game/GameActivity.java +++ b/app/src/main/java/se/oort/diplicity/game/GameActivity.java @@ -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; @@ -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 { @@ -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>, MultiContainer, Object>() { + .and(phaseService.PhaseLoad(game.ID, phaseMeta.PhaseOrdinal.toString())) + .then(new Func3>, MultiContainer, SingleContainer, Object>() { @Override - public Object call(SingleContainer> opts, MultiContainer ords) { + public Object call(SingleContainer> opts, MultiContainer ords, SingleContainer phase) { options = opts.Properties; orders.clear(); for (SingleContainer orderContainer : ords.Properties) { @@ -908,6 +913,33 @@ public Object call(SingleContainer> 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() { diff --git a/app/src/main/res/values/plurals.xml b/app/src/main/res/values/plurals.xml index d24cf63..c84865a 100644 --- a/app/src/main/res/values/plurals.xml +++ b/app/src/main/res/values/plurals.xml @@ -10,4 +10,9 @@ 1 msg %d msgs + + 0 units + 1 unit + %d units + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6893c9..cd2a507 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -142,4 +142,6 @@ email_notifications_pref_key local_development_mode_pref_key local_development_mode_fake_id_pref_key + You can build %s this phase. + You have to disband %s this phase.