From a15f6106ae1fd16e107798932f1f3c157098ae48 Mon Sep 17 00:00:00 2001 From: Distopico Vegan Date: Fri, 6 Nov 2020 23:34:18 -0500 Subject: [PATCH] improve account color dialog --- .../dystopia/email/ColorDialogFragment.java | 8 +++- .../org/dystopia/email/FragmentAccount.java | 20 ++------- .../org/dystopia/email/ViewButtonColor.java | 1 + app/src/main/res/layout/fragment_account.xml | 43 ++++++++----------- app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values-es-rES/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 35 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/org/dystopia/email/ColorDialogFragment.java b/app/src/main/java/org/dystopia/email/ColorDialogFragment.java index a1b7a00e..f8b1a84f 100644 --- a/app/src/main/java/org/dystopia/email/ColorDialogFragment.java +++ b/app/src/main/java/org/dystopia/email/ColorDialogFragment.java @@ -64,6 +64,7 @@ public class ColorDialogFragment extends DialogFragment { color = savedInstanceState == null ? args.getInt("color") : savedInstanceState.getInt("dialog:color"); String title = args.getString("title"); boolean reset = args.getBoolean("reset", false); + boolean hasColor = color != Color.TRANSPARENT; Context context = getContext(); int editTextColor = Helper.resolveColor(context, android.R.attr.editTextColor); @@ -90,12 +91,15 @@ public class ColorDialogFragment extends DialogFragment { } }); - if (color != Color.TRANSPARENT) { + if (!hasColor) { + builder.initialColor(Helper.resolveColor(getContext(), android.R.attr.colorPrimary)); + } else { builder.initialColor(color); } if (reset) { - builder.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() { + int negativeText = !hasColor ? R.string.title_cancel : R.string.title_reset; + builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getArguments().putInt("color", Color.TRANSPARENT); diff --git a/app/src/main/java/org/dystopia/email/FragmentAccount.java b/app/src/main/java/org/dystopia/email/FragmentAccount.java index cfa5dee1..e2e55df2 100644 --- a/app/src/main/java/org/dystopia/email/FragmentAccount.java +++ b/app/src/main/java/org/dystopia/email/FragmentAccount.java @@ -34,7 +34,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -54,14 +53,13 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageButton; -import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.constraintlayout.widget.Group; import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentResultListener; @@ -109,7 +107,7 @@ public class FragmentAccount extends FragmentEx { private EditText etName; private ViewButtonColor btnColor; - private ImageView ibColorReset; + private LinearLayout llContainerColor; private EditText etSignature; private CheckBox cbSynchronize; @@ -178,6 +176,7 @@ public class FragmentAccount extends FragmentEx { btnAutoConfig = view.findViewById(R.id.btnAutoConfig); etHost = view.findViewById(R.id.etHost); + llContainerColor = view.findViewById(R.id.llContainerColor); etPort = view.findViewById(R.id.etPort); cbStartTls = view.findViewById(R.id.cbStartTls); cbInsecure = view.findViewById(R.id.cbInsecure); @@ -190,7 +189,6 @@ public class FragmentAccount extends FragmentEx { etName = view.findViewById(R.id.etName); btnColor = view.findViewById(R.id.btnColor); tvName = view.findViewById(R.id.tvName); - ibColorReset = view.findViewById(R.id.ibColorReset); etSignature = view.findViewById(R.id.etSignature); cbSynchronize = view.findViewById(R.id.cbSynchronize); @@ -377,7 +375,7 @@ public class FragmentAccount extends FragmentEx { }); btnColor.setColor(color); - btnColor.setOnClickListener( + llContainerColor.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { @@ -392,15 +390,6 @@ public class FragmentAccount extends FragmentEx { } }); - ibColorReset.setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View v) { - btnColor.setColor(Color.TRANSPARENT); - ibColorReset.setVisibility(View.GONE); - } - }); - cbSynchronize.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override @@ -1101,7 +1090,6 @@ public class FragmentAccount extends FragmentEx { if (resultCode == RESULT_OK) { color = result.getInt("color"); btnColor.setColor(color); - ibColorReset.setVisibility(View.VISIBLE); } } catch (Throwable ex) { Log.e(Helper.TAG, "Set account color error: " + ex + "\n" + Log.getStackTraceString(ex)); diff --git a/app/src/main/java/org/dystopia/email/ViewButtonColor.java b/app/src/main/java/org/dystopia/email/ViewButtonColor.java index 43fa6118..1d41c653 100644 --- a/app/src/main/java/org/dystopia/email/ViewButtonColor.java +++ b/app/src/main/java/org/dystopia/email/ViewButtonColor.java @@ -68,6 +68,7 @@ public class ViewButtonColor extends AppCompatButton { background.setStroke( ViewHelper.dp2px(getContext(), 1), Helper.resolveColor(getContext(), R.attr.colorSeparator)); + background.setCornerRadius(50); setBackground(background); if (color == Color.TRANSPARENT) diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 61291a23..23d8d4e5 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -221,39 +221,34 @@ - - + android:id="@+id/llContainerColor" + android:clickable="true" + android:focusable="true" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:gravity="center" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/tilPassword"> - + android:background="@color/colorAccent" + android:tag="disable" />