use of com.ichi2.async.CollectionTask.TASK_TYPE.EXPORT_APKG in project AnkiChinaAndroid by ankichinateam.
the class AnkiActivity method exportApkg.
@Override
public void exportApkg(String filename, Long did, boolean includeSched, boolean includeMedia, boolean exportCard, boolean exportApkg) {
File exportDir = new File(getExternalCacheDir(), "export");
exportDir.mkdirs();
File exportPath;
String timeStampSuffix = "-" + TimeUtils.getTimestamp(getCol().getTime());
if (filename != null) {
// filename has been explicitly specified
exportPath = new File(exportDir, filename);
} else if (did != null) {
// filename not explicitly specified, but a deck has been specified so use deck name
exportPath = new File(exportDir, getCol().getDecks().get(did).getString("name").replaceAll("\\W+", "_") + timeStampSuffix + ".apkg");
} else if (!includeSched) {
// full export without scheduling is assumed to be shared with someone else -- use "All Decks.apkg"
exportPath = new File(exportDir, "All Decks" + timeStampSuffix + ".apkg");
} else {
// full collection export -- use "collection.colpkg"
File colPath = new File(getCol().getPath());
String newFileName = colPath.getName().replace(".anki2", timeStampSuffix + ".colpkg");
exportPath = new File(exportDir, newFileName);
}
// add input arguments to new generic structure
Object[] inputArgs = new Object[7];
inputArgs[0] = getCol();
inputArgs[1] = exportPath.getPath();
inputArgs[2] = did;
inputArgs[3] = includeSched;
inputArgs[4] = includeMedia;
inputArgs[5] = exportApkg;
inputArgs[6] = exportCard;
try {
CollectionTask.launchCollectionTask(EXPORT_APKG, exportListener(), new TaskData(inputArgs));
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.EXPORT_APKG in project AnkiChinaAndroid by ankichinateam.
the class ExportDialog method onCreateDialog.
@Override
public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
final Long did = getArguments().getLong("did", -1L);
Integer[] checked;
final String[] items;
if (did != -1L) {
mIncludeSched = false;
checked = new Integer[] { EXPORT_APKG };
items = new String[] { res.getString(R.string.export_include_schedule), res.getString(R.string.export_include_media), "Apkg格式", "Card格式" };
} else {
mIncludeSched = true;
checked = new Integer[] { INCLUDE_SCHED };
items = new String[] { res.getString(R.string.export_include_schedule), res.getString(R.string.export_include_media) };
}
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.export).content(getArguments().getString("dialogMessage")).positiveText(android.R.string.ok).negativeText(android.R.string.cancel).cancelable(true).items(items).alwaysCallMultiChoiceCallback().itemsCallbackMultiChoice(checked, (materialDialog, integers, charSequences) -> {
mIncludeMedia = false;
mIncludeSched = false;
mExportApkg = false;
mExportCard = false;
for (Integer integer : integers) {
switch(integer) {
case INCLUDE_SCHED:
mIncludeSched = true;
break;
case INCLUDE_MEDIA:
mIncludeMedia = true;
break;
case EXPORT_CARD:
mExportCard = true;
// mExportApkg = false;
break;
case EXPORT_APKG:
mExportApkg = true;
// mExportCard = false;
break;
}
}
return true;
}).onPositive((dialog, which) -> {
if (mExportApkg && mExportCard) {
Toast.makeText(getContext(), "不能同时导出Apkg和Card格式", Toast.LENGTH_SHORT).show();
return;
}
if (did != -1L && !mExportApkg && !mExportCard) {
Toast.makeText(getContext(), "请至少选择一种导出格式", Toast.LENGTH_SHORT).show();
return;
}
listener.exportApkg(null, did != -1L ? did : null, mIncludeSched, mIncludeMedia, mExportCard, mExportApkg);
dismissAllDialogFragments();
}).onNegative((dialog, which) -> dismissAllDialogFragments());
return builder.show();
}
Aggregations