correct challenge sorting

This commit is contained in:
Phillip Thelen 2017-07-10 19:43:15 +02:00
parent 2239ed50e8
commit e93cf6e044
4 changed files with 15 additions and 4 deletions

View file

@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="1911"
android:versionName="1.1.2"
android:versionCode="1912"
android:versionName="1.1.3"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -38,7 +38,7 @@ public class RealmChallengeLocalRepository extends RealmBaseLocalRepository impl
public Observable<RealmResults<Challenge>> getChallenges() {
return realm.where(Challenge.class)
.isNotNull("name")
.findAllSortedAsync("memberCount", Sort.DESCENDING)
.findAllSortedAsync("official", Sort.DESCENDING, "createdAt", Sort.DESCENDING)
.asObservable()
.filter(RealmResults::isLoaded);
}
@ -48,7 +48,7 @@ public class RealmChallengeLocalRepository extends RealmBaseLocalRepository impl
return realm.where(Challenge.class)
.isNotNull("name")
.equalTo("isParticipating", true)
.findAllSortedAsync("memberCount", Sort.DESCENDING)
.findAllSortedAsync("official", Sort.DESCENDING, "createdAt", Sort.DESCENDING)
.asObservable()
.filter(RealmResults::isLoaded);
}

View file

@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName;
import com.habitrpg.android.habitica.models.tasks.TasksOrder;
import com.habitrpg.android.habitica.models.user.User;
import java.util.Date;
import java.util.HashMap;
import io.realm.RealmObject;
@ -33,6 +34,8 @@ public class Challenge extends RealmObject {
public String habitList;
public String dailyList;
public String rewardList;
public Date createdAt;
public Date updatedAt;
public Group group;

View file

@ -12,6 +12,7 @@ import com.google.gson.JsonSerializer;
import com.habitrpg.android.habitica.models.social.Challenge;
import java.lang.reflect.Type;
import java.util.Date;
public class ChallengeDeserializer implements JsonDeserializer<Challenge>, JsonSerializer<Challenge> {
@Override
@ -59,6 +60,13 @@ public class ChallengeDeserializer implements JsonDeserializer<Challenge>, JsonS
}
}
if (jsonObject.has("createdAt")) {
challenge.createdAt = context.deserialize(jsonObject.get("createdAt"), Date.class);
}
if (jsonObject.has("updatedAt")) {
challenge.updatedAt = context.deserialize(jsonObject.get("updatedAt"), Date.class);
}
JsonElement groupElement = jsonObject.get("group");
if (groupElement != null && !groupElement.isJsonNull()) {