Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2415 from vector-im/feature/favorite_issue
Browse files Browse the repository at this point in the history
Fix issue on favorite and low priority room by clearing cache
  • Loading branch information
bmarty authored Jul 6, 2018
2 parents 08cb89f + b002e8f commit 57a3655
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Other changes:
-

Bugfix:
-
- Fix issue on vanished favorite and low priority room (#2413)

Translations:
-
Expand Down
27 changes: 23 additions & 4 deletions vector/src/main/java/im/vector/activity/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package im.vector.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;

import org.jetbrains.annotations.NotNull;
import org.matrix.androidsdk.MXSession;
Expand All @@ -39,6 +41,7 @@
import im.vector.gcm.GcmRegistrationManager;
import im.vector.receiver.VectorUniversalLinkReceiver;
import im.vector.services.EventStreamService;
import im.vector.util.PreferencesManager;
import kotlin.Pair;

/**
Expand All @@ -50,11 +53,13 @@ public class SplashActivity extends MXCActionBarActivity {
public static final String EXTRA_MATRIX_ID = "EXTRA_MATRIX_ID";
public static final String EXTRA_ROOM_ID = "EXTRA_ROOM_ID";

private Map<MXSession, IMXEventListener> mListeners;
private Map<MXSession, IMXEventListener> mDoneListeners;
private Map<MXSession, IMXEventListener> mListeners = new HashMap<>();
private Map<MXSession, IMXEventListener> mDoneListeners = new HashMap<>();

private final long mLaunchTime = System.currentTimeMillis();

private static final String NEED_TO_CLEAR_CACHE_BEFORE_81200 = "NEED_TO_CLEAR_CACHE_BEFORE_81200";

/**
* @return true if a store is corrupted.
*/
Expand Down Expand Up @@ -133,8 +138,22 @@ public void initUiAndData() {
return;
}

mListeners = new HashMap<>();
mDoneListeners = new HashMap<>();
// Check if store is corrupted, due to change of type of some maps from HashMap to Map in Serialized objects
// Only on Android 7.1+
// Only if previous versionCode of the installation is < 81200
// Only once
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
&& PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferencesManager.VERSION_BUILD, 0) < 81200
&& PreferenceManager.getDefaultSharedPreferences(this).getBoolean(NEED_TO_CLEAR_CACHE_BEFORE_81200, true)) {
PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putBoolean(NEED_TO_CLEAR_CACHE_BEFORE_81200, false)
.apply();

// Force a clear cache
Matrix.getInstance(this).reloadSessions(this);
return;
}

List<String> matrixIds = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,15 @@ public void initUiAndData() {

// track if the application update
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int version = preferences.getInt("VERSION_BUILD", 0);
int version = preferences.getInt(PreferencesManager.VERSION_BUILD, 0);

if (version != VectorApp.VERSION_BUILD) {
Log.d(LOG_TAG, "The application has been updated from version " + version + " to version " + VectorApp.VERSION_BUILD);

// TODO add some dedicated actions here

preferences
.edit()
.putInt("VERSION_BUILD", VectorApp.VERSION_BUILD)
preferences.edit()
.putInt(PreferencesManager.VERSION_BUILD, VectorApp.VERSION_BUILD)
.apply();
}

Expand Down
2 changes: 2 additions & 0 deletions vector/src/main/java/im/vector/util/PreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class PreferencesManager {

private static final String LOG_TAG = PreferencesManager.class.getSimpleName();

public static final String VERSION_BUILD = "VERSION_BUILD";

public static final String SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2";
public static final String SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY";
public static final String SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY";
Expand Down

0 comments on commit 57a3655

Please sign in to comment.