Integracte HabitRPGWrapper library directly

This commit is contained in:
Phillip Thelen 2015-06-23 12:02:32 +02:00
parent 3fad261e3a
commit 3619a5e7b2
37 changed files with 2454 additions and 7 deletions

View file

@ -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 {

View file

@ -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<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 com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily
*/
public void getDaily(String dailyId, Callback<Daily> 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<Habit> 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<ToDo> 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<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 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<Daily> 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<Habit> 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<ToDo> 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<Reward> 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<Habit> 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<Daily> 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<ToDo> 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<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);
}
}

View file

@ -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<Status> statusCallback);
@GET("/user/")
void getUser(Callback<HabitRPGUser> habitRPGUserCallback);
// @POST("/user/revive")
// void revive(Callback<HabitRPGUser> habitRPGUserCallback);
@GET("/user/tasks/{id}")
void getHabit(@Path("id") String id, Callback<Habit> habitItemCallback);
@GET("/user/tasks/{id}")
void getDaily(@Path("id") String id, Callback<Daily> habitItemCallback);
@GET("/user/tasks/{id}")
void getToDo(@Path("id") String id, Callback<ToDo> habitItemCallback);
@GET("/user/tasks/{id}")
void getReward(@Path("id") String id, Callback<Reward> habitItemCallback);
@POST("/user/tasks/{id}/{direction}")
void postTaskDirection(@Path("id") String id, @Path("direction") String direction, Callback<TaskDirectionData> taskDirectionCallback);
@POST("/user/tasks")
void createItem(@Body Habit item, Callback<Habit> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body Daily item, Callback<Daily> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body ToDo item, Callback<ToDo> habitItemCallback);
@POST("/user/tasks")
void createItem(@Body Reward item, Callback<Reward> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Habit item, Callback<Habit> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Daily item, Callback<Daily> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body ToDo item, Callback<ToDo> habitItemCallback);
@PUT("/user/tasks/{id}")
void updateTask(@Path("id") String id, @Body Reward item, Callback<Reward> habitItemCallback);
@DELETE("/user/tasks/{id}")
void deleteTask(@Path("id") String id, Callback<Void> voidCallback);
@POST("/user/tags")
void createTag(@Body Tag tag, Callback<List<Tag>> multiTagCallback);
@PUT("/user/tags/{id}")
void updateTag(@Path("id") String id, @Body Tag tag, Callback<Tag> multiTagCallback);
@DELETE("/user/tags/{id}")
void deleteTag(@Path("id") String id, Callback<Void> voidCallback);
@POST("/user/auth/local")
void connectLocal(@Body UserAuth auth, Callback<UserAuthResponse> callback);
/*
@GET("/content")
void getContent();//Check Callback
@POST("/user/sleep")
void sleep(Callback<HabitRPGDataCallback> 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
*/
}

View file

@ -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<T extends HabitItem> implements Callback<T> {
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());
}
}

View file

@ -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<List<Tag>> {
private static final String TAG = "MultiTag";
@Override
public void success(List<Tag> 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());
}
}

View file

@ -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;
}
}

View file

@ -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<Status> {
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());
}
}

View file

@ -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<Tag> {
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());
}
}

View file

@ -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<TaskDirectionData> {
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!!");
}
}

View file

@ -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<Tags>{
@Override
public void write(JsonWriter out, Tags value) throws IOException {
List<String> 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<String> 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);
}
}

View file

@ -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<HabitRPGUser> {
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);
}
}

View file

@ -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<Void> {
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());
}
}

View file

@ -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;
}
}

View file

@ -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;
}
*/
}

View file

@ -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<Daily> dailys;
private List<ToDo> todos;
private List<Reward> rewards;
private List<Habit> habits;
private List<Tag> 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<Daily> getDailys() {
return dailys;
}
public void setDailys(List<Daily> dailys) {
this.dailys = dailys;
}
public List<ToDo> getTodos() {
return todos;
}
public void setTodos(List<ToDo> todos) {
this.todos = todos;
}
public List<Reward> getRewards() {
return rewards;
}
public void setRewards(List<Reward> rewards) {
this.rewards = rewards;
}
public List<Habit> getHabits() {
return habits;
}
public void setHabits(List<Habit> habits) {
this.habits = habits;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> 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;
}
}

View file

@ -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
}

View file

@ -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;
}
}

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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<ChecklistItem> 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<ChecklistItem>();
}
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<this.checklist.size() && !flag; i++) {
ChecklistItem it = this.checklist.get(i);
if(it.getId().equals(id)) {
it.setCompleted(!it.isCompleted());
flag=true;
}
}
}
public List<ChecklistItem> 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;
}
}
}

View file

@ -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.<br/>
* 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;
}
}
}

View file

@ -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;
}
}

View file

@ -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<String> getTags() {
return tags.getTags();
}
/**
* @param tags the tagsId to set
*/
public void setTags(List<String> tags) {
this.tags.setTags(tags);
}
public boolean isTagged(List<String> 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.<br>
* 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;
}
}

View file

@ -0,0 +1,9 @@
package com.magicmicky.habitrpgwrapper.lib.models.tasks;
public enum HabitType {
habit,
reward,
todo,
daily
}

View file

@ -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;
}
}
}

View file

@ -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<String> tags;
public Tags() {
this.tags = new ArrayList<>();
}
public Tags(List<String> tags) {
this.tags = tags;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}