Search in sources :

Example 1 with NextcloudHttpRequestFailedException

use of com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException in project nextcloud-notes by stefan-niedermann.

the class MainViewModel method synchronizeCapabilities.

/**
 * Updates the network status if necessary and pulls the latest {@link Capabilities} of the given {@param localAccount}
 */
public void synchronizeCapabilities(@NonNull Account localAccount, @NonNull IResponseCallback<Void> callback) {
    executor.submit(() -> {
        if (!repo.isSyncPossible()) {
            repo.updateNetworkStatus();
        }
        if (repo.isSyncPossible()) {
            try {
                final var ssoAccount = AccountImporter.getSingleSignOnAccount(getApplication(), localAccount.getAccountName());
                try {
                    final var capabilities = CapabilitiesClient.getCapabilities(getApplication(), ssoAccount, localAccount.getCapabilitiesETag(), ApiProvider.getInstance());
                    repo.updateCapabilitiesETag(localAccount.getId(), capabilities.getETag());
                    repo.updateBrand(localAccount.getId(), capabilities.getColor(), capabilities.getTextColor());
                    localAccount.setColor(capabilities.getColor());
                    localAccount.setTextColor(capabilities.getTextColor());
                    BrandingUtil.saveBrandColors(getApplication(), localAccount.getColor(), localAccount.getTextColor());
                    repo.updateApiVersion(localAccount.getId(), capabilities.getApiVersion());
                    callback.onSuccess(null);
                } catch (Throwable t) {
                    if (t.getClass() == NextcloudHttpRequestFailedException.class || t instanceof NextcloudHttpRequestFailedException) {
                        if (((NextcloudHttpRequestFailedException) t).getStatusCode() == HTTP_NOT_MODIFIED) {
                            Log.d(TAG, "Server returned HTTP Status Code " + ((NextcloudHttpRequestFailedException) t).getStatusCode() + " - Capabilities not modified.");
                            callback.onSuccess(null);
                            return;
                        }
                    }
                    callback.onError(t);
                }
            } catch (NextcloudFilesAppAccountNotFoundException e) {
                repo.deleteAccount(localAccount);
                callback.onError(e);
            }
        } else {
            if (repo.isNetworkConnected() && repo.isSyncOnlyOnWifi()) {
                callback.onError(new IntendedOfflineException("Network is connected, but sync is not possible."));
            } else {
                callback.onError(new NetworkErrorException("Sync is not possible, because network is not connected."));
            }
        }
    }, "SYNC_CAPABILITIES");
}
Also used : NetworkErrorException(android.accounts.NetworkErrorException) IntendedOfflineException(it.niedermann.owncloud.notes.exception.IntendedOfflineException) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)

Example 2 with NextcloudHttpRequestFailedException

use of com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException in project nextcloud-notes by stefan-niedermann.

the class NotesServerSyncTask method pushLocalChanges.

/**
 * Push local changes: for each locally created/edited/deleted Note, use NotesClient in order to push the changed to the server.
 */
private boolean pushLocalChanges() {
    Log.d(TAG, "pushLocalChanges()");
    boolean success = true;
    final var notes = repo.getLocalModifiedNotes(localAccount.getId());
    for (Note note : notes) {
        Log.d(TAG, "   Process Local Note: " + (BuildConfig.DEBUG ? note : note.getTitle()));
        try {
            Note remoteNote;
            switch(note.getStatus()) {
                case LOCAL_EDITED:
                    Log.v(TAG, "   ...create/edit");
                    if (note.getRemoteId() != null) {
                        Log.v(TAG, "   ...Note has remoteId → try to edit");
                        final var editResponse = notesAPI.editNote(note).execute();
                        if (editResponse.isSuccessful()) {
                            remoteNote = editResponse.body();
                            if (remoteNote == null) {
                                Log.e(TAG, "   ...Tried to edit \"" + note.getTitle() + "\" (#" + note.getId() + ") but the server response was null.");
                                throw new Exception("Server returned null after editing \"" + note.getTitle() + "\" (#" + note.getId() + ")");
                            }
                        } else if (editResponse.code() == HTTP_NOT_FOUND) {
                            Log.v(TAG, "   ...Note does no longer exist on server → recreate");
                            final var createResponse = notesAPI.createNote(note).execute();
                            if (createResponse.isSuccessful()) {
                                remoteNote = createResponse.body();
                                if (remoteNote == null) {
                                    Log.e(TAG, "   ...Tried to recreate \"" + note.getTitle() + "\" (#" + note.getId() + ") but the server response was null.");
                                    throw new Exception("Server returned null after recreating \"" + note.getTitle() + "\" (#" + note.getId() + ")");
                                }
                            } else {
                                throw new Exception(createResponse.message());
                            }
                        } else {
                            throw new Exception(editResponse.message());
                        }
                    } else {
                        Log.v(TAG, "   ...Note does not have a remoteId yet → create");
                        final var createResponse = notesAPI.createNote(note).execute();
                        if (createResponse.isSuccessful()) {
                            remoteNote = createResponse.body();
                            if (remoteNote == null) {
                                Log.e(TAG, "   ...Tried to create \"" + note.getTitle() + "\" (#" + note.getId() + ") but the server response was null.");
                                throw new Exception("Server returned null after creating \"" + note.getTitle() + "\" (#" + note.getId() + ")");
                            }
                            repo.updateRemoteId(note.getId(), remoteNote.getRemoteId());
                        } else {
                            throw new Exception(createResponse.message());
                        }
                    }
                    // Please note, that db.updateNote() realized an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
                    repo.updateIfNotModifiedLocallyDuringSync(note.getId(), remoteNote.getModified().getTimeInMillis(), remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getETag(), remoteNote.getContent(), generateNoteExcerpt(remoteNote.getContent(), remoteNote.getTitle()), note.getContent(), note.getCategory(), note.getFavorite());
                    break;
                case LOCAL_DELETED:
                    if (note.getRemoteId() == null) {
                        Log.v(TAG, "   ...delete (only local, since it has never been synchronized)");
                    } else {
                        Log.v(TAG, "   ...delete (from server and local)");
                        final var deleteResponse = notesAPI.deleteNote(note.getRemoteId()).execute();
                        if (!deleteResponse.isSuccessful()) {
                            if (deleteResponse.code() == HTTP_NOT_FOUND) {
                                Log.v(TAG, "   ...delete (note has already been deleted remotely)");
                            } else {
                                throw new Exception(deleteResponse.message());
                            }
                        }
                    }
                    // Please note, that db.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
                    repo.deleteByNoteId(note.getId(), LOCAL_DELETED);
                    break;
                default:
                    throw new IllegalStateException("Unknown State of Note " + note + ": " + note.getStatus());
            }
        } catch (NextcloudHttpRequestFailedException e) {
            if (e.getStatusCode() == HTTP_NOT_MODIFIED) {
                Log.d(TAG, "Server returned HTTP Status Code 304 - Not Modified");
            } else {
                exceptions.add(e);
                success = false;
            }
        } catch (Exception e) {
            if (e instanceof TokenMismatchException) {
                apiProvider.invalidateAPICache(ssoAccount);
            }
            exceptions.add(e);
            success = false;
        }
    }
    return success;
}
Also used : TokenMismatchException(com.nextcloud.android.sso.exceptions.TokenMismatchException) Note(it.niedermann.owncloud.notes.persistence.entity.Note) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) NextcloudApiNotRespondingException(com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) TokenMismatchException(com.nextcloud.android.sso.exceptions.TokenMismatchException) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException)

Example 3 with NextcloudHttpRequestFailedException

use of com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException in project nextcloud-notes by stefan-niedermann.

the class MainActivity method setupNotesList.

