From fdd8b10a22fd734364db93e009b15cdaf6069090 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 27 Sep 2019 20:04:33 +0200 Subject: [PATCH] Added style to answers --- .../eu/faircode/email/FragmentAnswer.java | 60 ++++++++++++++- .../eu/faircode/email/FragmentCompose.java | 57 --------------- .../eu/faircode/email/FragmentDialogLink.java | 73 +++++++++++++++++++ app/src/main/res/layout/fragment_answer.xml | 17 ++++- app/src/main/res/menu/action_answer_style.xml | 27 +++++++ 5 files changed, 173 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/FragmentDialogLink.java create mode 100644 app/src/main/res/menu/action_answer_style.xml diff --git a/app/src/main/java/eu/faircode/email/FragmentAnswer.java b/app/src/main/java/eu/faircode/email/FragmentAnswer.java index 80fa24db62..253cca205d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAnswer.java +++ b/app/src/main/java/eu/faircode/email/FragmentAnswer.java @@ -20,8 +20,10 @@ package eu.faircode.email; */ import android.app.Dialog; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.text.Spanned; import android.view.LayoutInflater; @@ -46,8 +48,9 @@ public class FragmentAnswer extends FragmentBase { private ViewGroup view; private EditText etName; private CheckBox cbHide; - private EditText etText; + private EditTextCompose etText; private ImageButton ibInfo; + private BottomNavigationView style_bar; private BottomNavigationView bottom_navigation; private ContentLoadingProgressBar pbWait; private Group grpReady; @@ -55,7 +58,8 @@ public class FragmentAnswer extends FragmentBase { private long id = -1; private long copy = -1; - private final static int REQUEST_DELETE = 1; + private static final int REQUEST_LINK = 1; + private final static int REQUEST_DELETE = 2; @Override public void onCreate(Bundle savedInstanceState) { @@ -83,11 +87,19 @@ public class FragmentAnswer extends FragmentBase { etText = view.findViewById(R.id.etText); ibInfo = view.findViewById(R.id.ibInfo); + style_bar = view.findViewById(R.id.style_bar); bottom_navigation = view.findViewById(R.id.bottom_navigation); pbWait = view.findViewById(R.id.pbWait); grpReady = view.findViewById(R.id.grpReady); + etText.setSelectionListener(new EditTextCompose.ISelection() { + @Override + public void onSelected(boolean selection) { + style_bar.setVisibility(selection ? View.VISIBLE : View.GONE); + } + }); + ibInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -95,6 +107,13 @@ public class FragmentAnswer extends FragmentBase { } }); + style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + return onActionStyle(item.getItemId()); + } + }); + bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { @@ -113,6 +132,7 @@ public class FragmentAnswer extends FragmentBase { // Initialize grpReady.setVisibility(View.GONE); + style_bar.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); return view; @@ -223,6 +243,10 @@ public class FragmentAnswer extends FragmentBase { try { switch (requestCode) { + case REQUEST_LINK: + if (resultCode == RESULT_OK && data != null) + onLinkSelected(data.getBundleExtra("args")); + break; case REQUEST_DELETE: if (resultCode == RESULT_OK) onDelete(); @@ -233,6 +257,11 @@ public class FragmentAnswer extends FragmentBase { } } + private void onLinkSelected(Bundle args) { + String link = args.getString("link"); + StyleHelper.apply(R.id.menu_link, etText, link); + } + private void onDelete() { Bundle args = new Bundle(); args.putLong("id", id); @@ -267,6 +296,33 @@ public class FragmentAnswer extends FragmentBase { }.execute(this, args, "answer:delete"); } + private boolean onActionStyle(int action) { + Log.i("Style action=" + action); + + if (action == R.id.menu_link) { + Uri uri = null; + + ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); + if (cbm.hasPrimaryClip()) { + String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString(); + uri = Uri.parse(link); + if (uri.getScheme() == null) + uri = null; + } + + Bundle args = new Bundle(); + args.putParcelable("uri", uri); + + FragmentDialogLink fragment = new FragmentDialogLink(); + fragment.setArguments(args); + fragment.setTargetFragment(this, REQUEST_LINK); + fragment.show(getFragmentManager(), "compose:link"); + + return true; + } else + return StyleHelper.apply(action, etText); + } + public static class FragmentInfo extends FragmentDialogBase { @NonNull @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index fcb45894c5..ec45ec42ef 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -58,13 +58,11 @@ import android.os.Looper; import android.provider.ContactsContract; import android.provider.MediaStore; import android.provider.OpenableColumns; -import android.text.Editable; import android.text.Html; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; -import android.text.TextWatcher; import android.text.style.ImageSpan; import android.text.style.QuoteSpan; import android.util.DisplayMetrics; @@ -3430,61 +3428,6 @@ public class FragmentCompose extends FragmentBase { } } - public static class FragmentDialogLink extends FragmentDialogBase { - private EditText etLink; - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - outState.putString("fair:link", etLink.getText().toString()); - super.onSaveInstanceState(outState); - } - - @NonNull - @Override - public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - Uri uri = getArguments().getParcelable("uri"); - - View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_insert_link, null); - etLink = view.findViewById(R.id.etLink); - final TextView tvInsecure = view.findViewById(R.id.tvInsecure); - - etLink.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - @Override - public void afterTextChanged(Editable editable) { - Uri uri = Uri.parse(editable.toString()); - tvInsecure.setVisibility(!uri.isOpaque() && - "http".equals(uri.getScheme()) ? View.VISIBLE : View.GONE); - } - }); - - if (savedInstanceState == null) - etLink.setText(uri == null ? "https://" : uri.toString()); - else - etLink.setText(savedInstanceState.getString("fair:link")); - - return new AlertDialog.Builder(getContext()) - .setView(view) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String link = etLink.getText().toString(); - getArguments().putString("link", link); - sendResult(RESULT_OK); - } - }) - .setNegativeButton(android.R.string.cancel, null) - .create(); - } - } - public static class FragmentDialogSend extends FragmentDialogBase { @NonNull @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogLink.java b/app/src/main/java/eu/faircode/email/FragmentDialogLink.java new file mode 100644 index 0000000000..f24e7b9e16 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/FragmentDialogLink.java @@ -0,0 +1,73 @@ +package eu.faircode.email; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.net.Uri; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; + +import static android.app.Activity.RESULT_OK; + +public class FragmentDialogLink extends FragmentDialogBase { + private EditText etLink; + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + outState.putString("fair:link", etLink.getText().toString()); + super.onSaveInstanceState(outState); + } + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + Uri uri = getArguments().getParcelable("uri"); + + View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_insert_link, null); + etLink = view.findViewById(R.id.etLink); + final TextView tvInsecure = view.findViewById(R.id.tvInsecure); + + etLink.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable editable) { + Uri uri = Uri.parse(editable.toString()); + tvInsecure.setVisibility(!uri.isOpaque() && + "http".equals(uri.getScheme()) ? View.VISIBLE : View.GONE); + } + }); + + if (savedInstanceState == null) + etLink.setText(uri == null ? "https://" : uri.toString()); + else + etLink.setText(savedInstanceState.getString("fair:link")); + + return new AlertDialog.Builder(getContext()) + .setView(view) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String link = etLink.getText().toString(); + getArguments().putString("link", link); + sendResult(RESULT_OK); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .create(); + } +} diff --git a/app/src/main/res/layout/fragment_answer.xml b/app/src/main/res/layout/fragment_answer.xml index ef72c0d258..29c577725f 100644 --- a/app/src/main/res/layout/fragment_answer.xml +++ b/app/src/main/res/layout/fragment_answer.xml @@ -41,7 +41,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/cbHide" /> - @@ -69,6 +69,19 @@ app:layout_constraintEnd_toEndOf="@id/etText" app:srcCompat="@drawable/baseline_info_24" /> + + + + + + + + + + + + +