Create NotesClient in updateAccount when null

This commit is contained in:
stefan-niedermann 2019-10-04 17:46:52 +02:00
parent a85e93e1fb
commit 99d0bf944e

View file

@ -76,19 +76,6 @@ public class NoteServerSyncHelper {
} }
}; };
public void updateAccount(){
try {
if(notesClient != null) {
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");
};
private final BroadcastReceiver networkReceiver = new BroadcastReceiver() { private final BroadcastReceiver networkReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -131,6 +118,23 @@ public class NoteServerSyncHelper {
updateNetworkStatus(); updateNetworkStatus();
} }
public void updateAccount() {
try {
this.localAccount = dbHelper.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(appContext).name);
if (notesClient == null) {
if(this.localAccount != null) {
notesClient = new NotesClient(appContext, localAccount.getToken());
}
} else {
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");
}
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
appContext.unregisterReceiver(networkReceiver); appContext.unregisterReceiver(networkReceiver);
@ -282,7 +286,7 @@ public class NoteServerSyncHelper {
* Push local changes: for each locally created/edited/deleted Note, use NotesClient in order to push the changed to the server. * Push local changes: for each locally created/edited/deleted Note, use NotesClient in order to push the changed to the server.
*/ */
private void pushLocalChanges() { private void pushLocalChanges() {
if(localAccount == null) { if (localAccount == null) {
return; return;
} }
Log.d(getClass().getSimpleName(), "pushLocalChanges()"); Log.d(getClass().getSimpleName(), "pushLocalChanges()");
@ -331,7 +335,7 @@ public class NoteServerSyncHelper {
* Pull remote Changes: update or create each remote note (if local pendant has no changes) and remove remotely deleted notes. * Pull remote Changes: update or create each remote note (if local pendant has no changes) and remove remotely deleted notes.
*/ */
private LoginStatus pullRemoteChanges() { private LoginStatus pullRemoteChanges() {
if(localAccount == null) { if (localAccount == null) {
return LoginStatus.NO_NETWORK; return LoginStatus.NO_NETWORK;
} }
Log.d(getClass().getSimpleName(), "pullRemoteChanges() for account " + localAccount.getAccountName()); Log.d(getClass().getSimpleName(), "pullRemoteChanges() for account " + localAccount.getAccountName());