mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Save attachments in background thread
This commit is contained in:
parent
a7b16c1210
commit
da51bdf1b3
@ -138,19 +138,7 @@ public class AttachmentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveLocalAttachmentTo(File directory) {
|
private void saveLocalAttachmentTo(File directory) {
|
||||||
//FIXME: write file in background thread
|
new SaveAttachmentAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, directory);
|
||||||
try {
|
|
||||||
File file = saveAttachmentWithUniqueFileName(directory);
|
|
||||||
|
|
||||||
displayAttachmentSavedMessage(file.toString());
|
|
||||||
|
|
||||||
MediaScannerNotifier.notify(context, file);
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
if (K9.DEBUG) {
|
|
||||||
Log.e(K9.LOG_TAG, "Error saving attachment", ioe);
|
|
||||||
}
|
|
||||||
displayAttachmentNotSavedMessage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File saveAttachmentWithUniqueFileName(File directory) throws IOException {
|
private File saveAttachmentWithUniqueFileName(File directory) throws IOException {
|
||||||
@ -346,4 +334,36 @@ public class AttachmentController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SaveAttachmentAsyncTask extends AsyncTask<File, Void, File> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
messageViewFragment.disableAttachmentButtons(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected File doInBackground(File... params) {
|
||||||
|
try {
|
||||||
|
File directory = params[0];
|
||||||
|
return saveAttachmentWithUniqueFileName(directory);
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (K9.DEBUG) {
|
||||||
|
Log.e(K9.LOG_TAG, "Error saving attachment", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(File file) {
|
||||||
|
messageViewFragment.enableAttachmentButtons(attachment);
|
||||||
|
if (file != null) {
|
||||||
|
displayAttachmentSavedMessage(file.toString());
|
||||||
|
MediaScannerNotifier.notify(context, file);
|
||||||
|
} else {
|
||||||
|
displayAttachmentNotSavedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user