Dismiss color picker on pause

Signed-off-by: M66B <M66B@users.noreply.github.com>
This commit is contained in:
M66B 2019-06-30 10:25:50 +02:00
parent ea1f85e712
commit 29ec1ef5bc
7 changed files with 41 additions and 6 deletions

View File

@ -1092,7 +1092,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private void onColor(final Intent intent) {
int color = intent.getIntExtra("color", -1);
int[] colors = getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(this);
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override

View File

@ -0,0 +1,35 @@
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;
}
}

View File

@ -291,7 +291,7 @@ public class FragmentAccount extends FragmentBase {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override

View File

@ -3220,7 +3220,7 @@ public class FragmentCompose extends FragmentBase {
int color = (spans.length > 0 ? spans[0].getForegroundColor() : Color.TRANSPARENT);
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_style_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override

View File

@ -262,7 +262,7 @@ public class FragmentIdentity extends FragmentBase {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override

View File

@ -1806,7 +1806,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private void onActionFlagColorSelection(int color, final Long id) {
int[] colors = getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override

View File

@ -296,7 +296,7 @@ public class FragmentRule extends FragmentBase {
@Override
public void onClick(View v) {
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
ColorPickerDialog colorPickerDialog = new ColorPickerDialogEx(getViewLifecycleOwner());
colorPickerDialog.initialize(R.string.title_flag_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override