database bug fix

This commit is contained in:
nuclearfog 2022-12-07 21:08:04 +01:00
parent 7a9be36e79
commit 50e7b3c52d
No known key found for this signature in database
GPG Key ID: 03488A185C476379
3 changed files with 19 additions and 20 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId 'org.nuclearfog.twidda'
minSdkVersion 21
targetSdkVersion 33
versionCode 66
versionName '3.0a'
versionCode 67
versionName '3.0b'
resConfigs 'en', 'de-rDE', 'zh-rCN'
}

View File

@ -681,7 +681,7 @@ public class Mastodon implements Connection {
ResponseBody body = response.body();
if (response.code() == 200 && body != null) {
JSONObject json = new JSONObject(body.string());
return new MastodonUser(json, settings.getLogin().getId());
return new MastodonUser(json);
}
throw new MastodonException(response);
} catch (IOException | JSONException e) {

View File

@ -4,6 +4,7 @@ import static android.content.Context.MODE_PRIVATE;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import androidx.annotation.NonNull;
@ -19,7 +20,7 @@ public class DatabaseAdapter {
/**
* database version
*/
private static final int DB_VERSION = 10;
private static final int DB_VERSION = 9;
/**
* database file name
@ -128,7 +129,7 @@ public class DatabaseAdapter {
/**
* SQL query to create a table for user logins
*/
private static final String TABLE_LOGINS = "CREATE TABLE IF NOT EXISTS "
private static final String TABLE_ACCOUNTS = "CREATE TABLE IF NOT EXISTS "
+ AccountTable.NAME + "("
+ AccountTable.ID + " INTEGER PRIMARY KEY,"
+ AccountTable.DATE + " INTEGER,"
@ -143,7 +144,7 @@ public class DatabaseAdapter {
/**
* SQL query to create user exclude table
*/
private static final String TABLE_USER_EXCLUDE = "CREATE TABLE IF NOT EXISTS "
private static final String TABLE_USER_BLOCKLIST = "CREATE TABLE IF NOT EXISTS "
+ UserExcludeTable.NAME + "("
+ UserExcludeTable.OWNER + " INTEGER,"
+ UserExcludeTable.ID + " INTEGER);";
@ -208,11 +209,6 @@ public class DatabaseAdapter {
*/
private static final String UPDATE_ADD_BEARER = "ALTER TABLE " + AccountTable.NAME + " ADD " + AccountTable.BEARER + " TEXT;";
/**
* update account table to add API client secret
*/
private static final String UPDATE_ADD_NOTIFICATION_USER = "ALTER TABLE " + NotificationTable.NAME + " ADD " + NotificationTable.USER + " INTEGER;";
/**
* singleton instance
*/
@ -252,8 +248,15 @@ public class DatabaseAdapter {
* @return database instance
*/
public static DatabaseAdapter getInstance(@NonNull Context context) {
if (INSTANCE.db == null)
INSTANCE.init(context.getApplicationContext());
if (INSTANCE.db == null) {
try {
INSTANCE.init(context.getApplicationContext());
} catch (SQLiteException e) {
// if database is corrupted, clear and create a new one
e.printStackTrace();
deleteDatabase(context);
}
}
return INSTANCE;
}
@ -282,8 +285,8 @@ public class DatabaseAdapter {
db.execSQL(TABLE_FAVORITES);
db.execSQL(TABLE_TRENDS);
db.execSQL(TABLE_MESSAGES);
db.execSQL(TABLE_LOGINS);
db.execSQL(TABLE_USER_EXCLUDE);
db.execSQL(TABLE_ACCOUNTS);
db.execSQL(TABLE_USER_BLOCKLIST);
db.execSQL(TABLE_STATUS_REGISTER);
db.execSQL(TABLE_USER_REGISTER);
db.execSQL(TABLE_NOTIFICATION);
@ -309,12 +312,8 @@ public class DatabaseAdapter {
db.execSQL(UPDATE_ADD_REPLY_COUNT);
db.setVersion(8);
}
if (db.getVersion() < 9) {
db.execSQL(UPDATE_ADD_BEARER);
db.setVersion(9);
}
if (db.getVersion() < DB_VERSION) {
db.execSQL(UPDATE_ADD_NOTIFICATION_USER);
db.execSQL(UPDATE_ADD_BEARER);
db.setVersion(DB_VERSION);
}
}