Use dialog fragment to select colors

pull/157/head
M66B 6 years ago
parent d2b0cba6a6
commit 0f7f0e1ad3

@ -45,15 +45,6 @@ import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class ActivityCompose extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
static final int REQUEST_CONTACT_TO = 1;
static final int REQUEST_CONTACT_CC = 2;
static final int REQUEST_CONTACT_BCC = 3;
static final int REQUEST_IMAGE = 4;
static final int REQUEST_ATTACHMENT = 5;
static final int REQUEST_TAKE_PHOTO = 6;
static final int REQUEST_RECORD_AUDIO = 7;
static final int REQUEST_ENCRYPT = 8;
static final int PI_REPLY = 1;
static final String ACTION_SHOW_PRO = BuildConfig.APPLICATION_ID + ".SHOW_PRO";

@ -68,9 +68,6 @@ import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
@ -117,9 +114,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
static final int REQUEST_ERROR = 5;
static final int REQUEST_UPDATE = 6;
static final int REQUEST_SENDER = 1;
static final int REQUEST_RECIPIENT = 2;
static final String ACTION_VIEW_FOLDERS = BuildConfig.APPLICATION_ID + ".VIEW_FOLDERS";
static final String ACTION_VIEW_MESSAGES = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGES";
static final String ACTION_SEARCH = BuildConfig.APPLICATION_ID + ".SEARCH";
@ -129,7 +123,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
static final String ACTION_EDIT_ANSWER = BuildConfig.APPLICATION_ID + ".EDIT_ANSWER";
static final String ACTION_EDIT_RULES = BuildConfig.APPLICATION_ID + ".EDIT_RULES";
static final String ACTION_EDIT_RULE = BuildConfig.APPLICATION_ID + ".EDIT_RULE";
static final String ACTION_COLOR = BuildConfig.APPLICATION_ID + ".COLOR";
static final String ACTION_PRINT = BuildConfig.APPLICATION_ID + ".PRINT";
static final String ACTION_SHOW_PRO = BuildConfig.APPLICATION_ID + ".SHOW_PRO";
@ -514,7 +507,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
iff.addAction(ACTION_EDIT_ANSWER);
iff.addAction(ACTION_EDIT_RULES);
iff.addAction(ACTION_EDIT_RULE);
iff.addAction(ACTION_COLOR);
iff.addAction(ACTION_PRINT);
iff.addAction(ACTION_SHOW_PRO);
lbm.registerReceiver(receiver, iff);
@ -939,8 +931,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
onEditRules(intent);
else if (ACTION_EDIT_RULE.equals(action))
onEditRule(intent);
else if (ACTION_COLOR.equals(action))
onColor(intent);
else if (ACTION_PRINT.equals(action))
onPrint(intent);
else if (ACTION_SHOW_PRO.equals(action))
@ -1045,53 +1035,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
fragmentTransaction.commit();
}
private void onColor(final Intent intent) {
int color = intent.getIntExtra("color", -1);
int[] colors = getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(this);
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
if (!Helper.isPro(ActivityView.this)) {
onShowPro(null);
return;
}
Bundle args = new Bundle();
args.putLong("id", intent.getLongExtra("id", -1));
args.putInt("color", color);
new SimpleTask<Void>() {
@Override
protected Void onExecute(final Context context, Bundle args) {
final long id = args.getLong("id");
final int color = args.getInt("color");
final DB db = DB.getInstance(context);
db.runInTransaction(new Runnable() {
@Override
public void run() {
EntityMessage message = db.message().getMessage(id);
if (message == null)
return;
EntityOperation.queue(context, message, EntityOperation.FLAG, true, color);
}
});
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
}
}.execute(ActivityView.this, ActivityView.this, args, "message:color");
}
});
colorPickerDialog.show(getSupportFragmentManager(), "colorpicker");
}
private void onPrint(Intent intent) {
long id = intent.getLongExtra("id", -1);

@ -85,6 +85,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@ -143,7 +144,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private Context context;
private LayoutInflater inflater;
private LifecycleOwner owner;
private View parentView;
private Fragment parentFragment;
private ViewType viewType;
private boolean compact;
private int zoom;
@ -411,7 +412,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
rvImage.setLayoutManager(sglm);
adapterImage = new AdapterImage(context, owner, parentView);
adapterImage = new AdapterImage(context, owner, parentFragment.getView());
rvImage.setAdapter(adapterImage);
grpAddresses = vsBody.findViewById(R.id.grpAddresses);
@ -1491,7 +1492,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
DateFormat day = new SimpleDateFormat("E");
Snackbar.make(
parentView,
parentFragment.getView(),
day.format(message.ui_snoozed) + " " + df.format(message.ui_snoozed),
Snackbar.LENGTH_LONG).show();
}
@ -1701,7 +1702,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
PackageManager pm = context.getPackageManager();
if (edit.resolveActivity(pm) == null)
Snackbar.make(parentView, R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
Snackbar.make(parentFragment.getView(),
R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
else
context.startActivity(edit);
}
@ -2481,12 +2483,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void onMenuColoredStar(final TupleMessageEx message) {
Intent color = new Intent(ActivityView.ACTION_COLOR);
color.putExtra("id", message.id);
color.putExtra("color", message.color == null ? Color.TRANSPARENT : message.color);
int color = (message.color == null ? Color.TRANSPARENT : message.color);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(color);
Bundle args = new Bundle();
args.putLong("id", message.id);
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_flag_color, color, args, context);
fragment.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_COLOR);
fragment.show(parentFragment.getFragmentManager(), "message:color");
}
private void onMenuDelete(final TupleMessageEx message) {
@ -2790,7 +2795,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
PackageManager pm = context.getPackageManager();
if (share.resolveActivity(pm) == null)
Snackbar.make(parentView, R.string.title_no_viewer, Snackbar.LENGTH_LONG).show();
Snackbar.make(parentFragment.getView(),
R.string.title_no_viewer, Snackbar.LENGTH_LONG).show();
else
context.startActivity(share);
}
@ -3078,7 +3084,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private void onActionMove(final TupleMessageEx message, final boolean copy) {
DialogFolder.show(
context, owner, parentView,
context, owner, parentFragment.getView(),
copy ? R.string.title_copy_to : R.string.title_move_to_folder,
message.account, Arrays.asList(message.folder),
new DialogFolder.IDialogFolder() {
@ -3290,7 +3296,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
protected void onExecuted(Bundle args, List<EntityAnswer> answers) {
if (answers == null || answers.size() == 0) {
Snackbar snackbar = Snackbar.make(
parentView,
parentFragment.getView(),
context.getString(R.string.title_no_answers),
Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@ -3352,7 +3358,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
AdapterMessage(Context context, LifecycleOwner owner, View parentView,
AdapterMessage(Context context, LifecycleOwner owner, Fragment parentFragment,
ViewType viewType, boolean compact, int zoom, String sort, boolean filter_duplicates, final IProperties properties) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -3361,7 +3367,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.context = context;
this.owner = owner;
this.inflater = LayoutInflater.from(context);
this.parentView = parentView;
this.parentFragment = parentFragment;
this.viewType = viewType;
this.compact = compact;
this.zoom = zoom;

@ -1,35 +0,0 @@
package eu.faircode.email;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
import com.android.colorpicker.ColorPickerDialog;
public class ColorPickerDialogEx extends ColorPickerDialog implements LifecycleObserver {
private LifecycleOwner owner;
private ColorPickerDialogEx() {
}
ColorPickerDialogEx(LifecycleOwner owner) {
super();
this.owner = owner;
}
@Override
public void show(@NonNull FragmentManager manager, @Nullable String tag) {
owner.getLifecycle().addObserver(this);
super.show(manager, tag);
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onOwnerPause() {
dismiss();
this.owner = null;
}
}

@ -55,8 +55,6 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
import com.sun.mail.imap.IMAPFolder;
@ -75,6 +73,7 @@ import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;
import static android.app.Activity.RESULT_OK;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
@ -142,6 +141,8 @@ public class FragmentAccount extends FragmentBase {
private boolean saving = false;
private int color = Color.TRANSPARENT;
private static final int REQUEST_COLOR = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -290,22 +291,10 @@ public class FragmentAccount extends FragmentBase {
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_SHOW_PRO));
return;
}
setColor(color);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_account_color, color, new Bundle(), getContext());
fragment.setTargetFragment(FragmentAccount.this, REQUEST_COLOR);
fragment.show(getFragmentManager(), "account:color");
}
});
@ -1311,6 +1300,26 @@ public class FragmentAccount extends FragmentBase {
.show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_COLOR:
if (resultCode == RESULT_OK && data != null) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_SHOW_PRO));
return;
}
Bundle args = data.getBundleExtra("args");
setColor(args.getInt("color"));
}
break;
}
}
private void setColor(int color) {
this.color = color;

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -27,6 +28,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
@ -114,6 +116,13 @@ public class FragmentBase extends Fragment {
super.onPause();
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Log.i("Result class=" + this.getClass().getSimpleName() +
" request=" + requestCode + " result=" + resultCode + " data=" + data);
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onDetach() {
super.onDetach();

@ -0,0 +1,67 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import com.android.colorpicker.ColorPickerDialog;
import static android.app.Activity.RESULT_OK;
public class FragmentColor extends ColorPickerDialog {
private Bundle args;
public void initialize(int title, int color, Bundle args, Context context) {
this.args = args;
int[] colors = context.getResources().getIntArray(R.array.colorPicker);
super.initialize(title, colors, color, 4, colors.length);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null)
this.args = savedInstanceState.getBundle("fair:extra");
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBundle("fair:extra", args);
super.onSaveInstanceState(outState);
}
@Override
public void onColorSelected(int color) {
Fragment target = getTargetFragment();
if (target != null) {
args.putInt("color", color);
Intent data = new Intent();
data.putExtra("args", args);
target.onActivityResult(getTargetRequestCode(), RESULT_OK, data);
}
dismiss();
}
}

@ -105,8 +105,6 @@ import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
import com.google.android.material.snackbar.Snackbar;
@ -207,6 +205,16 @@ public class FragmentCompose extends FragmentBase {
private static final int ADDRESS_ELLIPSIZE = 50;
private static final int REQUEST_CONTACT_TO = 1;
private static final int REQUEST_CONTACT_CC = 2;
private static final int REQUEST_CONTACT_BCC = 3;
private static final int REQUEST_IMAGE = 4;
private static final int REQUEST_ATTACHMENT = 5;
private static final int REQUEST_TAKE_PHOTO = 6;
private static final int REQUEST_RECORD_AUDIO = 7;
private static final int REQUEST_ENCRYPT = 8;
private static final int REQUEST_COLOR = 9;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -284,13 +292,13 @@ public class FragmentCompose extends FragmentBase {
int request;
switch (view.getId()) {
case R.id.ivToAdd:
request = ActivityCompose.REQUEST_CONTACT_TO;
request = REQUEST_CONTACT_TO;
break;
case R.id.ivCcAdd:
request = ActivityCompose.REQUEST_CONTACT_CC;
request = REQUEST_CONTACT_CC;
break;
case R.id.ivBccAdd:
request = ActivityCompose.REQUEST_CONTACT_BCC;
request = REQUEST_CONTACT_BCC;
break;
default:
return;
@ -1113,7 +1121,7 @@ public class FragmentCompose extends FragmentBase {
private void onActionRecordAudio() {
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, ActivityCompose.REQUEST_RECORD_AUDIO);
startActivityForResult(intent, REQUEST_RECORD_AUDIO);
}
private void onActionTakePhoto() {
@ -1125,7 +1133,7 @@ public class FragmentCompose extends FragmentBase {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoURI = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(intent, ActivityCompose.REQUEST_TAKE_PHOTO);
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
}
private void onActionImage() {
@ -1136,7 +1144,7 @@ public class FragmentCompose extends FragmentBase {
if (intent.resolveActivity(pm) == null)
Snackbar.make(view, R.string.title_no_saf, Snackbar.LENGTH_LONG).show();
else
startActivityForResult(Helper.getChooser(getContext(), intent), ActivityCompose.REQUEST_IMAGE);
startActivityForResult(Helper.getChooser(getContext(), intent), REQUEST_IMAGE);
}
private void onActionAttachment() {
@ -1148,7 +1156,7 @@ public class FragmentCompose extends FragmentBase {
if (intent.resolveActivity(pm) == null)
Snackbar.make(view, R.string.title_no_saf, Snackbar.LENGTH_LONG).show();
else
startActivityForResult(Helper.getChooser(getContext(), intent), ActivityCompose.REQUEST_ATTACHMENT);
startActivityForResult(Helper.getChooser(getContext(), intent), REQUEST_ATTACHMENT);
}
private void onActionLink() {
@ -1518,7 +1526,7 @@ public class FragmentCompose extends FragmentBase {
PendingIntent pi = (PendingIntent) result;
startIntentSenderForResult(
pi.getIntentSender(),
ActivityCompose.REQUEST_ENCRYPT,
REQUEST_ENCRYPT,
null, 0, 0, 0, null);
} catch (IntentSender.SendIntentException ex) {
Log.e(ex);
@ -1538,45 +1546,65 @@ public class FragmentCompose extends FragmentBase {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == ActivityCompose.REQUEST_IMAGE) {
if (data != null) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_IMAGE:
if (resultCode == RESULT_OK && data != null) {
Uri uri = data.getData();
if (uri != null)
handleAddAttachment(uri, true);
}
} else if (requestCode == ActivityCompose.REQUEST_ATTACHMENT ||
requestCode == ActivityCompose.REQUEST_RECORD_AUDIO ||
requestCode == ActivityCompose.REQUEST_TAKE_PHOTO) {
if (requestCode == ActivityCompose.REQUEST_TAKE_PHOTO)
data = new Intent().setData(photoURI);
if (data != null) {
ClipData clipData = data.getClipData();
if (clipData == null) {
Uri uri = data.getData();
if (uri != null)
handleAddAttachment(uri, false);
} else {
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item = clipData.getItemAt(i);
Uri uri = item.getUri();
break;
case REQUEST_ATTACHMENT:
case REQUEST_RECORD_AUDIO:
case REQUEST_TAKE_PHOTO:
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_TAKE_PHOTO)
data = new Intent().setData(photoURI);
if (data != null) {
ClipData clipData = data.getClipData();
if (clipData == null) {
Uri uri = data.getData();
if (uri != null)
handleAddAttachment(uri, false);
} else {
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item = clipData.getItemAt(i);
Uri uri = item.getUri();
if (uri != null)
handleAddAttachment(uri, false);
}
}
}
}
} else if (requestCode == ActivityCompose.REQUEST_ENCRYPT) {
if (data != null) {
break;
case REQUEST_ENCRYPT:
if (resultCode == RESULT_OK && data != null) {
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE)
Log.logExtras(data);
doPgp(data);
}
} else {
if (data != null)
break;
case REQUEST_COLOR:
if (resultCode == RESULT_OK && data != null) {
Bundle args = data.getBundleExtra("args");
int color = args.getInt("color");
int start = args.getInt("start");
int end = args.getInt("end");
SpannableString ss = new SpannableString(etBody.getText());
for (ForegroundColorSpan span : ss.getSpans(start, end, ForegroundColorSpan.class))
ss.removeSpan(span);
ss.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(ss);
etBody.setSelection(end);
}
break;
default:
if (resultCode == RESULT_OK && data != null)
handlePickContact(requestCode, data);
}
}
}
@ -1621,11 +1649,11 @@ public class FragmentCompose extends FragmentBase {
return null;
Address[] address = null;
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
if (requestCode == REQUEST_CONTACT_TO)
address = draft.to;
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
else if (requestCode == REQUEST_CONTACT_CC)
address = draft.cc;
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
else if (requestCode == REQUEST_CONTACT_BCC)
address = draft.bcc;
List<Address> list = new ArrayList<>();
@ -1634,11 +1662,11 @@ public class FragmentCompose extends FragmentBase {
list.add(new InternetAddress(email, name));
if (requestCode == ActivityCompose.REQUEST_CONTACT_TO)
if (requestCode == REQUEST_CONTACT_TO)
draft.to = list.toArray(new Address[0]);
else if (requestCode == ActivityCompose.REQUEST_CONTACT_CC)
else if (requestCode == REQUEST_CONTACT_CC)
draft.cc = list.toArray(new Address[0]);
else if (requestCode == ActivityCompose.REQUEST_CONTACT_BCC)
else if (requestCode == REQUEST_CONTACT_BCC)
draft.bcc = list.toArray(new Address[0]);
db.message().updateMessage(draft);
@ -3153,7 +3181,7 @@ public class FragmentCompose extends FragmentBase {
end = tmp;
}
final SpannableString ss = new SpannableString(etBody.getText());
SpannableString ss = new SpannableString(etBody.getText());
switch (item.getItemId()) {
case R.string.title_style_bold:
@ -3213,26 +3241,17 @@ public class FragmentCompose extends FragmentBase {
}
case R.string.title_style_color: {
final int s = start;
final int e = end;
Bundle args = new Bundle();
args.putInt("start", start);
args.putInt("end", end);
ForegroundColorSpan[] spans = ss.getSpans(start, end, ForegroundColorSpan.class);
int color = (spans.length > 0 ? spans[0].getForegroundColor() : Color.TRANSPARENT);
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_style_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
for (ForegroundColorSpan span : ss.getSpans(s, e, ForegroundColorSpan.class))
ss.removeSpan(span);
ss.setSpan(new ForegroundColorSpan(color), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(ss);
etBody.setSelection(e);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_style_color, color, args, getContext());
fragment.setTargetFragment(FragmentCompose.this, REQUEST_COLOR);
fragment.show(getFragmentManager(), "account:color");
return true;
}

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -49,6 +48,8 @@ import com.google.android.material.snackbar.Snackbar;
import java.util.Objects;
import static android.app.Activity.RESULT_OK;
public class FragmentFolder extends FragmentBase {
private ViewGroup view;
private ScrollView scroll;
@ -242,7 +243,7 @@ public class FragmentFolder extends FragmentBase {
switch (requestCode) {
case REQUEST_SAVE_CHANGES:
if (resultCode == Activity.RESULT_OK) {
if (resultCode == RESULT_OK) {
new Handler().post(new Runnable() {
@Override
public void run() {
@ -255,7 +256,7 @@ public class FragmentFolder extends FragmentBase {
break;
case REQUEST_DELETE_FOLDER:
if (resultCode == Activity.RESULT_OK)
if (resultCode == RESULT_OK)
onDelete();
break;
}

@ -56,8 +56,6 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
@ -73,6 +71,7 @@ import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import static android.app.Activity.RESULT_OK;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
@ -132,6 +131,8 @@ public class FragmentIdentity extends FragmentBase {
private boolean saving = false;
private int color = Color.TRANSPARENT;
private static final int REQUEST_COLOR = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -261,22 +262,10 @@ public class FragmentIdentity extends FragmentBase {
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_SHOW_PRO));
return;
}
setColor(color);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_flag_color, color, new Bundle(), getContext());
fragment.setTargetFragment(FragmentIdentity.this, REQUEST_COLOR);
fragment.show(getFragmentManager(), "identity:color");
}
});
@ -1063,6 +1052,26 @@ public class FragmentIdentity extends FragmentBase {
.show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_COLOR:
if (resultCode == RESULT_OK && data != null) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_SHOW_PRO));
return;
}
Bundle args = data.getBundleExtra("args");
setColor(args.getInt("color"));
}
break;
}
}
private void setColor(int color) {
this.color = color;

@ -91,8 +91,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.bugsnag.android.Bugsnag;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -130,6 +128,7 @@ import java.util.Properties;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import static android.app.Activity.RESULT_OK;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
@ -229,6 +228,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static final int REQUEST_JUNK = 6;
private static final int REQUEST_MOVE = 7;
private static final int REQUEST_MOVE_ACROSS = 8;
static final int REQUEST_MESSAGE_COLOR = 9;
private static final int REQUEST_MESSAGES_COLOR = 10;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_STORE_ATTACHMENT = BuildConfig.APPLICATION_ID + ".STORE_ATTACHMENT";
@ -505,7 +506,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
boolean filter_duplicates = prefs.getBoolean("filter_duplicates", false);
adapter = new AdapterMessage(
getContext(), getViewLifecycleOwner(), view,
getContext(), getViewLifecycleOwner(), this,
viewType, compact, zoom, sort, filter_duplicates, iProperties);
rvMessage.setAdapter(adapter);
@ -1245,7 +1246,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionSnoozeSelection(message.id);
return true;
case R.string.title_flag_color:
onActionFlagColorSelection(message.color == null ? Color.TRANSPARENT : message.color, message.id);
onMenuColor();
return true;
case R.string.title_move:
onMenuMove();
@ -1255,6 +1256,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
}
private void onMenuColor() {
int color = (message.color == null ? Color.TRANSPARENT : message.color);
Bundle args = new Bundle();
args.putLong("id", message.id);
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_flag_color, color, args, getContext());
fragment.setTargetFragment(FragmentMessages.this, FragmentMessages.REQUEST_MESSAGE_COLOR);
fragment.show(getFragmentManager(), "message:color");
}
private void onMenuMove() {
Bundle args = new Bundle();
args.putLong("account", message.account);
@ -1612,13 +1625,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionSnoozeSelection(null);
return true;
case R.string.title_flag:
onActionFlagSelection(true, null, null);
onActionFlagSelection(true, null);
return true;
case R.string.title_unflag:
onActionFlagSelection(false, null, null);
onActionFlagSelection(false, null);
return true;
case R.string.title_flag_color:
onActionFlagColorSelection(Color.TRANSPARENT, null);
onActionFlagColorSelection();
return true;
case R.string.title_archive:
onActionMoveSelection(EntityFolder.ARCHIVE);
@ -1764,9 +1777,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
});
}
private void onActionFlagSelection(boolean flagged, Integer color, Long id) {
private void onActionFlagSelection(boolean flagged, Integer color) {
Bundle args = new Bundle();
args.putLongArray("ids", id == null ? getSelection() : new long[]{id});
args.putLongArray("ids", getSelection());
args.putBoolean("flagged", flagged);
if (color != null)
args.putInt("color", color);
@ -1809,23 +1822,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(FragmentMessages.this, args, "messages:flag");
}
private void onActionFlagColorSelection(int color, final Long id) {
int[] colors = getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
return;
}
onActionFlagSelection(true, color, id);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
private void onActionFlagColorSelection() {
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_flag_color, Color.TRANSPARENT, new Bundle(), getContext());
fragment.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGES_COLOR);
fragment.show(getFragmentManager(), "messages:color");
}
private void onActionDeleteSelection() {
@ -3634,37 +3635,59 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
switch (requestCode) {
case REQUEST_RAW:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
saveRaw(data);
break;
case REQUEST_ATTACHMENT:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
saveAttachment(data);
break;
case REQUEST_ATTACHMENTS:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
saveAttachments(data);
break;
case REQUEST_DECRYPT:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
decrypt(data, message);
break;
case REQUEST_DELETE:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
onDelete(data.getBundleExtra("args").getLongArray("ids"));
break;
case REQUEST_JUNK:
if (resultCode == Activity.RESULT_OK)
if (resultCode == RESULT_OK)
onActionMoveSelection(EntityFolder.JUNK);
break;
case REQUEST_MOVE:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
moveAskAcross(data.getBundleExtra("args").<MessageTarget>getParcelableArrayList("result"));
break;
case REQUEST_MOVE_ACROSS:
if (resultCode == Activity.RESULT_OK && data != null)
if (resultCode == RESULT_OK && data != null)
moveAskConfirmed(data.getBundleExtra("args").<MessageTarget>getParcelableArrayList("result"));
break;
case REQUEST_MESSAGE_COLOR:
if (resultCode == RESULT_OK && data != null) {
Bundle args = data.getBundleExtra("args");
long id = args.getLong("id");
int color = args.getInt("color");
onColorSelected(id, color);
}
break;
case REQUEST_MESSAGES_COLOR:
if (resultCode == RESULT_OK && data != null) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
return;
}
Bundle args = data.getBundleExtra("args");
int color = args.getInt("color");
onActionFlagSelection(true, color);
}
break;
}
}
@ -3924,6 +3947,44 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "attachments:save");
}
public void onColorSelected(long id, int color) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
return;
}
Bundle args = new Bundle();
args.putLong("id", id);
args.putInt("color", color);
new SimpleTask<Void>() {
@Override
protected Void onExecute(final Context context, Bundle args) {
final long id = args.getLong("id");
final int color = args.getInt("color");
final DB db = DB.getInstance(context);
db.runInTransaction(new Runnable() {
@Override
public void run() {
EntityMessage message = db.message().getMessage(id);
if (message == null)
return;
EntityOperation.queue(context, message, EntityOperation.FLAG, true, color);
}
});
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(getContext(), getViewLifecycleOwner(), args, "message:color");
}
static void search(
final Context context, final LifecycleOwner owner, final FragmentManager manager,
long folder, boolean server, String query) {

@ -249,8 +249,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("Result class=" + this.getClass().getSimpleName() +
" request=" + requestCode + " result=" + resultCode + " data=" + data);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ActivitySetup.REQUEST_SOUND)
if (resultCode == RESULT_OK) {

@ -54,8 +54,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.Snackbar;
@ -136,6 +134,10 @@ public class FragmentRule extends FragmentBase {
private final static int MAX_CHECK = 10;
private static final int REQUEST_SENDER = 1;
private static final int REQUEST_RECIPIENT = 2;
private static final int REQUEST_COLOR = 3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -219,7 +221,7 @@ public class FragmentRule extends FragmentBase {
if (pick.resolveActivity(getContext().getPackageManager()) == null)
Snackbar.make(view, R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
else
startActivityForResult(Helper.getChooser(getContext(), pick), ActivityView.REQUEST_SENDER);
startActivityForResult(Helper.getChooser(getContext(), pick), REQUEST_SENDER);
}
});
@ -230,7 +232,7 @@ public class FragmentRule extends FragmentBase {
if (pick.resolveActivity(getContext().getPackageManager()) == null)
Snackbar.make(view, R.string.title_no_contacts, Snackbar.LENGTH_LONG).show();
else
startActivityForResult(Helper.getChooser(getContext(), pick), ActivityView.REQUEST_RECIPIENT);
startActivityForResult(Helper.getChooser(getContext(), pick), REQUEST_RECIPIENT);
}
});
@ -295,16 +297,10 @@ public class FragmentRule extends FragmentBase {
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
setColor(color);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
FragmentColor fragment = new FragmentColor();
fragment.initialize(R.string.title_flag_color, color, new Bundle(), getContext());
fragment.setTargetFragment(FragmentRule.this, REQUEST_COLOR);
fragment.show(getFragmentManager(), "rule:color");
}
});
@ -417,12 +413,29 @@ public class FragmentRule extends FragmentBase {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("Request=" + requestCode + " result=" + resultCode + " data=" + data);
if (resultCode == RESULT_OK) {
if (data != null && requestCode == ActivityView.REQUEST_SENDER)
handlePickContact(data, true);
if (data != null && requestCode == ActivityView.REQUEST_RECIPIENT)
handlePickContact(data, false);
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_SENDER:
if (resultCode == RESULT_OK && data != null)
handlePickContact(data, true);
break;
case REQUEST_RECIPIENT:
if (resultCode == RESULT_OK && data != null)
handlePickContact(data, true);
break;
case REQUEST_COLOR:
if (resultCode == RESULT_OK && data != null) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_SHOW_PRO));
return;
}
Bundle args = data.getBundleExtra("args");
setColor(args.getInt("color"));
}
break;
}
}

Loading…
Cancel
Save