Search in sources :

Example 6 with AsyncDialogFragment

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

the class DeckPicker method showSyncErrorDialog.

/**
 * Show a specific sync error dialog
 *
 * @param id      id of dialog to show
 * @param message text to show
 */
public void showSyncErrorDialog(int id, String message) {
    AsyncDialogFragment newFragment = SyncErrorDialog.newInstance(id, message, this);
    showAsyncDialogFragment(newFragment, NotificationChannels.Channel.SYNC);
}
Also used : AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment)

Example 7 with AsyncDialogFragment

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

the class AnkiActivity method showImportDialog.

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void showImportDialog(int id, String message) {
    // On API19+ we only use import dialog to confirm, otherwise we use it the whole time
    if ((CompatHelper.getSdkVersion() < 19) || (id == ImportDialog.DIALOG_IMPORT_ADD_CONFIRM) || (id == ImportDialog.DIALOG_IMPORT_REPLACE_CONFIRM)) {
        Timber.d("showImportDialog() delegating to ImportDialog");
        AsyncDialogFragment newFragment = ImportDialog.newInstance(id, message, this);
        showAsyncDialogFragment(newFragment);
    } else {
        Timber.d("showImportDialog() delegating to file picker intent");
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
        intent.putExtra("android.content.extra.FANCY", true);
        intent.putExtra("android.content.extra.SHOW_FILESIZE", true);
        startActivityForResultWithoutAnimation(intent, PICK_APKG_FILE);
    }
}
Also used : AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment) PendingIntent(android.app.PendingIntent) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Example 8 with AsyncDialogFragment

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

the class AnkiActivity method showSimpleMessageDialog.

protected void showSimpleMessageDialog(String title, @Nullable String message, boolean reload) {
    AsyncDialogFragment newFragment = SimpleMessageDialog.newInstance(title, message, reload);
    showAsyncDialogFragment(newFragment);
}
Also used : AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment)

Example 9 with AsyncDialogFragment

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

the class DialogHandler method handleMessage.

@Override
public void handleMessage(Message msg) {
    Bundle msgData = msg.getData();
    String messageName = sMessageNameList[msg.what];
    UsageAnalytics.sendAnalyticsScreenView(messageName);
    Timber.i("Handling Message: %s", messageName);
    if (msg.what == MSG_SHOW_COLLECTION_LOADING_ERROR_DIALOG) {
        // Collection could not be opened
        mActivity.get().showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_LOAD_FAILED);
    } else if (msg.what == MSG_SHOW_COLLECTION_IMPORT_REPLACE_DIALOG) {
        // Handle import of collection package APKG
        mActivity.get().showImportDialog(ImportDialog.DIALOG_IMPORT_REPLACE_CONFIRM, msgData.getString("importPath"));
    } else if (msg.what == MSG_SHOW_COLLECTION_IMPORT_ADD_DIALOG) {
        // Handle import of deck package APKG
        mActivity.get().showImportDialog(ImportDialog.DIALOG_IMPORT_ADD_CONFIRM, msgData.getString("importPath"));
    } else if (msg.what == MSG_SHOW_SYNC_ERROR_DIALOG) {
        if (mActivity.get() instanceof DeckPicker) {
            int id = msgData.getInt("dialogType");
            String message = msgData.getString("dialogMessage");
            ((DeckPicker) mActivity.get()).showSyncErrorDialog(id, message);
        }
    } else if (msg.what == MSG_SHOW_EXPORT_COMPLETE_DIALOG) {
        // Export complete
        AsyncDialogFragment f = DeckPickerExportCompleteDialog.newInstance(msgData.getString("exportPath"));
        mActivity.get().showAsyncDialogFragment(f);
    } else if (msg.what == MSG_SHOW_MEDIA_CHECK_COMPLETE_DIALOG) {
        if (mActivity.get() instanceof DeckPicker) {
            // Media check results
            int id = msgData.getInt("dialogType");
            if (id != MediaCheckDialog.DIALOG_CONFIRM_MEDIA_CHECK) {
                List<List<String>> checkList = new ArrayList<>();
                checkList.add(msgData.getStringArrayList("nohave"));
                checkList.add(msgData.getStringArrayList("unused"));
                checkList.add(msgData.getStringArrayList("invalid"));
                ((DeckPicker) mActivity.get()).showMediaCheckDialog(id, checkList);
            }
        }
    } else if (msg.what == MSG_SHOW_DATABASE_ERROR_DIALOG) {
        // Database error dialog
        mActivity.get().showDatabaseErrorDialog(msgData.getInt("dialogType"));
    } else if (msg.what == MSG_SHOW_FORCE_FULL_SYNC_DIALOG) {
        // Confirmation dialog for forcing full sync
        ConfirmationDialog dialog = new ConfirmationDialog();
        Runnable confirm = new Runnable() {

            @Override
            public void run() {
                // Bypass the check once the user confirms
                CollectionHelper.getInstance().getCol(AnkiDroidApp.getInstance()).modSchemaNoCheck();
            }
        };
        dialog.setConfirm(confirm);
        dialog.setArgs(msgData.getString("message"));
        (mActivity.get()).showDialogFragment(dialog);
    } else if (msg.what == MSG_DO_SYNC) {
        if (mActivity.get() instanceof DeckPicker) {
            SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(mActivity.get());
            Resources res = mActivity.get().getResources();
            Collection col = mActivity.get().getCol();
            String hkey = preferences.getString("hkey", "");
            long millisecondsSinceLastSync = col.getTime().intTimeMS() - preferences.getLong("lastSyncTime", 0);
            boolean limited = millisecondsSinceLastSync < INTENT_SYNC_MIN_INTERVAL;
            if (!limited && hkey.length() > 0 && Connection.isOnline()) {
                ((DeckPicker) mActivity.get()).sync();
            } else {
                String err = res.getString(R.string.sync_error);
                if (limited) {
                    long remainingTimeInSeconds = Math.max((INTENT_SYNC_MIN_INTERVAL - millisecondsSinceLastSync) / 1000, 1);
                    // getQuantityString needs an int
                    int remaining = (int) Math.min(Integer.MAX_VALUE, remainingTimeInSeconds);
                    String message = res.getQuantityString(R.plurals.sync_automatic_sync_needs_more_time, remaining, remaining);
                    mActivity.get().showSimpleNotification(err, message, NotificationChannels.Channel.SYNC);
                } else {
                    mActivity.get().showSimpleNotification(err, res.getString(R.string.youre_offline), NotificationChannels.Channel.SYNC);
                }
            }
            mActivity.get().finishWithoutAnimation();
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Collection(com.ichi2.libanki.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Resources(android.content.res.Resources) DeckPicker(com.ichi2.anki.DeckPicker)

Example 10 with AsyncDialogFragment

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

the class DeckPicker method showDatabaseErrorDialog.

// Show dialogs to deal with database loading issues etc
public void showDatabaseErrorDialog(int id) {
    AsyncDialogFragment newFragment = DatabaseErrorDialog.newInstance(id);
    showAsyncDialogFragment(newFragment);
}
Also used : AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment)

Aggregations

AsyncDialogFragment (com.ichi2.anki.dialogs.AsyncDialogFragment)9 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Dialog (android.app.Dialog)1 PendingIntent (android.app.PendingIntent)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 Color (android.graphics.Color)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Environment (android.os.Environment)1 TextUtils (android.text.TextUtils)1 Gravity (android.view.Gravity)1 KeyEvent (android.view.KeyEvent)1