Implement subscriber features

This commit is contained in:
Phillip Thelen 2017-01-30 12:47:54 +01:00
parent 19d0798719
commit 6af6c29e3d
21 changed files with 306 additions and 14 deletions

View file

@ -23,14 +23,21 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Title"
style="@style/RowTitle" />
style="@style/Subheader1" />
<TextView
android:id="@+id/limitedCountText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
tools:text="2 Left"
style="@style/Caption3" />
<TextView
android:id="@+id/descriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Description"
android:maxLines="5"
style="@style/RowText" />
style="@style/Caption2.Regular" />
</LinearLayout>
<Button

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="profile_pets_and_mounts">Pets & Mounts</string>
<string name="profile_pets_and_mounts">Pets &amp; Mounts</string>
<string name="profile_pets_found">Pets Found</string>
<string name="profile_mounts_tamed">Mounts Tamed</string>
<string name="profile_loading_data">loading member data.</string>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="profile_pets_and_mounts">Mascotes & Montarias</string>
<string name="profile_pets_and_mounts">Mascotes &amp; Montarias</string>
<string name="profile_pets_found">Mascotes Encontrados</string>
<string name="profile_mounts_tamed">Montarias Domesticadas</string>
<string name="profile_loading_data">Carregando dados de membro</string>

View file

@ -14,6 +14,7 @@
<declare-styleable name="MaxHeightScrollView">
<attr name="maxHeightMultiplier" format="float" />
</declare-styleable>
<declare-styleable name="SubscriptionOptionView">
<attr name="recurringText" format="string" />
<attr name="gemCapText" format="string" />

View file

@ -309,7 +309,7 @@ To start, which parts of your life do you want to improve?</string>
<string name="armoireNotesFull" formatted="false">Open the Armoire to randomly receive special Equipment, Experience, or food! Equipment pieces remaining: %d</string>
<string name="armoireLastItem">You\'ve found the last piece of rare Equipment in the Enchanted Armoire.</string>
<string name="armoireNotesEmpty">The Armoire will have new Equipment in the first week of every month. Until then, keep clicking for Experience and Food!</string>
<string name="sell" formatted="false">Sell (%s Gold)</string>
<string name="sell" formatted="false">Sell (%d Gold)</string>
<string name="hatch_with_potion">Hatch with potion</string>
<string name="feed_to_pet">Feed to pet</string>
<string name="hatch_egg">Hatch with egg</string>
@ -511,4 +511,12 @@ To start, which parts of your life do you want to improve?</string>
<string name="dont_keep_activities_warning">It seems like you have the Developer option \"Don\'t keep Activities\" active. Currently this option causes issues with the habitica app, so we suggest disabling it.</string>
<string name="inbox">Inbox</string>
<string name="FAQ">Frequently Asked Questions</string>
<string name="special">Special</string>
<string name="gem_for_gold_description">Because you subscribe to Habitica, you can purchase a number of Gems each month using Gold.</string>
<string name="limited_count" formatted="false">%d left</string>
<string name="gem_shop">Gem</string>
<string name="mystery_item">Mystery Item</string>
<string name="myster_item_notes">Each month, subscribers will receive a mystery item. This is usually released about one week before the end of the month.</string>
<string name="open">Open</string>
<string name="notification_mystery_item">You open the box and find %s!</string>
</resources>

View file

@ -0,0 +1,5 @@
package com.habitrpg.android.habitica.events;
public class OpenMysteryItemEvent {
}

View file

@ -0,0 +1,10 @@
package com.habitrpg.android.habitica.events;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
public class OpenedMysteryItemEvent {
public int numberLeft;
public ItemData mysteryItem;
}

View file