private void setupNotesList() {
    adapter = new ItemAdapter(this, gridView);
    listView.setAdapter(adapter);
    listView.setItemAnimator(null);
    if (gridView) {
        final int spanCount = getResources().getInteger(R.integer.grid_view_span_count);
        final var gridLayoutManager = new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL);
        listView.setLayoutManager(gridLayoutManager);
        listView.addItemDecoration(new GridItemDecoration(adapter, spanCount, getResources().getDimensionPixelSize(R.dimen.spacer_3x), getResources().getDimensionPixelSize(R.dimen.spacer_5x), getResources().getDimensionPixelSize(R.dimen.spacer_3x), getResources().getDimensionPixelSize(R.dimen.spacer_1x), getResources().getDimensionPixelSize(R.dimen.spacer_activity_sides) + getResources().getDimensionPixelSize(R.dimen.spacer_1x)));
    } else {
        final var layoutManager = new LinearLayoutManager(this);
        listView.setLayoutManager(layoutManager);
        listView.addItemDecoration(new SectionItemDecoration(adapter, getResources().getDimensionPixelSize(R.dimen.spacer_activity_sides) + getResources().getDimensionPixelSize(R.dimen.spacer_1x) + getResources().getDimensionPixelSize(R.dimen.spacer_3x) + getResources().getDimensionPixelSize(R.dimen.spacer_2x), getResources().getDimensionPixelSize(R.dimen.spacer_5x), getResources().getDimensionPixelSize(R.dimen.spacer_1x), 0));
    }
    listView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0)
                fabCreate.hide();
            else if (dy < 0)
                fabCreate.show();
        }
    });
    swipeRefreshLayout.setOnRefreshListener(() -> {
        CustomAppGlideModule.clearCache(this);
        final var syncLiveData = mainViewModel.getCurrentAccount();
        final Observer<Account> syncObserver = currentAccount -> {
            syncLiveData.removeObservers(this);
            mainViewModel.synchronizeCapabilitiesAndNotes(currentAccount, new IResponseCallback<>() {

                @Override
                public void onSuccess(Void v) {
                    Log.d(TAG, "Successfully synchronized capabilities and notes for " + currentAccount.getAccountName());
                }

                @Override
                public void onError(@NonNull Throwable t) {
                    runOnUiThread(() -> {
                        swipeRefreshLayout.setRefreshing(false);
                        if (t instanceof IntendedOfflineException) {
                            Log.i(TAG, "Capabilities and notes not updated because " + currentAccount.getAccountName() + " is offline by intention.");
                        } else if (t instanceof NextcloudHttpRequestFailedException && ((NextcloudHttpRequestFailedException) t).getStatusCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
                            BrandedSnackbar.make(coordinatorLayout, R.string.error_maintenance_mode, Snackbar.LENGTH_LONG).show();
                        } else if (t instanceof NetworkErrorException) {
                            BrandedSnackbar.make(coordinatorLayout, getString(R.string.error_sync, getString(R.string.error_no_network)), Snackbar.LENGTH_LONG).show();
                        } else {
                            BrandedSnackbar.make(coordinatorLayout, R.string.error_synchronization, Snackbar.LENGTH_LONG).setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(t).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())).show();
                        }
                    });
                }
            });
        };
        syncLiveData.observe(this, syncObserver);
    });
    tracker = ItemSelectionTracker.build(listView, adapter);
    adapter.setTracker(tracker);
    tracker.addObserver(new SelectionTracker.SelectionObserver<Long>() {

        @Override
        public void onSelectionChanged() {
            super.onSelectionChanged();
            if (tracker.hasSelection() && mActionMode == null) {
                mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback(MainActivity.this, coordinatorLayout, mainViewModel, MainActivity.this, canMoveNoteToAnotherAccounts, tracker, getSupportFragmentManager()));
            }
            if (mActionMode != null) {
                if (tracker.hasSelection()) {
                    int selected = tracker.getSelection().size();
                    mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, selected, selected));
                } else {
                    mActionMode.finish();
                    mActionMode = null;
                }
            }
        }
    });
    itemTouchHelper = new NotesListViewItemTouchHelper(this, mainViewModel, this, tracker, adapter, swipeRefreshLayout, coordinatorLayout, gridView);
    itemTouchHelper.attachToRecyclerView(listView);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ImportAccountActivity(it.niedermann.owncloud.notes.importaccount.ImportAccountActivity) NotesApplication.isDarkThemeActive(it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive) Bundle(android.os.Bundle) BrandedSnackbar(it.niedermann.owncloud.notes.branding.BrandedSnackbar) NonNull(androidx.annotation.NonNull) NoteClickListener(it.niedermann.owncloud.notes.shared.model.NoteClickListener) Uri(android.net.Uri) NotesColorUtil.contrastRatioIsSufficient(it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient) AccountPickerListener(it.niedermann.owncloud.notes.accountpicker.AccountPickerListener) SDK_INT(android.os.Build.VERSION.SDK_INT) ItemSelectionTracker(it.niedermann.owncloud.notes.main.items.selection.ItemSelectionTracker) GridItemDecoration(it.niedermann.owncloud.notes.main.items.grid.GridItemDecoration) UNCATEGORIZED(it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED) IntendedOfflineException(it.niedermann.owncloud.notes.exception.IntendedOfflineException) ApiProvider(it.niedermann.owncloud.notes.persistence.ApiProvider) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) ActivityNotesListViewBinding(it.niedermann.owncloud.notes.databinding.ActivityNotesListViewBinding) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ItemAdapter(it.niedermann.owncloud.notes.main.items.ItemAdapter) VISIBLE(android.view.View.VISIBLE) View(android.view.View) CategoryDialogFragment(it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) TokenMismatchException(com.nextcloud.android.sso.exceptions.TokenMismatchException) Log(android.util.Log) AccountSwitcherDialog(it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog) NavigationAdapter(it.niedermann.owncloud.notes.main.navigation.NavigationAdapter) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) O(android.os.Build.VERSION_CODES.O) CategoryViewModel(it.niedermann.owncloud.notes.edit.category.CategoryViewModel) R(it.niedermann.owncloud.notes.R) SearchView(androidx.appcompat.widget.SearchView) PorterDuff(android.graphics.PorterDuff) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) NetworkErrorException(android.accounts.NetworkErrorException) AccountImporter(com.nextcloud.android.sso.AccountImporter) Nullable(androidx.annotation.Nullable) UnknownErrorException(com.nextcloud.android.sso.exceptions.UnknownErrorException) SingleAccountHelper(com.nextcloud.android.sso.helper.SingleAccountHelper) GONE(android.view.View.GONE) RECENT(it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SearchManager(android.app.SearchManager) Snackbar(com.google.android.material.snackbar.Snackbar) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Note(it.niedermann.owncloud.notes.persistence.entity.Note) AlertDialog(androidx.appcompat.app.AlertDialog) LockedActivity(it.niedermann.owncloud.notes.LockedActivity) CategorySortingMethod(it.niedermann.owncloud.notes.shared.model.CategorySortingMethod) NotesApplication.isGridViewEnabled(it.niedermann.owncloud.notes.NotesApplication.isGridViewEnabled) NavigationClickListener(it.niedermann.owncloud.notes.main.navigation.NavigationClickListener) Intent(android.content.Intent) CapabilitiesWorker(it.niedermann.owncloud.notes.persistence.CapabilitiesWorker) DEFAULT_CATEGORY(it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) BrandingUtil.getSecondaryForegroundColorDependingOnTheme(it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme) NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory) CustomAppGlideModule(it.niedermann.owncloud.notes.shared.util.CustomAppGlideModule) NoteUtil(it.niedermann.owncloud.notes.shared.util.NoteUtil) MenuAdapter(it.niedermann.owncloud.notes.main.menu.MenuAdapter) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) RequestOptions(com.bumptech.glide.request.RequestOptions) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ActivityCompat(androidx.core.app.ActivityCompat) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) FAVORITES(it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES) DrawerLayoutBinding(it.niedermann.owncloud.notes.databinding.DrawerLayoutBinding) NotesListViewItemTouchHelper(it.niedermann.owncloud.notes.main.items.list.NotesListViewItemTouchHelper) GravityCompat(androidx.core.view.GravityCompat) AccountImportCancelledException(com.nextcloud.android.sso.exceptions.AccountImportCancelledException) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) CapabilitiesClient(it.niedermann.owncloud.notes.persistence.CapabilitiesClient) NavigationItem(it.niedermann.owncloud.notes.main.navigation.NavigationItem) TextUtils(android.text.TextUtils) AccountSwitcherListener(it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherListener) ShareUtil(it.niedermann.owncloud.notes.shared.util.ShareUtil) ActionMode(androidx.appcompat.view.ActionMode) AnimatorInflater(android.animation.AnimatorInflater) Color(android.graphics.Color) ExceptionDialogFragment(it.niedermann.owncloud.notes.exception.ExceptionDialogFragment) SelectionTracker(androidx.recyclerview.selection.SelectionTracker) NoCurrentAccountSelectedException(com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException) Observer(androidx.lifecycle.Observer) Glide(com.bumptech.glide.Glide) EditNoteActivity(it.niedermann.owncloud.notes.edit.EditNoteActivity) SectionItemDecoration(it.niedermann.owncloud.notes.main.items.section.SectionItemDecoration) SSOUtil.askForNewAccount(it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount) Account(it.niedermann.owncloud.notes.persistence.entity.Account) SSOUtil.askForNewAccount(it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NonNull(androidx.annotation.NonNull) GridItemDecoration(it.niedermann.owncloud.notes.main.items.grid.GridItemDecoration) ItemAdapter(it.niedermann.owncloud.notes.main.items.ItemAdapter) NotesListViewItemTouchHelper(it.niedermann.owncloud.notes.main.items.list.NotesListViewItemTouchHelper) NetworkErrorException(android.accounts.NetworkErrorException) IntendedOfflineException(it.niedermann.owncloud.notes.exception.IntendedOfflineException) ExceptionDialogFragment(it.niedermann.owncloud.notes.exception.ExceptionDialogFragment) ItemSelectionTracker(it.niedermann.owncloud.notes.main.items.selection.ItemSelectionTracker) SelectionTracker(androidx.recyclerview.selection.SelectionTracker) RecyclerView(androidx.recyclerview.widget.RecyclerView) SectionItemDecoration(it.niedermann.owncloud.notes.main.items.section.SectionItemDecoration)

Example 4 with NextcloudHttpRequestFailedException

use of com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException in project nextcloud-notes by stefan-niedermann.

the class TipsAdapter method setThrowables.

public void setThrowables(@NonNull List<Throwable> throwables) {
    for (final var throwable : throwables) {
        if (throwable instanceof TokenMismatchException) {
            add(R.string.error_dialog_tip_token_mismatch_retry);
            add(R.string.error_dialog_tip_token_mismatch_clear_storage);
            final var intent = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_deck_info);
            add(R.string.error_dialog_tip_clear_storage, intent);
        } else if (throwable instanceof NextcloudFilesAppNotSupportedException) {
            add(R.string.error_dialog_tip_files_outdated);
        } else if (throwable instanceof NextcloudApiNotRespondingException) {
            if (VERSION.SDK_INT >= VERSION_CODES.M) {
                add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings));
            } else {
                add(R.string.error_dialog_tip_disable_battery_optimizations);
            }
            add(R.string.error_dialog_tip_files_force_stop);
            add(R.string.error_dialog_tip_files_delete_storage);
            final var intent = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_deck_info);
            add(R.string.error_dialog_tip_clear_storage, intent);
        } else if (throwable instanceof SocketTimeoutException || throwable instanceof ConnectException) {
            add(R.string.error_dialog_timeout_instance);
            add(R.string.error_dialog_timeout_toggle, new Intent(Settings.ACTION_WIFI_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_network));
        } else if (throwable instanceof JSONException || throwable instanceof NullPointerException) {
            add(R.string.error_dialog_check_server);
        } else if (throwable instanceof NextcloudHttpRequestFailedException) {
            final int statusCode = ((NextcloudHttpRequestFailedException) throwable).getStatusCode();
            switch(statusCode) {
                case 302:
                    add(R.string.error_dialog_server_app_enabled);
                    add(R.string.error_dialog_redirect);
                    break;
                case 500:
                    add(R.string.error_dialog_check_server_logs);
                    break;
                case 503:
                    add(R.string.error_dialog_check_maintenance);
                    break;
                case 507:
                    add(R.string.error_dialog_insufficient_storage);
                    break;
            }
        } else if (throwable instanceof UnknownErrorException) {
            if ("com.nextcloud.android.sso.QueryParam".equals(throwable.getMessage())) {
                add(R.string.error_dialog_min_version, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.nextcloud.client")).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_update_files_app));
            }
        }
    }
    notifyDataSetChanged();
}
Also used : TokenMismatchException(com.nextcloud.android.sso.exceptions.TokenMismatchException) SocketTimeoutException(java.net.SocketTimeoutException) UnknownErrorException(com.nextcloud.android.sso.exceptions.UnknownErrorException) NextcloudApiNotRespondingException(com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException) NextcloudHttpRequestFailedException(com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException) JSONException(org.json.JSONException) Intent(android.content.Intent) NextcloudFilesAppNotSupportedException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException) ConnectException(java.net.ConnectException)

Aggregations

NextcloudHttpRequestFailedException (com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException)4 TokenMismatchException (com.nextcloud.android.sso.exceptions.TokenMismatchException)3 NetworkErrorException (android.accounts.NetworkErrorException)2 Intent (android.content.Intent)2 NextcloudFilesAppAccountNotFoundException (com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)2 UnknownErrorException (com.nextcloud.android.sso.exceptions.UnknownErrorException)2 AnimatorInflater (android.animation.AnimatorInflater)1 SearchManager (android.app.SearchManager)1 Color (android.graphics.Color)1 PorterDuff (android.graphics.PorterDuff)1 Uri (android.net.Uri)1 SDK_INT (android.os.Build.VERSION.SDK_INT)1 O (android.os.Build.VERSION_CODES.O)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 View (android.view.View)1 GONE (android.view.View.GONE)1 VISIBLE (android.view.View.VISIBLE)1 NonNull (androidx.annotation.NonNull)1