mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 12:49:02 +00:00
Improve loading pets and mounts. Fixes #1208
This commit is contained in:
parent
de87ca5505
commit
c689f9a8d0
1 changed files with 24 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ import com.habitrpg.android.habitica.models.*
|
|||
import com.habitrpg.android.habitica.models.social.ChallengeMembership
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import io.reactivex.Flowable
|
||||
import io.realm.Realm
|
||||
|
|
@ -70,6 +72,8 @@ class RealmUserLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm),
|
|||
if (user.challenges != null) {
|
||||
removeOldChallenges(user.id ?: "", user.challenges ?: emptyList())
|
||||
}
|
||||
removeOldPets(user.id ?: "", user.items?.pets ?: emptyList())
|
||||
removeOldMounts(user.id ?: "", user.items?.mounts ?: emptyList())
|
||||
}
|
||||
|
||||
override fun saveMessages(messages: List<ChatMessage>) {
|
||||
|
|
@ -98,6 +102,26 @@ class RealmUserLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm),
|
|||
}
|
||||
}
|
||||
|
||||
private fun removeOldPets(userID: String, onlinePets: List<OwnedPet>) {
|
||||
val pets = realm.where(OwnedPet::class.java).equalTo("userID", userID).findAll().createSnapshot()
|
||||
val petsToDelete = pets.filterNot { onlinePets.contains(it) }
|
||||
realm.executeTransaction {
|
||||
petsToDelete.forEach {
|
||||
it.deleteFromRealm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeOldMounts(userID: String, onlineMounts: List<OwnedMount>) {
|
||||
val mount = realm.where(OwnedMount::class.java).equalTo("userID", userID).findAll().createSnapshot()
|
||||
val mountsToDelete = mount.filterNot { onlineMounts.contains(it) }
|
||||
realm.executeTransaction {
|
||||
mountsToDelete.forEach {
|
||||
it.deleteFromRealm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSkills(user: User): Flowable<RealmResults<Skill>> {
|
||||
val habitClass = if (user.preferences?.disableClasses == true) "none" else user.stats?.habitClass
|
||||
return realm.where(Skill::class.java)
|
||||
|
|
|
|||
Loading…
Reference in a new issue