fix minor issues

This commit is contained in:
Phillip Thelen 2017-06-07 10:51:23 -07:00
parent c2269f0da0
commit bb6565b688
10 changed files with 33 additions and 10 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="1891"
android:versionCode="1894"
android:versionName="1.1"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -309,7 +309,7 @@ public interface ApiService {
// Notifications
@POST("notifications/{notificationId}/read")
Observable<HabitResponse<Void>> readNotification(@Path("notificationId") String notificationId);
Observable<HabitResponse<List>> readNotification(@Path("notificationId") String notificationId);
@POST("user/open-mystery-item")
Observable<HabitResponse<Equipment>> openMysteryItem();

View file

@ -51,4 +51,6 @@ public interface TaskRepository extends BaseRepository {
void updateTaskInBackground(Task task);
void createTaskInBackground(Task task);
Observable<List<Task>> getTaskCopies(String userId);
}

View file

@ -62,7 +62,7 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
public Observable<TaskScoringResult> taskChecked(User user, Task task, boolean up) {
long now = new Date().getTime();
if (lastTaskAction > now-500) {
return Observable.empty();
return Observable.just(null);
}
lastTaskAction = now;
return this.apiClient.postTaskDirection(task.getId(), (up ? TaskDirection.up : TaskDirection.down).toString())
@ -127,7 +127,7 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
public Observable<Task> createTask(Task task) {
long now = new Date().getTime();
if (lastTaskAction > now-500) {
return Observable.empty();
return Observable.just(task);
}
lastTaskAction = now;
return localRepository.getTaskCopy(task.getId()).first()
@ -139,7 +139,7 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
public Observable<Task> updateTask(Task task) {
long now = new Date().getTime();
if (lastTaskAction > now-500) {
return Observable.empty();
return Observable.just(task);
}
lastTaskAction = now;
return localRepository.getTaskCopy(task.getId()).first()
@ -207,4 +207,10 @@ public class TaskRepositoryImpl extends BaseRepositoryImpl<TaskLocalRepository>
public void createTaskInBackground(Task task) {
createTask(task).subscribe(task1 -> {}, RxErrorHandler.handleEmptyError());
}
@Override
public Observable<List<Task>> getTaskCopies(String userId) {
return getTasks(userId)
.map(localRepository::getUnmanagedCopy);
}
}

View file

@ -179,7 +179,7 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository>
path = path + "," + customization.getPath();
}
if (path.length() == 0) {
return Observable.empty();
return Observable.just(null);
}
path = path.substring(1);
return apiClient.unlockPath(path)

View file

@ -7,6 +7,7 @@ import com.habitrpg.android.habitica.models.user.User;
import java.util.List;
import io.realm.OrderedRealmCollection;
import io.realm.Realm;
import io.realm.RealmObject;
@ -17,6 +18,7 @@ public interface BaseLocalRepository {
void executeTransaction(Realm.Transaction transaction);
<T extends RealmObject> T getUnmanagedCopy(T object);
<T extends RealmObject> List<T> getUnmanagedCopy(OrderedRealmCollection<T> list);
<T extends RealmObject>void save(List<T> objects);
<T extends RealmObject>void save(T object);

View file

@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.data.local.BaseLocalRepository;
import java.util.List;
import io.realm.OrderedRealmCollection;
import io.realm.Realm;
import io.realm.RealmObject;
@ -30,6 +31,11 @@ abstract class RealmBaseLocalRepository implements BaseLocalRepository {
return realm.copyFromRealm(object);
}
@Override
public <T extends RealmObject> List<T> getUnmanagedCopy(OrderedRealmCollection<T> list) {
return realm.copyFromRealm(list);
}
@Override
public <T extends RealmObject> void save(T object) {
realm.executeTransactionAsync(realm1 -> realm1.insertOrUpdate(object));

View file

@ -142,14 +142,14 @@ public class TaskAlarmManager {
//We currently only use this function to schedule the next reminder for dailies
//We may be able to use repeating alarms instead of this in the future
public void addAlarmForTaskId(String taskId) {
taskRepository.getTask(taskId)
.filter(task -> task.isManaged() && Task.TYPE_DAILY.equals(task.type))
taskRepository.getTaskCopy(taskId)
.filter(task -> task.isValid() && task.isManaged() && Task.TYPE_DAILY.equals(task.type))
.first()
.subscribe(this::setAlarmsForTask, RxErrorHandler.handleEmptyError());
}
public void scheduleAllSavedAlarms() {
taskRepository.getTasks(userId)
taskRepository.getTaskCopies(userId)
.first()
.flatMap(Observable::from)
.subscribe(this::setAlarmsForTask, crashlyticsProxy::logException);

View file

@ -176,6 +176,9 @@ public class SetupActivity extends BaseActivity implements ViewPager.OnPageChang
Integer.toString(Calendar.getInstance().getFirstDayOfWeek()));
editor.apply();
if (isLastPage()) {
if (this.taskSetupFragment == null) {
return;
}
List<Task> newTasks = this.taskSetupFragment.createSampleTasks();
this.completedSetup = true;
this.taskRepository.createTasks(newTasks)

View file

@ -323,7 +323,11 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
if (Task.TYPE_REWARD.equals(getClassName())) {
compositeSubscription.add(taskRepository.getTasks(this.getClassName(), userID)
.subscribe(recyclerAdapter::updateData, RxErrorHandler.handleEmptyError()));
.subscribe(tasks -> {
if (recyclerAdapter != null) {
recyclerAdapter.updateData(tasks);
}
}, RxErrorHandler.handleEmptyError()));
}
}