Search in sources :

Example 1 with StartupFailure

use of com.ichi2.anki.InitialActivity.StartupFailure in project Anki-Android by ankidroid.

the class DeckPicker method handleStartup.

/**
 * The first call in showing dialogs for startup - error or success.
 * Attempts startup if storage permission has been acquired, else, it requests the permission
 */
public void handleStartup() {
    if (Permissions.hasStorageAccessPermission(this)) {
        StartupFailure failure = InitialActivity.getStartupFailureType(this);
        if (failure == null) {
            // Show any necessary dialogs (e.g. changelog, special messages, etc)
            SharedPreferences sharedPrefs = AnkiDroidApp.getSharedPrefs(this);
            showStartupScreensAndDialogs(sharedPrefs, 0);
            mStartupError = false;
        } else {
            // Show error dialogs
            handleStartupFailure(failure);
            mStartupError = true;
        }
    } else {
        requestStoragePermission();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) StartupFailure(com.ichi2.anki.InitialActivity.StartupFailure)

Example 2 with StartupFailure

use of com.ichi2.anki.InitialActivity.StartupFailure in project Anki-Android by ankidroid.

the class DeckPicker method handleStartupFailure.

@VisibleForTesting
void handleStartupFailure(StartupFailure failure) {
    switch(failure) {
        case SD_CARD_NOT_MOUNTED:
            Timber.i("SD card not mounted");
            onSdCardNotMounted();
            break;
        case DIRECTORY_NOT_ACCESSIBLE:
            Timber.i("AnkiDroid directory inaccessible");
            Intent i = Preferences.AdvancedSettingsFragment.getSubscreenIntent(this);
            startActivityForResultWithoutAnimation(i, REQUEST_PATH_UPDATE);
            UIUtils.showThemedToast(this, R.string.directory_inaccessible, false);
            break;
        case FUTURE_ANKIDROID_VERSION:
            Timber.i("Displaying database versioning");
            showDatabaseErrorDialog(DatabaseErrorDialog.INCOMPATIBLE_DB_VERSION);
            break;
        case DATABASE_LOCKED:
            Timber.i("Displaying database locked error");
            showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_DB_LOCKED);
            break;
        case DATABASE_DOWNGRADE_REQUIRED:
            // This has a callback to continue with handleStartup
            InitialActivity.downgradeBackend(this);
            break;
        case WEBVIEW_FAILED:
            new MaterialDialog.Builder(this).title(R.string.ankidroid_init_failed_webview_title).content(getString(R.string.ankidroid_init_failed_webview, AnkiDroidApp.getWebViewErrorMessage())).positiveText(R.string.close).onPositive((d, w) -> exit()).cancelable(false).show();
            break;
        case DB_ERROR:
        default:
            displayDatabaseFailure();
    }
}
Also used : BadgeDrawableBuilder(com.ichi2.ui.BadgeDrawableBuilder) Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 StartupFailure (com.ichi2.anki.InitialActivity.StartupFailure)1 BadgeDrawableBuilder (com.ichi2.ui.BadgeDrawableBuilder)1