mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-17 03:22:04 +00:00
display seasonal NPC shop banners
This commit is contained in:
parent
528b9124ed
commit
25a3208054
3 changed files with 27 additions and 19 deletions
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,8 +50,10 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
private List<Object> items;
|
||||
private String shopIdentifier;
|
||||
private Map<String, Item> 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<RecyclerView.ViewH
|
|||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
Object obj = this.items.get(position);
|
||||
if (obj.getClass().equals(Shop.class)) {
|
||||
((ShopHeaderViewHolder) holder).bind((Shop) obj);
|
||||
((ShopHeaderViewHolder) holder).bind((Shop) obj, shopSpriteSuffix);
|
||||
} else if (obj.getClass().equals(ShopCategory.class)) {
|
||||
((SectionViewHolder) holder).bind(((ShopCategory) obj).getText());
|
||||
} else {
|
||||
|
|
@ -162,13 +164,13 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void bind(Shop shop) {
|
||||
DataBindingUtils.loadImage(sceneView, shop.identifier+"_scene");
|
||||
public void bind(Shop shop, String shopSpriteSuffix) {
|
||||
DataBindingUtils.loadImage(sceneView, shop.identifier+"_scene"+shopSpriteSuffix);
|
||||
|
||||
backgroundView.setScaleType(ImageView.ScaleType.FIT_START);
|
||||
|
||||
ImageRequest imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + shop.identifier+"_background.png"))
|
||||
.newBuilderWithSource(Uri.parse("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + shop.identifier+"_background.png"+shopSpriteSuffix))
|
||||
.build();
|
||||
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.helpers.RemoteConfigManager;
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
import com.habitrpg.android.habitica.models.shops.ShopCategory;
|
||||
|
|
@ -43,6 +44,9 @@ public class ShopFragment extends BaseFragment {
|
|||
InventoryRepository inventoryRepository;
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
@Inject
|
||||
RemoteConfigManager configManager;
|
||||
|
||||
private View view;
|
||||
|
||||
private GridLayoutManager layoutManager;
|
||||
|
|
@ -86,7 +90,7 @@ public class ShopFragment extends BaseFragment {
|
|||
if (shop == null) {
|
||||
loadShopInventory();
|
||||
} else {
|
||||
adapter.setShop(shop);
|
||||
adapter.setShop(shop, configManager.shopSpriteSuffix());
|
||||
}
|
||||
|
||||
return view;
|
||||
|
|
@ -139,7 +143,7 @@ public class ShopFragment extends BaseFragment {
|
|||
})
|
||||
.subscribe(shop -> {
|
||||
this.shop = shop;
|
||||
this.adapter.setShop(shop);
|
||||
this.adapter.setShop(shop, configManager.shopSpriteSuffix());
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
|
||||
compositeSubscription.add(this.inventoryRepository.getOwnedItems(user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue