Added style to answers

pull/162/head
M66B 5 years ago
parent f7aa12b083
commit fdd8b10a22

@ -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

@ -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

@ -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();
}
}

@ -41,7 +41,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbHide" />
<EditText
<eu.faircode.email.EditTextCompose
android:id="@+id/etText"
android:layout_width="0dp"
android:layout_height="0dp"
@ -55,7 +55,7 @@
android:isScrollContainer="true"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:windowSoftInputMode="adjustPan"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintBottom_toTopOf="@+id/style_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparator" />
@ -69,6 +69,19 @@
app:layout_constraintEnd_toEndOf="@id/etText"
app:srcCompat="@drawable/baseline_info_24" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/style_bar"
android:layout_width="0dp"
android:layout_height="36dp"
android:background="?attr/colorActionBackground"
app:itemIconTint="@color/action_foreground"
app:itemTextColor="@color/action_foreground"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_answer_style" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_bold"
android:icon="@drawable/baseline_format_bold_24"
android:title="@string/title_style_bold" />
<item
android:id="@+id/menu_italic"
android:icon="@drawable/baseline_format_italic_24"
android:title="@string/title_style_italic" />
<item
android:id="@+id/menu_underline"
android:icon="@drawable/baseline_format_underlined_24"
android:title="@string/title_style_underline" />
<item
android:id="@+id/menu_size"
android:icon="@drawable/baseline_format_size_24"
android:title="@string/title_style_size" />
<item
android:id="@+id/menu_link"
android:icon="@drawable/baseline_insert_link_24"
android:title="@string/title_style_link" />
</menu>
Loading…
Cancel
Save