Store account token in database

This commit is contained in:
stefan-niedermann 2019-10-04 17:26:48 +02:00
parent 1c3db28fc5
commit cf886e4490
3 changed files with 6 additions and 5 deletions

View file

@ -118,7 +118,8 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
key_url + " TEXT, " +
key_username + " TEXT, " +
key_account_name + " TEXT UNIQUE, " +
key_display_name + " TEXT)");
key_display_name + " TEXT, " +
key_token + " TEXT)");
createAccountIndexes(db);
}

View file

@ -79,12 +79,12 @@ public class NoteServerSyncHelper {
public void updateAccount(){
try {
this.localAccount = dbHelper.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(appContext).name);
notesClient.updateAccount(localAccount.getToken());
Log.v("Notes", "NextcloudRequest account: " + localAccount);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
}
Log.v("Note", "Reinstanziation NotesClient because of SSO acc changed");
notesClient.updateAccount();
};
private final BroadcastReceiver networkReceiver = new BroadcastReceiver() {
@ -112,6 +112,7 @@ public class NoteServerSyncHelper {
this.appContext = db.getContext().getApplicationContext();
try {
this.localAccount = db.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(appContext).name);
notesClient = new NotesClient(appContext, localAccount.getToken());
Log.v("Notes", "NextcloudRequest account: " + localAccount);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
@ -120,7 +121,6 @@ public class NoteServerSyncHelper {
// Registers BroadcastReceiver to track network connection changes.
appContext.registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
notesClient = new NotesClient(appContext);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.appContext);
prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);

View file

@ -74,7 +74,7 @@ public class NotesClient {
public static final String JSON_MODIFIED = "modified";
private static final String application_json = "application/json";
public NotesClient(Context context) {
public NotesClient(Context context, String token) {
this.context = context;
try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
@ -95,7 +95,7 @@ public class NotesClient {
}
}
public void updateAccount() {
public void updateAccount(String token) {
if(mNextcloudAPI != null) {
mNextcloudAPI.stop();
}