mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
commit
b215baff39
@ -41,8 +41,8 @@ public class AnkiActivity extends ActionBarActivity implements LoaderManager.Loa
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(SIMPLE_NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
|
@ -417,10 +417,14 @@ public class AnkiDroidApp extends Application {
|
||||
|
||||
|
||||
public static synchronized Collection openCollection(String path) {
|
||||
return openCollection(path, false);
|
||||
}
|
||||
|
||||
public static synchronized Collection openCollection(String path, boolean force) {
|
||||
mLock.lock();
|
||||
Log.i(AnkiDroidApp.TAG, "openCollection: " + path);
|
||||
try {
|
||||
if (!colIsOpen() || !sInstance.mCurrentCollection.getPath().equals(path)) {
|
||||
if (!colIsOpen() || !sInstance.mCurrentCollection.getPath().equals(path) || force) {
|
||||
if (colIsOpen()) {
|
||||
// close old collection prior to opening new one
|
||||
sInstance.mCurrentCollection.close();
|
||||
|
@ -819,15 +819,19 @@ public class DeckPicker extends NavigationDrawerActivity implements OnShowcaseEv
|
||||
// Start import process if apkg file was opened via another app
|
||||
Intent intent = getIntent();
|
||||
if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
|
||||
if (mHandler == null) {
|
||||
mHandler = new DialogHandler(this);
|
||||
}
|
||||
if (mImportPath.split("/")[mImportPath.split("/").length - 1].equals("collection.apkg")) {
|
||||
// Show confirmation dialog asking to confirm import with replace when file called "collection.apkg"
|
||||
mHandler.sendEmptyMessage(MSG_SHOW_COLLECTION_IMPORT_REPLACE_DIALOG);
|
||||
if ((new File(mImportPath)).exists()) {
|
||||
if (mHandler == null) {
|
||||
mHandler = new DialogHandler(this);
|
||||
}
|
||||
if (mImportPath.split("/")[mImportPath.split("/").length - 1].equals("collection.apkg")) {
|
||||
// Show confirmation dialog asking to confirm import with replace when file called "collection.apkg"
|
||||
mHandler.sendEmptyMessage(MSG_SHOW_COLLECTION_IMPORT_REPLACE_DIALOG);
|
||||
} else {
|
||||
// Otherwise show confirmation dialog asking to confirm import with add
|
||||
mHandler.sendEmptyMessage(MSG_SHOW_COLLECTION_IMPORT_ADD_DIALOG);
|
||||
}
|
||||
} else {
|
||||
// Otherwise show confirmation dialog asking to confirm import with add
|
||||
mHandler.sendEmptyMessage(MSG_SHOW_COLLECTION_IMPORT_ADD_DIALOG);
|
||||
Themes.showThemedToast(this, getResources().getString(R.string.import_log_no_apkg), true);
|
||||
}
|
||||
} else if (intent!= null && intent.getExtras()!= null && intent.getExtras().getBoolean("showAsyncDialogFragment")) {
|
||||
Message m = Message.obtain();
|
||||
@ -1662,7 +1666,7 @@ public class DeckPicker extends NavigationDrawerActivity implements OnShowcaseEv
|
||||
} else if (did != null) {
|
||||
// filename not explicitly specified, but a deck has been specified so use deck name
|
||||
try {
|
||||
exportPath = new File(exportDir, getCol().getDecks().get(did).getString("name") + ".apkg");
|
||||
exportPath = new File(exportDir, getCol().getDecks().get(did).getString("name").replaceAll("\\W+", "_") + ".apkg");
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -57,12 +57,12 @@ public class IntentHandler extends Activity {
|
||||
}
|
||||
// Copy to temp file
|
||||
if (filename != null && filename.endsWith(".apkg")) {
|
||||
File tempImportPath = new File(getCacheDir(), filename);
|
||||
Uri importUri = Uri.fromFile(new File(getCacheDir(), filename));
|
||||
try {
|
||||
// Get an input stream to the data in ContentProvider
|
||||
InputStream in = getContentResolver().openInputStream(intent.getData());
|
||||
// Create new output stream in temporary path
|
||||
OutputStream out = new FileOutputStream(tempImportPath);
|
||||
OutputStream out = new FileOutputStream(importUri.getEncodedPath());
|
||||
// Copy the input stream to temporary file
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
@ -77,7 +77,7 @@ public class IntentHandler extends Activity {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
// Replace the intent URI with the URI to temporary file
|
||||
reloadIntent.setData(Uri.fromFile(tempImportPath));
|
||||
reloadIntent.setData(importUri);
|
||||
reloadIntent.putExtra("deleteTempFile", true);
|
||||
} else {
|
||||
// Don't import the file if it didn't load properly or doesn't have apkg extension
|
||||
|
@ -232,9 +232,13 @@ public class Preferences extends PreferenceActivity implements OnSharedPreferenc
|
||||
Preference fullSyncPreference = (Preference) getPreferenceScreen().findPreference("force_full_sync");
|
||||
fullSyncPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
mCol.modSchema(true);
|
||||
mCol.setMod();
|
||||
Toast.makeText(getApplicationContext(), R.string.ok , Toast.LENGTH_SHORT).show();
|
||||
if (mCol != null && mCol.getDb()!= null) {
|
||||
mCol.modSchema(true);
|
||||
mCol.setMod();
|
||||
Toast.makeText(getApplicationContext(), R.string.ok , Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.vague_error , Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -134,8 +134,7 @@ public class TagsDialog extends DialogFragment implements OnDismissListener, OnC
|
||||
builder.setPositiveButton(res.getString(R.string.select), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mCurrentTags.addAll(mStyledDialog.getCheckedItems());
|
||||
mTagsDialogListener.onPositive(new ArrayList<String>(mCurrentTags), mSelectedOption);
|
||||
mTagsDialogListener.onPositive(new ArrayList<String>(mStyledDialog.getCheckedItems()), mSelectedOption);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(res.getString(R.string.cancel), mNegativeButtonListener);
|
||||
|
@ -912,10 +912,14 @@ public class DeckTask extends BaseAsyncTask<DeckTask.TaskData, DeckTask.TaskData
|
||||
// overwrite collection
|
||||
colPath = AnkiDroidApp.getCollectionPath();
|
||||
File f = new File(colFile);
|
||||
f.renameTo(new File(colPath));
|
||||
if (!f.renameTo(new File(colPath))) {
|
||||
// Exit early if this didn't work
|
||||
return new TaskData(-2, null, false);
|
||||
}
|
||||
int addedCount = -1;
|
||||
try {
|
||||
col = AnkiDroidApp.openCollection(colPath);
|
||||
// open using force close of old collection, as background loader may have reopened the col
|
||||
col = AnkiDroidApp.openCollection(colPath, true);
|
||||
|
||||
// because users don't have a backup of media, it's safer to import new
|
||||
// data and rely on them running a media db check to get rid of any
|
||||
|
Loading…
Reference in New Issue
Block a user