From 25a320805434a120b5f858fe7f9f3f2284c6063b Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 25 Sep 2017 11:42:41 +0200 Subject: [PATCH] display seasonal NPC shop banners --- .../habitica/helpers/RemoteConfigManager.java | 26 ++++++++++--------- .../inventory/ShopRecyclerAdapter.java | 12 +++++---- .../inventory/shops/ShopFragment.java | 8 ++++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java index 2e9ea2bea..b0a8fb525 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java @@ -17,15 +17,12 @@ import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; -/** - * Created by keith holliday on 4/7/2017. - */ - public class RemoteConfigManager { private Context context; private Boolean enableRepeatbles = false; private Boolean enableNewShops = false; + private String shopSpriteSuffix = ""; private String REMOTE_STRING_KEY = "remote-string"; public RemoteConfigManager(Context context) { @@ -42,6 +39,10 @@ public class RemoteConfigManager { return enableNewShops; } + public String shopSpriteSuffix() { + return shopSpriteSuffix; + } + private void loadFromPreferences () { String storedPreferences = PreferenceManager.getDefaultSharedPreferences(context) .getString(REMOTE_STRING_KEY, ""); @@ -50,12 +51,19 @@ public class RemoteConfigManager { return; } + parseConfig(storedPreferences); + } + + private void parseConfig(String jsonString) { try { - JSONObject obj = new JSONObject(storedPreferences); + JSONObject obj = new JSONObject(jsonString); enableRepeatbles = obj.getBoolean("enableRepeatables"); if (obj.has("enableNewShops")) { enableNewShops = obj.getBoolean("enableNewShops"); } + if (obj.has("shopSpriteSuffix")) { + shopSpriteSuffix = obj.getString("shopSpriteSuffix"); + } } catch (JSONException e) { e.printStackTrace(); } @@ -127,13 +135,7 @@ public class RemoteConfigManager { PreferenceManager.getDefaultSharedPreferences(context) .edit().putString(REMOTE_STRING_KEY, text.toString()).apply(); - try { - JSONObject obj = new JSONObject(text.toString()); - enableRepeatbles = obj.getBoolean("enableRepeatables"); - enableNewShops = obj.getBoolean("enableNewShops"); - } catch (JSONException e) { - e.printStackTrace(); - } + parseConfig(text.toString()); } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.java b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.java index 76ffbf719..980ca40ea 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ShopRecyclerAdapter.java @@ -50,8 +50,10 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter items; private String shopIdentifier; private Map ownedItems = new HashMap<>(); + private String shopSpriteSuffix; - public void setShop(Shop shop) { + public void setShop(Shop shop, String shopSpriteSuffix) { + this.shopSpriteSuffix = shopSpriteSuffix; shopIdentifier = shop.identifier; items = new ArrayList<>(); items.add(shop); @@ -92,7 +94,7 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter { this.shop = shop; - this.adapter.setShop(shop); + this.adapter.setShop(shop, configManager.shopSpriteSuffix()); }, RxErrorHandler.handleEmptyError()); compositeSubscription.add(this.inventoryRepository.getOwnedItems(user)