Added button to show images in replied/forwarded text

This commit is contained in:
M66B 2019-01-13 08:39:50 +00:00
parent 6eda79aa83
commit bc774ca6e6
2 changed files with 57 additions and 6 deletions

View File

@ -74,6 +74,7 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FilterQueryProvider; import android.widget.FilterQueryProvider;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.MultiAutoCompleteTextView; import android.widget.MultiAutoCompleteTextView;
import android.widget.NumberPicker; import android.widget.NumberPicker;
@ -151,6 +152,7 @@ public class FragmentCompose extends FragmentEx {
private TextView tvNoInternet; private TextView tvNoInternet;
private TextView tvSignature; private TextView tvSignature;
private TextView tvReference; private TextView tvReference;
private ImageButton ibImages;
private BottomNavigationView edit_bar; private BottomNavigationView edit_bar;
private BottomNavigationView bottom_navigation; private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
@ -167,6 +169,7 @@ public class FragmentCompose extends FragmentEx {
private long working = -1; private long working = -1;
private State state = State.NONE; private State state = State.NONE;
private boolean show_images = false;
private boolean autosave = false; private boolean autosave = false;
private boolean busy = false; private boolean busy = false;
@ -204,6 +207,7 @@ public class FragmentCompose extends FragmentEx {
tvNoInternet = view.findViewById(R.id.tvNoInternet); tvNoInternet = view.findViewById(R.id.tvNoInternet);
tvSignature = view.findViewById(R.id.tvSignature); tvSignature = view.findViewById(R.id.tvSignature);
tvReference = view.findViewById(R.id.tvReference); tvReference = view.findViewById(R.id.tvReference);
ibImages = view.findViewById(R.id.ibImages);
edit_bar = view.findViewById(R.id.edit_bar); edit_bar = view.findViewById(R.id.edit_bar);
bottom_navigation = view.findViewById(R.id.bottom_navigation); bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
@ -279,6 +283,34 @@ public class FragmentCompose extends FragmentEx {
ivCcAdd.setOnClickListener(onPick); ivCcAdd.setOnClickListener(onPick);
ivBccAdd.setOnClickListener(onPick); ivBccAdd.setOnClickListener(onPick);
ibImages.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
show_images = true;
Bundle args = new Bundle();
args.putLong("id", working);
new SimpleTask<EntityMessage>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) {
long id = args.getLong("id");
return DB.getInstance(context).message().getMessage(id);
}
@Override
protected void onExecuted(Bundle args, EntityMessage draft) {
showDraft(draft);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentCompose.this, args, "compose:images:show");
}
});
edit_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { edit_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@ -398,6 +430,7 @@ public class FragmentCompose extends FragmentEx {
tvNoInternet.setVisibility(View.GONE); tvNoInternet.setVisibility(View.GONE);
grpSignature.setVisibility(View.GONE); grpSignature.setVisibility(View.GONE);
grpReference.setVisibility(View.GONE); grpReference.setVisibility(View.GONE);
ibImages.setVisibility(View.GONE);
edit_bar.setVisibility(View.GONE); edit_bar.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
@ -498,6 +531,7 @@ public class FragmentCompose extends FragmentEx {
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putLong("working", working); outState.putLong("working", working);
outState.putBoolean("show_images", show_images);
} }
@Override @Override
@ -531,6 +565,8 @@ public class FragmentCompose extends FragmentEx {
} }
} else { } else {
working = savedInstanceState.getLong("working"); working = savedInstanceState.getLong("working");
show_images = savedInstanceState.getBoolean("show_images");
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("action", working < 0 ? "new" : "edit"); args.putString("action", working < 0 ? "new" : "edit");
args.putLong("id", working); args.putLong("id", working);
@ -2083,6 +2119,7 @@ public class FragmentCompose extends FragmentEx {
args.putLong("reference", draft.replying); args.putLong("reference", draft.replying);
else if (draft.forwarding != null) else if (draft.forwarding != null)
args.putLong("reference", draft.forwarding); args.putLong("reference", draft.forwarding);
args.putBoolean("show_images", show_images);
new SimpleTask<Spanned[]>() { new SimpleTask<Spanned[]>() {
@Override @Override
@ -2102,6 +2139,7 @@ public class FragmentCompose extends FragmentEx {
protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable { protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable {
long id = args.getLong("id"); long id = args.getLong("id");
final long reference = args.getLong("reference", -1); final long reference = args.getLong("reference", -1);
final boolean show_images = args.getBoolean("show_images", false);
String body = EntityMessage.read(context, id); String body = EntityMessage.read(context, id);
Spanned spannedBody = Html.fromHtml(body, cidGetter, null); Spanned spannedBody = Html.fromHtml(body, cidGetter, null);
@ -2113,7 +2151,7 @@ public class FragmentCompose extends FragmentEx {
new Html.ImageGetter() { new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
Drawable image = HtmlHelper.decodeImage(source, context, reference, true); Drawable image = HtmlHelper.decodeImage(source, context, reference, show_images);
float width = context.getResources().getDisplayMetrics().widthPixels - float width = context.getResources().getDisplayMetrics().widthPixels -
Helper.dp2pixels(context, 12); // margins; Helper.dp2pixels(context, 12); // margins;
@ -2148,13 +2186,17 @@ public class FragmentCompose extends FragmentEx {
} }
@Override @Override
protected void onExecuted(Bundle args, Spanned[] texts) { protected void onExecuted(Bundle args, Spanned[] text) {
etBody.setText(texts[0]); etBody.setText(text[0]);
etBody.setSelection(0); etBody.setSelection(0);
etBody.setVisibility(View.VISIBLE); etBody.setVisibility(View.VISIBLE);
tvReference.setText(texts[1]); boolean has_images = (text[1] != null &&
grpReference.setVisibility(texts[1] == null ? View.GONE : View.VISIBLE); text[1].getSpans(0, text[1].length(), ImageSpan.class).length > 0);
tvReference.setText(text[1]);
grpReference.setVisibility(text[1] == null ? View.GONE : View.VISIBLE);
ibImages.setVisibility(has_images && !show_images ? View.VISIBLE : View.GONE);
new Handler().post(new Runnable() { new Handler().post(new Runnable() {
@Override @Override

View File

@ -158,7 +158,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvAttachment" android:id="@+id/rvAttachment"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="10dp"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
@ -256,6 +256,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorSignature" /> app:layout_constraintTop_toBottomOf="@id/vSeparatorSignature" />
<ImageButton
android:id="@+id/ibImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:src="@drawable/baseline_image_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvReference" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpHeader" android:id="@+id/grpHeader"
android:layout_width="0dp" android:layout_width="0dp"