Skip to content

Instantly share code, notes, and snippets.

@anirudh24seven
Created March 4, 2014 04:18
Show Gist options
  • Save anirudh24seven/9340209 to your computer and use it in GitHub Desktop.
Save anirudh24seven/9340209 to your computer and use it in GitHub Desktop.
WordPress for Android - initWpDb() and createAndVerifyWpDb in WordPress.java
...
private void initWpDb() {
if (!createAndVerifyWpDb()) {
AppLog.e(T.DB, "Invalid database, sign out user and delete database");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
currentBlog = null;
editor.remove(WordPress.WPCOM_USERNAME_PREFERENCE);
editor.remove(WordPress.WPCOM_PASSWORD_PREFERENCE);
editor.remove(WordPress.ACCESS_TOKEN_PREFERENCE);
editor.commit();
if (wpDB != null) {
wpDB.updateLastBlogId(-1);
wpDB.deleteDatabase(this);
}
wpDB = new WordPressDB(this);
}
}
private boolean createAndVerifyWpDb() {
try {
wpDB = new WordPressDB(this);
// verify account data
List<Map<String, Object>> accounts = wpDB.getAllAccounts();
for (Map<String, Object> account : accounts) {
if (account == null || account.get("blogName") == null || account.get("url") == null) {
return false;
}
}
return true;
} catch (SQLiteException sqle) {
AppLog.e(T.DB, sqle);
return false;
} catch (RuntimeException re) {
AppLog.e(T.DB, re);
return false;
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment