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);
}
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);
}
}
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);
}
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();
}
}
}
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);
}
Aggregations