mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-23 14:17:15 +00:00
Load buyable gear rewards & save them to the db too
This commit is contained in:
parent
ca43925f7d
commit
310cba8449
9 changed files with 357 additions and 196 deletions
|
|
@ -111,8 +111,8 @@
|
|||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.19" level="project" />
|
||||
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.19" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="okhttp-2.3.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="rxjava-1.0.10" level="project" />
|
||||
|
|
@ -129,11 +129,11 @@
|
|||
<orderEntry type="library" exported="" name="materialdrawer-4.3.8" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="checkout-0.7.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="compiler-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="materialize-0.2.7" level="project" />
|
||||
<orderEntry type="library" exported="" name="gridlayout-v7-23.0.1" level="project" />
|
||||
|
|
|
|||
|
|
@ -19,13 +19,6 @@
|
|||
android:layout_marginTop="@dimen/abc_action_bar_content_inset_material"
|
||||
android:layout_marginBottom="@dimen/abc_action_bar_content_inset_material">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/task"
|
||||
android:id="@+id/task_text_textview" />
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
|
|
|
|||
|
|
@ -1,85 +1,96 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:bind="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Task" />
|
||||
<import type="android.view.View"/>
|
||||
|
||||
<variable
|
||||
name="reward"
|
||||
type="Task" />
|
||||
</data>
|
||||
|
||||
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/checkedTextView"
|
||||
style="@style/CardTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toEndOf="@+id/imageView3"
|
||||
android:layout_toRightOf="@+id/imageView3"
|
||||
android:layout_toStartOf="@+id/btnReward"
|
||||
android:layout_toLeftOf="@+id/btnReward"
|
||||
android:padding="5dp"
|
||||
android:text="@{reward.text}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
style="@style/CardText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@+id/checkedTextView"
|
||||
android:layout_alignStart="@+id/checkedTextView"
|
||||
android:layout_alignRight="@+id/checkedTextView"
|
||||
android:layout_alignEnd="@+id/checkedTextView"
|
||||
android:layout_below="@+id/checkedTextView"
|
||||
android:maxLines="3"
|
||||
android:minLines="2"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@{reward.notes}" />
|
||||
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/btnLayout">
|
||||
<Button
|
||||
android:id="@+id/btnReward"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textSize="15sp"
|
||||
android:drawableLeft="@drawable/gold"
|
||||
android:maxHeight="10dp"
|
||||
android:text="@{String.valueOf(reward.value)}" />
|
||||
android:text='@{String.format("%.0f", reward.value)}'
|
||||
app:backgroundColor="@{reward.getLightTaskColor}" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView3"
|
||||
android:layout_width="65dp"
|
||||
android:layout_width="60dp"
|
||||
android:padding="5dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="60dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
app:imageName="@{reward.id}"/>
|
||||
android:visibility='@{reward.specialTag == "item" ? View.VISIBLE : View.GONE}'
|
||||
bind:imageName='@{"shop_"+reward.id}'/>
|
||||
|
||||
</LinearLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerVertical="true">
|
||||
<TextView
|
||||
android:id="@+id/checkedTextView"
|
||||
style="@style/CardTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingTop="5dp"
|
||||
android:text="@{reward.text}" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
style="@style/CardText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{reward.notes}"
|
||||
android:visibility="@{reward.notes != null ? View.VISIBLE : View.GONE}"/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:id="@+id/rightBorderView"
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="match_parent"
|
||||
app:backgroundColor="@{reward.getLightTaskColor}"
|
||||
android:gravity="center"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/bottomBorderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:background="@color/cell_separator"/>
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
|
@ -4,8 +4,14 @@ import com.magicmicky.habitrpgwrapper.lib.api.ApiService;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.ContentResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestBoss;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestContent;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
|
|
@ -15,58 +21,179 @@ import retrofit.client.Response;
|
|||
* Created by Negue on 29.09.2015.
|
||||
*/
|
||||
public class ContentCache {
|
||||
public interface QuestContentCallback{
|
||||
public interface GotContentEntryCallback<T extends Object> {
|
||||
void GotObject(T obj);
|
||||
}
|
||||
|
||||
public interface QuestContentCallback {
|
||||
void GotQuest(QuestContent content);
|
||||
}
|
||||
|
||||
|
||||
private ApiService apiService;
|
||||
|
||||
public ContentCache(ApiService apiService){
|
||||
public ContentCache(ApiService apiService) {
|
||||
|
||||
this.apiService = apiService;
|
||||
}
|
||||
|
||||
public void GetQuestContent(final String key, final QuestContentCallback cb){
|
||||
public void GetQuestContent(final String key, final QuestContentCallback cb) {
|
||||
final QuestContent quest = new Select().from(QuestContent.class).where(Condition.column("key").eq(key)).querySingle();
|
||||
|
||||
if(quest != null){
|
||||
if (quest != null) {
|
||||
QuestBoss boss = new Select().from(QuestBoss.class).where(Condition.column("key").eq(key)).querySingle();
|
||||
quest.boss = boss;
|
||||
|
||||
cb.GotQuest(quest);
|
||||
}
|
||||
else
|
||||
{
|
||||
// load from api and save to db
|
||||
} else {
|
||||
|
||||
apiService.getContent(new Callback<ContentResult>() {
|
||||
getContentAndSearchFor("quest", key, new GotContentEntryCallback<QuestContent>() {
|
||||
@Override
|
||||
public void success(ContentResult contentResult, Response response) {
|
||||
|
||||
QuestContent searchedQuest = null;
|
||||
|
||||
for (QuestContent quest : contentResult.quests.values()) {
|
||||
quest.save();
|
||||
|
||||
if(quest.boss != null) {
|
||||
quest.boss.key = quest.key;
|
||||
quest.boss.save();
|
||||
}
|
||||
|
||||
if(quest.key.equals(key)){
|
||||
searchedQuest = quest;
|
||||
}
|
||||
}
|
||||
|
||||
cb.GotQuest(searchedQuest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
public void GotObject(QuestContent obj) {
|
||||
cb.GotQuest(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void GetItemData(final String key, final GotContentEntryCallback<ItemData> gotEntry) {
|
||||
final ItemData itemData = new Select().from(ItemData.class).where(Condition.column("key").eq(key)).querySingle();
|
||||
|
||||
if (itemData != null) {
|
||||
gotEntry.GotObject(itemData);
|
||||
} else {
|
||||
getContentAndSearchFor("item", key, gotEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetItemDataList(final List<String> keysToSearch, GotContentEntryCallback<List<ItemData>> gotEntries) {
|
||||
|
||||
Condition.In keyCondition = Condition.column("key").in("potion");
|
||||
|
||||
for (String item : keysToSearch) {
|
||||
keyCondition = keyCondition.and(item);
|
||||
}
|
||||
|
||||
|
||||
Where<ItemData> query = new Select().from(ItemData.class).where(keyCondition);
|
||||
|
||||
String queryString = query.getQuery();
|
||||
List<ItemData> items = query.queryList();
|
||||
|
||||
|
||||
if (items != null && items.size() != 0) {
|
||||
gotEntries.GotObject(items);
|
||||
} else {
|
||||
getContentAndSearchForList("item", keysToSearch, gotEntries);
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Object> void getContentAndSearchFor(final String typeOfSearch, final String searchKey, final GotContentEntryCallback<T> gotEntry) {
|
||||
apiService.getContent(new Callback<ContentResult>() {
|
||||
@Override
|
||||
public void success(ContentResult contentResult, Response response) {
|
||||
switch (typeOfSearch) {
|
||||
case "quest": {
|
||||
Collection<QuestContent> questList = contentResult.quests.values();
|
||||
|
||||
for (QuestContent quest : questList) {
|
||||
if (quest.key == searchKey) {
|
||||
gotEntry.GotObject((T) quest);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "item": {
|
||||
T searchedItem = null;
|
||||
|
||||
if (searchKey == "potion") {
|
||||
searchedItem = (T) contentResult.potion;
|
||||
} else if (searchKey == "armoire") {
|
||||
searchedItem = (T) contentResult.armoire;
|
||||
} else {
|
||||
Collection<ItemData> itemList = contentResult.gear.flat.values();
|
||||
|
||||
for (ItemData item : itemList) {
|
||||
if (item.key == searchKey) {
|
||||
searchedItem = (T) item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gotEntry.GotObject((T) searchedItem);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
saveContentResultToDb(contentResult);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private <T extends Object> void getContentAndSearchForList(final String typeOfSearch, final List<String> searchKeys, final GotContentEntryCallback<List<T>> gotEntry) {
|
||||
apiService.getContent(new Callback<ContentResult>() {
|
||||
@Override
|
||||
public void success(ContentResult contentResult, Response response) {
|
||||
|
||||
switch (typeOfSearch) {
|
||||
case "item": {
|
||||
List<T> resultList = new ArrayList<T>();
|
||||
|
||||
List<ItemData> itemList = new ArrayList<ItemData>(contentResult.gear.flat.values());
|
||||
itemList.add(contentResult.potion);
|
||||
itemList.add(contentResult.armoire);
|
||||
|
||||
for (ItemData item : itemList) {
|
||||
if (searchKeys.contains(item.key)) {
|
||||
resultList.add((T) item);
|
||||
}
|
||||
}
|
||||
|
||||
gotEntry.GotObject(resultList);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
saveContentResultToDb(contentResult);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void saveContentResultToDb(ContentResult contentResult) {
|
||||
Collection<QuestContent> questList = contentResult.quests.values();
|
||||
|
||||
for (QuestContent quest : questList) {
|
||||
quest.save();
|
||||
|
||||
if (quest.boss != null) {
|
||||
quest.boss.key = quest.key;
|
||||
quest.boss.save();
|
||||
}
|
||||
}
|
||||
|
||||
contentResult.armoire.save();
|
||||
contentResult.potion.save();
|
||||
|
||||
Collection<ItemData> itemList = contentResult.gear.flat.values();
|
||||
|
||||
for (ItemData item : itemList) {
|
||||
item.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.util.Log;
|
||||
|
|
@ -34,6 +33,7 @@ import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
|||
import com.habitrpg.android.habitica.ui.EditTextDrawer;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.adapter.HabitItemRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.IReceiveNewEntries;
|
||||
import com.habitrpg.android.habitica.ui.fragments.TaskRecyclerViewFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.Debounce;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
|
@ -48,7 +48,7 @@ import com.mikepenz.materialdrawer.DrawerBuilder;
|
|||
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener ;
|
||||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
||||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
|
|
@ -61,7 +61,6 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
|
|
@ -72,7 +71,7 @@ import retrofit.client.Response;
|
|||
|
||||
public class MainActivity extends AvatarActivityBase implements HabitRPGUserCallback.OnUserReceived,
|
||||
TaskScoringCallback.OnTaskScored, FlowContentObserver.OnSpecificModelStateChangedListener,
|
||||
Callback<List<ItemData>>, OnCheckedChangeListener {
|
||||
OnCheckedChangeListener {
|
||||
|
||||
static final int TASK_CREATED_RESULT = 1;
|
||||
static final int TASK_UPDATED_RESULT = 2;
|
||||
|
|
@ -89,6 +88,9 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
FlowContentObserver observer;
|
||||
|
||||
private TagsHelper tagsHelper;
|
||||
|
||||
private ContentCache contentCache;
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes() {
|
||||
return R.layout.activity_main;
|
||||
|
|
@ -133,6 +135,8 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
this.mAPIHelper = new APIHelper(this, hostConfig);
|
||||
|
||||
mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||
|
||||
contentCache = new ContentCache(mAPIHelper.apiService);
|
||||
}
|
||||
SetUserData();
|
||||
}
|
||||
|
|
@ -259,10 +263,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
return;
|
||||
}
|
||||
|
||||
mAPIHelper.updateTaskDirection(rewardKey, TaskDirection.down, new TaskScoringCallback(this, rewardKey));
|
||||
|
||||
/*
|
||||
if (event.Reward instanceof RewardItem) {
|
||||
if (event.Reward.specialTag == "item") {
|
||||
if (rewardKey.equals("potion")) {
|
||||
int currentHp = User.getStats().getHp().intValue();
|
||||
int maxHp = User.getStats().getMaxHealth();
|
||||
|
|
@ -274,9 +275,9 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
}
|
||||
|
||||
mAPIHelper.apiService.buyItem(event.Reward.getId(), new Callback<Void>() {
|
||||
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
|
||||
switch (rewardKey) {
|
||||
case "potion":
|
||||
double newHp = Math.min(User.getStats().getMaxHealth(), User.getStats().getHp() + 15);
|
||||
|
|
@ -284,6 +285,11 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
|
||||
updateHeader();
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
// TODO Add bought item to the avatar
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -292,13 +298,14 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
showSnackbar("Buy Reward Error " + event.Reward.getText(), true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// User created Rewards
|
||||
}*/
|
||||
|
||||
mAPIHelper.updateTaskDirection(rewardKey, TaskDirection.down, new TaskScoringCallback(this, rewardKey));
|
||||
}
|
||||
}
|
||||
|
||||
public void onEvent(final TaskSaveEvent event) {
|
||||
|
|
@ -384,7 +391,59 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
break;
|
||||
case 3:
|
||||
layoutOfType = R.layout.reward_item_card;
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(Task.TYPE_REWARD, MainActivity.this.tagsHelper, layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, MainActivity.this), Task.TYPE_REWARD);
|
||||
HabitItemRecyclerViewAdapter adapter = new HabitItemRecyclerViewAdapter(Task.TYPE_REWARD, MainActivity.this.tagsHelper,
|
||||
layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, MainActivity.this,
|
||||
new HabitItemRecyclerViewAdapter.IAdditionalEntries() {
|
||||
@Override
|
||||
public void GetAdditionalEntries(final IReceiveNewEntries callBack) {
|
||||
|
||||
// request buyable gear
|
||||
mAPIHelper.apiService.getInventoryBuyableGear(new Callback<List<ItemData>>() {
|
||||
@Override
|
||||
public void success(List<ItemData> itemDatas, Response response) {
|
||||
|
||||
// get itemdata list
|
||||
ArrayList<String> itemKeys = new ArrayList<String>();
|
||||
for (ItemData item : itemDatas) {
|
||||
itemKeys.add(item.key);
|
||||
}
|
||||
|
||||
contentCache.GetItemDataList(itemKeys, new ContentCache.GotContentEntryCallback<List<ItemData>>() {
|
||||
@Override
|
||||
public void GotObject(List<ItemData> obj) {
|
||||
ArrayList<Task> buyableItems = new ArrayList<Task>();
|
||||
|
||||
for (ItemData item : obj) {
|
||||
Task reward = new Task();
|
||||
reward.text = item.text;
|
||||
reward.notes = item.notes;
|
||||
reward.value = item.value;
|
||||
reward.setType("reward");
|
||||
reward.specialTag = "item";
|
||||
reward.setId(item.key);
|
||||
|
||||
buyableItems.add(reward);
|
||||
}
|
||||
|
||||
callBack.GotAdditionalItems(buyableItems);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
fragment = TaskRecyclerViewFragment.newInstance(adapter, Task.TYPE_REWARD);
|
||||
break;
|
||||
default:
|
||||
layoutOfType = R.layout.todo_item_card;
|
||||
|
|
@ -481,47 +540,6 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void success(List<ItemData> items, Response response) {
|
||||
|
||||
// TODO Order Rewards
|
||||
// TODO add Gear Images
|
||||
|
||||
Condition.In keyCondition = Condition.column("key").in("potion");
|
||||
|
||||
for (ItemData item : items) {
|
||||
keyCondition = keyCondition.and(item.key);
|
||||
}
|
||||
|
||||
/*
|
||||
ConditionQueryBuilder<ItemData> queryBuilder = new ConditionQueryBuilder<ItemData>(ItemData.class,
|
||||
keyCondition);
|
||||
|
||||
List<ItemData> itemsFromDb = new Select().from(ItemData.class).where(queryBuilder).queryList();
|
||||
|
||||
ArrayList<RewardItem> rewardList = new ArrayList<>();
|
||||
|
||||
for (ItemData item : itemsFromDb) {
|
||||
RewardItem reward = new RewardItem();
|
||||
reward.text = item.text;
|
||||
reward.notes = item.notes;
|
||||
reward.value = item.value;
|
||||
reward.setId(item.key);
|
||||
|
||||
rewardList.add(reward);
|
||||
}
|
||||
|
||||
GearRewards.clear();
|
||||
GearRewards.addAll(rewardList);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskDataReceived(TaskDirectionData data) {
|
||||
notifyUser(data.getExp(), data.getHp(), data.getGp(), data.getLvl(), data.getDelta());
|
||||
|
|
@ -534,6 +552,10 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
|
||||
@Override
|
||||
public void onModelStateChanged(Class<? extends Model> aClass, BaseModel.Action action, String s, String s1) {
|
||||
if(aClass != HabitRPGUser.class)
|
||||
return;
|
||||
|
||||
|
||||
new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).async().querySingle(userTransactionListener);
|
||||
Log.d("db", "received notif");
|
||||
// SetUserData();
|
||||
|
|
@ -576,6 +598,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Updates concerned tags.
|
||||
*/
|
||||
|
|
@ -583,17 +606,16 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
Log.d("tags", "Updating tags");
|
||||
List<IDrawerItem> filters = filterDrawer.getDrawerItems();
|
||||
for (IDrawerItem filter : filters) {
|
||||
if(filter instanceof SwitchDrawerItem) {
|
||||
if (filter instanceof SwitchDrawerItem) {
|
||||
SwitchDrawerItem currentfilter = (SwitchDrawerItem) filter;
|
||||
Log.v("tags", "Tag " + currentfilter.getName());
|
||||
String tagId = ((Tag) currentfilter.getTag()).getId();
|
||||
for(TaskTag tag : tags) {
|
||||
for (TaskTag tag : tags) {
|
||||
Tag currentTag = tag.getTag();
|
||||
|
||||
|
||||
|
||||
if(tagId != null && currentTag!=null && tagId.equals(currentTag.getId())) {
|
||||
currentfilter.withDescription(""+(currentTag.getTasks().size()+1));
|
||||
if (tagId != null && currentTag != null && tagId.equals(currentTag.getId())) {
|
||||
currentfilter.withDescription("" + (currentTag.getTasks().size() + 1));
|
||||
filterDrawer.updateItem(currentfilter);
|
||||
}
|
||||
}
|
||||
|
|
@ -639,10 +661,12 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
User = habitRPGUser;
|
||||
SetUserData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<HabitRPGUser> baseTransaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<HabitRPGUser> baseTransaction, HabitRPGUser habitRPGUser) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.databinding.ObservableArrayList;
|
||||
import android.databinding.ObservableList;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
|
|
@ -42,15 +41,23 @@ import com.raizlabs.android.dbflow.sql.language.Select;
|
|||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
import com.raizlabs.android.dbflow.structure.Model;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
|
||||
public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
||||
extends RecyclerView.Adapter<HabitItemRecyclerViewAdapter.ViewHolder>
|
||||
implements FlowContentObserver.OnModelStateChangedListener {
|
||||
implements FlowContentObserver.OnModelStateChangedListener, IReceiveNewEntries {
|
||||
|
||||
|
||||
public interface IAdditionalEntries
|
||||
{
|
||||
void GetAdditionalEntries(IReceiveNewEntries callBack);
|
||||
}
|
||||
|
||||
|
||||
int layoutResource;
|
||||
private Class<ViewHolder<Task>> viewHolderClass;
|
||||
|
|
@ -65,59 +72,24 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
static final int TYPE_CELL = 1;
|
||||
private RecyclerView.Adapter<ViewHolder> parentAdapter;
|
||||
private TagsHelper tagsHelper;
|
||||
private IAdditionalEntries additionalEntries;
|
||||
|
||||
public HabitItemRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Class<ViewHolder<Task>> viewHolderClass, Context newContext) {
|
||||
this(taskType, tagsHelper, layoutResource, viewHolderClass, newContext, null);
|
||||
}
|
||||
|
||||
public HabitItemRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Class<ViewHolder<Task>> viewHolderClass,
|
||||
Context newContext, final ObservableArrayList<Task> content) {
|
||||
Context newContext, final IAdditionalEntries additionalEntries) {
|
||||
this.taskType = taskType;
|
||||
this.context = newContext;
|
||||
observableContent = content;
|
||||
this.tagsHelper = tagsHelper;
|
||||
if (content == null) {
|
||||
this.loadContent();
|
||||
this.additionalEntries = additionalEntries;
|
||||
|
||||
observer = new FlowContentObserver();
|
||||
observer.registerForContentChanges(this.context, Task.class);
|
||||
observer.addModelChangeListener(this);
|
||||
} else {
|
||||
this.filter();
|
||||
content.addOnListChangedCallback(new ObservableList.OnListChangedCallback() {
|
||||
@Override
|
||||
public void onChanged(ObservableList sender) {
|
||||
handler.removeCallbacks(reloadContentRunable);
|
||||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
this.loadContent();
|
||||
|
||||
@Override
|
||||
public void onItemRangeChanged(ObservableList sender, int positionStart, int itemCount) {
|
||||
handler.removeCallbacks(reloadContentRunable);
|
||||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeInserted(ObservableList sender, int positionStart, int itemCount) {
|
||||
handler.removeCallbacks(reloadContentRunable);
|
||||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeMoved(ObservableList sender, int fromPosition, int toPosition, int itemCount) {
|
||||
handler.removeCallbacks(reloadContentRunable);
|
||||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeRemoved(ObservableList sender, int positionStart, int itemCount) {
|
||||
handler.removeCallbacks(reloadContentRunable);
|
||||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
});
|
||||
|
||||
loadContent();
|
||||
}
|
||||
observer = new FlowContentObserver();
|
||||
observer.registerForContentChanges(this.context, Task.class);
|
||||
observer.addModelChangeListener(this);
|
||||
|
||||
this.layoutResource = layoutResource;
|
||||
this.viewHolderClass = viewHolderClass;
|
||||
|
|
@ -251,6 +223,8 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
handler.postDelayed(reloadContentRunable, 200);
|
||||
}
|
||||
|
||||
// region ViewHolders
|
||||
|
||||
public abstract class ViewHolder<THabitItem extends Task> extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
|
||||
protected android.content.res.Resources resources;
|
||||
|
|
@ -515,6 +489,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
public void loadContent() {
|
||||
if (this.observableContent == null) {
|
||||
|
|
@ -525,6 +500,10 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
.where(Condition.column("type").eq(this.taskType))
|
||||
.orderBy(OrderBy.columns("dateCreated").descending())
|
||||
.queryList());
|
||||
|
||||
if(additionalEntries != null){
|
||||
additionalEntries.GetAdditionalEntries(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (parentAdapter != null) {
|
||||
|
|
@ -533,4 +512,16 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void GotAdditionalItems(List<Task> items) {
|
||||
this.observableContent.addAll(items);
|
||||
|
||||
if (parentAdapter != null) {
|
||||
parentAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter;
|
||||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IReceiveNewEntries{
|
||||
void GotAdditionalItems(List<Task> items);
|
||||
}
|
||||
|
|
@ -24,7 +24,11 @@ public class DataBindingUtils {
|
|||
|
||||
@BindingAdapter("bind:imageName")
|
||||
public static void loadImage(ImageView view, String imageName) {
|
||||
Picasso.with(view.getContext()).load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/"+ imageName +".png").into(view);
|
||||
if(view.getVisibility() == View.VISIBLE) {
|
||||
Picasso.with(view.getContext())
|
||||
.load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + imageName + ".png")
|
||||
.into(view);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("bind:cardColor")
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ public class Task extends BaseModel {
|
|||
@Column
|
||||
public String date;
|
||||
|
||||
// used for buyable items
|
||||
public String specialTag;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
|
|
|
|||
Loading…
Reference in a new issue