mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
add more usecases / extract them from MainActivity
This commit is contained in:
parent
6106bb2fa3
commit
cb7395bc4f
8 changed files with 249 additions and 58 deletions
|
|
@ -15,5 +15,6 @@ public interface TaskRepository extends BaseRepository {
|
||||||
|
|
||||||
Observable<TaskList> refreshTasks(TasksOrder tasksOrder);
|
Observable<TaskList> refreshTasks(TasksOrder tasksOrder);
|
||||||
|
|
||||||
Observable<TaskDirectionData> scoreHabit(Task task, boolean up);
|
Observable<TaskDirectionData> taskChecked(Task task, boolean up);
|
||||||
|
Observable<Task> scoreChecklistItem(String taskId, String itemId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Observable<TaskDirectionData> scoreHabit(Task task, boolean up) {
|
public Observable<TaskDirectionData> taskChecked(Task task, boolean up) {
|
||||||
return this.apiClient.postTaskDirection(task.getId(), (up ? TaskDirection.up : TaskDirection.down).toString())
|
return this.apiClient.postTaskDirection(task.getId(), (up ? TaskDirection.up : TaskDirection.down).toString())
|
||||||
.doOnNext(res -> {
|
.doOnNext(res -> {
|
||||||
// save local task changes
|
// save local task changes
|
||||||
|
|
@ -43,4 +43,10 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Observable<Task> scoreChecklistItem(String taskId, String itemId){
|
||||||
|
return apiClient.scoreChecklistItem(taskId, itemId).doOnNext(res -> {
|
||||||
|
this.localRepository.saveTask(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.habitrpg.android.habitica.interactors;
|
||||||
|
|
||||||
|
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||||
|
import com.habitrpg.android.habitica.executors.PostExecutionThread;
|
||||||
|
import com.habitrpg.android.habitica.executors.ThreadExecutor;
|
||||||
|
import com.habitrpg.android.habitica.helpers.SoundManager;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class BuyRewardUseCase extends UseCase<BuyRewardUseCase.RequestValues, TaskDirectionData> {
|
||||||
|
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
private SoundManager soundManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public BuyRewardUseCase(TaskRepository taskRepository, SoundManager soundManager,
|
||||||
|
ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
|
||||||
|
super(threadExecutor, postExecutionThread);
|
||||||
|
this.taskRepository = taskRepository;
|
||||||
|
this.soundManager = soundManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Observable<TaskDirectionData> buildUseCaseObservable(BuyRewardUseCase.RequestValues requestValues) {
|
||||||
|
return taskRepository.taskChecked(requestValues.task, false).doOnNext(res -> {
|
||||||
|
|
||||||
|
soundManager.loadAndPlayAudio(SoundManager.SoundReward);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RequestValues implements UseCase.RequestValues {
|
||||||
|
protected final Task task;
|
||||||
|
|
||||||
|
public RequestValues(Task task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.habitrpg.android.habitica.interactors;
|
||||||
|
|
||||||
|
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||||
|
import com.habitrpg.android.habitica.executors.PostExecutionThread;
|
||||||
|
import com.habitrpg.android.habitica.executors.ThreadExecutor;
|
||||||
|
import com.habitrpg.android.habitica.helpers.SoundManager;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class ChecklistCheckUseCase extends UseCase<ChecklistCheckUseCase.RequestValues, Task> {
|
||||||
|
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ChecklistCheckUseCase(TaskRepository taskRepository, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
|
||||||
|
super(threadExecutor, postExecutionThread);
|
||||||
|
this.taskRepository = taskRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Observable<Task> buildUseCaseObservable(ChecklistCheckUseCase.RequestValues requestValues) {
|
||||||
|
return taskRepository.scoreChecklistItem(requestValues.taskId, requestValues.itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RequestValues implements UseCase.RequestValues {
|
||||||
|
|
||||||
|
protected final String itemId;
|
||||||
|
|
||||||
|
protected final String taskId;
|
||||||
|
|
||||||
|
public RequestValues(String taskId, String itemId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.habitrpg.android.habitica.interactors;
|
||||||
|
|
||||||
|
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||||
|
import com.habitrpg.android.habitica.executors.PostExecutionThread;
|
||||||
|
import com.habitrpg.android.habitica.executors.ThreadExecutor;
|
||||||
|
import com.habitrpg.android.habitica.helpers.SoundManager;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class DailyCheckUseCase extends UseCase<DailyCheckUseCase.RequestValues, TaskDirectionData> {
|
||||||
|
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
private SoundManager soundManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public DailyCheckUseCase(TaskRepository taskRepository, SoundManager soundManager,
|
||||||
|
ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
|
||||||
|
super(threadExecutor, postExecutionThread);
|
||||||
|
this.taskRepository = taskRepository;
|
||||||
|
this.soundManager = soundManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Observable<TaskDirectionData> buildUseCaseObservable(DailyCheckUseCase.RequestValues requestValues) {
|
||||||
|
return taskRepository.taskChecked(requestValues.task, requestValues.Up).doOnNext(res -> {
|
||||||
|
|
||||||
|
soundManager.loadAndPlayAudio(SoundManager.SoundDaily);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RequestValues implements UseCase.RequestValues {
|
||||||
|
|
||||||
|
protected boolean Up = false;
|
||||||
|
|
||||||
|
protected final Task task;
|
||||||
|
|
||||||
|
public RequestValues(Task task, boolean up) {
|
||||||
|
this.task = task;
|
||||||
|
this.Up = up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,6 @@ import rx.Observable;
|
||||||
|
|
||||||
public class HabitScoreUseCase extends UseCase<HabitScoreUseCase.RequestValues, TaskDirectionData> {
|
public class HabitScoreUseCase extends UseCase<HabitScoreUseCase.RequestValues, TaskDirectionData> {
|
||||||
|
|
||||||
|
|
||||||
private TaskRepository taskRepository;
|
private TaskRepository taskRepository;
|
||||||
private SoundManager soundManager;
|
private SoundManager soundManager;
|
||||||
|
|
||||||
|
|
@ -27,7 +26,7 @@ public class HabitScoreUseCase extends UseCase<HabitScoreUseCase.RequestValues,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Observable<TaskDirectionData> buildUseCaseObservable(RequestValues requestValues) {
|
protected Observable<TaskDirectionData> buildUseCaseObservable(RequestValues requestValues) {
|
||||||
return taskRepository.scoreHabit(requestValues.habit, requestValues.Up).doOnNext(res -> {
|
return taskRepository.taskChecked(requestValues.habit, requestValues.Up).doOnNext(res -> {
|
||||||
|
|
||||||
soundManager.loadAndPlayAudio(requestValues.Up ? SoundManager.SoundPlusHabit : SoundManager.SoundMinusHabit);
|
soundManager.loadAndPlayAudio(requestValues.Up ? SoundManager.SoundPlusHabit : SoundManager.SoundMinusHabit);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.habitrpg.android.habitica.interactors;
|
||||||
|
|
||||||
|
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||||
|
import com.habitrpg.android.habitica.executors.PostExecutionThread;
|
||||||
|
import com.habitrpg.android.habitica.executors.ThreadExecutor;
|
||||||
|
import com.habitrpg.android.habitica.helpers.SoundManager;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||||
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class TodoCheckUseCase extends UseCase<TodoCheckUseCase.RequestValues, TaskDirectionData> {
|
||||||
|
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
private SoundManager soundManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public TodoCheckUseCase(TaskRepository taskRepository, SoundManager soundManager,
|
||||||
|
ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
|
||||||
|
super(threadExecutor, postExecutionThread);
|
||||||
|
this.taskRepository = taskRepository;
|
||||||
|
this.soundManager = soundManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Observable<TaskDirectionData> buildUseCaseObservable(TodoCheckUseCase.RequestValues requestValues) {
|
||||||
|
return taskRepository.taskChecked(requestValues.task, requestValues.Up).doOnNext(res -> {
|
||||||
|
|
||||||
|
soundManager.loadAndPlayAudio(SoundManager.SoundTodo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class RequestValues implements UseCase.RequestValues {
|
||||||
|
|
||||||
|
protected boolean Up = false;
|
||||||
|
|
||||||
|
protected final Task task;
|
||||||
|
|
||||||
|
public RequestValues(Task task, boolean up) {
|
||||||
|
this.task = task;
|
||||||
|
this.Up = up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package com.habitrpg.android.habitica.ui.activities;
|
package com.habitrpg.android.habitica.ui.activities;
|
||||||
|
|
||||||
import com.facebook.drawee.view.SimpleDraweeView;
|
import com.facebook.drawee.view.SimpleDraweeView;
|
||||||
|
import com.habitrpg.android.habitica.interactors.BuyRewardUseCase;
|
||||||
|
import com.habitrpg.android.habitica.interactors.ChecklistCheckUseCase;
|
||||||
|
import com.habitrpg.android.habitica.interactors.DailyCheckUseCase;
|
||||||
|
import com.habitrpg.android.habitica.interactors.TodoCheckUseCase;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.api.IApiClient;
|
import com.magicmicky.habitrpgwrapper.lib.api.IApiClient;
|
||||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||||
import com.habitrpg.android.habitica.HostConfig;
|
import com.habitrpg.android.habitica.HostConfig;
|
||||||
|
|
@ -196,6 +200,18 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
@Inject
|
@Inject
|
||||||
HabitScoreUseCase habitScoreUseCase;
|
HabitScoreUseCase habitScoreUseCase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DailyCheckUseCase dailyCheckUseCase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
TodoCheckUseCase todoCheckUseCase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BuyRewardUseCase buyRewardUseCase;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ChecklistCheckUseCase checklistCheckUseCase;
|
||||||
|
|
||||||
private Drawer drawer;
|
private Drawer drawer;
|
||||||
private Drawer filterDrawer;
|
private Drawer filterDrawer;
|
||||||
private AccountHeader accountHeader;
|
private AccountHeader accountHeader;
|
||||||
|
|
@ -244,10 +260,10 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
LanguageHelper languageHelper = new LanguageHelper(sharedPreferences.getString("language","en"));
|
LanguageHelper languageHelper = new LanguageHelper(sharedPreferences.getString("language", "en"));
|
||||||
Locale.setDefault(languageHelper.getLocale());
|
Locale.setDefault(languageHelper.getLocale());
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN){
|
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
configuration.locale = languageHelper.getLocale();
|
configuration.locale = languageHelper.getLocale();
|
||||||
} else {
|
} else {
|
||||||
configuration.setLocale(languageHelper.getLocale());
|
configuration.setLocale(languageHelper.getLocale());
|
||||||
|
|
@ -256,7 +272,6 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
getResources().getDisplayMetrics());
|
getResources().getDisplayMetrics());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!HabiticaApplication.checkUserAuthentication(this, hostConfig)) {
|
if (!HabiticaApplication.checkUserAuthentication(this, hostConfig)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -351,10 +366,10 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWidget(Class widgetClass) {
|
private void updateWidget(Class widgetClass) {
|
||||||
Intent intent = new Intent(this,widgetClass);
|
Intent intent = new Intent(this, widgetClass);
|
||||||
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||||
int ids[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), widgetClass));
|
int ids[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), widgetClass));
|
||||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -402,7 +417,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
|
|
||||||
Preferences preferences = user.getPreferences();
|
Preferences preferences = user.getPreferences();
|
||||||
|
|
||||||
if(preferences!= null) {
|
if (preferences != null) {
|
||||||
apiClient.setLanguageCode(preferences.getLanguage());
|
apiClient.setLanguageCode(preferences.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -882,13 +897,12 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
this.drawer.setSelectionAtPosition(this.activeFragment.fragmentSidebarPosition, false);
|
this.drawer.setSelectionAtPosition(this.activeFragment.fragmentSidebarPosition, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTranslatedFragmentTitle(BaseMainFragment fragment){
|
private void setTranslatedFragmentTitle(BaseMainFragment fragment) {
|
||||||
if(fragment!= null && fragment.customTitle() != null){
|
if (fragment != null && fragment.customTitle() != null) {
|
||||||
getSupportActionBar().setTitle(fragment.customTitle());
|
getSupportActionBar().setTitle(fragment.customTitle());
|
||||||
}
|
} else if (user != null && user.getProfile() != null) {
|
||||||
else if(user != null && user.getProfile() != null){
|
getSupportActionBar().setTitle(user.getProfile().getName());
|
||||||
getSupportActionBar().setTitle(user.getProfile().getName());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
@ -913,13 +927,13 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
if (resultCode == SELECT_CLASS_RESULT) {
|
if (resultCode == SELECT_CLASS_RESULT) {
|
||||||
if (this.apiClient != null) {
|
if (this.apiClient != null) {
|
||||||
this.apiClient.retrieveUser(true)
|
this.apiClient.retrieveUser(true)
|
||||||
|
|
||||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (requestCode == GEM_PURCHASE_REQUEST) {
|
} else if (requestCode == GEM_PURCHASE_REQUEST) {
|
||||||
this.apiClient.retrieveUser(true)
|
this.apiClient.retrieveUser(true)
|
||||||
|
|
||||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -949,7 +963,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEvent(EquipCommand event) {
|
public void onEvent(EquipCommand event) {
|
||||||
this.apiClient.equipItem(event.type, event.key)
|
this.apiClient.equipItem(event.type, event.key)
|
||||||
.subscribe(new ItemsCallback(this, this.user), throwable -> {
|
.subscribe(new ItemsCallback(this, this.user), throwable -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -958,7 +972,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
this.user.setBalance(this.user.getBalance() - event.balanceDiff);
|
this.user.setBalance(this.user.getBalance() - event.balanceDiff);
|
||||||
this.setUserData(false);
|
this.setUserData(false);
|
||||||
apiClient.unlockPath(event.path)
|
apiClient.unlockPath(event.path)
|
||||||
|
|
||||||
.subscribe(new UnlockCallback(this, this.user), throwable -> {
|
.subscribe(new UnlockCallback(this, this.user), throwable -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -984,13 +998,13 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
observable = apiClient.purchaseItem(event.item.purchaseType, event.item.key);
|
observable = apiClient.purchaseItem(event.item.purchaseType, event.item.key);
|
||||||
}
|
}
|
||||||
observable
|
observable
|
||||||
|
|
||||||
.doOnNext(aVoid -> {
|
.doOnNext(aVoid -> {
|
||||||
showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL);
|
showSnackbar(this, floatingMenuWrapper, getString(R.string.successful_purchase, event.item.text), SnackbarDisplayType.NORMAL);
|
||||||
})
|
})
|
||||||
.subscribe(buyResponse -> {
|
.subscribe(buyResponse -> {
|
||||||
apiClient.retrieveUser(false)
|
apiClient.retrieveUser(false)
|
||||||
|
|
||||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||||
});
|
});
|
||||||
}, throwable -> {
|
}, throwable -> {
|
||||||
|
|
@ -1066,12 +1080,10 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
}, throwable -> {
|
}, throwable -> {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
soundManager.loadAndPlayAudio(SoundManager.SoundReward);
|
buyRewardUseCase.observable(new BuyRewardUseCase.RequestValues(event.Reward))
|
||||||
// user created Rewards
|
.subscribe(res -> {
|
||||||
apiClient.postTaskDirection(rewardKey, TaskDirection.down.toString())
|
onTaskDataReceived(res, event.Reward);
|
||||||
|
}, error -> {});
|
||||||
.subscribe(new TaskScoringCallback(this, rewardKey), throwable -> {
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update the users gold
|
//Update the users gold
|
||||||
|
|
@ -1110,7 +1122,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEvent(SellItemCommand event) {
|
public void onEvent(SellItemCommand event) {
|
||||||
this.apiClient.sellItem(event.item.getType(), event.item.getKey())
|
this.apiClient.sellItem(event.item.getType(), event.item.getKey())
|
||||||
|
|
||||||
.subscribe(habitRPGUser -> {
|
.subscribe(habitRPGUser -> {
|
||||||
user.setItems(habitRPGUser.getItems());
|
user.setItems(habitRPGUser.getItems());
|
||||||
user.save();
|
user.save();
|
||||||
|
|
@ -1126,7 +1138,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.apiClient.hatchPet(event.usingEgg.getKey(), event.usingHatchingPotion.getKey())
|
this.apiClient.hatchPet(event.usingEgg.getKey(), event.usingHatchingPotion.getKey())
|
||||||
|
|
||||||
.subscribe(new ItemsCallback(user1 -> {
|
.subscribe(new ItemsCallback(user1 -> {
|
||||||
FrameLayout petWrapper = (FrameLayout) getLayoutInflater().inflate(R.layout.pet_imageview, null);
|
FrameLayout petWrapper = (FrameLayout) getLayoutInflater().inflate(R.layout.pet_imageview, null);
|
||||||
SimpleDraweeView petImageView = (SimpleDraweeView) petWrapper.findViewById(R.id.pet_imageview);
|
SimpleDraweeView petImageView = (SimpleDraweeView) petWrapper.findViewById(R.id.pet_imageview);
|
||||||
|
|
@ -1164,7 +1176,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
}
|
}
|
||||||
final Pet pet = event.usingPet;
|
final Pet pet = event.usingPet;
|
||||||
this.apiClient.feedPet(event.usingPet.getKey(), event.usingFood.getKey())
|
this.apiClient.feedPet(event.usingPet.getKey(), event.usingFood.getKey())
|
||||||
|
|
||||||
.subscribe(feedResponse -> {
|
.subscribe(feedResponse -> {
|
||||||
MainActivity.this.user.getItems().getPets().put(pet.getKey(), feedResponse.value);
|
MainActivity.this.user.getItems().getPets().put(pet.getKey(), feedResponse.value);
|
||||||
MainActivity.this.user.getItems().getFood().put(event.usingFood.getKey(), event.usingFood.getOwned() - 1);
|
MainActivity.this.user.getItems().getFood().put(event.usingFood.getKey(), event.usingFood.getOwned() - 1);
|
||||||
|
|
@ -1251,7 +1263,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
displayLevelUpDialog(lvl);
|
displayLevelUpDialog(lvl);
|
||||||
|
|
||||||
this.apiClient.retrieveUser(true)
|
this.apiClient.retrieveUser(true)
|
||||||
|
|
||||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||||
});
|
});
|
||||||
user.getStats().setLvl(lvl);
|
user.getStats().setLvl(lvl);
|
||||||
|
|
@ -1312,7 +1324,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
.setPositiveButton(R.string.faint_button, (dialog, which) -> {
|
.setPositiveButton(R.string.faint_button, (dialog, which) -> {
|
||||||
faintDialog = null;
|
faintDialog = null;
|
||||||
apiClient.revive()
|
apiClient.revive()
|
||||||
|
|
||||||
.subscribe(new MergeUserCallback(MainActivity.this, MainActivity.this.user), throwable -> {
|
.subscribe(new MergeUserCallback(MainActivity.this, MainActivity.this.user), throwable -> {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
@ -1428,7 +1440,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
Map<String, Object> updateData = new HashMap<>();
|
Map<String, Object> updateData = new HashMap<>();
|
||||||
updateData.put(path, true);
|
updateData.put(path, true);
|
||||||
apiClient.updateUser(updateData)
|
apiClient.updateUser(updateData)
|
||||||
|
|
||||||
.subscribe(new MergeUserCallback(this, user), throwable -> {
|
.subscribe(new MergeUserCallback(this, user), throwable -> {
|
||||||
});
|
});
|
||||||
this.overlayFrameLayout.removeView(this.activeTutorialView);
|
this.overlayFrameLayout.removeView(this.activeTutorialView);
|
||||||
|
|
@ -1482,29 +1494,32 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEvent(TaskCheckedCommand event) {
|
public void onEvent(TaskCheckedCommand event) {
|
||||||
apiClient.postTaskDirection(event.Task.getId(), (event.Task.getCompleted() ? TaskDirection.down : TaskDirection.up).toString())
|
switch (event.Task.type) {
|
||||||
|
|
||||||
.subscribe(new TaskScoringCallback(this, event.Task.getId()), throwable -> {
|
|
||||||
event.Task.completed = !event.Task.completed;
|
|
||||||
event.Task.save();
|
|
||||||
EventBus.getDefault().post(new TaskUpdatedEvent(event.Task));
|
|
||||||
});
|
|
||||||
|
|
||||||
switch(event.Task.type){
|
|
||||||
case Task.TYPE_DAILY: {
|
case Task.TYPE_DAILY: {
|
||||||
soundManager.loadAndPlayAudio(SoundManager.SoundDaily);
|
dailyCheckUseCase.observable(new DailyCheckUseCase.RequestValues(event.Task, !event.Task.getCompleted()))
|
||||||
} break;
|
.subscribe(res -> {
|
||||||
|
EventBus.getDefault().post(new TaskUpdatedEvent(event.Task));
|
||||||
|
}, error -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Task.TYPE_TODO: {
|
case Task.TYPE_TODO: {
|
||||||
soundManager.loadAndPlayAudio(SoundManager.SoundTodo);
|
todoCheckUseCase.observable(new TodoCheckUseCase.RequestValues(event.Task, !event.Task.getCompleted()))
|
||||||
} break;
|
.subscribe(res -> {
|
||||||
|
EventBus.getDefault().post(new TaskUpdatedEvent(event.Task));
|
||||||
|
}, error -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEvent(ChecklistCheckedCommand event) {
|
public void onEvent(ChecklistCheckedCommand event) {
|
||||||
apiClient.scoreChecklistItem(event.task.getId(), event.item.getId())
|
checklistCheckUseCase.observable(new ChecklistCheckUseCase.RequestValues(event.task.getId(), event.item.getId()))
|
||||||
|
.subscribe(res -> {
|
||||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
EventBus.getDefault().post(new TaskUpdatedEvent(event.task));
|
||||||
|
}, error -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1514,8 +1529,6 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
.subscribe(res -> {
|
.subscribe(res -> {
|
||||||
onTaskDataReceived(res, event.habit);
|
onTaskDataReceived(res, event.habit);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1524,12 +1537,10 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
Task task = event.task;
|
Task task = event.task;
|
||||||
if (event.created) {
|
if (event.created) {
|
||||||
this.apiClient.createItem(task)
|
this.apiClient.createItem(task)
|
||||||
|
|
||||||
.subscribe(new TaskCreationCallback(), throwable -> {
|
.subscribe(new TaskCreationCallback(), throwable -> {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.apiClient.updateTask(task.getId(), task)
|
this.apiClient.updateTask(task.getId(), task)
|
||||||
|
|
||||||
.subscribe(new TaskUpdateCallback(), throwable -> {
|
.subscribe(new TaskUpdateCallback(), throwable -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1629,7 +1640,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEvent(OpenFullProfileCommand cmd) {
|
public void onEvent(OpenFullProfileCommand cmd) {
|
||||||
if(cmd.MemberId.equals("system"))
|
if (cmd.MemberId.equals("system"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
@ -1645,8 +1656,8 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
||||||
this.filterDrawer.removeItemByPosition(position);
|
this.filterDrawer.removeItemByPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFilterDrawerItem (IDrawerItem item, int position) {
|
public void updateFilterDrawerItem(IDrawerItem item, int position) {
|
||||||
this.filterDrawer.removeItemByPosition(position);
|
this.filterDrawer.removeItemByPosition(position);
|
||||||
this.filterDrawer.addItemAtPosition(item,position);
|
this.filterDrawer.addItemAtPosition(item, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue