Commit b53e23a8 authored by Vadim Kotov's avatar Vadim Kotov

Export chat in the background thread

parent f99f705f
...@@ -21,6 +21,7 @@ import android.app.Dialog; ...@@ -21,6 +21,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.view.ContextMenu; import android.view.ContextMenu;
...@@ -745,28 +746,53 @@ public class ChatViewer extends ManagedActivity implements ...@@ -745,28 +746,53 @@ public class ChatViewer extends ManagedActivity implements
switch (dialogBuilder.getDialogId()) { switch (dialogBuilder.getDialogId()) {
case DIALOG_EXPORT_CHAT_ID: case DIALOG_EXPORT_CHAT_ID:
ExportChatDialogBuilder builder = (ExportChatDialogBuilder) dialogBuilder; ExportChatDialogBuilder builder = (ExportChatDialogBuilder) dialogBuilder;
File file; exportChat(builder);
}
}
private void exportChat(ExportChatDialogBuilder dialogBuilder) {
//TODO: retain AsyncTask via retained fragment
new ChatExportAsyncTask(dialogBuilder).execute();
}
private class ChatExportAsyncTask extends AsyncTask<Void, Void, File> {
private ExportChatDialogBuilder builder;
public ChatExportAsyncTask(ExportChatDialogBuilder builder) {
this.builder = builder;
}
@Override
protected File doInBackground(Void... params) {
File file = null;
try { try {
file = MessageManager.getInstance().exportChat( file = MessageManager.getInstance().exportChat(
actionWithAccount, actionWithUser, builder.getName()); actionWithAccount, actionWithUser, builder.getName());
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
return;
} }
return file;
}
@Override
public void onPostExecute(File result) {
if (result != null) {
if (builder.isSendChecked()) { if (builder.isSendChecked()) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND); Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain"); intent.setType("text/plain");
Uri uri = Uri.fromFile(file); Uri uri = Uri.fromFile(result);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri); intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, startActivity(Intent.createChooser(intent,
getString(R.string.export_chat))); getString(R.string.export_chat)));
} else { } else {
Toast.makeText(this, R.string.export_chat_done, Toast.makeText(ChatViewer.this, R.string.export_chat_done,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
} }
} }
}
@Override @Override
public void onDecline(DialogBuilder dialogBuilder) { public void onDecline(DialogBuilder dialogBuilder) {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment