From 8c2efa24861a3ca99b98c3d1fab2949f8171198b Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 Sep 2018 12:34:54 +0000 Subject: [PATCH] Layout improvements --- .../eu/faircode/email/FragmentAccount.java | 21 ++++-- .../java/eu/faircode/email/FragmentSetup.java | 39 ++++++++--- .../main/res/drawable/baseline_check_24.xml | 10 +++ app/src/main/res/layout/fragment_account.xml | 27 ++++---- app/src/main/res/layout/fragment_setup.xml | 69 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 6 ++ 7 files changed, 130 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_check_24.xml diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 47a0933b..ebc9ba08 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -29,10 +29,10 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; -import android.graphics.Paint; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.preference.PreferenceManager; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -50,7 +50,6 @@ import android.widget.ImageButton; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.Spinner; -import android.widget.TextView; import android.widget.Toast; import com.google.android.material.snackbar.Snackbar; @@ -90,8 +89,8 @@ public class FragmentAccount extends FragmentEx { private TextInputLayout tilPassword; private Button btnAdvanced; private EditText etName; - private TextView tvSignaturePro; private EditText etSignature; + private ImageButton ibPro; private CheckBox cbSynchronize; private CheckBox cbPrimary; private Button btnCheck; @@ -140,8 +139,9 @@ public class FragmentAccount extends FragmentEx { btnAdvanced = view.findViewById(R.id.btnAdvanced); etName = view.findViewById(R.id.etName); - tvSignaturePro = view.findViewById(R.id.tvSignaturePro); etSignature = view.findViewById(R.id.etSignature); + ibPro = view.findViewById(R.id.ibPro); + cbSynchronize = view.findViewById(R.id.cbSynchronize); cbPrimary = view.findViewById(R.id.cbPrimary); @@ -248,8 +248,7 @@ public class FragmentAccount extends FragmentEx { } }); - tvSignaturePro.setPaintFlags(tvSignaturePro.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvSignaturePro.setOnClickListener(new View.OnClickListener() { + ibPro.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); @@ -803,6 +802,16 @@ public class FragmentAccount extends FragmentEx { Helper.setViewsEnabled(view, true); + boolean pro = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("pro", false); + etSignature.setHint(pro ? R.string.title_optional : R.string.title_pro_feature); + etSignature.setEnabled(pro); + if (pro) { + ViewGroup.LayoutParams lp = ibPro.getLayoutParams(); + lp.height = 0; + lp.width = 0; + ibPro.setLayoutParams(lp); + } + cbPrimary.setEnabled(cbSynchronize.isChecked()); // Consider previous check/save/delete as cancelled diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index ae389afa..ad8b2aef 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -26,6 +26,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.Uri; import android.os.Build; @@ -38,10 +39,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.TextView; import android.widget.Toast; +import android.widget.ToggleButton; import java.util.List; @@ -67,10 +68,12 @@ public class FragmentSetup extends FragmentEx { private Button btnData; - private CheckBox cbDarkTheme; + private ToggleButton tbDarkTheme; private Button btnOptions; + private Drawable check; + private static final String[] permissions = new String[]{ Manifest.permission.READ_CONTACTS }; @@ -80,6 +83,8 @@ public class FragmentSetup extends FragmentEx { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { setSubtitle(R.string.title_setup); + check = getResources().getDrawable(R.drawable.baseline_check_24, getContext().getTheme()); + View view = inflater.inflate(R.layout.fragment_setup, container, false); // Get controls @@ -97,7 +102,7 @@ public class FragmentSetup extends FragmentEx { btnData = view.findViewById(R.id.btnData); - cbDarkTheme = view.findViewById(R.id.cbDarkTheme); + tbDarkTheme = view.findViewById(R.id.tbDarkTheme); btnOptions = view.findViewById(R.id.btnOptions); // Wire controls @@ -165,14 +170,14 @@ public class FragmentSetup extends FragmentEx { String theme = prefs.getString("theme", "light"); boolean dark = "dark".equals(theme); - cbDarkTheme.setTag(dark); - cbDarkTheme.setChecked(dark); - cbDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + tbDarkTheme.setTag(dark); + tbDarkTheme.setChecked(dark); + tbDarkTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton button, boolean checked) { if (checked != (Boolean) button.getTag()) { button.setTag(checked); - cbDarkTheme.setChecked(checked); + tbDarkTheme.setChecked(checked); prefs.edit().putString("theme", checked ? "dark" : "light").apply(); } } @@ -190,11 +195,19 @@ public class FragmentSetup extends FragmentEx { // Initialize tvAccountDone.setText(null); + tvAccountDone.setCompoundDrawables(null, null, null, null); + btnIdentity.setEnabled(false); tvIdentityDone.setText(null); + tvIdentityDone.setCompoundDrawables(null, null, null, null); + tvPermissionsDone.setText(null); + tvPermissionsDone.setCompoundDrawables(null, null, null, null); + btnDoze.setEnabled(false); tvDozeDone.setText(null); + tvDozeDone.setCompoundDrawables(null, null, null, null); + btnData.setVisibility(View.GONE); int[] grantResults = new int[permissions.length]; @@ -247,15 +260,19 @@ public class FragmentSetup extends FragmentEx { db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List accounts) { - btnIdentity.setEnabled(accounts != null && accounts.size() > 0); - tvAccountDone.setText(accounts != null && accounts.size() > 0 ? R.string.title_setup_done : R.string.title_setup_to_do); + boolean done = (accounts != null && accounts.size() > 0); + btnIdentity.setEnabled(done); + tvAccountDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do); + tvAccountDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null); } }); db.identity().liveIdentities(true).observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List identities) { - tvIdentityDone.setText(identities != null && identities.size() > 0 ? R.string.title_setup_done : R.string.title_setup_to_do); + boolean done = (identities != null && identities.size() > 0); + tvIdentityDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do); + tvIdentityDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null); } }); } @@ -268,6 +285,7 @@ public class FragmentSetup extends FragmentEx { boolean ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID); btnDoze.setEnabled(!ignoring); tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do); + tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ConnectivityManager cm = getContext().getSystemService(ConnectivityManager.class); @@ -287,5 +305,6 @@ public class FragmentSetup extends FragmentEx { btnPermissions.setEnabled(!has); tvPermissionsDone.setText(has ? R.string.title_setup_done : R.string.title_setup_to_do); + tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null); } } diff --git a/app/src/main/res/drawable/baseline_check_24.xml b/app/src/main/res/drawable/baseline_check_24.xml new file mode 100644 index 00000000..5291b7fa --- /dev/null +++ b/app/src/main/res/drawable/baseline_check_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index e8d99760..2ae48dc0 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -209,25 +209,26 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/etName" /> - - + app:layout_constraintTop_toBottomOf="@id/tvSignature" /> + + + app:constraint_referenced_ids="tvName,etName,tvSignature,etSignature,ibPro,cbSynchronize,cbPrimary" /> + +