Created
March 4, 2014 04:18
-
-
Save anirudh24seven/9340209 to your computer and use it in GitHub Desktop.
WordPress for Android - initWpDb() and createAndVerifyWpDb in WordPress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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