mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-01 04:17:21 +01:00
database bug fix
This commit is contained in:
parent
31badd586b
commit
01dc245f2d
@ -40,6 +40,7 @@ public class AccountAction extends AsyncExecutor<AccountAction.Param, AccountAct
|
||||
} else {
|
||||
settings.setPushEnabled(false);
|
||||
}
|
||||
database.resetDatabase();
|
||||
return new Result(Result.SELECT, param.account);
|
||||
|
||||
case Param.REMOVE:
|
||||
|
@ -1102,21 +1102,42 @@ public class AppDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* remove database tables except account table
|
||||
* reset database tables
|
||||
* re-create database tables and keep all login and web push subscriptions
|
||||
*/
|
||||
public void resetDatabase() {
|
||||
synchronized (adapter) {
|
||||
// save logins first
|
||||
List<Account> logins = getLogins();
|
||||
List<WebPush> webPushs = getWebPushs();
|
||||
// reset database
|
||||
adapter.resetDatabase();
|
||||
// restore saved logins
|
||||
for (Account login : logins) {
|
||||
saveLogin(login);
|
||||
}
|
||||
// restore web push subscription
|
||||
for (WebPush webPush : webPushs) {
|
||||
savePushSubscription(webPush);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all web push subscriptions
|
||||
*/
|
||||
private List<WebPush> getWebPushs() {
|
||||
List<WebPush> result = new LinkedList<>();
|
||||
|
||||
SQLiteDatabase db = adapter.getDbRead();
|
||||
Cursor c = db.query(PushTable.TABLE, DatabasePush.COLUMNS, null, null, null, null, null);
|
||||
if (c.moveToFirst()) {
|
||||
result.add(new DatabasePush(c));
|
||||
}
|
||||
c.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* get status information from database
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user