Search in sources :

Example 1 with DialogHandler

use of com.ichi2.anki.dialogs.DialogHandler in project Anki-Android by ankidroid.

the class DeckPicker method onFinishedStartup.

/**
 * Perform the following tasks:
 * Automatic backup
 * loadStudyOptionsFragment() if tablet
 * Automatic sync
 */
private void onFinishedStartup() {
    // create backup in background if needed
    BackupManager.performBackupInBackground(getCol().getPath(), getCol().getTime());
    // Force a full sync if flag was set in upgrade path, asking the user to confirm if necessary
    if (mRecommendFullSync) {
        mRecommendFullSync = false;
        try {
            getCol().modSchema();
        } catch (ConfirmModSchemaException e) {
            Timber.w("Forcing full sync");
            e.log();
            // If libanki determines it's necessary to confirm the full sync then show a confirmation dialog
            // We have to show the dialog via the DialogHandler since this method is called via an async task
            Resources res = getResources();
            Message handlerMessage = Message.obtain();
            handlerMessage.what = DialogHandler.MSG_SHOW_FORCE_FULL_SYNC_DIALOG;
            Bundle handlerMessageData = new Bundle();
            handlerMessageData.putString("message", res.getString(R.string.full_sync_confirmation_upgrade) + "\n\n" + res.getString(R.string.full_sync_confirmation));
            handlerMessage.setData(handlerMessageData);
            getDialogHandler().sendMessage(handlerMessage);
        }
    }
    automaticSync();
}
Also used : Message(android.os.Message) Bundle(android.os.Bundle) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Resources(android.content.res.Resources)

Example 2 with DialogHandler

use of com.ichi2.anki.dialogs.DialogHandler in project AnkiChinaAndroid by ankichinateam.

the class DeckPicker method onFinishedStartup.

/**
 * Perform the following tasks:
 * Automatic backup
 * loadStudyOptionsFragment() if tablet
 * Automatic sync
 */
private void onFinishedStartup() {
    // create backup in background if needed
    if (getCol() == null) {
        return;
    }
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
    if (preferences.getBoolean(AUTO_TURN_TO_LOGIN, true) && !Consts.isLogin()) {
        Intent myAccount = new Intent(this, MyAccount.class);
        myAccount.putExtra("notLoggedIn", true);
        startActivityForResultWithAnimation(myAccount, LOG_IN_FOR_SYNC, ActivityTransitionAnimation.FADE);
        preferences.edit().putBoolean(AUTO_TURN_TO_LOGIN, false).apply();
    }
    BackupManager.performBackupInBackground(getCol().getPath(), getCol().getTime());
    // Force a full sync if flag was set in upgrade path, asking the user to confirm if necessary
    if (mRecommendFullSync) {
        mRecommendFullSync = false;
        try {
            getCol().modSchema();
        } catch (ConfirmModSchemaException e) {
            Timber.w("Forcing full sync");
            // If libanki determines it's necessary to confirm the full sync then show a confirmation dialog
            // We have to show the dialog via the DialogHandler since this method is called via an async task
            Resources res = getResources();
            Message handlerMessage = Message.obtain();
            handlerMessage.what = DialogHandler.MSG_SHOW_FORCE_FULL_SYNC_DIALOG;
            Bundle handlerMessageData = new Bundle();
            handlerMessageData.putString("message", res.getString(R.string.full_sync_confirmation_upgrade) + "\n\n" + res.getString(R.string.full_sync_confirmation));
            handlerMessage.setData(handlerMessageData);
            getDialogHandler().sendMessage(handlerMessage);
        }
    }
    // Open StudyOptionsFragment if in fragmented mode
    automaticSync();
}
Also used : Message(android.os.Message) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Intent(android.content.Intent) Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)2 Bundle (android.os.Bundle)2 Message (android.os.Message)2 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1