use of it.niedermann.owncloud.notes.shared.model.ImportStatus in project nextcloud-notes by stefan-niedermann.
the class NotesRepository method addAccount.
// Accounts
@AnyThread
public LiveData<ImportStatus> addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities, @Nullable String displayName, @NonNull IResponseCallback<Account> callback) {
final var account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account(url, username, accountName, displayName, capabilities)));
if (account == null) {
callback.onError(new Exception("Could not read created account."));
} else {
if (isSyncPossible()) {
syncActive.put(account.getId(), true);
try {
Log.d(TAG, "… starting now");
final NotesImportTask importTask = new NotesImportTask(context, this, account, importExecutor, apiProvider);
return importTask.importNotes(new IResponseCallback<>() {
@Override
public void onSuccess(Void result) {
callback.onSuccess(account);
}
@Override
public void onError(@NonNull Throwable t) {
callback.onError(t);
}
});
} catch (NextcloudFilesAppAccountNotFoundException e) {
Log.e(TAG, "… Could not find " + SingleSignOnAccount.class.getSimpleName() + " for account name " + account.getAccountName());
callback.onError(e);
}
} else {
callback.onError(new NetworkErrorException());
}
}
return new MutableLiveData<>(new ImportStatus());
}
Aggregations