mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 13:48:55 +00:00
fix various crashes
This commit is contained in:
parent
9063705c99
commit
95a217ea3f
5 changed files with 8 additions and 14 deletions
|
|
@ -71,11 +71,6 @@ public abstract class HabiticaBaseApplication extends MultiDexApplication {
|
|||
return (HabiticaBaseApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
private static void setFinalStatic(Field field, @Nullable Object newValue) throws NoSuchFieldException, IllegalAccessException {
|
||||
field.setAccessible(true);
|
||||
field.set(null, newValue);
|
||||
}
|
||||
|
||||
public static void logout(Context context) {
|
||||
Realm realm = Realm.getDefaultInstance();
|
||||
getInstance(context).deleteDatabase(realm.getPath());
|
||||
|
|
@ -235,7 +230,7 @@ public abstract class HabiticaBaseApplication extends MultiDexApplication {
|
|||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
if (currentActivity.equals(activity)) {
|
||||
if (currentActivity != null && currentActivity.equals(activity)) {
|
||||
currentActivity = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.realm.OrderedRealmCollectionSnapshot;
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmResults;
|
||||
import io.realm.Sort;
|
||||
|
|
@ -101,7 +102,7 @@ public class RealmTaskLocalRepository extends RealmBaseLocalRepository implement
|
|||
}
|
||||
|
||||
private void removeOldTasks(Realm realm, String userID, List<Task> onlineTaskList) {
|
||||
RealmResults<Task> localTasks = realm.where(Task.class).equalTo("userId", userID).findAll();
|
||||
OrderedRealmCollectionSnapshot<Task> localTasks = realm.where(Task.class).equalTo("userId", userID).findAll().createSnapshot();
|
||||
for (Task localTask : localTasks) {
|
||||
if (!onlineTaskList.contains(localTask)) {
|
||||
for (ChecklistItem item : localTask.checklist) {
|
||||
|
|
@ -116,7 +117,7 @@ public class RealmTaskLocalRepository extends RealmBaseLocalRepository implement
|
|||
}
|
||||
|
||||
private void removeOldChecklists(Realm realm, List<ChecklistItem> onlineItems) {
|
||||
RealmResults<ChecklistItem> localItems = realm.where(ChecklistItem.class).findAll();
|
||||
OrderedRealmCollectionSnapshot<ChecklistItem> localItems = realm.where(ChecklistItem.class).findAll().createSnapshot();
|
||||
for (ChecklistItem localItem : localItems) {
|
||||
if (!onlineItems.contains(localItem)) {
|
||||
localItem.deleteFromRealm();
|
||||
|
|
@ -125,7 +126,7 @@ public class RealmTaskLocalRepository extends RealmBaseLocalRepository implement
|
|||
}
|
||||
|
||||
private void removeOldReminders(Realm realm, List<RemindersItem> onlineReminders) {
|
||||
RealmResults<RemindersItem> localReminders = realm.where(RemindersItem.class).findAll();
|
||||
OrderedRealmCollectionSnapshot<RemindersItem> localReminders = realm.where(RemindersItem.class).findAll().createSnapshot();
|
||||
for (RemindersItem localItem : localReminders) {
|
||||
if (!onlineReminders.contains(localItem)) {
|
||||
localItem.deleteFromRealm();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.habitrpg.android.habitica.models.user.User;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.realm.OrderedRealmCollectionSnapshot;
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmResults;
|
||||
import rx.Observable;
|
||||
|
|
@ -43,7 +44,7 @@ public class RealmUserLocalRepository extends RealmBaseLocalRepository implement
|
|||
}
|
||||
|
||||
private void removeOldTags(String userId, List<Tag> onlineTags) {
|
||||
RealmResults<Tag> tags = realm.where(Tag.class).equalTo("userId", userId).findAll();
|
||||
OrderedRealmCollectionSnapshot<Tag> tags = realm.where(Tag.class).equalTo("userId", userId).findAll().createSnapshot();
|
||||
|
||||
for (Tag tag : tags) {
|
||||
if (!onlineTags.contains(tag)) {
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class ChecklistItem extends RealmObject {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj.getClass().equals(ChecklistItem.class)) {
|
||||
if (obj.getClass().equals(ChecklistItem.class) && this.id != null) {
|
||||
return this.id.equals(((ChecklistItem)obj).id);
|
||||
}
|
||||
return super.equals(obj);
|
||||
|
|
|
|||
|
|
@ -215,9 +215,6 @@ public class PreferencesFragment extends BasePreferencesFragment implements
|
|||
userRepository.updateUser(user, "preferences.sound", newAudioTheme)
|
||||
.subscribe(habitRPGUser -> {}, throwable -> {});
|
||||
|
||||
Preferences preferences = user.getPreferences();
|
||||
preferences.setSound(newAudioTheme);
|
||||
|
||||
soundManager.setSoundTheme(newAudioTheme);
|
||||
|
||||
soundManager.preloadAllFiles();
|
||||
|
|
|
|||
Loading…
Reference in a new issue