fix notifications for task completion

This commit is contained in:
Phillip Thelen 2017-04-05 22:00:07 +02:00
parent c0c3e047b2
commit 4a92a2c214
3 changed files with 15 additions and 6 deletions

View file

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="165"
android:versionCode="166"
android:versionName="1.0"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -18,7 +18,7 @@ import rx.functions.Action0;
import static com.habitrpg.android.habitica.helpers.MathHelper.round;
import static com.habitrpg.android.habitica.ui.helpers.UiUtils.showSnackbar;
public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues, Void> {
public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues, Stats> {
public static final int MIN_LEVEL_FOR_SKILLS = 11;
private LevelUpUseCase levelUpUseCase;
@ -31,8 +31,8 @@ public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues,
}
@Override
protected Observable<Void> buildUseCaseObservable(RequestValues r) {
return Observable.from(() -> {
protected Observable<Stats> buildUseCaseObservable(RequestValues r) {
return Observable.defer(() -> {
Stats stats = r.user.getStats();
if (r.lvl > stats.getLvl()) {
@ -49,7 +49,7 @@ public class NotifyUserUseCase extends UseCase<NotifyUserUseCase.RequestValues,
showSnackbar(r.context, r.snackbarTargetView, pair.first, pair.second);
}
return null;
return Observable.just(stats);
});
}

View file

@ -1280,6 +1280,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
@Override
public void onTaskDataReceived(TaskDirectionData data, Task task) {
if (task.type.equals("reward")) {
showSnackbar(this, floatingMenuWrapper, getString(R.string.notification_purchase, task.getText()), SnackbarDisplayType.NORMAL);
@ -1288,12 +1289,20 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
if (user != null) {
notifyUserUseCase.observable(new NotifyUserUseCase.RequestValues(this, floatingMenuWrapper, this::retrieveUser,
user, data.getExp(), data.getHp(), data.getGp(), data.getMp(), data.getLvl()));
user, data.getExp(), data.getHp(), data.getGp(), data.getMp(), data.getLvl()))
.subscribe(aVoid -> {
user.getStats().hp = data.getHp();
user.getStats().exp = data.getExp();
user.getStats().mp = data.getMp();
user.getStats().gp = data.getGp();
setUserData(true);
}, throwable -> {});
}
displayItemDropUseCase.observable(new DisplayItemDropUseCase.RequestValues(data, this, floatingMenuWrapper))
.subscribe(aVoid -> {}, throwable -> {});
}
}