use of com.github.moko256.twicalico.entity.Type in project twicalico by moko256.
the class TokenSQLiteOpenHelper method onUpgrade.
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
if (oldVersion == 1) {
Cursor c = sqLiteDatabase.query("AccountTokenList", new String[] { "userName", "userId", "token", "tokenSecret" }, null, null, null, null, null);
AccessToken[] accessTokens = new AccessToken[c.getCount()];
while (c.moveToNext()) {
Integer type;
String url;
String userName;
String tokenSecret = null;
if (c.getString(3).matches(".*\\..*")) {
type = Type.MASTODON;
userName = c.getString(0).split("@")[0];
url = c.getString(3);
} else {
type = Type.TWITTER;
userName = c.getString(0);
url = TWITTER_URL;
tokenSecret = c.getString(3);
}
accessTokens[c.getPosition()] = new AccessToken(type, url, Long.valueOf(c.getString(1)), userName, c.getString(2), tokenSecret);
}
c.close();
sqLiteDatabase.beginTransaction();
sqLiteDatabase.execSQL("DROP TABLE AccountTokenList");
onCreate(sqLiteDatabase);
for (AccessToken accessToken : accessTokens) {
ContentValues contentValues = new ContentValues();
contentValues.put("type", accessToken.getType());
contentValues.put("url", accessToken.getUrl());
contentValues.put("userName", accessToken.getScreenName());
contentValues.put("userId", String.valueOf(accessToken.getUserId()));
contentValues.put("token", accessToken.getToken());
contentValues.put("tokenSecret", accessToken.getTokenSecret());
sqLiteDatabase.replace("AccountTokenList", null, contentValues);
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
}
use of com.github.moko256.twicalico.entity.Type in project twicalico by moko256.
the class TokenSQLiteOpenHelper method onUpgrade.
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
if (oldVersion < 2) {
sqLiteDatabase.execSQL("update " + TABLE_NAME + " set token='',tokenSecret='' where type=0");
}
if (oldVersion < 3) {
TableDBUtilKt.addColumn(sqLiteDatabase, TABLE_NAME, "consumerKey", null);
TableDBUtilKt.addColumn(sqLiteDatabase, TABLE_NAME, "consumerSecret", null);
}
if (oldVersion < 4) {
AccessToken[] accessTokens;
try {
accessTokens = getAccessTokenInternal(sqLiteDatabase);
} catch (Throwable throwable) {
accessTokens = new AccessToken[0];
}
sqLiteDatabase.execSQL("drop table if exists " + TABLE_NAME);
sqLiteDatabase.execSQL("drop index if exists idindex");
onCreate(sqLiteDatabase);
for (AccessToken accessToken : accessTokens) {
addAccessTokenInternal(sqLiteDatabase, accessToken);
}
}
}
Aggregations