support old reward column

This commit is contained in:
Phillip Thelen 2017-09-07 20:38:17 +02:00
parent 69f5254f9e
commit a1b9b9db3e
9 changed files with 72 additions and 14 deletions

View file

@ -69,6 +69,8 @@ public interface ApiService {
@GET("user/in-app-rewards")
Observable<HabitResponse<List<ShopItem>>> retrieveInAppRewards();
@GET("user/inventory/buy")
Observable<HabitResponse<List<ShopItem>>> retrieveOldGearRewards();
@POST("user/equip/{type}/{key}")
Observable<HabitResponse<Items>> equipItem(@Path("type") String type, @Path("key") String itemKey);

View file

@ -56,6 +56,7 @@ public interface ApiClient {
Observable<User> registrationLanguage(String registrationLanguage);
Observable<List<ShopItem>> retrieveInAppRewards();
Observable<List<ShopItem>> retrieveOldGear();
Observable<Items> equipItem(String type, String itemKey);

View file

@ -442,6 +442,11 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
return apiService.retrieveInAppRewards().compose(configureApiCallObserver());
}
@Override
public Observable<List<ShopItem>> retrieveOldGear() {
return apiService.retrieveOldGearRewards().compose(configureApiCallObserver());
}
@Override
public Observable<Items> equipItem(String type, String itemKey) {
if (itemKey == null) {

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.data.implementation;
import com.habitrpg.android.habitica.data.ApiClient;
import com.habitrpg.android.habitica.data.InventoryRepository;
import com.habitrpg.android.habitica.data.local.InventoryLocalRepository;
import com.habitrpg.android.habitica.helpers.RemoteConfigManager;
import com.habitrpg.android.habitica.models.inventory.Egg;
import com.habitrpg.android.habitica.models.inventory.Equipment;
import com.habitrpg.android.habitica.models.inventory.Food;
@ -21,6 +22,7 @@ import com.habitrpg.android.habitica.models.user.Outfit;
import com.habitrpg.android.habitica.models.user.Stats;
import com.habitrpg.android.habitica.models.user.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -29,8 +31,11 @@ import rx.Observable;
public class InventoryRepositoryImpl extends ContentRepositoryImpl<InventoryLocalRepository> implements InventoryRepository {
public InventoryRepositoryImpl(InventoryLocalRepository localRepository, ApiClient apiClient) {
private final RemoteConfigManager remoteConfigManager;
public InventoryRepositoryImpl(InventoryLocalRepository localRepository, ApiClient apiClient, RemoteConfigManager remoteConfigManager) {
super(localRepository, apiClient);
this.remoteConfigManager = remoteConfigManager;
}
@Override
@ -55,8 +60,39 @@ public class InventoryRepositoryImpl extends ContentRepositoryImpl<InventoryLoca
@Override
public Observable<List<ShopItem>> retrieveInAppRewards() {
return apiClient.retrieveInAppRewards()
.doOnNext(localRepository::saveInAppRewards);
if (remoteConfigManager.newShopsEnabled()) {
return apiClient.retrieveInAppRewards()
.doOnNext(localRepository::saveInAppRewards);
} else {
return apiClient.retrieveOldGear()
.map(items -> {
List<String> itemKeys = new ArrayList<>();
for (ShopItem item : items) {
itemKeys.add(item.key);
}
itemKeys.add("potion");
itemKeys.add("armoire");
return itemKeys;
})
.flatMap(this::getItems)
.map(items -> {
List<ShopItem> buyableItems = new ArrayList<>();
if (items != null) {
for (Equipment item : items) {
ShopItem shopItem = new ShopItem();
shopItem.key = item.key;
shopItem.text = item.text;
shopItem.notes = item.notes;
shopItem.value = (int)item.value;
shopItem.currency = "gold";
buyableItems.add(shopItem);
}
}
return buyableItems;
})
.doOnNext(localRepository::saveInAppRewards);
}
}
@Override

View file

@ -25,6 +25,7 @@ public class RemoteConfigManager {
private Context context;
private Boolean enableRepeatbles = false;
private Boolean enableNewShops = false;
private String REMOTE_STRING_KEY = "remote-string";
public RemoteConfigManager(Context context) {
@ -33,10 +34,14 @@ public class RemoteConfigManager {
new DownloadFileFromURL().execute("https://s3.amazonaws.com/habitica-assets/mobileApp/endpoint/config-android.json");
}
public Boolean repeatablesAreEnabled () {
public Boolean repeatablesAreEnabled() {
return enableRepeatbles;
}
public Boolean newShopsEnabled() {
return enableNewShops;
}
private void loadFromPreferences () {
String storedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
.getString(REMOTE_STRING_KEY, "");
@ -48,6 +53,7 @@ public class RemoteConfigManager {
try {
JSONObject obj = new JSONObject(storedPreferences);
enableRepeatbles = obj.getBoolean("enableRepeatables");
enableNewShops = obj.getBoolean("enableNewShops");
} catch (JSONException e) {
e.printStackTrace();
}
@ -122,6 +128,7 @@ public class RemoteConfigManager {
try {
JSONObject obj = new JSONObject(text.toString());
enableRepeatbles = obj.getBoolean("enableRepeatables");
enableNewShops = obj.getBoolean("enableNewShops");
} catch (JSONException e) {
e.printStackTrace();
}

View file

@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.models;
import com.habitrpg.android.habitica.models.inventory.Customization;
import com.habitrpg.android.habitica.models.inventory.Egg;
import com.habitrpg.android.habitica.models.inventory.Equipment;
import com.habitrpg.android.habitica.models.inventory.Food;
import com.habitrpg.android.habitica.models.inventory.HatchingPotion;
import com.habitrpg.android.habitica.models.inventory.Mount;
@ -18,9 +19,9 @@ import io.realm.RealmList;
*/
public class ContentResult {
public ShopItem potion;
public Equipment potion;
public ShopItem armoire;
public Equipment armoire;
public ContentGear gear;

View file

@ -42,6 +42,7 @@ import com.habitrpg.android.habitica.data.local.implementation.RealmTagLocalRepo
import com.habitrpg.android.habitica.data.local.implementation.RealmTaskLocalRepository;
import com.habitrpg.android.habitica.data.local.implementation.RealmTutorialLocalRepository;
import com.habitrpg.android.habitica.data.local.implementation.RealmUserLocalRepository;
import com.habitrpg.android.habitica.helpers.RemoteConfigManager;
import javax.inject.Named;
import javax.inject.Singleton;
@ -120,8 +121,8 @@ public class RepositoryModule {
}
@Provides
InventoryRepository providesInventoryRepository(InventoryLocalRepository localRepository, ApiClient apiClient) {
return new InventoryRepositoryImpl(localRepository, apiClient);
InventoryRepository providesInventoryRepository(InventoryLocalRepository localRepository, ApiClient apiClient, RemoteConfigManager remoteConfigManager) {
return new InventoryRepositoryImpl(localRepository, apiClient, remoteConfigManager);
}

View file

@ -13,6 +13,7 @@ import com.habitrpg.android.habitica.models.FAQArticle;
import com.habitrpg.android.habitica.models.Skill;
import com.habitrpg.android.habitica.models.inventory.Customization;
import com.habitrpg.android.habitica.models.inventory.Egg;
import com.habitrpg.android.habitica.models.inventory.Equipment;
import com.habitrpg.android.habitica.models.inventory.Food;
import com.habitrpg.android.habitica.models.inventory.HatchingPotion;
import com.habitrpg.android.habitica.models.inventory.Mount;
@ -39,12 +40,12 @@ public class ContentDeserializer implements JsonDeserializer<ContentResult> {
ContentResult result = new ContentResult();
JsonObject object = json.getAsJsonObject();
result.potion = context.deserialize(object.get("potion"), ShopItem.class);
result.potion.imageName = "shop_potion";
result.potion.currency = "gold";
result.armoire = context.deserialize(object.get("armoire"), ShopItem.class);
result.armoire.imageName = "shop_armoire";
result.armoire.currency = "gold";
result.potion = context.deserialize(object.get("potion"), Equipment.class);
//result.potion.imageName = "shop_potion";
//result.potion.currency = "gold";
result.armoire = context.deserialize(object.get("armoire"), Equipment.class);
//result.armoire.imageName = "shop_armoire";
//result.armoire.currency = "gold";
result.gear = context.deserialize(object.get("gear"), ContentGear.class);
result.quests = context.deserialize(object.get("quests"), new TypeToken<RealmList<QuestContent>>() {

4
config-android.json Normal file
View file

@ -0,0 +1,4 @@
{
"enableRepeatables": true,
"enableNewShops": false
}