Search in sources :

Example 1 with ImportStatus

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());
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) NetworkErrorException(android.accounts.NetworkErrorException) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) NoCurrentAccountSelectedException(com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException) NetworkErrorException(android.accounts.NetworkErrorException) ImportStatus(it.niedermann.owncloud.notes.shared.model.ImportStatus) MutableLiveData(androidx.lifecycle.MutableLiveData) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) AnyThread(androidx.annotation.AnyThread)

Aggregations

NetworkErrorException (android.accounts.NetworkErrorException)1 AnyThread (androidx.annotation.AnyThread)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 NextcloudFilesAppAccountNotFoundException (com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)1 NoCurrentAccountSelectedException (com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException)1 SingleSignOnAccount (com.nextcloud.android.sso.model.SingleSignOnAccount)1 Account (it.niedermann.owncloud.notes.persistence.entity.Account)1 ImportStatus (it.niedermann.owncloud.notes.shared.model.ImportStatus)1