Commit 156897f1 authored by a-iv's avatar a-iv

Merge pull request #141 from vkotovv/history_export

Export chat in the background thread
parents 79d1abb6 b53e23a8
...@@ -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,26 +746,51 @@ public class ChatViewer extends ManagedActivity implements ...@@ -745,26 +746,51 @@ 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;
} }
if (builder.isSendChecked()) { return file;
Intent intent = new Intent(android.content.Intent.ACTION_SEND); }
intent.setType("text/plain");
Uri uri = Uri.fromFile(file); @Override
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri); public void onPostExecute(File result) {
startActivity(Intent.createChooser(intent, if (result != null) {
getString(R.string.export_chat))); if (builder.isSendChecked()) {
} else { Intent intent = new Intent(android.content.Intent.ACTION_SEND);
Toast.makeText(this, R.string.export_chat_done, intent.setType("text/plain");
Toast.LENGTH_LONG).show(); Uri uri = Uri.fromFile(result);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent,
getString(R.string.export_chat)));
} else {
Toast.makeText(ChatViewer.this, R.string.export_chat_done,
Toast.LENGTH_LONG).show();
}
} }
} }
} }
@Override @Override
......
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