mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-01 04:17:21 +01:00
database bug fix
Signed-off-by: nuclearfog <hatespirit666@gmail.com>
This commit is contained in:
parent
0bfbd410c3
commit
1339ee0d7d
@ -280,7 +280,8 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
||||
// reset twitter singleton
|
||||
TwitterEngine.resetTwitter();
|
||||
// remove account from database
|
||||
AccountDatabase.getInstance(this).removeLogin(settings.getCurrentUserId());
|
||||
AccountDatabase accountDB = new AccountDatabase(this);
|
||||
accountDB.removeLogin(settings.getCurrentUserId());
|
||||
settings.logout();
|
||||
setResult(RETURN_APP_LOGOUT);
|
||||
finish();
|
||||
|
@ -28,7 +28,7 @@ public class AccountLoader extends AsyncTask<Account, Void, List<Account>> {
|
||||
public AccountLoader(AccountFragment fragment) {
|
||||
super();
|
||||
callback = new WeakReference<>(fragment);
|
||||
accountDatabase = AccountDatabase.getInstance(fragment.requireContext());
|
||||
accountDatabase = new AccountDatabase(fragment.requireContext());
|
||||
appDatabase = new AppDatabase(fragment.requireContext());
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class Registration extends AsyncTask<String, Void, String> {
|
||||
super();
|
||||
this.callback = new WeakReference<>(activity);
|
||||
// init database and storage
|
||||
accountDB = AccountDatabase.getInstance(activity);
|
||||
accountDB = new AccountDatabase(activity);
|
||||
settings = GlobalSettings.getInstance(activity);
|
||||
mTwitter = TwitterEngine.getEmptyInstance(activity);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class UserAction extends AsyncTask<UserAction.Action, User, Relation> {
|
||||
super();
|
||||
this.callback = new WeakReference<>(callback);
|
||||
mTwitter = TwitterEngine.getInstance(callback);
|
||||
exclDB = ExcludeDatabase.getInstance(callback);
|
||||
exclDB = new ExcludeDatabase(callback);
|
||||
appDB = new AppDatabase(callback);
|
||||
this.userId = userId;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class UserExcludeLoader extends AsyncTask<String, Void, Void> {
|
||||
public UserExcludeLoader(UserExclude callback, Mode mode) {
|
||||
super();
|
||||
mTwitter = TwitterEngine.getInstance(callback);
|
||||
excludeDatabase = ExcludeDatabase.getInstance(callback);
|
||||
excludeDatabase = new ExcludeDatabase(callback);
|
||||
this.callback = new WeakReference<>(callback);
|
||||
this.mode = mode;
|
||||
}
|
||||
|
@ -124,8 +124,8 @@ public class TwitterEngine {
|
||||
mTwitter.isInitialized = true;
|
||||
// initialize database and settings
|
||||
mTwitter.settings = GlobalSettings.getInstance(context);
|
||||
mTwitter.accountDB = AccountDatabase.getInstance(context);
|
||||
mTwitter.excludeDB = ExcludeDatabase.getInstance(context);
|
||||
mTwitter.accountDB = new AccountDatabase(context);
|
||||
mTwitter.excludeDB = new ExcludeDatabase(context);
|
||||
// check if already logged in
|
||||
if (mTwitter.settings.isLoggedIn()) {
|
||||
// init login access
|
||||
@ -148,7 +148,7 @@ public class TwitterEngine {
|
||||
public static TwitterEngine getEmptyInstance(Context context) {
|
||||
// initialize storage
|
||||
mTwitter.settings = GlobalSettings.getInstance(context);
|
||||
mTwitter.accountDB = AccountDatabase.getInstance(context);
|
||||
mTwitter.accountDB = new AccountDatabase(context);
|
||||
// init empty session
|
||||
mTwitter.isInitialized = false;
|
||||
mTwitter.initTwitter(null);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.nuclearfog.twidda.database;
|
||||
|
||||
import static android.database.sqlite.SQLiteDatabase.CONFLICT_REPLACE;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
@ -11,8 +13,6 @@ import org.nuclearfog.twidda.database.DatabaseAdapter.AccountTable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.database.sqlite.SQLiteDatabase.CONFLICT_REPLACE;
|
||||
|
||||
/**
|
||||
* this database stores multi user logins
|
||||
*
|
||||
@ -41,27 +41,14 @@ public class AccountDatabase {
|
||||
*/
|
||||
private static final String SORT_BY_CREATION = AccountTable.DATE + " DESC";
|
||||
|
||||
/**
|
||||
* singleton instance
|
||||
*/
|
||||
private static final AccountDatabase INSTANCE = new AccountDatabase();
|
||||
|
||||
|
||||
private DatabaseAdapter dataHelper;
|
||||
|
||||
|
||||
private AccountDatabase() {
|
||||
}
|
||||
|
||||
/**
|
||||
* get singleton instance
|
||||
*
|
||||
* @return instance
|
||||
* @param context current activity context
|
||||
*/
|
||||
public static AccountDatabase getInstance(Context context) {
|
||||
if (INSTANCE.dataHelper == null)
|
||||
INSTANCE.dataHelper = DatabaseAdapter.getInstance(context.getApplicationContext());
|
||||
return INSTANCE;
|
||||
public AccountDatabase(Context context) {
|
||||
dataHelper = DatabaseAdapter.getInstance(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,7 +236,7 @@ public class AppDatabase {
|
||||
private DatabaseAdapter adapter;
|
||||
|
||||
/**
|
||||
* initialize database
|
||||
* @param context activity context
|
||||
*/
|
||||
public AppDatabase(Context context) {
|
||||
adapter = DatabaseAdapter.getInstance(context);
|
||||
|
@ -186,24 +186,24 @@ public class DatabaseAdapter {
|
||||
/**
|
||||
* singleton instance
|
||||
*/
|
||||
private static DatabaseAdapter instance;
|
||||
private static final DatabaseAdapter INSTANCE = new DatabaseAdapter();
|
||||
|
||||
/**
|
||||
* path to the database file
|
||||
*/
|
||||
private final File databasePath;
|
||||
private File databasePath;
|
||||
|
||||
/**
|
||||
* database
|
||||
*/
|
||||
private SQLiteDatabase db;
|
||||
|
||||
private boolean isInitialized = false;
|
||||
|
||||
private DatabaseAdapter(Context context) {
|
||||
databasePath = context.getDatabasePath(DB_NAME);
|
||||
db = context.openOrCreateDatabase(databasePath.toString(), MODE_PRIVATE, null);
|
||||
initTables();
|
||||
updateTable();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private DatabaseAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,7 +212,6 @@ public class DatabaseAdapter {
|
||||
* @return SQLite database
|
||||
*/
|
||||
public synchronized SQLiteDatabase getDatabase() {
|
||||
// TODO add Multithreading safety
|
||||
if (!db.isOpen())
|
||||
db = SQLiteDatabase.openOrCreateDatabase(databasePath, null);
|
||||
return db;
|
||||
@ -225,9 +224,9 @@ public class DatabaseAdapter {
|
||||
* @return database instance
|
||||
*/
|
||||
public static DatabaseAdapter getInstance(@NonNull Context context) {
|
||||
if (instance == null)
|
||||
instance = new DatabaseAdapter(context.getApplicationContext());
|
||||
return instance;
|
||||
if (!INSTANCE.isInitialized)
|
||||
INSTANCE.init(context.getApplicationContext());
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +236,20 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
public static void deleteDatabase(Context c) {
|
||||
SQLiteDatabase.deleteDatabase(c.getDatabasePath(DB_NAME));
|
||||
instance = null;
|
||||
INSTANCE.init(c.getApplicationContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize databases
|
||||
*
|
||||
* @param c application context
|
||||
*/
|
||||
private void init(Context c) {
|
||||
databasePath = c.getDatabasePath(DB_NAME);
|
||||
db = c.openOrCreateDatabase(databasePath.toString(), MODE_PRIVATE, null);
|
||||
initTables();
|
||||
updateTable();
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,6 +300,12 @@ public class DatabaseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return databasePath.toString() + ":" + db.getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* table for user information
|
||||
*/
|
||||
|
@ -34,26 +34,15 @@ public class ExcludeDatabase {
|
||||
private static final String[] LIST_ID_COL = {UserExcludeTable.ID};
|
||||
|
||||
|
||||
private static final ExcludeDatabase INSTANCE = new ExcludeDatabase();
|
||||
private DatabaseAdapter dataHelper;
|
||||
private GlobalSettings settings;
|
||||
|
||||
|
||||
private ExcludeDatabase() {
|
||||
}
|
||||
|
||||
/**
|
||||
* get singleton instance
|
||||
*
|
||||
* @param context activity context
|
||||
* @return instance of this class
|
||||
* @param context current context
|
||||
*/
|
||||
public static ExcludeDatabase getInstance(Context context) {
|
||||
if (INSTANCE.dataHelper == null) {
|
||||
INSTANCE.dataHelper = DatabaseAdapter.getInstance(context.getApplicationContext());
|
||||
INSTANCE.settings = GlobalSettings.getInstance(context);
|
||||
}
|
||||
return INSTANCE;
|
||||
public ExcludeDatabase(Context context) {
|
||||
dataHelper = DatabaseAdapter.getInstance(context);
|
||||
settings = GlobalSettings.getInstance(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user