Search in sources :

Example 1 with NextcloudApiNotRespondingException

use of com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException 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

Intent (android.content.Intent)1 NextcloudApiNotRespondingException (com.nextcloud.android.sso.exceptions.NextcloudApiNotRespondingException)1 NextcloudFilesAppNotSupportedException (com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotSupportedException)1 NextcloudHttpRequestFailedException (com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException)1 TokenMismatchException (com.nextcloud.android.sso.exceptions.TokenMismatchException)1 UnknownErrorException (com.nextcloud.android.sso.exceptions.UnknownErrorException)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 JSONException (org.json.JSONException)1