From 3619a5e7b2e0bc43e6385d48da8ca75bd40725f0 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 23 Jun 2015 12:02:32 +0200 Subject: [PATCH] Integracte HabitRPGWrapper library directly --- Habitica/build.gradle | 12 +- .../lib/HabitRPGInteractor.java | 249 ++++++++++++++++++ .../habitrpgwrapper/lib/api/ApiService.java | 121 +++++++++ .../lib/api/HabitItemCallback.java | 53 ++++ .../lib/api/MultiTagsCallback.java | 38 +++ .../habitrpgwrapper/lib/api/Server.java | 28 ++ .../lib/api/StatusCallback.java | 31 +++ .../habitrpgwrapper/lib/api/TagCallback.java | 32 +++ .../lib/api/TaskDirectionCallback.java | 30 +++ .../lib/api/TypeAdapter/TagsAdapter.java | 58 ++++ .../habitrpgwrapper/lib/api/UserCallback.java | 41 +++ .../habitrpgwrapper/lib/api/VoidCallback.java | 29 ++ .../lib/models/BasicStats.java | 55 ++++ .../lib/models/DefaultResponse.java | 26 ++ .../lib/models/HabitRPGUser.java | 115 ++++++++ .../lib/models/HabitRpgClass.java | 13 + .../habitrpgwrapper/lib/models/Items.java | 54 ++++ .../habitrpgwrapper/lib/models/Party.java | 125 +++++++++ .../lib/models/PlayerMinStats.java | 120 +++++++++ .../lib/models/Preferences.java | 214 +++++++++++++++ .../habitrpgwrapper/lib/models/Profile.java | 42 +++ .../habitrpgwrapper/lib/models/Stats.java | 36 +++ .../habitrpgwrapper/lib/models/Status.java | 16 ++ .../habitrpgwrapper/lib/models/Tag.java | 37 +++ .../lib/models/TaskDirection.java | 17 ++ .../lib/models/TaskDirectionData.java | 20 ++ .../habitrpgwrapper/lib/models/UserAuth.java | 25 ++ .../lib/models/UserAuthResponse.java | 25 ++ .../lib/models/tasks/Checklist.java | 105 ++++++++ .../lib/models/tasks/Daily.java | 168 ++++++++++++ .../lib/models/tasks/Habit.java | 65 +++++ .../lib/models/tasks/HabitItem.java | 179 +++++++++++++ .../lib/models/tasks/HabitType.java | 9 + .../lib/models/tasks/Reward.java | 140 ++++++++++ .../lib/models/tasks/Tags.java | 26 ++ .../lib/models/tasks/ToDo.java | 73 +++++ .../habitrpgwrapper/lib/utils/DaysUtils.java | 34 +++ 37 files changed, 2454 insertions(+), 7 deletions(-) create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/MultiTagsCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/Server.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/StatusCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TagCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TaskDirectionCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/UserCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/VoidCallback.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/BasicStats.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/DefaultResponse.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRpgClass.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Items.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Party.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/PlayerMinStats.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Preferences.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Profile.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Stats.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Status.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirection.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirectionData.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuth.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuthResponse.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java create mode 100644 Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java diff --git a/Habitica/build.gradle b/Habitica/build.gradle index de56696db..64476716e 100644 --- a/Habitica/build.gradle +++ b/Habitica/build.gradle @@ -30,9 +30,7 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.magicmicky.habitrpgwrapper:lib:1.8' - aarLinkSources 'com.magicmicky.habitrpgwrapper:lib:1.8:sources@jar' - + compile 'com.squareup.retrofit:retrofit:1.6.0' compile('com.crashlytics.sdk.android:crashlytics:2.3.0@aar') { transitive = true; @@ -49,10 +47,10 @@ dependencies { transitive = true } - compile 'com.android.support:appcompat-v7:22.2.0' - compile 'com.android.support:design:22.2.0' - compile 'com.android.support:gridlayout-v7:22.2.0' - compile 'com.android.support:recyclerview-v7:22.2.0' + compile 'com.android.support:appcompat-v7:22.2.+' + compile 'com.android.support:design:22.2.+' + compile 'com.android.support:gridlayout-v7:22.2.+' + compile 'com.android.support:recyclerview-v7:22.2.+' // Icons dependencies { diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java new file mode 100644 index 000000000..43e8f61f9 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/HabitRPGInteractor.java @@ -0,0 +1,249 @@ +package com.magicmicky.habitrpgwrapper.lib; + +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.Daily; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Tags; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; + +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); + } + }; + Gson gson = new GsonBuilder().registerTypeAdapter(Tags.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 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 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 com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily + */ + public void getDaily(String dailyId, Callback dailyCallback) { + this.apiService.getDaily(dailyId,dailyCallback); + } + + /** + * Retrieve a Habit from HabitRPG's API + * @param habitId the id of the habit to retrieve. + * @param habitCallback the callback called when the habit is retrieved. + * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit + */ + public void getHabit(String habitId, Callback habitCallback) { + this.apiService.getHabit(habitId,habitCallback); + } + + /** + * Retrieve a To do from HabitRPG's API + * @param todoId the id of the item to retrieve + * @param todoCallback the callback called when the item is retrieved. + * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo + */ + public void getToDo(String todoId, Callback todoCallback) { + this.apiService.getToDo(todoId,todoCallback); + } + + /** + * 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 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 taskDirectionCallback) { + this.apiService.postTaskDirection(taskId, direction.toString(), taskDirectionCallback); + } + + /** + * Create a daily on HabitRPG + * @param daily the daily to create + * @param dailyCallback the callback called when the daily is created + * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily + */ + public void createItem(Daily daily, Callback dailyCallback) { + this.apiService.createItem(daily, dailyCallback ); + } + + /** + * Create an Habit + * @param habit the haibt to create + * @param habitCallback the callback called once the habit is created + * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit + */ + public void createItem(Habit habit, Callback habitCallback) { + this.apiService.createItem(habit, habitCallback); + } + + /** + * Create a To do + * @param todoItem the item to create + * @param toDoCallback the callback called once the item is created + * @see com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo + */ + public void createItem(ToDo todoItem, Callback toDoCallback) { + this.apiService.createItem(todoItem, toDoCallback); + } + + /** + * 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 rewardCallback) { + this.apiService.createItem(reward, rewardCallback); + } + + /** + * Update an habit + * @param habitId the id of the habit to update + * @param habit the habit to update, with updated field + * @param habitCallback the callback called once the habit is updated + */ + public void updateItem(String habitId, Habit habit, Callback habitCallback) { + this.apiService.updateTask(habitId, habit, habitCallback); + } + + /** + * Updates a daily + * @param dailyId the id of the daily to update + * @param daily the new daily item, with updated field + * @param habitCallback the callback called once the daily is updated + */ + public void updateItem(String dailyId, Daily daily, Callback habitCallback) { + this.apiService.updateTask(dailyId, daily, habitCallback); + } + + /** + * Updates a To do item + * @param todoId the id of the item to update + * @param todoItem the item to udpate, with updated field + * @param toDoCallback the callback called once the item is updated + */ + public void updateItem(String todoId, ToDo todoItem, Callback toDoCallback) { + this.apiService.updateTask(todoId, todoItem, toDoCallback); + } + + /** + * 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 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 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> 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 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 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 responseCallback) { + this.apiService.connectLocal(authData,responseCallback); + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java new file mode 100644 index 000000000..a2f29258b --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/ApiService.java @@ -0,0 +1,121 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +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.Daily; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; + +import java.util.List; + +import retrofit.Callback; +import retrofit.http.Body; +import retrofit.http.DELETE; +import retrofit.http.GET; +import retrofit.http.POST; +import retrofit.http.PUT; +import retrofit.http.Path; + +/** + * Created by MagicMicky on 10/06/2014. + */ +public interface ApiService { + @GET("/status") + void getStatus(Callback statusCallback); + + + @GET("/user/") + void getUser(Callback habitRPGUserCallback); + + + // @POST("/user/revive") + // void revive(Callback habitRPGUserCallback); + + + @GET("/user/tasks/{id}") + void getHabit(@Path("id") String id, Callback habitItemCallback); + @GET("/user/tasks/{id}") + void getDaily(@Path("id") String id, Callback habitItemCallback); + @GET("/user/tasks/{id}") + void getToDo(@Path("id") String id, Callback habitItemCallback); + @GET("/user/tasks/{id}") + void getReward(@Path("id") String id, Callback habitItemCallback); + + + @POST("/user/tasks/{id}/{direction}") + void postTaskDirection(@Path("id") String id, @Path("direction") String direction, Callback taskDirectionCallback); + + + @POST("/user/tasks") + void createItem(@Body Habit item, Callback habitItemCallback); + @POST("/user/tasks") + void createItem(@Body Daily item, Callback habitItemCallback); + @POST("/user/tasks") + void createItem(@Body ToDo item, Callback habitItemCallback); + @POST("/user/tasks") + void createItem(@Body Reward item, Callback habitItemCallback); + + + @PUT("/user/tasks/{id}") + void updateTask(@Path("id") String id, @Body Habit item, Callback habitItemCallback); + @PUT("/user/tasks/{id}") + void updateTask(@Path("id") String id, @Body Daily item, Callback habitItemCallback); + @PUT("/user/tasks/{id}") + void updateTask(@Path("id") String id, @Body ToDo item, Callback habitItemCallback); + @PUT("/user/tasks/{id}") + void updateTask(@Path("id") String id, @Body Reward item, Callback habitItemCallback); + + + @DELETE("/user/tasks/{id}") + void deleteTask(@Path("id") String id, Callback voidCallback); + + + @POST("/user/tags") + void createTag(@Body Tag tag, Callback> multiTagCallback); + + + @PUT("/user/tags/{id}") + void updateTag(@Path("id") String id, @Body Tag tag, Callback multiTagCallback); + + + @DELETE("/user/tags/{id}") + void deleteTag(@Path("id") String id, Callback voidCallback); + + @POST("/user/auth/local") + void connectLocal(@Body UserAuth auth, Callback callback); +/* + @GET("/content") + void getContent();//Check Callback + + @POST("/user/sleep") + void sleep(Callback habitRPGDataCallbackCallback);//Check callback. + + @POST("/user/inventory/buy/{key}") + void buyItem(@Path("key") String itemKey);//Check callback. Key --> /content + + @POST("/user/inventory/sell/{type}/{key}") + void sellItem(@Path("type") String type, @Path("key") String key);//Check callback + + @POST("/user/inventory/purchase/{type}/{key}") + void purchaseItem(@Path("type") String type, @Path("key") String key);//Check callback + + @POST("/user/inventory/feed/{pet}/{food}") + void feedPet(@Path("pet") String pet, @Path("food") String food);//Check Callback + + @POST("/user/inventory/equip/{type}/{key}") + void equip(@Path("type") String type, @Path("key") String key); + + @POST("/user/inventory/hatch/{egg}/{hatchingPotion}") + void hatch(@Path("egg") String egg, @Path("hatchingPotion") String potion);//Check Callback + + + +*/ +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java new file mode 100644 index 000000000..19072cb92 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/HabitItemCallback.java @@ -0,0 +1,53 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.google.gson.Gson; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * TODO: Tags + * Simple implementation of a HabitItem callback, supposed to be called when the result is either a single + * to do, daily, habit or reward. + * Created by MagicMicky on 10/06/2014. + */ +public class HabitItemCallback implements Callback { + private static final String TAG = "HabitCallback"; + + @Override + public void success(T habitItem, Response response) { + if(habitItem instanceof ToDo) { + Log.d(TAG, "todo"); + + } else if(habitItem instanceof Habit){ + Log.d(TAG, "habit"); + } else if(habitItem instanceof Daily) { + Log.d(TAG, "daily"); + ((Daily) habitItem).addItem(new Checklist.ChecklistItem("OMG")); + } else if(habitItem instanceof Reward) { + Log.d(TAG, "reward"); + } else { + Log.d(TAG, "Unknown"); + } + + Log.d(TAG +"_ans", new Gson().toJson(habitItem)); + + } + + @Override + public void failure(RetrofitError retrofitError){ + Log.w(TAG, "Failure ! "); + Log.e(TAG, retrofitError.getUrl() + ":" + retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + Log.e(TAG, "HTTP Response:" + retrofitError.getResponse().getStatus() + " - " + retrofitError.getResponse().getReason()); + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/MultiTagsCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/MultiTagsCallback.java new file mode 100644 index 000000000..958d7cb9e --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/MultiTagsCallback.java @@ -0,0 +1,38 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.magicmicky.habitrpgwrapper.lib.models.Tag; + +import java.util.List; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple callback implementation when the result is a list of tags. + * Created by MagicMicky on 12/06/2014. + */ +public class MultiTagsCallback implements Callback> { + private static final String TAG = "MultiTag"; + + @Override + public void success(List tags, Response response) { + StringBuilder s=new StringBuilder(); + s.append("Success with tags : "); + for(Tag t : tags) { + s.append(t.getName() + ", "); + } + Log.d(TAG, s.toString()); + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "Failure ! "); + Log.e(TAG, retrofitError.getUrl() + ":" + retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + Log.e(TAG, "HTTP Response:" + retrofitError.getResponse().getStatus() + " - " + retrofitError.getResponse().getReason()); + + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/Server.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/Server.java new file mode 100644 index 000000000..df7fddbbb --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/Server.java @@ -0,0 +1,28 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +/** + * Created by MagicMicky on 15/06/2014. + */ +public class Server { + public final static Server NORMAL = new Server("https://habitrpg.com"); + public final static Server BETA = new Server("https://beta.habitrpg.com"); + + private String addr; + + public Server(String addr) { + if(addr.endsWith("/api/v2") || addr.endsWith("/api/v2/")) + this.addr=addr; + else if(addr.endsWith("/")) + this.addr=addr + "api/v2"; + else + this.addr = addr + "/api/v2"; + } + public Server(Server s) { + this.addr = s.toString(); + } + + @Override + public String toString() { + return this.addr; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/StatusCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/StatusCallback.java new file mode 100644 index 000000000..061d1cd7d --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/StatusCallback.java @@ -0,0 +1,31 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.magicmicky.habitrpgwrapper.lib.models.Status; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple Status callback implementation. + * Created by MagicMicky on 10/06/2014. + */ +public class StatusCallback implements Callback { + private static final String TAG = "Status"; + + @Override + public void success(Status status, Response response) { + Log.d(TAG, "Success ! " + status.getStatus()); + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "Failure ! "); + Log.e(TAG, retrofitError.getUrl() + ":" + retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + Log.e(TAG, "HTTP Response:" + retrofitError.getResponse().getStatus() + " - " + retrofitError.getResponse().getReason()); + + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TagCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TagCallback.java new file mode 100644 index 000000000..451b9149a --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TagCallback.java @@ -0,0 +1,32 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.magicmicky.habitrpgwrapper.lib.models.Tag; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple tag callback implementation. Used when the result is only a single tag. + * Created by MagicMicky on 12/06/2014. + */ +public class TagCallback implements Callback { + private static final String TAG = "SingleTag"; + + @Override + public void success(Tag tag, Response response) { + + Log.d(TAG, tag.getName()); + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "Failure ! "); + Log.e(TAG, retrofitError.getUrl() + ":" + retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + Log.e(TAG, "HTTP Response:" + retrofitError.getResponse().getStatus() + " - " + retrofitError.getResponse().getReason()); + + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TaskDirectionCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TaskDirectionCallback.java new file mode 100644 index 000000000..31cee3475 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TaskDirectionCallback.java @@ -0,0 +1,30 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.google.gson.Gson; +import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple implementation for TaskDirection callback. When the result is the result for a taskDirection. + * Created by MagicMicky on 12/06/2014. + */ +public class TaskDirectionCallback implements Callback { + private static final String TAG = "TaskDirection"; + @Override + public void success(TaskDirectionData taskDirectionData, Response response) { + Log.d(TAG, "Task value modified:" + taskDirectionData.getDelta()); + Log.d(TAG +"_ans", new Gson().toJson(taskDirectionData)); + + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "failure!!"); + + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java new file mode 100644 index 000000000..326ca02ae --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/TypeAdapter/TagsAdapter.java @@ -0,0 +1,58 @@ +package com.magicmicky.habitrpgwrapper.lib.api.TypeAdapter; + +import android.util.Log; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Tags; + +import org.json.JSONTokener; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by magicmicky on 15/05/15. + */ +public class TagsAdapter extends TypeAdapter{ + + @Override + public void write(JsonWriter out, Tags value) throws IOException { + List list = value.getTags(); + out.beginObject(); + for(String s : list) { + out.name(s); + out.value(true); + } + out.endObject(); + Log.d("TagsAdapter", "Finished tagging"); + } + + @Override + public Tags read(JsonReader in) throws IOException { + List tags = new ArrayList<>(); + boolean isClosed=false; + do { + switch(in.peek()) { + case BEGIN_OBJECT: + in.beginObject(); + break; + case NAME: + String tag = in.nextName(); + if(in.nextBoolean()) { + tags.add(tag); + } + Log.d("TagsAdapter", "Added tag " + tag); + break; + case END_OBJECT: + in.endObject(); + isClosed=true; + default: + } + } while(!isClosed); + return new Tags(tags); + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/UserCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/UserCallback.java new file mode 100644 index 000000000..b6eb45930 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/UserCallback.java @@ -0,0 +1,41 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import com.google.gson.Gson; +import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple implementation of a user callback. + * Created by MagicMicky on 10/06/2014. + */ +public class UserCallback implements Callback { + private final String TAG = "HabitRPGDataCallback"; + private static final int BUFFER_SIZE = 0x1000; + + @Override + public void success(HabitRPGUser habitRPGUserCallback, Response response) { + Log.d(TAG, "Success ! " + habitRPGUserCallback.getId()); + longInfo(new Gson().toJson(habitRPGUserCallback)); + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "Failure ! " + retrofitError.getUrl()); + Log.e(TAG, retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + } + + public static void longInfo(String str) { + if(str.length() > 4000) { + System.out.println(str.substring(0, 4000)); + longInfo(str.substring(4000)); + } else + System.out.println(str); + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/VoidCallback.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/VoidCallback.java new file mode 100644 index 000000000..5590d254c --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/api/VoidCallback.java @@ -0,0 +1,29 @@ +package com.magicmicky.habitrpgwrapper.lib.api; + +import android.util.Log; + +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + +/** + * Simple void callback implementation. + * Created by MagicMicky on 12/06/2014. + */ +public class VoidCallback implements Callback { + private static final String TAG = "VOID"; + + @Override + public void success(Void aVoid, Response response) { + Log.d(TAG, "Success with void!"); + } + + @Override + public void failure(RetrofitError retrofitError) { + Log.w(TAG, "Failure ! "); + Log.e(TAG, retrofitError.getUrl() + ":" + retrofitError.getMessage()); + Log.e(TAG, "Network?" + retrofitError.isNetworkError()); + Log.e(TAG, "HTTP Response:" + retrofitError.getResponse().getStatus() + " - " + retrofitError.getResponse().getReason()); + + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/BasicStats.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/BasicStats.java new file mode 100644 index 000000000..7f7ce39de --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/BasicStats.java @@ -0,0 +1,55 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +import com.google.gson.annotations.SerializedName; + +/** + * Created by MagicMicky on 10/06/2014. + */ +public class BasicStats { + private float con, str, per; + @SerializedName("int") + private float _int; + + public BasicStats() { + this(0,0,0,0); + } + public BasicStats(int con, int str, int per, int _int) { + this.con = con; + this.str = str; + this.per = per; + this._int = _int; + } + + public float getCon() { + return con; + } + + public void setCon(float con) { + this.con = con; + } + + public float getStr() { + return str; + } + + public void setStr(float str) { + this.str = str; + } + + public float getPer() { + return per; + } + + public void setPer(float per) { + this.per = per; + } + + public float get_int() { + return _int; + } + + public void set_int(float _int) { + this._int = _int; + } +} + diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/DefaultResponse.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/DefaultResponse.java new file mode 100644 index 000000000..ddc623ab8 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/DefaultResponse.java @@ -0,0 +1,26 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 10/06/2014. + */ +public class DefaultResponse { + private boolean result; + // private HabitRPGData habitRPGData; + + public boolean isResult() { + return result; + } + + public void setResult(boolean result) { + this.result = result; + } +/* + public HabitRPGData getHabitRPGData() { + return habitRPGData; + } + + public void setHabitRPGData(HabitRPGData habitRPGData) { + this.habitRPGData = habitRPGData; + } +*/ +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java new file mode 100644 index 000000000..d454421a9 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRPGUser.java @@ -0,0 +1,115 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward; +import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo; + +import java.util.List; + +/** + * Created by MagicMicky on 10/06/2014. + */ +public class HabitRPGUser { + private String id; + private List dailys; + private List todos; + private List rewards; + private List habits; + private List tags; + private Stats stats; + private Preferences preferences; + private Profile profile; + private Party party; + private Items items; + + public Preferences getPreferences() { + return preferences; + } + + public void setPreferences(Preferences preferences) { + this.preferences = preferences; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getDailys() { + return dailys; + } + + public void setDailys(List dailys) { + this.dailys = dailys; + } + + public List getTodos() { + return todos; + } + + public void setTodos(List todos) { + this.todos = todos; + } + + public List getRewards() { + return rewards; + } + + public void setRewards(List rewards) { + this.rewards = rewards; + } + + public List getHabits() { + return habits; + } + + public void setHabits(List habits) { + this.habits = habits; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public Stats getStats() { + return stats; + } + + public void setStats(Stats stats) { + this.stats = stats; + } + + public Profile getProfile() { + return profile; + } + + public void setProfile(Profile profile) { + this.profile = profile; + } + + public Party getParty() { + return party; + } + + public void setParty(Party party) { + this.party = party; + } + + public Items getItems() { + return items; + } + + public void setItems(Items items) { + this.items = items; + } + + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRpgClass.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRpgClass.java new file mode 100644 index 000000000..71eee8036 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/HabitRpgClass.java @@ -0,0 +1,13 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public enum HabitRpgClass { + rogue, + wizard, + warrior, + healer, + base + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Items.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Items.java new file mode 100644 index 000000000..7febbd007 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Items.java @@ -0,0 +1,54 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +import java.util.Date; + +/** + * Created by MagicMicky on 16/03/14. + */ +public class Items { + private String currentMount, currentPet; + private int lastDrop_count; + private Date lastDrop_date; + + //private Quest quest; + + + public Items(String currentMount, String currentPet, int lastDrop_count, Date lastDrop_date) { + this.currentMount = currentMount; + this.currentPet = currentPet; + this.lastDrop_count = lastDrop_count; + this.lastDrop_date = lastDrop_date; + } + + public String getCurrentMount() { + return currentMount; + } + + public void setCurrentMount(String currentMount) { + this.currentMount = currentMount; + } + + public String getCurrentPet() { + return currentPet; + } + + public void setCurrentPet(String currentPet) { + this.currentPet = currentPet; + } + + public int getLastDrop_count() { + return lastDrop_count; + } + + public void setLastDrop_count(int lastDrop_count) { + this.lastDrop_count = lastDrop_count; + } + + public Date getLastDrop_date() { + return lastDrop_date; + } + + public void setLastDrop_date(Date lastDrop_date) { + this.lastDrop_date = lastDrop_date; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Party.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Party.java new file mode 100644 index 000000000..b39a46877 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Party.java @@ -0,0 +1,125 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public class Party { + private String currrent; //id + private String invitation; + private String lastMessageSeen; + private boolean leader; + private Quest quest; + private String order;//Order to display ppl + + public Party() { + + } + + public Party(String currrent, String invitation, String lastMessageSeen, boolean leader, Quest quest, String order) { + this.currrent = currrent; + this.invitation = invitation; + this.lastMessageSeen = lastMessageSeen; + this.leader = leader; + this.quest = quest; + this.order = order; + } + + public String getCurrrent() { + return currrent; + } + + public void setCurrrent(String currrent) { + this.currrent = currrent; + } + + public String getInvitation() { + return invitation; + } + + public void setInvitation(String invitation) { + this.invitation = invitation; + } + + public String getLastMessageSeen() { + return lastMessageSeen; + } + + public void setLastMessageSeen(String lastMessageSeen) { + this.lastMessageSeen = lastMessageSeen; + } + + public boolean isLeader() { + return leader; + } + + public void setLeader(boolean leader) { + this.leader = leader; + } + + public Quest getQuest() { + return quest; + } + + public void setQuest(Quest quest) { + this.quest = quest; + } + + public String getOrder() { + return order; + } + + public void setOrder(String order) { + this.order = order; + } + + public class Quest { + private String key; + private Progress progress; + + private Quest(String key, Progress progress) { + this.key = key; + this.progress = progress; + } + + public Progress getProgress() { + return progress; + } + + public void setProgress(Progress progress) { + this.progress = progress; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + private class Progress { + private float down, up; + + private Progress(float down, float up) { + this.down = down; + this.up = up; + } + + public float getDown() { + return down; + } + + public void setDown(float down) { + this.down = down; + } + + public float getUp() { + return up; + } + + public void setUp(float up) { + this.up = up; + } + } + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/PlayerMinStats.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/PlayerMinStats.java new file mode 100644 index 000000000..bf807aef9 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/PlayerMinStats.java @@ -0,0 +1,120 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +import com.google.gson.annotations.SerializedName; + +/** + * Created by MagicMicky on 12/06/2014. + */ +public class PlayerMinStats extends BasicStats { + private BasicStats training;//stats.training + private Buffs buffs;//stats.buffs + private int points, lvl; + @SerializedName("class") + private HabitRpgClass _class; + private Double gp, exp, mp, hp; + + + + public BasicStats getTraining() { + return training; + } + + public void setTraining(BasicStats training) { + this.training = training; + } + + public Buffs getBuffs() { + return buffs; + } + + public void setBuffs(Buffs buffs) { + this.buffs = buffs; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public int getLvl() { + return lvl; + } + + public void setLvl(int lvl) { + this.lvl = lvl; + } + + public HabitRpgClass get_class() { + return _class; + } + + public void set_class(HabitRpgClass _class) { + this._class = _class; + } + + public Double getGp() { + return gp; + } + + public void setGp(Double gp) { + this.gp = gp; + } + + public Double getExp() { + return exp; + } + + public void setExp(Double exp) { + this.exp = exp; + } + + public Double getMp() { + return mp; + } + + public void setMp(Double mp) { + this.mp = mp; + } + + public Double getHp() { + return hp; + } + + public void setHp(Double hp) { + this.hp = hp; + } + + + + protected class Buffs extends BasicStats { + private boolean snowball; + private boolean streaks; + private Buffs() { + this(false,false); + } + private Buffs(boolean snowball, boolean streaks) { + this.snowball = snowball; + this.streaks = streaks; + } + + public boolean getSnowball() { + return snowball; + } + + public void setSnowball(boolean snowball) { + this.snowball = snowball; + } + + public boolean getStreaks() { + return streaks; + } + + public void setStreaks(boolean streaks) { + this.streaks = streaks; + } + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Preferences.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Preferences.java new file mode 100644 index 000000000..eae6fe032 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Preferences.java @@ -0,0 +1,214 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public class Preferences { + private boolean costume, toolbarCollapsed, advancedCollapsed, tagsCollapsed, newTaskEdit, disableClasses, stickyHeader, sleep, hideHeader; + private String allocationMode, shirt, skin, size; + private int dayStart, timezoneOffset; + private Hair hair; + public Preferences() { + } + + public Preferences(boolean costume, boolean toolbarCollapsed, boolean advancedCollapsed, boolean tagsCollapsed, boolean newTaskEdit, boolean disableClasses, boolean stickyHeader, boolean sleep, boolean hideHeader, String allocationMode, String shirt, String skin, String size, int dayStart, int timezoneOffset, Hair hair) { + this.costume = costume; + this.toolbarCollapsed = toolbarCollapsed; + this.advancedCollapsed = advancedCollapsed; + this.tagsCollapsed = tagsCollapsed; + this.newTaskEdit = newTaskEdit; + this.disableClasses = disableClasses; + this.stickyHeader = stickyHeader; + this.sleep = sleep; + this.hideHeader = hideHeader; + this.allocationMode = allocationMode; + this.shirt = shirt; + this.skin = skin; + this.size = size; + this.dayStart = dayStart; + this.timezoneOffset = timezoneOffset; + } + + public int getDayStart() { + return dayStart; + } + + public void setDayStart(int dayStart) { + this.dayStart = dayStart; + } + + public boolean isCostume() { + return costume; + } + + public void setCostume(boolean costume) { + this.costume = costume; + } + + public boolean isToolbarCollapsed() { + return toolbarCollapsed; + } + + public void setToolbarCollapsed(boolean toolbarCollapsed) { + this.toolbarCollapsed = toolbarCollapsed; + } + + public boolean isAdvancedCollapsed() { + return advancedCollapsed; + } + + public void setAdvancedCollapsed(boolean advancedCollapsed) { + this.advancedCollapsed = advancedCollapsed; + } + + public boolean isTagsCollapsed() { + return tagsCollapsed; + } + + public void setTagsCollapsed(boolean tagsCollapsed) { + this.tagsCollapsed = tagsCollapsed; + } + + public boolean isNewTaskEdit() { + return newTaskEdit; + } + + public void setNewTaskEdit(boolean newTaskEdit) { + this.newTaskEdit = newTaskEdit; + } + + public boolean isDisableClasses() { + return disableClasses; + } + + public void setDisableClasses(boolean disableClasses) { + this.disableClasses = disableClasses; + } + + public boolean isStickyHeader() { + return stickyHeader; + } + + public void setStickyHeader(boolean stickyHeader) { + this.stickyHeader = stickyHeader; + } + + public boolean isSleep() { + return sleep; + } + + public void setSleep(boolean sleep) { + this.sleep = sleep; + } + + public boolean isHideHeader() { + return hideHeader; + } + + public void setHideHeader(boolean hideHeader) { + this.hideHeader = hideHeader; + } + + public String getAllocationMode() { + return allocationMode; + } + + public void setAllocationMode(String allocationMode) { + this.allocationMode = allocationMode; + } + + public String getShirt() { + return shirt; + } + + public void setShirt(String shirt) { + this.shirt = shirt; + } + + public String getSkin() { + return skin; + } + + public void setSkin(String skin) { + this.skin = skin; + } + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + + public int getTimezoneOffset() { + return timezoneOffset; + } + + public void setTimezoneOffset(int timezoneOffset) { + this.timezoneOffset = timezoneOffset; + } + + public Hair getHair() { + return hair; + } + + public void setHair(Hair hair) { + this.hair = hair; + } + + public class Hair{ + private int mustache,beard, bangs,base; + private String color; + private Hair() { + } + private Hair(int mustache, int beard, int bangs, int base, String color) { + this.mustache = mustache; + this.beard = beard; + this.bangs = bangs; + this.base = base; + this.color = color; + } + + public int getMustache() { + return mustache; + } + + public void setMustache(int mustache) { + this.mustache = mustache; + } + + public int getBeard() { + return beard; + } + + public void setBeard(int beard) { + this.beard = beard; + } + + public int getBangs() { + return bangs; + } + + public void setBangs(int bangs) { + this.bangs = bangs; + } + + public int getBase() { + return base; + } + + public void setBase(int base) { + this.base = base; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Profile.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Profile.java new file mode 100644 index 000000000..326173757 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Profile.java @@ -0,0 +1,42 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public class Profile { + private String name; + private String blurb, imageUrl; + + public Profile(String name) { + this(name, "",""); + } + public Profile(String name, String blurb, String imageUrl) { + this.name = name; + this.blurb = blurb; + this.imageUrl = imageUrl; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBlurb() { + return blurb; + } + + public void setBlurb(String blurb) { + this.blurb = blurb; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Stats.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Stats.java new file mode 100644 index 000000000..eb196f24d --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Stats.java @@ -0,0 +1,36 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public class Stats extends PlayerMinStats{ + private int toNextLevel;//xp needed to be earned + private int maxHealth, maxMP; + + + public int getToNextLevel() { + return toNextLevel; + } + + public void setToNextLevel(int toNextLevel) { + this.toNextLevel = toNextLevel; + } + + public int getMaxHealth() { + return maxHealth; + } + + public void setMaxHealth(int maxHealth) { + this.maxHealth = maxHealth; + } + + public int getMaxMP() { + return maxMP; + } + + public void setMaxMP(int maxMP) { + this.maxMP = maxMP; + } + + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Status.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Status.java new file mode 100644 index 000000000..5687a40e8 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Status.java @@ -0,0 +1,16 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 10/06/2014. + */ +public class Status { + private String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java new file mode 100644 index 000000000..a2dbfee51 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/Tag.java @@ -0,0 +1,37 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Description of a Tag in HabitRPG + * Created by MagicMicky on 16/03/14. + */ +public class Tag { + String id; + String name; + + public Tag() { + this(null,null); + } + + public Tag(String id, String name) { + this.setId(id); + this.setName(name); + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirection.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirection.java new file mode 100644 index 000000000..92f6caf93 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirection.java @@ -0,0 +1,17 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by MagicMicky on 16/03/14. + */ +public enum TaskDirection { + up("up"), + down("down"); + private final String dir; + private TaskDirection(String dir) { + this.dir=dir; + } + public String toString() { + return this.dir; + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirectionData.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirectionData.java new file mode 100644 index 000000000..85b500675 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/TaskDirectionData.java @@ -0,0 +1,20 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * This class represent the data sent back from the API when calling /user/tasks/{id}/{direction}. + * It holds almost the same thing as Stats, except toNextLevel & maxHealth & maxHP. + * It also holds a delta, which represent the task value modification. + * Created by MagicMicky on 12/06/2014. + */ +public class TaskDirectionData extends PlayerMinStats{ + private float delta; + + public float getDelta() { + return delta; + } + + public void setDelta(float delta) { + this.delta = delta; + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuth.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuth.java new file mode 100644 index 000000000..4c48405e1 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuth.java @@ -0,0 +1,25 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by magicmicky on 04/02/15. + */ +public class UserAuth { + private String username; + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuthResponse.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuthResponse.java new file mode 100644 index 000000000..138af3f73 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/UserAuthResponse.java @@ -0,0 +1,25 @@ +package com.magicmicky.habitrpgwrapper.lib.models; + +/** + * Created by magicmicky on 04/02/15. + */ +public class UserAuthResponse { + private String token; + private String id; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java new file mode 100644 index 000000000..79bad8536 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Checklist.java @@ -0,0 +1,105 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +import java.util.ArrayList; +import java.util.List; + +/** + * Description of Checklist on HabitRPG + * Created by MagicMicky + */ +public abstract class Checklist extends HabitItem{ + final private List checklist; + + public Checklist() { + this(null,null,null,null,null); + } + + public Checklist(String id, String notes, Float priority, String text, Double value) { + super(id, notes, priority, text, value); + this.checklist = new ArrayList(); + } + public Checklist(String id, String notes, Float priority, String text, + double value, Checklist checklistToCopy) { + this(id, notes, priority, text, value); + for(ChecklistItem item : checklistToCopy.getItems()) { + checklist.add(new ChecklistItem(item)); + } + } + + + public void addItem(ChecklistItem item) { + this.checklist.add(item); + } + + + public void toggleItem(String id) { + boolean flag = false; + for(int i=0;i getItems() { + return checklist; + } + + public int getSize() { + return checklist.size(); + } + public int getNbCompleted() { + int nbCompleted =0; + for(ChecklistItem it : checklist) { + if(it.isCompleted()) nbCompleted++; + } + return nbCompleted; + } + + +public static class ChecklistItem { + private String id; + private String text; + private boolean completed; + public ChecklistItem() { + this(null,null); + } + public ChecklistItem(String id, String text) { + this(id,text,false); + } + public ChecklistItem(String id,String text, boolean completed) { + this.setText(text); + this.setId(id); + this.setCompleted(completed); + } + public ChecklistItem(String s) { + this(null,s); + } + public ChecklistItem(ChecklistItem item) { + this.text = item.getText(); + this.id= item.getId(); + this.completed=item.isCompleted(); + } + public String getText() { + return text; + } + public void setText(String text) { + this.text = text; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public boolean isCompleted() { + return completed; + } + public void setCompleted(boolean completed) { + this.completed = completed; + } +} + + +} \ No newline at end of file diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java new file mode 100644 index 000000000..548e34fd0 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Daily.java @@ -0,0 +1,168 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + + +/** + * A daily item. It contains the item called "Daily" on the website + * @author MagicMicky + */ +public class Daily extends Checklist{ + private final HabitType type=HabitType.daily; + private Boolean completed; + private Days repeat; + //TODO: private String lastCompleted; + private Integer streak; + /** + * Construct a daily based on all the information needed + * @param id the id of the daily + * @param notes the notes associated to a daily + * @param priority the priority of the daily + * @param text the text of the daily + * @param value the value (points) of the daily + * @param completed whether or not the daily is completed + * @param repeat when does it repeat? + * @param streak the streak + * @param lastCompleted when was the last time it was completed? + */ + public Daily(String id, String notes, Float priority, String text, + Double value, Boolean completed, Days repeat, Integer streak, String lastCompleted) { + //this(id, notes, priority, text, value,completed,repeat,lastCompleted); + super(id,notes,priority,text,value); + this.setCompleted(completed); + this.setRepeat(repeat); + this.setStreak(streak); + //this.setLastCompleted(lastCompleted); + } + public Daily(String id, String notes, Float priority, String text, + Double value, Boolean completed, Days repeat) { + this(id, notes, priority, text, value,completed,repeat,null,null); + } + + public Daily() { + this(null,null,null,null,null,null,null); + } + /** + * @return if the daily is completed + */ + public boolean isCompleted() { + return completed; + } + /** + * Set whether or not the daily is completed + * @param completed + */ + public void setCompleted(Boolean completed) { + this.completed = completed; + } + /** + * @return the repeat array.
+ * This array contains 7 values, one for each days, starting from monday. + */ + public Days getRepeat() { + return repeat; + } + /** + * @param repeat the repeat array to set + */ + public void setRepeat(Days repeat) { + this.repeat = repeat; + } + @Override + protected HabitType getType() { + return type; + } + /** + * 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 + */ + public int getStreak() { + return streak; + } + /** + * @param streak the streak to set + */ + public void setStreak(Integer streak) { + this.streak = streak; + } + + public static class Days { + private boolean m, t,w, th,f,s,su; + public Days() { + this.m=false; + this.t=false; + this.w=false; + this.th=false; + this.f=false; + this.s=true; + this.su=true; + } + + public boolean isT() { + return t; + } + + public void setT(boolean t) { + this.t = t; + } + + public boolean isW() { + return w; + } + + public void setW(boolean w) { + this.w = w; + } + + public boolean isTh() { + return th; + } + + public void setTh(boolean th) { + this.th = th; + } + + public boolean isF() { + return f; + } + + public void setF(boolean f) { + this.f = f; + } + + public boolean isS() { + return s; + } + + public void setS(boolean s) { + this.s = s; + } + + public boolean isSu() { + return su; + } + + public void setSu(boolean su) { + this.su = su; + } + + public boolean isM() { + return m; + } + + public void setM(boolean m) { + this.m = m; + } + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java new file mode 100644 index 000000000..80e4fdc18 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Habit.java @@ -0,0 +1,65 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + + +/** + * An habit item. It contains the item called "Habits" on the website + * @author MagicMicky + * + */ +public class Habit extends HabitItem{ + private final HabitType type = HabitType.habit; + private Boolean up; + private Boolean down; + /** + * Create a new Habit based on all the information needed + * @param id the id of the habit + * @param notes the notes associated to a habit + * @param priority the priority of the habit + * @param text the text of the habit + * @param value the value (points) of the habit + * @param up whether or not the habit can be "upped" + * @param down whether or not the habit can be "downed" + */ + public Habit(String id, String notes, Float priority, String text, double value + , Boolean up, Boolean down) { + super(id, notes, priority, text, value); + this.setUp(up); + this.setDown(down); + } + public Habit() { + super(); + this.setDown(null); + this.setUp(null); + } + /** + * @return whether or not the habit can be "upped" + */ + public boolean isUp() { + return up; + } + /** + * Set the Up value + * @param up + */ + public void setUp(Boolean up) { + this.up = up; + } + /** + * @return whether or not the habit can be "down" + */ + public boolean isDown() { + return down; + } + /** + * Set the Down value + * @param down + */ + public void setDown(Boolean down) { + this.down = down; + } + @Override + protected HabitType getType() { + return type; + } + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java new file mode 100644 index 000000000..127ec29d9 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitItem.java @@ -0,0 +1,179 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +import org.json.JSONObject; + +import java.util.List; + +/** + * Custom Item that regroup all the others. + * @author MagicMicky + * + */ +public abstract class HabitItem { + private String _id; + private String id; + private String notes; + private Float priority; + private String text; + private Double value; + private String attribute; + private Tags tags; + /** + * Create a new HabitItem from what is necessary + * @param id the id of the habit + * @param notes the notes associated to a habit + * @param priority the priority of the habit + * @param text the text of the habit + * @param value the value (points) of the habit + */ + public HabitItem(String id, String notes, Float priority, String text, Double value) { + this.setId(id); + this.setNotes(notes); + this.setPriority(priority); + this.setText(text); + this.setValue(value); + this.tags=new Tags(); + this.id = id; + + } + public HabitItem() { + this(null,null,null,null,null); + } + /** + * @return the id + */ + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + /** + * @return the notes + */ + public String getNotes() { + return notes; + } + /** + * @param notes the notes to set + */ + public void setNotes(String notes) { + this.notes = notes; + } + /** + * @return the priority + */ + public Float getPriority() { + return priority; + } + /** + * @param i the priority to set + */ + public void setPriority(Float i) { + this.priority = i; + } + /** + * @return the text + */ + public String getText() { + return text; + } + /** + * @param text the text to set + */ + public void setText(String text) { + this.text = text; + } + /** + * @return the value + */ + public double getValue() { + return value; + } + /** + * @param value the value to set + */ + public void setValue(Double value) { + this.value = value; + } + + /** + * To be allowed to set int value without problems + * @param value the value to set + */ + public void setValue(double value) { + this.setValue(Double.valueOf(value)); + } + + /** + * @return the tags + */ + public List getTags() { + return tags.getTags(); + } + /** + * @param tags the tagsId to set + */ + public void setTags(List tags) { + this.tags.setTags(tags); + } + + public boolean isTagged(List tags) { + if(this.getTags()==null) { + System.out.println("getTags is null!!!"); + } + return (this.getTags() != null && this.getTags().size() != 0); + + } + /** + * Returns a string of the type of the HabitItem + * @return the string of the Item type + */ + protected abstract HabitType getType(); + + /** + * Creates a JSON String for this HabitItem using the basic information.
+ * Doesn't have the necessary open and close brackets to create an item. + * @return + */ + protected String getJSONBaseString() { + StringBuilder json = new StringBuilder(); + if(this.getId()!=null) + json.append("\"id\":").append(JSONObject.quote(this.getId())).append(","); + json + .append("\"type\":\"").append(this.getType()).append("\"," ) + .append("\"text\":").append(JSONObject.quote(this.getText())).append("," ); + if(this.getPriority()!=null) + json.append("\"priority\":").append(this.getPriority()).append(","); + if(this.getNotes()!=null && !this.getNotes().contentEquals("")) + json.append("\"notes\":").append(JSONObject.quote(this.getNotes())).append("," ); + json.append("\"value\":").append(this.getValue()).append(","); + if(this.getTags()!=null) { //TODO: && this.getTags().size()!=0 + json.append("\"tags\":{"); + /*for(String tagId : this.getTags()) { + json.append("").append(JSONObject.quote(tagId)).append(":").append("true").append(","); + }*/ + json.deleteCharAt(json.length()-1); + json.append("},"); + } + if(this.getAttribute()!=null) { + json.append("\"attribute\":\"").append(this.getAttribute()).append("\","); + } + return json.toString(); + } + /** + * @return the attribute + */ + public String getAttribute() { + return attribute; + } + /** + * @param attribute the attribute to set + */ + public void setAttribute(String attribute) { + this.attribute = attribute; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java new file mode 100644 index 000000000..0a4e43aa3 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/HabitType.java @@ -0,0 +1,9 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +public enum HabitType { + habit, + reward, + todo, + daily + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java new file mode 100644 index 000000000..c44700098 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Reward.java @@ -0,0 +1,140 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + + +/** + * A reward. Contain a reward that you can see on the website + * @author MagicMicky + * + */ +public class Reward extends HabitItem{ + private final HabitType type = HabitType.reward; + /** + * Create a new Reward + * @param id the id of the habit + * @param notes the notes associated to a habit + * @param priority the priority of the habit + * @param text the text of the habit + * @param value the value (points) of the habit + */ + public Reward(String id, String notes, Float priority, String text, + double value) { + super(id, notes, priority, text, value); + } + + public Reward() { + super(); + } + + @Override + protected HabitType getType() { + return type; + } + + public static class SpecialReward extends Reward { + private static SpecialReward[] weapons= { + new SpecialReward(0, "Training Sword","weapon_0","Training weapon.",0,0), + new SpecialReward(1, "Sword","weapon_1","Increases experience gain by 3%.",3,20), + new SpecialReward(2, "Axe", "weapon_2","Increases experience gain by 6%.",6,30), + new SpecialReward(3, "Morningstar", "weapon_3","Increases experience gain by 9%.",9,45), + new SpecialReward(4, "Blue Sword", "weapon_4","Increases experience gain by 12%.",12,65), + new SpecialReward(5, "Red Sword", "weapon_5","Increases experience gain by 15%.",15,90), + new SpecialReward(6, "Golden Sword", "weapon_6","Increases experience gain by 18%.",18,120), + new SpecialReward(7, "Dark Souls Blade", "weapon_7","Increases experience gain by 21%.",21,150) + }; + private static SpecialReward[] armors={ + new SpecialReward(0, "Cloth Armor","armor_0","Training armor.",0,0), + new SpecialReward(1, "Leather Armor","armor_1","Decreases HP loss by 4%.",4,30), + new SpecialReward(2, "Chain Mail","armor_2","Decreases HP loss by 6%.",6,45), + new SpecialReward(3, "Plate Mail","armor_3","Decreases HP loss by 7%.",7,65), + new SpecialReward(4, "Red Armor","armor_4","Decreases HP loss by 8%.",8,90), + new SpecialReward(5, "Golden Armor","armor_5","Decreases HP loss by 10%.",10,120), + new SpecialReward(6, "Shade Armor","armor_6","Decreases HP loss by 12%.",12,150) + };// + private static SpecialReward[] heads = { + new SpecialReward(0, "No Helm","head_0","Training helm.",0,0), + new SpecialReward(1, "Leather Helm","head_1","Decreases HP loss by 2%.",2,15), + new SpecialReward(2, "Chain Coif","head_2","Decreases HP loss by 3%.",3,25), + new SpecialReward(3, "Plate Helm","head_3","Decreases HP loss by 4%.",4,45), + new SpecialReward(4, "Red Helm","head_4","Decreases HP loss by 5%.",5,60), + new SpecialReward(5, "Golden Helm","head_5","Decreases HP loss by 6%.",6,80), + new SpecialReward(6, "Shade Helm","head_6","Decreases HP loss by 7%.",7,100) + };// + + private static SpecialReward[] shields= { + new SpecialReward(0, "No Shield","shield_0","No Shield.",0,0), + new SpecialReward(1, "Wooden Shield","shield_1","Decreases HP loss by 3%",3,20), + new SpecialReward(2, "Buckler","shield_2","Decreases HP loss by 4%.",4,35), + new SpecialReward(3, "Reinforced Shield","shield_3","Decreases HP loss by 5%.",5,55), + new SpecialReward(4, "Red Shield","shield_4","Decreases HP loss by 7%.",7,70), + new SpecialReward(5, "Golden Shield","shield_5","Decreases HP loss by 8%.",8,90), + new SpecialReward(6, "Tormented Skull","shield_6","Decreases HP loss by 9%.",9,120) + };// + + private String classes; + private int plusValue; + private SpecialReward currentReward; + private String type; + private int level; + private SpecialReward(int id, String text, String classes, String notes, int plusValue, double value) { + this.setId(id+""); + this.setText(text); + this.setNotes(notes); + this.setValue(value); + this.setClasses(classes); + this.setPlusValue(plusValue); + } + private SpecialReward(SpecialReward rew) { + this(Integer.parseInt(rew.getId()),rew.getText(),rew.getClasses(),rew.getNotes(),rew.getPlusValue(),rew.getValue()); + } + public SpecialReward(int level, String type) throws ArrayIndexOutOfBoundsException { + this(getRewardFromLevelAndType(level,type)); + + this.type=type; + this.level = level; + } + private static SpecialReward getRewardFromLevelAndType(int level, + String type) { + if(type.equals("armor")) { + if(level > 7) + level=7; + return armors[level]; + } + else if(type.equals("weapon")) { + if(level > 6) + level=6; + return weapons[level]; + } + else if(type.equals("head")) { + if(level > 6) + level=6; + return heads[level]; + } + else { + if(level > 6) + level=6; + return shields[level]; + } + } + public int getPlusValue() { + return this.plusValue; + } + public void setPlusValue(int plusValue) { + this.plusValue=plusValue; + } + public String getClasses() { + return this.classes; + } + public void setClasses(String classes) { + this.classes=classes; + } + public String getPlusValueType() { + if(type == "weapon") { + return "strength"; + } + return "defense"; + } + public int getLevel() { + return level; + } + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java new file mode 100644 index 000000000..374454f6f --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Tags.java @@ -0,0 +1,26 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by magicmicky on 15/05/15. + */ +public class Tags { + private List tags; + + public Tags() { + this.tags = new ArrayList<>(); + } + public Tags(List tags) { + this.tags = tags; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java new file mode 100644 index 000000000..3badf2ce1 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/ToDo.java @@ -0,0 +1,73 @@ +package com.magicmicky.habitrpgwrapper.lib.models.tasks; + + +/** + * A ToDo task that you can see of the website + * You can set a complete date to a ToDo, and you can complete them using a boolean + * @author MagicMicky + * + */ +public class ToDo extends Checklist{ + private final HabitType type=HabitType.todo; + private Boolean completed; + private String date; + /** + * Construct a daily based on all the information needed + * @param id the id of the daily + * @param notes the notes associated to a daily + * @param priority the priority of the daily + * @param text the text of the daily + * @param value the value (points) of the daily + * @param completed whether or not the daily is completed + * @param date the due date + */ + public ToDo(String id, String notes, Float priority, String text, + double value, boolean completed, String date) { + super(id, notes, priority, text, value); + this.setCompleted(completed); + this.setDate(date); + } + + public ToDo() { + super(); + this.setCompleted(null); + this.setDate(null); + } + + /** + * @return if the todo is completed + */ + public boolean isCompleted() { + return completed; + } + + /** + * Set whether or not the todo is completed + * @param completed + */ + public void setCompleted(Boolean completed) { + this.completed = completed; + } + + /** + * @return the due date + */ + public String getDate() { + return date; + } + + /** + * Set the due date + * @param date the date to set + */ + public void setDate(String date) { + this.date = date; + } + + @Override + protected HabitType getType() { + return type; + } + + +} diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java new file mode 100644 index 000000000..c4d7252a7 --- /dev/null +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/utils/DaysUtils.java @@ -0,0 +1,34 @@ +package com.magicmicky.habitrpgwrapper.lib.utils; + +import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily; +/** + * Created by magicmicky on 04/02/15. + */ + + + +public class DaysUtils { + public static Daily.Days getDaysFromBooleans(boolean[] b) { + Daily.Days d = new Daily.Days(); + d.setM(b[0]); + d.setT(b[1]); + d.setW(b[2]); + d.setTh(b[3]); + d.setF(b[4]); + d.setS(b[5]); + d.setSu(b[6]); + return d; + } + public static boolean[] getBooleansFromDays(Daily.Days days) { + boolean[] b = new boolean[7]; + b[0] = days.isM(); + b[1] = days.isT(); + b[2] = days.isW(); + b[3] = days.isTh(); + b[4] = days.isF(); + b[5] = days.isS(); + b[6] = days.isSu(); + return b; + } +} +