@ -0,0 +1,8 @@
package com.habitrpg.android.habitica.events;
public class UpdateGoldGemsPurchasedevent {
public int numberLeft;
}

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.activities;
import com.habitrpg.android.habitica.HabiticaApplication;
import com.habitrpg.android.habitica.HabiticaBaseApplication;
import com.habitrpg.android.habitica.components.AppComponent;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
import android.content.Intent;
import android.os.Build;
@ -82,4 +83,6 @@ public abstract class BaseActivity extends AppCompatActivity {
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
}

View file

@ -18,6 +18,8 @@ import com.habitrpg.android.habitica.events.ContentReloadedEvent;
import com.habitrpg.android.habitica.events.DisplayFragmentEvent;
import com.habitrpg.android.habitica.events.DisplayTutorialEvent;
import com.habitrpg.android.habitica.events.HabitScoreEvent;
import com.habitrpg.android.habitica.events.OpenMysteryItemEvent;
import com.habitrpg.android.habitica.events.OpenedMysteryItemEvent;
import com.habitrpg.android.habitica.events.ReloadContentEvent;
import com.habitrpg.android.habitica.events.SelectClassEvent;
import com.habitrpg.android.habitica.events.ShareEvent;
@ -26,6 +28,7 @@ import com.habitrpg.android.habitica.events.TaskSaveEvent;
import com.habitrpg.android.habitica.events.TaskUpdatedEvent;
import com.habitrpg.android.habitica.events.ToggledEditTagsEvent;
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
import com.habitrpg.android.habitica.events.UpdateGoldGemsPurchasedevent;
import com.habitrpg.android.habitica.events.commands.BuyGemItemCommand;
import com.habitrpg.android.habitica.events.commands.BuyRewardCommand;
import com.habitrpg.android.habitica.events.commands.ChecklistCheckedCommand;
@ -181,6 +184,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
CrashlyticsProxy crashlyticsProxy;
@BindView(R.id.floating_menu_wrapper)
public
FrameLayout floatingMenuWrapper;
@BindView(R.id.toolbar)
Toolbar toolbar;
@ -981,14 +985,16 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
}
observable
.compose(apiHelper.configureApiCallObserver())
.doOnNext(aVoid -> {
showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL);
})
.doOnNext(aVoid -> showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL))
.subscribe(buyResponse -> {
apiHelper.retrieveUser(false)
.compose(apiHelper.configureApiCallObserver())
.subscribe(new HabitRPGUserCallback(this), throwable -> {
});
.subscribe(new HabitRPGUserCallback(user1 -> {
UpdateGoldGemsPurchasedevent event1 = new UpdateGoldGemsPurchasedevent();
event1.numberLeft = user1.getPurchased().getPlan().numberOfGemsLeft();
EventBus.getDefault().post(event1);
MainActivity.this.onUserReceived(user1);
}), throwable -> {});
}, throwable -> {
HttpException error = (HttpException) throwable;
if (error.code() == 401 && event.item.getCurrency().equals("gems")) {
@ -1089,6 +1095,21 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
});
}
@Subscribe
public void openMysteryItem(OpenMysteryItemEvent event) {
apiHelper.apiService.openMysteryItem().compose(apiHelper.configureApiCallObserver())
.subscribe(mysteryItem -> {
apiHelper.retrieveUser(false).compose(apiHelper.configureApiCallObserver())
.subscribe(new HabitRPGUserCallback(user1 -> {
OpenedMysteryItemEvent openedEvent = new OpenedMysteryItemEvent();
openedEvent.numberLeft = user1.getPurchased().getPlan().mysteryItems.size();
openedEvent.mysteryItem = mysteryItem;
EventBus.getDefault().post(openedEvent);
MainActivity.this.onUserReceived(user1);
}), throwable -> {});
}, throwable -> {});
}
@Subscribe
public void openGemPurchaseFragment(OpenGemPurchaseFragmentCommand cmd) {
drawer.setSelection(MainDrawerBuilder.SIDEBAR_PURCHASE);

View file

@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.inventory;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.databinding.ItemItemBinding;
import com.habitrpg.android.habitica.events.OpenMysteryItemEvent;
import com.habitrpg.android.habitica.events.ReloadContentEvent;
import com.habitrpg.android.habitica.events.commands.FeedCommand;
import com.habitrpg.android.habitica.events.commands.HatchingCommand;
@ -10,12 +11,14 @@ import com.habitrpg.android.habitica.events.commands.SellItemCommand;
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment;
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu;
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem;
import com.magicmicky.habitrpgwrapper.lib.models.ShopItem;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Egg;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Food;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.HatchingPotion;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Item;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Pet;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.QuestContent;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.SpecialItem;
import org.greenrobot.eventbus.EventBus;
@ -67,6 +70,21 @@ public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapte
return itemList == null ? 0 : itemList.size();
}
public void openedMysteryItem(int numberLeft) {
int itemPos = 0;
for (Object obj : itemList) {
if (obj.getClass().equals(SpecialItem.class)) {
SpecialItem item = (SpecialItem) obj;
if (item.isMysteryItem) {
item.setOwned(numberLeft);
break;
}
}
itemPos++;
}
notifyItemChanged(itemPos);
}
class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
Item item;
@ -105,6 +123,8 @@ public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapte
binding.setDisabled(false);
if (item instanceof QuestContent) {
binding.setImageNamed("inventory_quest_scroll_" + item.getKey());
} else if (item instanceof SpecialItem) {
binding.setImageNamed(item.getKey());
} else {
String type = "";
if (item instanceof Egg) {
@ -127,7 +147,7 @@ public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapte
public void onClick(View v) {
if (!isHatching && !isFeeding) {
BottomSheetMenu menu = new BottomSheetMenu(context);
if (!(item instanceof QuestContent)) {
if (!(item instanceof QuestContent) && !(item instanceof SpecialItem)) {
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.sell, item.getValue()), true));
}
if (item instanceof Egg) {
@ -136,9 +156,14 @@ public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapte
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.hatch_egg)));
} else if (item instanceof QuestContent) {
menu.addMenuItem(new BottomSheetMenuItem(resources.getString(R.string.invite_party)));
} else if (item instanceof SpecialItem) {
SpecialItem specialItem = (SpecialItem)item;
if (specialItem.isMysteryItem && specialItem.getOwned() > 0) {
menu.addMenuItem(new BottomSheetMenuItem(context.getString(R.string.open)));
}
}
menu.setSelectionRunnable(index -> {
if (!(item instanceof QuestContent) && index == 0) {
if (!((item instanceof QuestContent) || (item instanceof SpecialItem)) && index == 0) {
SellItemCommand event = new SellItemCommand();
event.item = item;
EventBus.getDefault().post(event);
@ -170,6 +195,8 @@ public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapte
InvitePartyToQuestCommand event = new InvitePartyToQuestCommand();
event.questKey = item.getKey();
EventBus.getDefault().post(event);
} else if (item instanceof SpecialItem) {
EventBus.getDefault().post(new OpenMysteryItemEvent());
}
});
menu.show();

View file

@ -103,6 +103,21 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return items != null ? items.size() : 0;
}
public void updateGoldGemCount(int numberLeft) {
int itemPos = 0;
for (Object obj : items) {
if (obj.getClass().equals(ShopItem.class)) {
ShopItem item = (ShopItem) obj;
if (item.key.equals(ShopItem.GEM_FOR_GOLD)) {
item.limitedNumberLeft = numberLeft;
break;
}
}
itemPos++;
}
notifyItemChanged(itemPos);
}
static class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
@BindView(R.id.imageView)
@ -115,6 +130,8 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
Button buyButton;
@BindView(R.id.unlockView)
TextView unlockView;
@BindView(R.id.limitedCountText)
TextView limitedCountText;
String shopIdentifier;
ShopItem item;
@ -195,6 +212,13 @@ public class ShopRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
if (item.getLocked()) {
buyButton.setVisibility(View.GONE);
}
if (item.limitedNumberLeft != null) {
limitedCountText.setText(context.getString(R.string.limited_count, item.limitedNumberLeft));
limitedCountText.setVisibility(View.VISIBLE);
} else {
limitedCountText.setVisibility(View.GONE);
}
}
@Override

View file

@ -82,6 +82,7 @@ public abstract class BaseMainFragment extends BaseFragment {
if (this.usesTabLayout) {
tabLayout.removeAllTabs();
tabLayout.setVisibility(View.VISIBLE);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
} else {
tabLayout.setVisibility(View.GONE);
}

View file

@ -3,18 +3,27 @@ package com.habitrpg.android.habitica.ui.fragments.inventory.items;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.events.ContentReloadedEvent;
import com.habitrpg.android.habitica.events.OpenedMysteryItemEvent;
import com.habitrpg.android.habitica.events.UpdateGoldGemsPurchasedevent;
import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
import com.habitrpg.android.habitica.ui.adapter.inventory.ItemRecyclerAdapter;
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
import com.habitrpg.android.habitica.ui.menu.DividerItemDecoration;
import com.habitrpg.android.habitica.ui.menu.MainDrawerBuilder;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Egg;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Food;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.HatchingPotion;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Item;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Pet;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.QuestContent;
import com.magicmicky.habitrpgwrapper.lib.models.inventory.SpecialItem;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
import com.raizlabs.android.dbflow.sql.builder.Condition;
import com.raizlabs.android.dbflow.sql.language.From;
import com.raizlabs.android.dbflow.sql.language.Select;
@ -32,6 +41,7 @@ import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -39,6 +49,8 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import static com.habitrpg.android.habitica.ui.helpers.UiUtils.showSnackbar;
public class ItemRecyclerFragment extends BaseFragment {
private static final String ITEM_TYPE_KEY = "CLASS_TYPE_KEY";
@BindView(R.id.recyclerView)
@ -61,12 +73,14 @@ public class ItemRecyclerFragment extends BaseFragment {
public Item hatchingItem;
public Pet feedingPet;
public HashMap<String, Integer> ownedPets;
public HabitRPGUser user;
LinearLayoutManager layoutManager = null;
private View view;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
if (view == null) {
view = inflater.inflate(R.layout.fragment_items, container, false);
}
@ -183,8 +197,20 @@ public class ItemRecyclerFragment extends BaseFragment {
from = new Select().from(QuestContent.class);
}
List<Item> items = new ArrayList<>();
if (from != null) {
List<Item> items = from.where(Condition.column("owned").greaterThan(0)).queryList();
items.addAll(from.where(Condition.column("owned").greaterThan(0)).queryList());
}
if (this.itemType.equals("special")) {
if (user.getPurchased() != null && user.getPurchased().getPlan().isActive()) {
Item mysterItem = SpecialItem.makeMysteryItem(getContext());
mysterItem.setOwned(user.getPurchased().getPlan().mysteryItems.size());
items.add(mysterItem);
}
}
if (items.size() > 0) {
adapter.setItemList(items);
}
}
@ -205,4 +231,28 @@ public class ItemRecyclerFragment extends BaseFragment {
command.identifier = MainDrawerBuilder.SIDEBAR_SHOPS;
EventBus.getDefault().post(command);
}
@Subscribe
public void openedMysteryItem(OpenedMysteryItemEvent event) {
this.adapter.openedMysteryItem(event.numberLeft);
new Select().from(ItemData.class).where(Condition.column("key").eq(event.mysteryItem.getKey())).async().querySingle(new TransactionListener<ItemData>() {
@Override
public void onResultReceived(ItemData result) {
result.setOwned(true);
result.async().save();
MainActivity activity = (MainActivity) getActivity();
showSnackbar(activity, activity.floatingMenuWrapper, getString(R.string.notification_mystery_item, result.getText()), UiUtils.SnackbarDisplayType.NORMAL);
}
@Override
public boolean onReady(BaseTransaction<ItemData> transaction) {
return true;
}
@Override
public boolean hasResult(BaseTransaction<ItemData> transaction, ItemData result) {
return true;
}
});
}
}

View file

@ -6,12 +6,14 @@ import com.habitrpg.android.habitica.events.commands.HatchingCommand;
import com.habitrpg.android.habitica.events.commands.InvitePartyToQuestCommand;
import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand;
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
import com.habitrpg.android.habitica.ui.fragments.inventory.shops.ShopsFragment;
import com.habitrpg.android.habitica.ui.menu.MainDrawerBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
@ -71,17 +73,21 @@ public class ItemsFragment extends BaseMainFragment {
fragment.itemType = "quests";
break;
}
case 4: {
fragment.itemType = "special";
}
}
fragment.isHatching = false;
fragment.isFeeding = false;
fragment.itemTypeText = this.getPageTitle(position).toString();
fragment.user = ItemsFragment.this.user;
return fragment;
}
@Override
public int getCount() {
return 4;
return 5;
}
@Override
@ -95,12 +101,15 @@ public class ItemsFragment extends BaseMainFragment {
return activity.getString(R.string.food);
case 3:
return activity.getString(R.string.quests);
case 4:
return getString(R.string.special);
}
return "";
}
});
if (tabLayout != null && viewPager != null) {
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
}

View file

@ -3,12 +3,17 @@ package com.habitrpg.android.habitica.ui.fragments.inventory.shops;
import com.habitrpg.android.habitica.APIHelper;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.events.UpdateGoldGemsPurchasedevent;
import com.habitrpg.android.habitica.ui.adapter.inventory.ShopRecyclerAdapter;
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport;
import com.habitrpg.android.habitica.ui.menu.DividerItemDecoration;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Shop;
import com.magicmicky.habitrpgwrapper.lib.models.ShopCategory;
import com.magicmicky.habitrpgwrapper.lib.models.ShopItem;
import org.greenrobot.eventbus.Subscribe;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -18,6 +23,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import javax.inject.Inject;
import butterknife.BindView;
@ -102,6 +109,20 @@ public class ShopFragment extends BaseFragment {
}
this.apiHelper.apiService.fetchShopInventory(shopUrl)
.compose(this.apiHelper.configureApiCallObserver())
.map(shop1 -> {
if (shop1.identifier.equals(Shop.MARKET)) {
if (user.getPurchased().getPlan().isActive()) {
ShopCategory specialCategory = new ShopCategory();
specialCategory.text = getString(R.string.special);
specialCategory.items = new ArrayList<>();
ShopItem item = ShopItem.makeGemItem(getContext().getResources());
item.limitedNumberLeft = user.getPurchased().getPlan().numberOfGemsLeft();
specialCategory.items.add(item);
shop1.categories.add(specialCategory);
}
}
return shop1;
})
.subscribe(shop -> {
this.shop = shop;
this.adapter.setShop(shop);
@ -118,4 +139,9 @@ public class ShopFragment extends BaseFragment {
super.onSaveInstanceState(outState);
outState.putString(SHOP_IDENTIFIER_KEY, this.shopIdentifier);
}
@Subscribe
public void updateGoldGemCount(UpdateGoldGemsPurchasedevent event) {
this.adapter.updateGoldGemCount(event.numberLeft);
}
}

View file

@ -5,6 +5,7 @@ import android.databinding.ObservableList;
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
import com.magicmicky.habitrpgwrapper.lib.models.ContentResult;
import com.magicmicky.habitrpgwrapper.lib.models.Gear;
import com.magicmicky.habitrpgwrapper.lib.models.Group;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Items;
@ -172,6 +173,8 @@ public interface ApiService {
@POST("user/mark-pms-read")
Observable<HabitResponse<Void>> markPrivateMessagesRead();
/* Group API */
@GET("groups")
@ -295,4 +298,7 @@ public interface ApiService {
// Notifications
@POST("notifications/{notificationId}/read")
Observable<HabitResponse<Void>> readNotificaiton(@Path("notificationId") String notificationId);
@POST("user/open-mystery-item")
Observable<HabitResponse<ItemData>> openMysteryItem();
}

View file

@ -2,8 +2,13 @@ package com.magicmicky.habitrpgwrapper.lib.models;
import com.google.gson.annotations.SerializedName;
import com.habitrpg.android.habitica.R;
import android.content.res.Resources;
public class ShopItem {
public static final String GEM_FOR_GOLD = "gem";
public String key;
public String text;
public String notes;
@ -13,6 +18,7 @@ public class ShopItem {
public String currency;
public String purchaseType;
public String categoryIdentifier;
public Integer limitedNumberLeft;
public ShopItemUnlockCondition unlockCondition;
public String getKey() {
@ -86,6 +92,22 @@ public class ShopItem {
this.purchaseType = purchaseType;
}
public String getCategoryIdentifier() {
return categoryIdentifier;
}
public void setCategoryIdentifier(String categoryIdentifier) {
this.categoryIdentifier = categoryIdentifier;
}
public Integer getLimitedNumberLeft() {
return limitedNumberLeft;
}
public void setLimitedNumberLeft(Integer limitedNumberLeft) {
this.limitedNumberLeft = limitedNumberLeft;
}
public ShopItemUnlockCondition getUnlockCondition() {
return unlockCondition;
}
@ -103,4 +125,16 @@ public class ShopItem {
return false;
}
}
public static ShopItem makeGemItem(Resources res) {
ShopItem item = new ShopItem();
item.key = GEM_FOR_GOLD;
item.text = res.getString(R.string.gem_shop);
item.notes = res.getString(R.string.gem_for_gold_description);
item.imageName = "gem_shop";
item.value = 20;
item.currency = "gold";
item.purchaseType = "gems";
return item;
}
}

View file

@ -9,6 +9,7 @@ import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;
import java.util.Date;
import java.util.List;
@Table(databaseName = HabitDatabase.NAME)
public class SubscriptionPlan extends BaseModel {
@ -45,6 +46,8 @@ public class SubscriptionPlan extends BaseModel {
foreignColumnName = "customerId")})
public SubscriptionPlanConsecutive consecutive;
public List<String> mysteryItems;
public boolean isActive() {
Date today = new Date();
return (this.dateCreated != null && this.dateCreated.before(today)) && (this.dateTerminated == null || this.dateTerminated.after(today));
@ -59,4 +62,13 @@ public class SubscriptionPlan extends BaseModel {
super.save();
}
public Integer numberOfGemsLeft() {
if (customerId == null) {
return 0;
}
return 25+consecutive.getGemCapExtra()-gemsBought;
}
}

View file

@ -6,6 +6,8 @@ import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;
import java.util.List;
@Table(databaseName = HabitDatabase.NAME)
public class SubscriptionPlanConsecutive extends BaseModel {
@ -52,4 +54,12 @@ public class SubscriptionPlanConsecutive extends BaseModel {
public void setCount(int count) {
this.count = count;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
}

View file

@ -0,0 +1,30 @@
package com.magicmicky.habitrpgwrapper.lib.models.inventory;
import com.habitrpg.android.habitica.R;
import android.content.Context;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SpecialItem extends Item {
public boolean isMysteryItem;
@Override
public String getType() {
return "special";
}
public static Item makeMysteryItem(Context context) {
SpecialItem item = new SpecialItem();
item.text = context.getString(R.string.mystery_item);
item.notes = context.getString(R.string.myster_item_notes);
SimpleDateFormat sdf = new SimpleDateFormat("MM");
String month = sdf.format(new Date());
item.key = "inventory_present_"+month;
item.isMysteryItem = true;
return item;
}
}