mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 01:23:38 +02:00
Refactoring
This commit is contained in:
@@ -25,11 +25,12 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
@@ -134,23 +135,6 @@ public abstract class DB extends RoomDatabase {
|
||||
super.init(configuration);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected InvalidationTracker createInvalidationTracker() {
|
||||
final HashMap<String, String> _shadowTablesMap = new HashMap<String, String>(0);
|
||||
HashMap<String, Set<String>> _viewTables = new HashMap<String, Set<String>>(3);
|
||||
HashSet<String> _tables = new HashSet<String>(1);
|
||||
//_tables.add("account");
|
||||
_viewTables.put("account_view", _tables);
|
||||
HashSet<String> _tables_1 = new HashSet<String>(1);
|
||||
//_tables_1.add("identity");
|
||||
_viewTables.put("identity_view", _tables_1);
|
||||
HashSet<String> _tables_2 = new HashSet<String>(1);
|
||||
//_tables_2.add("folder");
|
||||
_viewTables.put("folder_view", _tables_2);
|
||||
return new InvalidationTracker(this, _shadowTablesMap, _viewTables, DB_TABLES);
|
||||
}
|
||||
|
||||
static void setupViewInvalidation(Context context) {
|
||||
// This needs to be done on a foreground thread
|
||||
DB db = DB.getInstance(context);
|
||||
@@ -176,7 +160,7 @@ public abstract class DB extends RoomDatabase {
|
||||
if (changed) {
|
||||
Log.i("Invalidating account view");
|
||||
last = accounts;
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("account_view");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -202,7 +186,7 @@ public abstract class DB extends RoomDatabase {
|
||||
if (changed) {
|
||||
Log.i("Invalidating identity view");
|
||||
last = identities;
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("identity_view");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -228,7 +212,7 @@ public abstract class DB extends RoomDatabase {
|
||||
if (changed) {
|
||||
Log.i("Invalidating folder view");
|
||||
last = folders;
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
||||
db.getInvalidationTracker().notifyObserversByTableNames("folder_view");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -240,6 +224,29 @@ public abstract class DB extends RoomDatabase {
|
||||
|
||||
sInstance = migrate(acontext, getBuilder(acontext)).build();
|
||||
|
||||
try {
|
||||
Log.i("Disabling view invalidation");
|
||||
Field fmTableNames = InvalidationTracker.class.getDeclaredField("mTableNames");
|
||||
Field fmViewTables = InvalidationTracker.class.getDeclaredField("mViewTables");
|
||||
|
||||
fmTableNames.setAccessible(true);
|
||||
fmViewTables.setAccessible(true);
|
||||
|
||||
Map<String, Set<String>> mViewTables = (Map) fmViewTables.get(sInstance.getInvalidationTracker());
|
||||
mViewTables.get("account_view").clear();
|
||||
mViewTables.get("identity_view").clear();
|
||||
mViewTables.get("folder_view").clear();
|
||||
|
||||
List<String> tableNames = new ArrayList<>(Arrays.asList(DB_TABLES));
|
||||
tableNames.addAll(mViewTables.keySet());
|
||||
Log.i("Observing invalidation tables=" + TextUtils.join(",", tableNames));
|
||||
fmTableNames.set(sInstance.getInvalidationTracker(), tableNames.toArray(new String[0]));
|
||||
|
||||
Log.i("Disabled view invalidation");
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
sInstance.getInvalidationTracker().addObserver(new InvalidationTracker.Observer(DB.DB_TABLES) {
|
||||
@Override
|
||||
public void onInvalidated(@NonNull Set<String> tables) {
|
||||
|
||||
Reference in New Issue
Block a user