Skip to content

Commit

Permalink
If no profiles exist, launch createaccount activity first
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Sep 27, 2014
1 parent 5408b05 commit 8bd1543
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/im/tox/antox/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ protected void onCreate(Bundle savedInstanceState) {
}

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if(preferences.getBoolean("loggedin", false)) {

UserDB db = new UserDB(this);

// Check to see if any users exist. If not, start the create account activity instead
if(!db.doUsersExist()) {
Intent createAccount = new Intent(getApplicationContext(), CreateAcccountActivity.class);
startActivity(createAccount);
finish();

} else if(preferences.getBoolean("loggedin", false)) {
/* Attempt to start service in case it's not running */
Intent startTox = new Intent(getApplicationContext(), ToxDoService.class);
getApplicationContext().startService(startTox);
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/im/tox/antox/data/UserDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ public boolean login(String username) {
cursor.close();
db.close();

if(count > 0)
return true;

return false;


return count > 0;
}

public String[] getUserDetails(String username) {
Expand All @@ -94,4 +89,15 @@ public void updateUserDetail(String username, String detail, String newDetail) {
db.execSQL(query);
db.close();
}

public boolean doUsersExist() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT count(*) FROM users", null);
cursor.moveToFirst();
int count = cursor.getInt(0);
cursor.close();
db.close();

return count > 0;
}
}

0 comments on commit 8bd1543

Please sign in to comment.