mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 12:18:59 +00:00
Updated interceptor to use HabitResponse
This commit is contained in:
parent
34a439c6b9
commit
f147bc0e6d
12 changed files with 312 additions and 134 deletions
|
|
@ -17,6 +17,9 @@ import com.magicmicky.habitrpgwrapper.lib.models.Customization;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.FAQArticle;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationRequest;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Purchases;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Skill;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TutorialStep;
|
||||
|
|
@ -66,7 +69,9 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
|
@ -98,6 +103,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
|||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
|
||||
|
|
@ -108,7 +114,13 @@ public class APIHelper implements Action1<Throwable> {
|
|||
// I think we don't need the APIHelper anymore we could just use ApiService
|
||||
public final ApiService apiService;
|
||||
final Observable.Transformer apiCallTransformer =
|
||||
observable -> ((Observable) observable).subscribeOn(Schedulers.io())
|
||||
observable -> ((Observable) observable)
|
||||
.map(new Func1<HabitResponse, Object>() {
|
||||
@Override public Object call(HabitResponse habitResponse) {
|
||||
return habitResponse.getData();
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnError(this);
|
||||
private final GsonConverterFactory gsonConverter;
|
||||
|
|
@ -128,31 +140,6 @@ public class APIHelper implements Action1<Throwable> {
|
|||
crashlyticsProxy.setUserName(this.hostConfig.getUser());
|
||||
Amplitude.getInstance().setUserId(this.hostConfig.getUser());
|
||||
|
||||
Interceptor remove_data_interceptor = chain -> {
|
||||
Response response = chain.proceed(chain.request());
|
||||
String stringJson = response.body().string();
|
||||
JSONObject jsonObject = null;
|
||||
String dataString = null;
|
||||
try {
|
||||
jsonObject = new JSONObject(stringJson);
|
||||
if (jsonObject.has("data")) {
|
||||
dataString = jsonObject.getString("data");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MediaType contentType = response.body().contentType();
|
||||
ResponseBody body = null;
|
||||
|
||||
if (dataString != null) {
|
||||
body = ResponseBody.create(contentType, dataString);
|
||||
} else {
|
||||
body = ResponseBody.create(contentType, stringJson);
|
||||
}
|
||||
crashlyticsProxy.setString("last_api_call",response.request().url().toString());
|
||||
return response.newBuilder().body(body).build();
|
||||
};
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
if (BuildConfig.DEBUG) {
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
|
@ -161,7 +148,6 @@ public class APIHelper implements Action1<Throwable> {
|
|||
String userAgent = System.getProperty("http.agent");
|
||||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(remove_data_interceptor)
|
||||
.addInterceptor(logging)
|
||||
.addNetworkInterceptor(chain -> {
|
||||
Request original = chain.request();
|
||||
|
|
@ -183,12 +169,14 @@ public class APIHelper implements Action1<Throwable> {
|
|||
.build();
|
||||
|
||||
Server server = new Server(this.hostConfig.getAddress());
|
||||
|
||||
retrofitAdapter = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl(server.toString())
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addConverterFactory(gsonConverter)
|
||||
.build();
|
||||
|
||||
this.apiService = retrofitAdapter.create(ApiService.class);
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +249,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
return GsonConverterFactory.create(gson);
|
||||
}
|
||||
|
||||
public Observable<UserAuthResponse> registerUser(String username, String email, String password, String confirmPassword) {
|
||||
public Observable<HabitResponse<UserAuthResponse>> registerUser(String username, String email, String password, String confirmPassword) {
|
||||
UserAuth auth = new UserAuth();
|
||||
auth.setUsername(username);
|
||||
auth.setPassword(password);
|
||||
|
|
@ -270,14 +258,14 @@ public class APIHelper implements Action1<Throwable> {
|
|||
return this.apiService.registerUser(auth);
|
||||
}
|
||||
|
||||
public Observable<UserAuthResponse> connectUser(String username, String password) {
|
||||
public Observable<HabitResponse<UserAuthResponse>> connectUser(String username, String password) {
|
||||
UserAuth auth = new UserAuth();
|
||||
auth.setUsername(username);
|
||||
auth.setPassword(password);
|
||||
return this.apiService.connectLocal(auth);
|
||||
}
|
||||
|
||||
public Observable<UserAuthResponse> connectSocial(String network, String userId, String accessToken) {
|
||||
public Observable<HabitResponse<UserAuthResponse>> connectSocial(String network, String userId, String accessToken) {
|
||||
UserAuthSocial auth = new UserAuthSocial();
|
||||
auth.setNetwork(network);
|
||||
UserAuthSocialTokens authResponse = new UserAuthSocialTokens();
|
||||
|
|
@ -333,32 +321,32 @@ public class APIHelper implements Action1<Throwable> {
|
|||
}
|
||||
}
|
||||
|
||||
public Observable<HabitRPGUser> retrieveUser(boolean withTasks) {
|
||||
Observable<HabitRPGUser> userObservable = apiService.getUser();
|
||||
public Observable<HabitResponse<HabitRPGUser>> retrieveUser(boolean withTasks) {
|
||||
Observable<HabitResponse<HabitRPGUser>> userObservable = apiService.getUser();
|
||||
if (withTasks) {
|
||||
Observable<TaskList> tasksObservable = apiService.getTasks();
|
||||
Observable<HabitResponse<TaskList>> tasksObservable = apiService.getTasks();
|
||||
|
||||
userObservable = Observable.zip(userObservable, tasksObservable, (habitRPGUser, tasks) -> {
|
||||
habitRPGUser.setHabits(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getHabits()));
|
||||
habitRPGUser.setDailys(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getDailys()));
|
||||
habitRPGUser.setTodos(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getTodos()));
|
||||
habitRPGUser.setRewards(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getRewards()));
|
||||
for (Task task : tasks.tasks.values()) {
|
||||
switch (task.getType()) {
|
||||
case "habit":
|
||||
habitRPGUser.getHabits().add(task);
|
||||
break;
|
||||
case "daily":
|
||||
habitRPGUser.getDailys().add(task);
|
||||
break;
|
||||
case "todo":
|
||||
habitRPGUser.getTodos().add(task);
|
||||
break;
|
||||
case "reward":
|
||||
habitRPGUser.getRewards().add(task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// habitRPGUser.setHabits(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getHabits()));
|
||||
// habitRPGUser.setDailys(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getDailys()));
|
||||
// habitRPGUser.setTodos(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getTodos()));
|
||||
// habitRPGUser.setRewards(sortTasks(tasks.tasks, habitRPGUser.getTasksOrder().getRewards()));
|
||||
// for (Task task : tasks.tasks.values()) {
|
||||
// switch (task.getType()) {
|
||||
// case "habit":
|
||||
// habitRPGUser.getHabits().add(task);
|
||||
// break;
|
||||
// case "daily":
|
||||
// habitRPGUser.getDailys().add(task);
|
||||
// break;
|
||||
// case "todo":
|
||||
// habitRPGUser.getTodos().add(task);
|
||||
// break;
|
||||
// case "reward":
|
||||
// habitRPGUser.getRewards().add(task);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
return habitRPGUser;
|
||||
});
|
||||
}
|
||||
|
|
@ -414,9 +402,33 @@ public class APIHelper implements Action1<Throwable> {
|
|||
});
|
||||
}
|
||||
|
||||
// private void showNotificationDialog(final List notifications) {
|
||||
// HabiticaApplication.currentActivity.runOnUiThread(() -> {
|
||||
// if (!(HabiticaApplication.currentActivity).isFinishing() && displayedAlert == null) {
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(HabiticaApplication.currentActivity)
|
||||
// .setTitle(resourceTitleString)
|
||||
// .setMessage(resourceMessageString)
|
||||
// .setNeutralButton(android.R.string.ok, (dialog, which) -> {
|
||||
// displayedAlert = null;
|
||||
// });
|
||||
//
|
||||
// if (!resourceTitleString.isEmpty()) {
|
||||
// builder.setIcon(R.drawable.ic_warning_black);
|
||||
// }
|
||||
//
|
||||
// displayedAlert = builder.show();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
/*
|
||||
This function is used with Observer.compose to reuse transformers across the application.
|
||||
See here for more info: http://blog.danlew.net/2015/03/02/dont-break-the-chain/
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Observable.Transformer<T, T> configureApiCallObserver() {
|
||||
return (Observable.Transformer<T, T>) apiCallTransformer;
|
||||
public <T> Observable.Transformer<HabitResponse<T>, T> configureApiCallObserver() {
|
||||
return (Observable.Transformer<HabitResponse<T>, T>) apiCallTransformer;
|
||||
}
|
||||
|
||||
public void updateAuthenticationCredentials(String userID, String apiToken) {
|
||||
|
|
@ -431,7 +443,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
public String message;
|
||||
}
|
||||
|
||||
public Observable<ContentResult> getContent() {
|
||||
public Observable<HabitResponse<ContentResult>>getContent() {
|
||||
return apiService.getContent(languageCode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ public class ContentCache {
|
|||
|
||||
private <T> void getContentAndSearchFor(final String typeOfSearch, final String searchKey, final GotContentEntryCallback<T> gotEntry) {
|
||||
apiHelper.getContent()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(contentResult -> {
|
||||
switch (typeOfSearch) {
|
||||
case "quest": {
|
||||
|
|
@ -116,6 +115,7 @@ public class ContentCache {
|
|||
private void getContentAndSearchForList(final String typeOfSearch, final List<String> searchKeys, final GotContentEntryCallback<List<ItemData>> gotEntry) {
|
||||
List<ItemData> resultList = new ArrayList<>();
|
||||
apiHelper.getContent()
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.flatMap(contentResult -> {
|
||||
List<ItemData> itemList = new ArrayList<ItemData>(contentResult.gear.flat);
|
||||
itemList.add(contentResult.potion);
|
||||
|
|
@ -123,8 +123,6 @@ public class ContentCache {
|
|||
return Observable.from(itemList);
|
||||
})
|
||||
.filter(item -> searchKeys.contains(item.key))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(resultList::add, throwable -> {
|
||||
}, () -> gotEntry.GotObject(resultList));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.Hair;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.Items;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Outfit;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Preferences;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.inventory.HatchingPotion;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Item;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.inventory.Pet;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.inventory.QuestContent;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.MaintenanceResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ChecklistItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Days;
|
||||
|
|
@ -940,7 +941,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
@Subscribe
|
||||
public void onEvent(final BuyGemItemCommand event) {
|
||||
if (event.item.canBuy(user) || !event.item.getCurrency().equals("gems")) {
|
||||
Observable<Void> observable;
|
||||
Observable<HabitResponse<Void>> observable;
|
||||
if (event.shopIdentifier.equals(Shop.TIME_TRAVELERS_SHOP)) {
|
||||
if (event.item.purchaseType.equals("gear")) {
|
||||
observable = apiHelper.apiService.purchaseMysterySet(event.item.categoryIdentifier);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class RewardsRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<Rew
|
|||
public void loadEquipmentRewards() {
|
||||
if (apiHelper != null) {
|
||||
apiHelper.apiService.getInventoryBuyableGear()
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.flatMap(items -> {
|
||||
// get itemdata list
|
||||
ArrayList<String> itemKeys = new ArrayList<>();
|
||||
|
|
@ -84,7 +85,6 @@ public class RewardsRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<Rew
|
|||
});
|
||||
});
|
||||
})
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(items -> {
|
||||
this.filteredContent.addAll(items);
|
||||
notifyDataSetChanged();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.ui.helpers.UiUtils;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Skill;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.SpecialItems;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.SkillResponse;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
|
@ -205,7 +206,7 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
|
||||
private void useSkill(Skill skill, String taskId) {
|
||||
displayProgressDialog();
|
||||
Observable<SkillResponse> observable;
|
||||
Observable<HabitResponse<SkillResponse>> observable;
|
||||
if (taskId != null) {
|
||||
observable = apiHelper.apiService.useSkill(skill.key, skill.target, taskId);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
package com.habitrpg.android.habitica.widget;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* The service that should update the simple widget
|
||||
*
|
||||
* @see com.habitrpg.android.habitica.widget.SimpleWidget
|
||||
* Created by Mickael on 01/11/13.
|
||||
*/
|
||||
public class UpdateWidgetService extends Service implements HabitRPGUserCallback.OnUserReceived {
|
||||
private static final String LOG = ".simplewidget.service";
|
||||
@Inject
|
||||
public APIHelper apiHelper;
|
||||
private AppWidgetManager appWidgetManager;
|
||||
|
||||
public UpdateWidgetService() {
|
||||
super();
|
||||
((HabiticaApplication) getApplication()).getComponent().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(final Intent intent, int flags, int startId) {
|
||||
this.appWidgetManager = AppWidgetManager.getInstance(this);
|
||||
int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
|
||||
ComponentName thisWidget = new ComponentName(this,
|
||||
SimpleWidget.class);
|
||||
int[] allWidgetIds2 = appWidgetManager.getAppWidgetIds(thisWidget);
|
||||
|
||||
if (apiHelper != null) {
|
||||
apiHelper.retrieveUser(true)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this));
|
||||
for (int widgetId : allWidgetIds) {
|
||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
} else {
|
||||
for (int widgetId : allWidgetIds) {
|
||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||
RemoteViews textConnect = new RemoteViews(this.getPackageName(), R.layout.simple_textview);
|
||||
textConnect.setTextViewText(R.id.TV_simple_textview, getString(R.string.please_connect));
|
||||
remoteViews.removeAllViews(R.id.LL_header);
|
||||
remoteViews.addView(R.id.LL_header, textConnect);
|
||||
|
||||
|
||||
Intent clickIntent = new Intent(this.getApplicationContext(), SimpleWidget.class);
|
||||
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
||||
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
remoteViews.setOnClickPendingIntent(R.id.BT_refresh, updateIntent);
|
||||
|
||||
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
||||
PendingIntent openApp = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
remoteViews.setOnClickPendingIntent(R.id.widget_main_view, openApp);
|
||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
|
||||
}
|
||||
}
|
||||
stopSelf();
|
||||
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
private void updateData(HabitRPGUser user, AppWidgetManager appWidgetManager) {
|
||||
ComponentName thisWidget = new ComponentName(this, SimpleWidget.class);
|
||||
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
|
||||
for (int widgetId : allWidgetIds) {
|
||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||
remoteViews.setTextViewText(R.id.TV_HP, "" + user.getStats().getHp().intValue() + "/" + (int) user.getStats().getMaxHealth() + " " + this.getString(R.string.HP_default));
|
||||
remoteViews.setTextViewText(R.id.TV_XP, "" + user.getStats().getExp().intValue() + "/" + (int) user.getStats().getToNextLevel() + " " + this.getString(R.string.XP_default));
|
||||
//remoteViews.setImageViewBitmap(R.id.IMG_ProfilePicture, dealWithUserPicture(user,this));
|
||||
remoteViews.setProgressBar(R.id.V_HPBar, (int) user.getStats().getMaxHealth(), user.getStats().getHp().intValue(), false);
|
||||
remoteViews.setProgressBar(R.id.V_XPBar, (int) user.getStats().getToNextLevel(), user.getStats().getExp().intValue(), false);
|
||||
|
||||
// If user click on refresh: refresh
|
||||
Intent clickIntent = new Intent(this.getApplicationContext(), SimpleWidget.class);
|
||||
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
||||
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
remoteViews.setOnClickPendingIntent(R.id.BT_refresh, updateIntent);
|
||||
|
||||
//If user click on life and xp: open the app
|
||||
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
||||
PendingIntent openApp = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
remoteViews.setOnClickPendingIntent(R.id.LL_header, openApp);
|
||||
remoteViews.setOnClickPendingIntent(R.id.IMG_ProfilePicture, openApp);
|
||||
|
||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserReceived(HabitRPGUser user) {
|
||||
this.updateData(user, appWidgetManager);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.UserAuthResponse;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.UserAuthSocial;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.BuyResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.FeedResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.SkillResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.UnlockResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
||||
|
|
@ -44,222 +45,222 @@ import rx.Observable;
|
|||
*/
|
||||
public interface ApiService {
|
||||
@GET("status")
|
||||
Observable<Status> getStatus();
|
||||
Observable<HabitResponse<Status>> getStatus();
|
||||
|
||||
@GET("content")
|
||||
Observable<ContentResult> getContent(@Query("language") String language);
|
||||
Observable<HabitResponse<ContentResult>> getContent(@Query("language") String language);
|
||||
|
||||
/* user API */
|
||||
|
||||
@GET("user/")
|
||||
Observable<HabitRPGUser> getUser();
|
||||
Observable<HabitResponse<HabitRPGUser>> getUser();
|
||||
|
||||
@PUT("user/")
|
||||
Observable<HabitRPGUser> updateUser(@Body Map<String, Object> updateDictionary);
|
||||
Observable<HabitResponse<HabitRPGUser>> updateUser(@Body Map<String, Object> updateDictionary);
|
||||
|
||||
@PUT("user/")
|
||||
Observable<HabitRPGUser> registrationLanguage(@Header("Accept-Language") String registrationLanguage);
|
||||
|
||||
@GET("user/inventory/buy")
|
||||
Observable<List<ItemData>> getInventoryBuyableGear();
|
||||
Observable<HabitResponse<List<ItemData>>> getInventoryBuyableGear();
|
||||
|
||||
@POST("user/equip/{type}/{key}")
|
||||
Observable<Items> equipItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
Observable<HabitResponse<Items>> equipItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
|
||||
@POST("user/buy/{key}")
|
||||
Observable<BuyResponse> buyItem(@Path("key") String itemKey);
|
||||
Observable<HabitResponse<BuyResponse>> buyItem(@Path("key") String itemKey);
|
||||
|
||||
@POST("user/purchase/{type}/{key}")
|
||||
Observable<Void> purchaseItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
Observable<HabitResponse<Void>> purchaseItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
|
||||
@POST("user/purchase-hourglass/{type}/{key}")
|
||||
Observable<Void> purchaseHourglassItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
Observable<HabitResponse<Void>> purchaseHourglassItem(@Path("type") String type, @Path("key") String itemKey);
|
||||
|
||||
@POST("user/buy-mystery-set/{key}")
|
||||
Observable<Void> purchaseMysterySet(@Path("key") String itemKey);
|
||||
Observable<HabitResponse<Void>> purchaseMysterySet(@Path("key") String itemKey);
|
||||
|
||||
@POST("user/buy-quest/{key}")
|
||||
Observable<Void> purchaseQuest(@Path("key") String key);
|
||||
Observable<HabitResponse<Void>> purchaseQuest(@Path("key") String key);
|
||||
|
||||
@POST("user/sell/{type}/{key}")
|
||||
Observable<HabitRPGUser> sellItem(@Path("type") String itemType, @Path("key") String itemKey);
|
||||
Observable<HabitResponse<HabitRPGUser>> sellItem(@Path("type") String itemType, @Path("key") String itemKey);
|
||||
|
||||
@POST("user/feed/{pet}/{food}")
|
||||
Observable<FeedResponse> feedPet(@Path("pet") String petKey, @Path("food") String foodKey);
|
||||
Observable<HabitResponse<FeedResponse>> feedPet(@Path("pet") String petKey, @Path("food") String foodKey);
|
||||
|
||||
@POST("user/hatch/{egg}/{hatchingPotion}")
|
||||
Observable<Items> hatchPet(@Path("egg") String eggKey, @Path("hatchingPotion") String hatchingPotionKey);
|
||||
Observable<HabitResponse<Items>> hatchPet(@Path("egg") String eggKey, @Path("hatchingPotion") String hatchingPotionKey);
|
||||
|
||||
|
||||
@GET("tasks/user")
|
||||
Observable<TaskList> getTasks();
|
||||
Observable<HabitResponse<TaskList>> getTasks();
|
||||
|
||||
@POST("user/unlock")
|
||||
Observable<UnlockResponse> unlockPath(@Query("path") String path);
|
||||
Observable<HabitResponse<UnlockResponse>> unlockPath(@Query("path") String path);
|
||||
|
||||
@GET("tasks/{id}")
|
||||
Observable<Task> getTask(@Path("id") String id);
|
||||
Observable<HabitResponse<Task>> getTask(@Path("id") String id);
|
||||
|
||||
@POST("tasks/{id}/score/{direction}")
|
||||
Observable<TaskDirectionData> postTaskDirection(@Path("id") String id, @Path("direction") String direction);
|
||||
Observable<HabitResponse<TaskDirectionData>> postTaskDirection(@Path("id") String id, @Path("direction") String direction);
|
||||
|
||||
@POST("tasks/{id}/move/to/{position}")
|
||||
Observable<Void> postTaskNewPosition(@Path("id") String id, @Path("position") String position);
|
||||
Observable<HabitResponse<Void>> postTaskNewPosition(@Path("id") String id, @Path("position") String position);
|
||||
|
||||
@POST("tasks/{taskId}/checklist/{itemId}/score")
|
||||
Observable<Task> scoreChecklistItem(@Path("taskId") String taskId, @Path("itemId") String itemId);
|
||||
Observable<HabitResponse<Task>> scoreChecklistItem(@Path("taskId") String taskId, @Path("itemId") String itemId);
|
||||
|
||||
@POST("tasks/user")
|
||||
Observable<Task> createItem(@Body Task item);
|
||||
Observable<HabitResponse<Task>> createItem(@Body Task item);
|
||||
|
||||
@POST("tasks/user")
|
||||
Observable<List<Task>> createTasks(@Body List<Task> tasks);
|
||||
Observable<HabitResponse<List<Task>>> createTasks(@Body List<Task> tasks);
|
||||
|
||||
@PUT("tasks/{id}")
|
||||
Observable<Task> updateTask(@Path("id") String id, @Body Task item);
|
||||
Observable<HabitResponse<Task>> updateTask(@Path("id") String id, @Body Task item);
|
||||
|
||||
@DELETE("tasks/{id}")
|
||||
Observable<Void> deleteTask(@Path("id") String id);
|
||||
Observable<HabitResponse<Void>> deleteTask(@Path("id") String id);
|
||||
|
||||
|
||||
@POST("tags")
|
||||
Observable<Tag> createTag(@Body Tag tag);
|
||||
Observable<HabitResponse<Tag>> createTag(@Body Tag tag);
|
||||
|
||||
@PUT("tags/{id}")
|
||||
Observable<Tag> updateTag(@Path("id") String id, @Body Tag tag);
|
||||
Observable<HabitResponse<Tag>> updateTag(@Path("id") String id, @Body Tag tag);
|
||||
|
||||
@DELETE("tags/{id}")
|
||||
Observable<Void> deleteTag(@Path("id") String id);
|
||||
Observable<HabitResponse<Void>> deleteTag(@Path("id") String id);
|
||||
|
||||
@POST("user/auth/local/register")
|
||||
Observable<UserAuthResponse> registerUser(@Body UserAuth auth);
|
||||
Observable<HabitResponse<UserAuthResponse>> registerUser(@Body UserAuth auth);
|
||||
|
||||
@POST("user/auth/local/login")
|
||||
Observable<UserAuthResponse> connectLocal(@Body UserAuth auth);
|
||||
Observable<HabitResponse<UserAuthResponse>> connectLocal(@Body UserAuth auth);
|
||||
|
||||
@POST("user/auth/social")
|
||||
Observable<UserAuthResponse> connectSocial(@Body UserAuthSocial auth);
|
||||
Observable<HabitResponse<UserAuthResponse>> connectSocial(@Body UserAuthSocial auth);
|
||||
|
||||
|
||||
@POST("user/sleep")
|
||||
Observable<Void> sleep();
|
||||
Observable<HabitResponse<Void>> sleep();
|
||||
|
||||
@POST("user/revive")
|
||||
Observable<HabitRPGUser> revive();
|
||||
Observable<HabitResponse<HabitRPGUser>> revive();
|
||||
|
||||
@POST("user/class/cast/{skill}")
|
||||
Observable<SkillResponse> useSkill(@Path("skill") String skillName, @Query("targetType") String targetType, @Query("targetId") String targetId);
|
||||
Observable<HabitResponse<SkillResponse>> useSkill(@Path("skill") String skillName, @Query("targetType") String targetType, @Query("targetId") String targetId);
|
||||
|
||||
@POST("user/class/cast/{skill}")
|
||||
Observable<SkillResponse> useSkill(@Path("skill") String skillName, @Query("targetType") String targetType);
|
||||
Observable<HabitResponse<SkillResponse>> useSkill(@Path("skill") String skillName, @Query("targetType") String targetType);
|
||||
|
||||
@POST("user/change-class")
|
||||
Observable<HabitRPGUser> changeClass();
|
||||
Observable<HabitResponse<HabitRPGUser>> changeClass();
|
||||
|
||||
@POST("user/change-class")
|
||||
Observable<HabitRPGUser> changeClass(@Query("class") String className);
|
||||
Observable<HabitResponse<HabitRPGUser>> changeClass(@Query("class") String className);
|
||||
|
||||
@POST("user/disable-classes")
|
||||
Observable<HabitRPGUser> disableClasses();
|
||||
Observable<HabitResponse<HabitRPGUser>> disableClasses();
|
||||
|
||||
@POST("user/mark-pms-read")
|
||||
Observable<Void> markPrivateMessagesRead();
|
||||
Observable<HabitResponse<Void>> markPrivateMessagesRead();
|
||||
|
||||
/* Group API */
|
||||
|
||||
@GET("groups")
|
||||
Observable<List<Group>> listGroups(@Query("type") String type);
|
||||
Observable<HabitResponse<List<Group>>> listGroups(@Query("type") String type);
|
||||
|
||||
@GET("groups/{gid}")
|
||||
Observable<Group> getGroup(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Group>> getGroup(@Path("gid") String groupId);
|
||||
|
||||
@PUT("groups/{id}")
|
||||
Observable<Void> updateGroup(@Path("id") String id, @Body Group item);
|
||||
Observable<HabitResponse<Void>> updateGroup(@Path("id") String id, @Body Group item);
|
||||
|
||||
@GET("groups/{gid}/chat")
|
||||
Observable<List<ChatMessage>> listGroupChat(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<List<ChatMessage>>> listGroupChat(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/join")
|
||||
Observable<Group> joinGroup(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Group>> joinGroup(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/leave")
|
||||
Observable<Void> leaveGroup(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> leaveGroup(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/chat")
|
||||
Observable<PostChatMessageResult> postGroupChat(@Path("gid") String groupId, @Body HashMap<String, String> message);
|
||||
Observable<HabitResponse<PostChatMessageResult>> postGroupChat(@Path("gid") String groupId, @Body HashMap<String, String> message);
|
||||
|
||||
@DELETE("groups/{gid}/chat/{messageId}")
|
||||
Observable<Void> deleteMessage(@Path("gid") String groupId, @Path("messageId") String messageId);
|
||||
Observable<HabitResponse<Void>> deleteMessage(@Path("gid") String groupId, @Path("messageId") String messageId);
|
||||
|
||||
@GET("groups/{gid}/members")
|
||||
Observable<List<HabitRPGUser>> getGroupMembers(@Path("gid") String groupId, @Query("includeAllPublicFields") Boolean includeAllPublicFields);
|
||||
Observable<HabitResponse<List<HabitRPGUser>>> getGroupMembers(@Path("gid") String groupId, @Query("includeAllPublicFields") Boolean includeAllPublicFields);
|
||||
|
||||
@GET("groups/{gid}/members")
|
||||
Observable<List<HabitRPGUser>> getGroupMembers(@Path("gid") String groupId, @Query("includeAllPublicFields") Boolean includeAllPublicFields, @Query("lastId") String lastId);
|
||||
Observable<HabitResponse<List<HabitRPGUser>>> getGroupMembers(@Path("gid") String groupId, @Query("includeAllPublicFields") Boolean includeAllPublicFields, @Query("lastId") String lastId);
|
||||
|
||||
// Like returns the full chat list
|
||||
@POST("groups/{gid}/chat/{mid}/like")
|
||||
Observable<ChatMessage> likeMessage(@Path("gid") String groupId, @Path("mid") String mid);
|
||||
Observable<HabitResponse<ChatMessage>> likeMessage(@Path("gid") String groupId, @Path("mid") String mid);
|
||||
|
||||
@POST("groups/{gid}/chat/{mid}/flag")
|
||||
Observable<Void> flagMessage(@Path("gid") String groupId, @Path("mid") String mid);
|
||||
Observable<HabitResponse<Void>> flagMessage(@Path("gid") String groupId, @Path("mid") String mid);
|
||||
|
||||
@POST("groups/{gid}/chat/seen")
|
||||
Observable<Void> seenMessages(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> seenMessages(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/invite")
|
||||
Observable<Void> inviteToGroup(@Path("gid") String groupId, @Body Map<String, Object> inviteData);
|
||||
Observable<HabitResponse<Void>> inviteToGroup(@Path("gid") String groupId, @Body Map<String, Object> inviteData);
|
||||
|
||||
@POST("groups/{gid}/reject-invite")
|
||||
Observable<Void> rejectGroupInvite(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> rejectGroupInvite(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/quests/accept")
|
||||
Observable<Void> acceptQuest(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> acceptQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/quests/reject")
|
||||
Observable<Void> rejectQuest(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> rejectQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/quests/cancel")
|
||||
Observable<Void> cancelQuest(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> cancelQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/quests/force-start")
|
||||
Observable<Quest> forceStartQuest(@Path("gid") String groupId, @Body Group group);
|
||||
Observable<HabitResponse<Quest>> forceStartQuest(@Path("gid") String groupId, @Body Group group);
|
||||
|
||||
@POST("groups/{gid}/quests/invite/{questKey}")
|
||||
Observable<Quest> inviteToQuest(@Path("gid") String groupId, @Path("questKey") String questKey);
|
||||
Observable<HabitResponse<Quest>> inviteToQuest(@Path("gid") String groupId, @Path("questKey") String questKey);
|
||||
|
||||
@POST("groups/{gid}/quests/abort")
|
||||
Observable<Quest> abortQuest(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Quest>> abortQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("groups/{gid}/quests/leave")
|
||||
Observable<Void> leaveQuest(@Path("gid") String groupId);
|
||||
Observable<HabitResponse<Void>> leaveQuest(@Path("gid") String groupId);
|
||||
|
||||
@POST("/iap/android/verify")
|
||||
Observable<PurchaseValidationResult> validatePurchase(@Body PurchaseValidationRequest request);
|
||||
Observable<HabitResponse<PurchaseValidationResult>> validatePurchase(@Body PurchaseValidationRequest request);
|
||||
|
||||
@POST("user/custom-day-start")
|
||||
Observable<HabitRPGUser> changeCustomDayStart(@Body Map<String, Object> updateObject);
|
||||
|
||||
//Members URL
|
||||
@GET("members/{mid}")
|
||||
Observable<HabitRPGUser> GetMember(@Path("mid") String memberId);
|
||||
Observable<HabitResponse<HabitRPGUser>> GetMember(@Path("mid") String memberId);
|
||||
|
||||
@POST("members/send-private-message")
|
||||
Observable<PostChatMessageResult> postPrivateMessage(@Body HashMap<String, String> messageDetails);
|
||||
|
||||
Observable<HabitResponse<PostChatMessageResult>> postPrivateMessage(@Body HashMap<String, String> messageDetails);
|
||||
|
||||
@GET("shops/{identifier}")
|
||||
Observable<Shop> fetchShopInventory(@Path("identifier") String identifier);
|
||||
Observable<HabitResponse<Shop>> fetchShopInventory(@Path("identifier") String identifier);
|
||||
|
||||
//Push notifications
|
||||
@POST("user/push-devices")
|
||||
Observable<Void> addPushDevice(@Body Map<String, String> pushDeviceData);
|
||||
Observable<HabitResponse<Void>> addPushDevice(@Body Map<String, String> pushDeviceData);
|
||||
|
||||
@DELETE("user/push-devices/{regId}")
|
||||
Observable<Void> deletePushDevice(@Path("regId") String regId);
|
||||
Observable<HabitResponse<Void>> deletePushDevice(@Path("regId") String regId);
|
||||
|
||||
//DEBUG: These calls only work on a local development server
|
||||
|
||||
@POST("debug/add-ten-gems")
|
||||
Observable<Void> debugAddTenGems();
|
||||
Observable<HabitResponse<Void>> debugAddTenGems();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.api;
|
||||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.HabitResponse;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.responses.MaintenanceResponse;
|
||||
|
||||
import retrofit2.http.GET;
|
||||
|
|
@ -8,9 +9,9 @@ import rx.Observable;
|
|||
public interface MaintenanceApiService {
|
||||
|
||||
@GET("maintenance-android.json")
|
||||
Observable<MaintenanceResponse> getMaintenanceStatus();
|
||||
Observable<HabitResponse<MaintenanceResponse>> getMaintenanceStatus();
|
||||
|
||||
@GET("deprecation-android.json")
|
||||
Observable<MaintenanceResponse> getDepricationStatus();
|
||||
Observable<HabitResponse<MaintenanceResponse>> getDepricationStatus();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models.responses;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by krh12 on 11/23/2016.
|
||||
*/
|
||||
|
||||
public class HabitResponse<T> {
|
||||
|
||||
private Boolean success;
|
||||
public T data;
|
||||
public List notifications;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The success
|
||||
*/
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param success
|
||||
* The success
|
||||
*/
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The data
|
||||
*/
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.2'
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
classpath 'com.android.databinding:dataBinder:1.0-rc4'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
classpath 'com.google.gms:google-services:3.0.0'
|
||||
|
|
|
|||
1
gradle/wrapper/gradle-wrapper.properties
vendored
1
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -4,3 +4,4 @@ distributionPath=wrapper/dists
|
|||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue