|
|
@ -24,9 +24,11 @@ import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
|
|
|
|
import android.provider.OpenableColumns;
|
|
|
|
import android.text.Html;
|
|
|
|
import android.text.Html;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
@ -36,6 +38,7 @@ import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.AutoCompleteTextView;
|
|
|
|
import android.widget.AutoCompleteTextView;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.EditText;
|
|
|
@ -47,6 +50,9 @@ import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -67,6 +73,7 @@ import androidx.lifecycle.Observer;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.content.AsyncTaskLoader;
|
|
|
|
import androidx.loader.content.AsyncTaskLoader;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
|
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
|
|
|
|
|
|
|
@ -84,10 +91,12 @@ public class FragmentCompose extends FragmentEx {
|
|
|
|
private AutoCompleteTextView etBcc;
|
|
|
|
private AutoCompleteTextView etBcc;
|
|
|
|
private ImageView ivBccAdd;
|
|
|
|
private ImageView ivBccAdd;
|
|
|
|
private EditText etSubject;
|
|
|
|
private EditText etSubject;
|
|
|
|
|
|
|
|
private RecyclerView rvAttachment;
|
|
|
|
private EditText etBody;
|
|
|
|
private EditText etBody;
|
|
|
|
private BottomNavigationView bottom_navigation;
|
|
|
|
private BottomNavigationView bottom_navigation;
|
|
|
|
private ProgressBar pbWait;
|
|
|
|
private ProgressBar pbWait;
|
|
|
|
private Group grpCc;
|
|
|
|
private Group grpAddresses;
|
|
|
|
|
|
|
|
private Group grpAttachments;
|
|
|
|
private Group grpReady;
|
|
|
|
private Group grpReady;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -112,10 +121,12 @@ public class FragmentCompose extends FragmentEx {
|
|
|
|
etBcc = view.findViewById(R.id.etBcc);
|
|
|
|
etBcc = view.findViewById(R.id.etBcc);
|
|
|
|
ivBccAdd = view.findViewById(R.id.ivBccAdd);
|
|
|
|
ivBccAdd = view.findViewById(R.id.ivBccAdd);
|
|
|
|
etSubject = view.findViewById(R.id.etSubject);
|
|
|
|
etSubject = view.findViewById(R.id.etSubject);
|
|
|
|
|
|
|
|
rvAttachment = view.findViewById(R.id.rvAttachment);
|
|
|
|
etBody = view.findViewById(R.id.etBody);
|
|
|
|
etBody = view.findViewById(R.id.etBody);
|
|
|
|
bottom_navigation = view.findViewById(R.id.bottom_navigation);
|
|
|
|
bottom_navigation = view.findViewById(R.id.bottom_navigation);
|
|
|
|
pbWait = view.findViewById(R.id.pbWait);
|
|
|
|
pbWait = view.findViewById(R.id.pbWait);
|
|
|
|
grpCc = view.findViewById(R.id.grpCc);
|
|
|
|
grpAddresses = view.findViewById(R.id.grpAddresses);
|
|
|
|
|
|
|
|
grpAttachments = view.findViewById(R.id.grpAttachments);
|
|
|
|
grpReady = view.findViewById(R.id.grpReady);
|
|
|
|
grpReady = view.findViewById(R.id.grpReady);
|
|
|
|
|
|
|
|
|
|
|
|
// Wire controls
|
|
|
|
// Wire controls
|
|
|
@ -183,7 +194,8 @@ public class FragmentCompose extends FragmentEx {
|
|
|
|
// Initialize
|
|
|
|
// Initialize
|
|
|
|
spFrom.setVisibility(View.GONE);
|
|
|
|
spFrom.setVisibility(View.GONE);
|
|
|
|
ivIdentityAdd.setVisibility(View.GONE);
|
|
|
|
ivIdentityAdd.setVisibility(View.GONE);
|
|
|
|
grpCc.setVisibility(View.GONE);
|
|
|
|
grpAddresses.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
grpAttachments.setVisibility(View.GONE);
|
|
|
|
grpReady.setVisibility(View.GONE);
|
|
|
|
grpReady.setVisibility(View.GONE);
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
bottom_navigation.getMenu().setGroupEnabled(0, false);
|
|
|
|
bottom_navigation.getMenu().setGroupEnabled(0, false);
|
|
|
@ -276,69 +288,135 @@ public class FragmentCompose extends FragmentEx {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_message, menu);
|
|
|
|
inflater.inflate(R.menu.menu_compose, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_address:
|
|
|
|
case R.id.menu_attachment:
|
|
|
|
onMenuCc();
|
|
|
|
onMenuAttachment();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case R.id.menu_addresses:
|
|
|
|
|
|
|
|
onMenuAddresses();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void onMenuCc() {
|
|
|
|
private void onMenuAttachment() {
|
|
|
|
grpCc.setVisibility(grpCc.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
|
|
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
|
|
|
|
intent.setType("*/*");
|
|
|
|
|
|
|
|
startActivityForResult(intent, ActivityCompose.REQUEST_ATTACHMENT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onMenuAddresses() {
|
|
|
|
|
|
|
|
grpAddresses.setVisibility(grpAddresses.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
if (requestCode == ActivityCompose.REQUEST_ATTACHMENT) {
|
|
|
|
try {
|
|
|
|
if (data != null) {
|
|
|
|
cursor = getContext().getContentResolver().query(data.getData(),
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
new String[]{
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
|
|
|
new SimpleLoader() {
|
|
|
|
ContactsContract.Contacts.DISPLAY_NAME
|
|
|
|
@Override
|
|
|
|
},
|
|
|
|
public Object onLoad(Bundle args) throws IOException {
|
|
|
|
null, null, null);
|
|
|
|
Uri uri = args.getParcelable("uri");
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
int colEmail = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS);
|
|
|
|
try {
|
|
|
|
int colName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
|
|
|
|
cursor = getActivity().getContentResolver().query(uri, null, null, null, null, null);
|
|
|
|
String email = cursor.getString(colEmail);
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
String name = cursor.getString(colName);
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
|
|
|
attachment.name = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
|
|
|
String text = null;
|
|
|
|
|
|
|
|
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
|
|
|
|
String extension = MimeTypeMap.getFileExtensionFromUrl(attachment.name.toLowerCase());
|
|
|
|
text = etTo.getText().toString();
|
|
|
|
if (extension != null)
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
|
|
|
|
attachment.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
|
|
|
text = etCc.getText().toString();
|
|
|
|
if (extension == null)
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
|
|
|
|
attachment.type = "application/octet-stream";
|
|
|
|
text = etBcc.getText().toString();
|
|
|
|
|
|
|
|
|
|
|
|
InputStream is = null;
|
|
|
|
InternetAddress address = new InternetAddress(email, name);
|
|
|
|
try {
|
|
|
|
StringBuilder sb = new StringBuilder(text);
|
|
|
|
is = getContext().getContentResolver().openInputStream(uri);
|
|
|
|
if (sb.length() > 0)
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
sb.append("; ");
|
|
|
|
|
|
|
|
sb.append(address.toString());
|
|
|
|
int len;
|
|
|
|
|
|
|
|
byte[] buffer = new byte[8192];
|
|
|
|
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
|
|
|
|
while ((len = is.read(buffer)) > 0)
|
|
|
|
etTo.setText(sb.toString());
|
|
|
|
bos.write(buffer, 0, len);
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
|
|
|
|
|
|
|
|
etCc.setText(sb.toString());
|
|
|
|
attachment.size = bos.size();
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
|
|
|
|
attachment.content = bos.toByteArray();
|
|
|
|
etBcc.setText(sb.toString());
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (is != null)
|
|
|
|
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return attachment;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onLoaded(Bundle args, Result result) {
|
|
|
|
|
|
|
|
EntityAttachment attachment = (EntityAttachment) result.data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(this, ActivityCompose.LOADER_COMPOSE_ATTACHMENT, args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
cursor = getContext().getContentResolver().query(data.getData(),
|
|
|
|
|
|
|
|
new String[]{
|
|
|
|
|
|
|
|
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
|
|
|
|
|
|
|
ContactsContract.Contacts.DISPLAY_NAME
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
null, null, null);
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
|
|
|
int colEmail = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS);
|
|
|
|
|
|
|
|
int colName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
|
|
|
|
|
|
|
|
String email = cursor.getString(colEmail);
|
|
|
|
|
|
|
|
String name = cursor.getString(colName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String text = null;
|
|
|
|
|
|
|
|
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
|
|
|
|
|
|
|
|
text = etTo.getText().toString();
|
|
|
|
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
|
|
|
|
|
|
|
|
text = etCc.getText().toString();
|
|
|
|
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
|
|
|
|
|
|
|
|
text = etBcc.getText().toString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InternetAddress address = new InternetAddress(email, name);
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(text);
|
|
|
|
|
|
|
|
if (sb.length() > 0)
|
|
|
|
|
|
|
|
sb.append("; ");
|
|
|
|
|
|
|
|
sb.append(address.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
|
|
|
|
|
|
|
|
etTo.setText(sb.toString());
|
|
|
|
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
|
|
|
|
|
|
|
|
etCc.setText(sb.toString());
|
|
|
|
|
|
|
|
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
|
|
|
|
|
|
|
|
etBcc.setText(sb.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
|
|
|
|
Toast.makeText(getContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
|
|
|
|
Toast.makeText(getContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -465,7 +543,7 @@ public class FragmentCompose extends FragmentEx {
|
|
|
|
String action = result.getString("action");
|
|
|
|
String action = result.getString("action");
|
|
|
|
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
grpCc.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
|
|
|
|
grpAddresses.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
|
|
|
|
grpReady.setVisibility(View.VISIBLE);
|
|
|
|
grpReady.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
|
|
FragmentCompose.this.thread = thread;
|
|
|
|
FragmentCompose.this.thread = thread;
|
|
|
|