mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 13:48:55 +00:00
Refactor models for checklists and tags
This commit is contained in:
parent
d116228b13
commit
92ef8c6e44
17 changed files with 182 additions and 401 deletions
|
|
@ -68,18 +68,18 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.databinding/library/1.0-rc0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/gridlayout-v7/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.databinding/library/1.0-rc1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/gridlayout-v7/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/answers/1.2.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.1.2/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics/2.3.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.florent37/materialviewpager/1.0.6/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.florent37/materialviewpager/1.1.0/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.ksoichiro/android-observablescrollview/1.5.2/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.porokoro/paperboy/364c77b49f/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.instabug.library/instabugcore/1.6.1/jars" />
|
||||
|
|
@ -109,58 +109,63 @@
|
|||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0.17" level="project" />
|
||||
<orderEntry type="library" exported="" name="kenburnsview-1.0.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="retrofit-1.6.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-4.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="rxjava-1.0.10" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-4.5" level="project" />
|
||||
<orderEntry type="library" exported="" name="crashlytics-core-2.3.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="aboutlibraries-5.0.5" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0-rc0" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-annotations-4.5" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" />
|
||||
<orderEntry type="library" exported="" name="instabugsupport-1.6.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-annotations-4.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="paperboy-364c77b49f" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-1.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="DBFlow-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="okio-1.4.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="guava-18.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="okhttp-urlconnection-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="iconics-1.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="auto-service-1.0-rc2" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr4-runtime-4.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc0" level="project" />
|
||||
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="fabric-1.3.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="materialviewpager-1.0.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="compiler-1.0-rc0" level="project" />
|
||||
<orderEntry type="library" exported="" name="beta-1.1.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="gridlayout-v7-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="gridlayout-v7-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
|
||||
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" />
|
||||
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="cardview-v7-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="DBFlow-Compiler-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="gson-2.2.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
|
||||
<orderEntry type="library" exported="" name="answers-1.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="okhttp-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="retrofit-1.9.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="DBFlow-Core-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="materialdrawer-3.0.8" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="auto-common-0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="adapters-1.0-rc0" level="project" />
|
||||
<orderEntry type="library" exported="" name="adapters-1.0-rc1" level="project" />
|
||||
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-2.1.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="materialviewpager-1.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-observablescrollview-1.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-stdlib-0.11.91" level="project" />
|
||||
<orderEntry type="library" exported="" name="instabugcore-1.6.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="crashlytics-2.3.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
|
||||
<orderEntry type="library" exported="" name="kotlin-runtime-0.11.91" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -34,7 +34,10 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.squareup.retrofit:retrofit:1.6.0'
|
||||
compile 'io.reactivex:rxjava:1.0.10'
|
||||
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
|
||||
compile 'com.squareup.okhttp:okhttp:2.4.0'
|
||||
compile 'com.squareup.retrofit:retrofit:1.9.0'
|
||||
|
||||
compile('com.crashlytics.sdk.android:crashlytics:2.3.0@aar') {
|
||||
transitive = true;
|
||||
|
|
|
|||
|
|
@ -11,22 +11,8 @@
|
|||
|
||||
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/card_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginBottom="@dimen/cardMarginVertical"
|
||||
android:layout_marginLeft="@dimen/cardMarginHorizontal"
|
||||
android:layout_marginRight="@dimen/cardMarginHorizontal"
|
||||
android:layout_marginTop="@dimen/cardMarginVertical"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardPreventCornerOverlap="false"
|
||||
app:contentPadding="0dp"
|
||||
app:cardColor="@{daily.getLightTaskColor}">
|
||||
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -40,12 +26,12 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:checked="@{daily.completed}"
|
||||
app:backgroundColor="@{daily.getDarkTaskColor}"
|
||||
app:backgroundColor="@{daily.getLightTaskColor}"
|
||||
android:gravity="center"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp">
|
||||
<CheckedTextView
|
||||
|
|
@ -62,9 +48,16 @@
|
|||
android:layout_height="match_parent"
|
||||
android:text="@{daily.notes}" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@{String.valueOf(daily.getCompletedChecklistCount)+'/'+String.valueOf(daily.checklist.size)}"/>
|
||||
<View
|
||||
android:id="@+id/rightBorderView"
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="fill_parent"
|
||||
app:backgroundColor="@{daily.getLightTaskColor}"
|
||||
android:gravity="center"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</FrameLayout>
|
||||
</layout>
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
<data>
|
||||
|
||||
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward" />
|
||||
<import type="com.magicmicky.habitrpgwrapper.lib.models.tasks.Task" />
|
||||
|
||||
<variable
|
||||
name="reward"
|
||||
type="Reward" />
|
||||
type="Task" />
|
||||
</data>
|
||||
|
||||
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.google.gson.FieldAttributes;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
|
@ -25,10 +26,12 @@ import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuth;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||
import com.raizlabs.android.dbflow.structure.ModelAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit.Callback;
|
||||
import retrofit.ErrorHandler;
|
||||
|
|
@ -59,7 +62,11 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
|
||||
}
|
||||
};
|
||||
//Exclusion stratety needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
|
||||
|
||||
Type taskTagClassListType = new TypeToken<List<TaskTag>>() {}.getType();
|
||||
|
||||
|
||||
//Exclusion stratety needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
@Override
|
||||
|
|
@ -72,7 +79,7 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
return false;
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(TagsAdapter.class, new TagsAdapter().nullSafe())
|
||||
.registerTypeAdapter(taskTagClassListType, new TagsAdapter())
|
||||
.registerTypeAdapter(Boolean.class, booleanAsIntAdapter)
|
||||
.registerTypeAdapter(boolean.class, booleanAsIntAdapter)
|
||||
.create();
|
||||
|
|
@ -152,11 +159,7 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
}
|
||||
|
||||
public void updateTask(Task item, Callback cb) {
|
||||
if(item instanceof Task) {
|
||||
this.apiService.updateTask(item.getId(), item, cb);
|
||||
} else if(item instanceof Reward) {
|
||||
this.apiService.updateTask(item.getId(), item, cb);
|
||||
}
|
||||
}
|
||||
|
||||
//public void buyItem(Reward.SpecialReward itemBought, View btn) {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.RewardItem;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
||||
|
|
@ -279,7 +277,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
}
|
||||
|
||||
public void onEvent(TaskTappedEvent event) {
|
||||
if(event.Task instanceof RewardItem)
|
||||
if(event.Task.type.equals("reward"))
|
||||
return;
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
|
@ -320,6 +318,9 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
return;
|
||||
}
|
||||
|
||||
mAPIHelper.updateTaskDirection(rewardKey, TaskDirection.down, new TaskScoringCallback(this));
|
||||
|
||||
/*
|
||||
if (event.Reward instanceof RewardItem) {
|
||||
if (rewardKey.equals("potion")) {
|
||||
int currentHp = User.getStats().getHp().intValue();
|
||||
|
|
@ -356,8 +357,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
});
|
||||
} else {
|
||||
// User created Rewards
|
||||
mAPIHelper.updateTaskDirection(rewardKey, TaskDirection.down, new TaskScoringCallback(this));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void onEvent(final TaskSaveEvent event) {
|
||||
|
|
@ -411,8 +411,6 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
}
|
||||
|
||||
private ObservableArrayList<RewardItem> GearRewards = new ObservableArrayList<>();
|
||||
|
||||
public void loadTaskLists() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
|
|
@ -440,7 +438,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
break;
|
||||
case 3:
|
||||
layoutOfType = R.layout.reward_item_card;
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("reward", Reward.class, layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, context), Reward.class);
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter("reward", Task.class, layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class, context), Task.class);
|
||||
break;
|
||||
default:
|
||||
layoutOfType = R.layout.todo_item_card;
|
||||
|
|
@ -577,7 +575,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
keyCondition = keyCondition.and(item.key);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ConditionQueryBuilder<ItemData> queryBuilder = new ConditionQueryBuilder<ItemData>(ItemData.class,
|
||||
keyCondition);
|
||||
|
||||
|
|
@ -597,6 +595,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
GearRewards.clear();
|
||||
GearRewards.addAll(rewardList);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.habitrpg.android.habitica.events;
|
||||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
/**
|
||||
* Created by Negue on 11.07.2015.
|
||||
*/
|
||||
public class BuyRewardTappedEvent {
|
||||
public Reward Reward;
|
||||
public Task Reward;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import android.databinding.BindingAdapter;
|
|||
import android.databinding.DataBindingUtil;
|
||||
import android.databinding.ObservableArrayList;
|
||||
import android.databinding.ObservableList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
|
@ -32,15 +30,12 @@ import com.habitrpg.android.habitica.events.TaskTappedEvent;
|
|||
import com.habitrpg.android.habitica.events.TodoCheckedEvent;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.RewardItem;
|
||||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
import com.raizlabs.android.dbflow.structure.Model;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.squareup.picasso.Target;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -174,8 +169,6 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
return new HabitItemRecyclerViewAdapter.TodoViewHolder(view);
|
||||
case "RewardViewHolder":
|
||||
return new HabitItemRecyclerViewAdapter.RewardViewHolder(view);
|
||||
case "RewardItemViewHolder":
|
||||
return new HabitItemRecyclerViewAdapter.RewardItemViewHolder(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -226,9 +219,6 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
|
||||
public abstract class ViewHolder<THabitItem extends Task> extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
|
||||
@InjectView(R.id.card_view)
|
||||
protected CardView cardView;
|
||||
|
||||
@InjectView(R.id.checkedTextView)
|
||||
protected CheckedTextView checkedTextView;
|
||||
|
||||
|
|
@ -376,7 +366,7 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
}
|
||||
}
|
||||
|
||||
public class RewardViewHolder extends ViewHolder<Reward> {
|
||||
public class RewardViewHolder extends ViewHolder<Task> {
|
||||
RewardItemCardBinding binding;
|
||||
|
||||
public RewardViewHolder(View itemView) {
|
||||
|
|
@ -401,58 +391,14 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Reward habitItem, int position) {
|
||||
super.bindHolder(habitItem, position);
|
||||
public void bindHolder(Task reward, int position) {
|
||||
super.bindHolder(reward, position);
|
||||
|
||||
binding.setReward(habitItem);
|
||||
binding.setReward(reward);
|
||||
}
|
||||
}
|
||||
|
||||
public class RewardItemViewHolder extends ViewHolder<RewardItem> implements Target
|
||||
{
|
||||
RewardItemCardBinding binding;
|
||||
|
||||
public RewardItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
binding = DataBindingUtil.bind(itemView);
|
||||
|
||||
binding.btnReward.setClickable(true);
|
||||
binding.btnReward.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BuyRewardTappedEvent event = new BuyRewardTappedEvent();
|
||||
|
||||
if (v == binding.btnReward) {
|
||||
event.Reward = Item;
|
||||
|
||||
EventBus.getDefault().post(event);
|
||||
} else super.onClick(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(RewardItem habitItem, int position) {
|
||||
super.bindHolder(habitItem, position);
|
||||
binding.setReward(habitItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
|
||||
binding.imageView3.setImageBitmap(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBitmapFailed(Drawable errorDrawable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareLoad(Drawable placeHolderDrawable) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void loadContent() {
|
||||
if(this.observableContent == null) {
|
||||
|
|
|
|||
|
|
@ -1,202 +0,0 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.ApiService;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.Server;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.TypeAdapter.TagsAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Status;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuth;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.raizlabs.android.dbflow.structure.ModelAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit.Callback;
|
||||
import retrofit.RequestInterceptor;
|
||||
import retrofit.RestAdapter;
|
||||
import retrofit.converter.GsonConverter;
|
||||
|
||||
/**
|
||||
* Created by MagicMicky on 13/06/2014.
|
||||
*/
|
||||
public class HabitRPGInteractor {
|
||||
|
||||
private ApiService apiService;
|
||||
public HabitRPGInteractor(final String apiKey, final String userKey, final Server server) {
|
||||
RequestInterceptor requestInterceptor = new RequestInterceptor() {
|
||||
@Override
|
||||
public void intercept(RequestInterceptor.RequestFacade request) {
|
||||
request.addHeader("x-api-key", apiKey);
|
||||
request.addHeader("x-api-user",userKey);
|
||||
}
|
||||
};
|
||||
|
||||
//Exclusion stratety needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
return f.getDeclaredClass().equals(ModelAdapter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
return false;
|
||||
}
|
||||
}).registerTypeAdapter(TagsAdapter.class, new TagsAdapter().nullSafe()).create();
|
||||
|
||||
RestAdapter adapter = new RestAdapter.Builder()
|
||||
.setEndpoint(server.toString())
|
||||
.setRequestInterceptor(requestInterceptor)
|
||||
.setConverter(new GsonConverter(gson))
|
||||
.build();
|
||||
this.apiService = adapter.create(ApiService.class);
|
||||
}
|
||||
public HabitRPGInteractor(final String apiKey, final String userKey) {
|
||||
this(apiKey, userKey, Server.NORMAL);
|
||||
}
|
||||
/**
|
||||
* Retrieve the Status of habitrpg
|
||||
* @see com.magicmicky.habitrpgwrapper.lib.models.Status
|
||||
* @param statusCallback the callback called when status is retrieved
|
||||
*/
|
||||
public void getStatus(Callback<Status> statusCallback) {
|
||||
this.apiService.getStatus(statusCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a User from HabitRPG's API.
|
||||
* @see com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser
|
||||
* @param callback The callback called when the user is retrieved
|
||||
*/
|
||||
public void getUser(Callback<HabitRPGUser> callback) {
|
||||
this.apiService.getUser(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a daily from HabitRPG's API
|
||||
* @param dailyId the id of the daily to retrieve
|
||||
* @param dailyCallback the callback called when the daily is retrieved
|
||||
* @see Task
|
||||
*/
|
||||
public void getTask(String dailyId, Callback<Task> dailyCallback) {
|
||||
this.apiService.getTask(dailyId, dailyCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a Reward form HabitRPG's API
|
||||
* @param rewardId the id of the reward to retrieve
|
||||
* @param rewardCallback the callback called when the reward is retrieved.
|
||||
* @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward
|
||||
*/
|
||||
public void getReward(String rewardId, Callback<Reward> rewardCallback) {
|
||||
this.apiService.getReward(rewardId, rewardCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the task to "up" or "down", and check or uncheck dailies/todos.
|
||||
* @param taskId the id of the task to update
|
||||
* @param direction the direction of the task
|
||||
* @param taskDirectionCallback the callback called when the direction is set.
|
||||
* @see com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData
|
||||
*/
|
||||
public void postTaskDirection(String taskId, TaskDirection direction, Callback<TaskDirectionData> taskDirectionCallback) {
|
||||
this.apiService.postTaskDirection(taskId, direction.toString(), taskDirectionCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a daily on HabitRPG
|
||||
* @param task the daily to create
|
||||
* @param taskCallback the callback called when the daily is created
|
||||
* @see Task
|
||||
*/
|
||||
public void createItem(Task task, Callback<Task> taskCallback) {
|
||||
this.apiService.createItem(task, taskCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a reward
|
||||
* @param reward the reward to create
|
||||
* @param rewardCallback the callback called once the item is created
|
||||
*/
|
||||
public void createItem(Reward reward, Callback<Reward> rewardCallback) {
|
||||
this.apiService.createItem(reward, rewardCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an habit
|
||||
* @param taskId the id of the habit to update
|
||||
* @param task the habit to update, with updated field
|
||||
* @param taskCallback the callback called once the habit is updated
|
||||
*/
|
||||
public void updateItem(String taskId, Task task, Callback<Task> taskCallback) {
|
||||
this.apiService.updateTask(taskId, task, taskCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a Reward
|
||||
* @param rewardId the id of the reward to update
|
||||
* @param reward the reward to update, with updated field
|
||||
* @param rewardCallback the callback called once the item is updated
|
||||
*/
|
||||
public void updateItem(String rewardId, Reward reward, Callback<Reward> rewardCallback) {
|
||||
this.apiService.updateTask(rewardId, reward, rewardCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a task.
|
||||
* @param itemId the id of the task to delete
|
||||
* @param voidCallback the callback (on void) called once the item is deleted
|
||||
*/
|
||||
public void deleteItem(String itemId, Callback<Void> voidCallback) {
|
||||
this.apiService.deleteTask(itemId, voidCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tag
|
||||
* @param tag The tag to create
|
||||
* @param multiTagCallback the callback called once the tag is created
|
||||
*/
|
||||
public void createTag(Tag tag, Callback<List<Tag>> multiTagCallback) {
|
||||
this.apiService.createTag(tag, multiTagCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a tag
|
||||
* @param tagId The id of the tag to udpate
|
||||
* @param tag The tag to update, with updated field
|
||||
* @param tagCallback The callback called once the tag is updated
|
||||
*/
|
||||
public void updateTag(String tagId, Tag tag, Callback<Tag> tagCallback) {
|
||||
this.apiService.updateTag(tagId, tag, tagCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a tag
|
||||
* @param tagId the id of the tag to delete
|
||||
* @param voidCallback the callback (on void) called once the item is deleted
|
||||
*/
|
||||
public void deleteTag(String tagId, Callback<Void> voidCallback) {
|
||||
this.apiService.deleteTag(tagId, voidCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects a user
|
||||
* @param authData The username & password of the user
|
||||
* @param responseCallback The callback called once the user is connected
|
||||
*/
|
||||
public void connectUser(UserAuth authData, Callback<UserAuthResponse> responseCallback) {
|
||||
this.apiService.connectLocal(authData,responseCallback);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,9 +7,8 @@ import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuth;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -45,8 +44,6 @@ public interface ApiService {
|
|||
// void revive(Callback<HabitRPGUser> habitRPGUserCallback);
|
||||
|
||||
|
||||
@GET("/user/tasks/{id}")
|
||||
void getReward(@Path("id") String id, Callback<Reward> habitItemCallback);
|
||||
@GET("/user/tasks/{id}")
|
||||
void getTask(@Path("id") String id, Callback<Task> habitItemCallback);
|
||||
|
||||
|
|
@ -55,14 +52,10 @@ public interface ApiService {
|
|||
void postTaskDirection(@Path("id") String id, @Path("direction") String direction, Callback<TaskDirectionData> taskDirectionCallback);
|
||||
|
||||
|
||||
@POST("/user/tasks")
|
||||
void createItem(@Body Reward item, Callback<Reward> habitItemCallback);
|
||||
@POST("/user/tasks")
|
||||
void createItem(@Body Task item, Callback<Task> habitItemCallback);
|
||||
|
||||
|
||||
@PUT("/user/tasks/{id}")
|
||||
void updateTask(@Path("id") String id, @Body Reward item, Callback<Reward> habitItemCallback);
|
||||
@PUT("/user/tasks/{id}")
|
||||
void updateTask(@Path("id") String id, @Body Task item, Callback<Task> habitItemCallback);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
|||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||
|
|
@ -29,7 +28,7 @@ public class HabitRPGUser extends BaseModel {
|
|||
|
||||
List<Task> dailys;
|
||||
List<Task> todos;
|
||||
List<Reward> rewards;
|
||||
List<Task> rewards;
|
||||
List<Task> habits;
|
||||
List<Tag> tags;
|
||||
|
||||
|
|
@ -89,7 +88,7 @@ public class HabitRPGUser extends BaseModel {
|
|||
this.todos = todos;
|
||||
}
|
||||
|
||||
public void setRewards(List<Reward> rewards) {
|
||||
public void setRewards(List<Task> rewards) {
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
|
|
@ -167,10 +166,10 @@ public class HabitRPGUser extends BaseModel {
|
|||
}
|
||||
|
||||
@OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "rewards")
|
||||
public List<Reward> getRewards() {
|
||||
public List<Task> getRewards() {
|
||||
if(rewards == null) {
|
||||
rewards = new Select()
|
||||
.from(Reward.class)
|
||||
.from(Task.class)
|
||||
.queryList();
|
||||
}
|
||||
return rewards;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
|||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
||||
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
|
|
@ -17,6 +18,7 @@ import java.util.List;
|
|||
* Created by MagicMicky on 16/03/14.
|
||||
*/
|
||||
|
||||
@ModelContainer
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Tag extends BaseModel{
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ public class Tag extends BaseModel{
|
|||
if(tasks == null) {
|
||||
tasks = new Select()
|
||||
.from(TaskTag.class)
|
||||
.where(Condition.column("tag_id").eq(this.id))
|
||||
.queryList();
|
||||
}
|
||||
return tasks;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class ChecklistItem extends BaseModel {
|
|||
|
||||
@Column
|
||||
private boolean completed;
|
||||
/*
|
||||
|
||||
@Column
|
||||
@ForeignKey(
|
||||
references = {@ForeignKeyReference(columnName = "task_id",
|
||||
|
|
@ -32,7 +32,7 @@ public class ChecklistItem extends BaseModel {
|
|||
foreignColumnName = "id")},
|
||||
saveForeignKeyModel = false)
|
||||
ForeignKeyContainer<Task> task;
|
||||
*/
|
||||
|
||||
public ChecklistItem() {
|
||||
this(null,null);
|
||||
}
|
||||
|
|
@ -70,4 +70,14 @@ public class ChecklistItem extends BaseModel {
|
|||
public void setCompleted(boolean completed) {
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
public Task getTask() {
|
||||
return task.toModel();
|
||||
}
|
||||
|
||||
public void setTask(Task task) {
|
||||
this.task = new ForeignKeyContainer<>(Task.class);
|
||||
this.task.setModel(task);
|
||||
this.task.put("id", task.id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models.tasks;
|
||||
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
|
||||
/**
|
||||
* A reward. Contain a reward that you can see on the website
|
||||
* @author MagicMicky
|
||||
*
|
||||
*/
|
||||
@Table(databaseName = HabitDatabase.NAME, allFields = true)
|
||||
public class Reward extends Task {
|
||||
|
||||
public Reward() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models.tasks;
|
||||
|
||||
/**
|
||||
* Created by Negue on 15.07.2015.
|
||||
*/
|
||||
public class RewardItem extends Reward {
|
||||
|
||||
}
|
||||
|
|
@ -5,9 +5,11 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
||||
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by viirus on 10/08/15.
|
||||
*/
|
||||
@ModelContainer
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Task extends BaseModel {
|
||||
|
||||
|
|
@ -31,13 +34,21 @@ public class Task extends BaseModel {
|
|||
@Column
|
||||
public Double value;
|
||||
|
||||
public List<TaskTag> tags;
|
||||
|
||||
//Habits
|
||||
@Column
|
||||
public Boolean up, down;
|
||||
|
||||
|
||||
//todos/dailies
|
||||
@Column
|
||||
public Boolean completed;
|
||||
|
||||
public List<ChecklistItem> checklist;
|
||||
|
||||
|
||||
//dailies
|
||||
@Column
|
||||
public String frequency;
|
||||
|
||||
|
|
@ -51,9 +62,12 @@ public class Task extends BaseModel {
|
|||
public Days repeat;
|
||||
//TODO: private String lastCompleted;
|
||||
|
||||
|
||||
//todos
|
||||
@Column
|
||||
public String date;
|
||||
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
|
|
@ -132,6 +146,24 @@ public class Task extends BaseModel {
|
|||
|
||||
public void setType(String type) {this.type = type;}
|
||||
|
||||
@OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "tags")
|
||||
public List<TaskTag> getTags() {
|
||||
if(tags == null) {
|
||||
tags = new Select()
|
||||
.from(TaskTag.class)
|
||||
.where(Condition.column("task_id").eq(this.id))
|
||||
.queryList();
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<TaskTag> tags) {
|
||||
for (TaskTag tag : tags) {
|
||||
tag.setTask(this);
|
||||
}
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether or not the habit can be "upped"
|
||||
*/
|
||||
|
|
@ -171,6 +203,35 @@ public class Task extends BaseModel {
|
|||
this.completed = completed;
|
||||
}
|
||||
|
||||
|
||||
@OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "checklist")
|
||||
public List<ChecklistItem> getChecklist() {
|
||||
if(this.checklist == null) {
|
||||
this.checklist = new Select()
|
||||
.from(ChecklistItem.class)
|
||||
.where(Condition.column("task_id").eq(this.id))
|
||||
.queryList();
|
||||
}
|
||||
return this.checklist;
|
||||
}
|
||||
|
||||
public void setChecklist(List<ChecklistItem> checklist) {
|
||||
for (ChecklistItem checklistItem : checklist) {
|
||||
checklistItem.setTask(this);
|
||||
}
|
||||
this.checklist = checklist;
|
||||
}
|
||||
|
||||
public Integer getCompletedChecklistCount() {
|
||||
Integer count = 0;
|
||||
for (ChecklistItem item : this.getChecklist()) {
|
||||
if (item.getCompleted()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public String getFrequency() { return frequency; }
|
||||
public void setFrequency(String frequency) { this.frequency = frequency; }
|
||||
|
||||
|
|
@ -190,20 +251,7 @@ public class Task extends BaseModel {
|
|||
public void setRepeat(Days repeat) {
|
||||
this.repeat = repeat;
|
||||
}
|
||||
/**
|
||||
* Formated:
|
||||
* SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
* @return the lastCompleted
|
||||
*/
|
||||
/* public String getLastCompleted() {
|
||||
return lastCompleted;
|
||||
}
|
||||
/**
|
||||
* @param lastCompleted the lastCompleted to set
|
||||
*/
|
||||
/* public void setLastCompleted(String lastCompleted) {
|
||||
this.lastCompleted = lastCompleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the streak
|
||||
*/
|
||||
|
|
@ -246,6 +294,22 @@ public class Task extends BaseModel {
|
|||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (this.tags != null) {
|
||||
for (TaskTag tag : this.tags) {
|
||||
tag.setTask(this);
|
||||
}
|
||||
}
|
||||
if (this.checklist != null) {
|
||||
for (ChecklistItem item : this.checklist) {
|
||||
item.setTask(this);
|
||||
}
|
||||
}
|
||||
super.save();
|
||||
}
|
||||
|
||||
public int getLightTaskColor()
|
||||
{
|
||||
if (this.value < -20)
|
||||
|
|
|
|||
|
|
@ -25,13 +25,15 @@ public class TaskTag extends BaseModel {
|
|||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "tag_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "id")})
|
||||
foreignColumnName = "id")},
|
||||
saveForeignKeyModel = false)
|
||||
public ForeignKeyContainer<Tag> tag;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "task_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "id")})
|
||||
foreignColumnName = "id")},
|
||||
saveForeignKeyModel = false)
|
||||
public ForeignKeyContainer<Task> task;
|
||||
|
||||
public Tag getTag() {
|
||||
|
|
@ -41,6 +43,7 @@ public class TaskTag extends BaseModel {
|
|||
public void setTag(Tag tag) {
|
||||
this.tag = new ForeignKeyContainer<>(Tag.class);
|
||||
this.tag.setModel(tag);
|
||||
this.tag.put("id", tag.id);
|
||||
}
|
||||
|
||||
public Task getTask() {
|
||||
|
|
@ -50,6 +53,7 @@ public class TaskTag extends BaseModel {
|
|||
public void setTask(Task task) {
|
||||
this.task = new ForeignKeyContainer<>(Task.class);
|
||||
this.task.setModel(task);
|
||||
this.task.put("id", task.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue