Added option to show inline attachments

Default hidden
pull/147/head
M66B 7 years ago
parent 4cbd0e5439
commit a9ebc0160b

@ -60,6 +60,8 @@ import android.view.TouchDelegate;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -190,6 +192,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private TextView tvNoInternetHeaders; private TextView tvNoInternetHeaders;
private RecyclerView rvAttachment; private RecyclerView rvAttachment;
private CheckBox cbInline;
private Button btnDownloadAttachments; private Button btnDownloadAttachments;
private Button btnSaveAttachments; private Button btnSaveAttachments;
private TextView tvNoInternetAttachments; private TextView tvNoInternetAttachments;
@ -266,6 +269,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
adapterAttachment = new AdapterAttachment(context, owner, true); adapterAttachment = new AdapterAttachment(context, owner, true);
rvAttachment.setAdapter(adapterAttachment); rvAttachment.setAdapter(adapterAttachment);
cbInline = itemView.findViewById(R.id.cbInline);
btnDownloadAttachments = itemView.findViewById(R.id.btnDownloadAttachments); btnDownloadAttachments = itemView.findViewById(R.id.btnDownloadAttachments);
btnSaveAttachments = itemView.findViewById(R.id.btnSaveAttachments); btnSaveAttachments = itemView.findViewById(R.id.btnSaveAttachments);
tvNoInternetAttachments = itemView.findViewById(R.id.tvNoInternetAttachments); tvNoInternetAttachments = itemView.findViewById(R.id.tvNoInternetAttachments);
@ -388,6 +392,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
pbHeaders.setVisibility(View.GONE); pbHeaders.setVisibility(View.GONE);
tvNoInternetHeaders.setVisibility(View.GONE); tvNoInternetHeaders.setVisibility(View.GONE);
cbInline.setVisibility(View.GONE);
btnDownloadAttachments.setVisibility(View.GONE); btnDownloadAttachments.setVisibility(View.GONE);
btnSaveAttachments.setVisibility(View.GONE); btnSaveAttachments.setVisibility(View.GONE);
tvNoInternetAttachments.setVisibility(View.GONE); tvNoInternetAttachments.setVisibility(View.GONE);
@ -548,6 +553,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivBrowsed.setVisibility(message.ui_browsed ? View.VISIBLE : View.GONE); ivBrowsed.setVisibility(message.ui_browsed ? View.VISIBLE : View.GONE);
ivAnswered.setVisibility(message.ui_answered ? View.VISIBLE : View.GONE); ivAnswered.setVisibility(message.ui_answered ? View.VISIBLE : View.GONE);
ivAttachments.setVisibility(message.attachments > 0 ? View.VISIBLE : View.GONE); ivAttachments.setVisibility(message.attachments > 0 ? View.VISIBLE : View.GONE);
cbInline.setVisibility(View.GONE);
btnDownloadAttachments.setVisibility(View.GONE); btnDownloadAttachments.setVisibility(View.GONE);
btnSaveAttachments.setVisibility(View.GONE); btnSaveAttachments.setVisibility(View.GONE);
tvNoInternetAttachments.setVisibility(View.GONE); tvNoInternetAttachments.setVisibility(View.GONE);
@ -705,24 +711,44 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
attachments = new ArrayList<>(); attachments = new ArrayList<>();
idAttachments.put(message.id, attachments); idAttachments.put(message.id, attachments);
adapterAttachment.set(attachments); boolean show_inline = properties.getValue("inline", message.id);
Log.i("Show inline=" + show_inline);
boolean inline = false;
boolean download = false; boolean download = false;
boolean save = (attachments.size() > 1); boolean save = (attachments.size() > 1);
boolean downloading = false; boolean downloading = false;
List<EntityAttachment> a = new ArrayList<>();
for (EntityAttachment attachment : attachments) { for (EntityAttachment attachment : attachments) {
if (attachment.isInline())
inline = true;
if (attachment.progress == null && !attachment.available) if (attachment.progress == null && !attachment.available)
download = true; download = true;
if (!attachment.available) if (!attachment.available)
save = false; save = false;
if (attachment.progress != null) if (attachment.progress != null)
downloading = true; downloading = true;
if (show_inline || !attachment.isInline())
a.add(attachment);
} }
adapterAttachment.set(a);
cbInline.setOnCheckedChangeListener(null);
cbInline.setChecked(show_inline);
cbInline.setVisibility(inline ? View.VISIBLE : View.GONE);
btnDownloadAttachments.setVisibility(download && internet ? View.VISIBLE : View.GONE); btnDownloadAttachments.setVisibility(download && internet ? View.VISIBLE : View.GONE);
btnSaveAttachments.setVisibility(save ? View.VISIBLE : View.GONE); btnSaveAttachments.setVisibility(save ? View.VISIBLE : View.GONE);
tvNoInternetAttachments.setVisibility(downloading && !internet ? View.VISIBLE : View.GONE); tvNoInternetAttachments.setVisibility(downloading && !internet ? View.VISIBLE : View.GONE);
cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
properties.setValue("inline", message.id, isChecked);
liveAttachments.removeObserver(observerAttachments);
liveAttachments.observe(owner, observerAttachments);
}
});
List<EntityAttachment> images = new ArrayList<>(); List<EntityAttachment> images = new ArrayList<>();
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (attachment.type.startsWith("image/") && !attachment.isInline()) if (attachment.type.startsWith("image/") && !attachment.isInline())

@ -597,6 +597,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" /> app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" />
<CheckBox
android:id="@+id/cbInline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/title_show_inline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rvAttachment" />
<Button <Button
android:id="@+id/btnDownloadAttachments" android:id="@+id/btnDownloadAttachments"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"
@ -606,7 +615,7 @@
android:minHeight="0dp" android:minHeight="0dp"
android:text="@string/title_download_all" android:text="@string/title_download_all"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> app:layout_constraintTop_toBottomOf="@id/cbInline" />
<Button <Button
android:id="@+id/btnSaveAttachments" android:id="@+id/btnSaveAttachments"
@ -617,7 +626,7 @@
android:minHeight="0dp" android:minHeight="0dp"
android:text="@string/title_save_all" android:text="@string/title_save_all"
app:layout_constraintEnd_toEndOf="@id/rvAttachment" app:layout_constraintEnd_toEndOf="@id/rvAttachment"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> app:layout_constraintTop_toBottomOf="@id/cbInline" />
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier_internet" android:id="@+id/barrier_internet"

@ -589,6 +589,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" /> app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" />
<CheckBox
android:id="@+id/cbInline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/title_show_inline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rvAttachment" />
<Button <Button
android:id="@+id/btnDownloadAttachments" android:id="@+id/btnDownloadAttachments"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"
@ -598,7 +607,7 @@
android:minHeight="0dp" android:minHeight="0dp"
android:text="@string/title_download_all" android:text="@string/title_download_all"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> app:layout_constraintTop_toBottomOf="@id/cbInline" />
<Button <Button
android:id="@+id/btnSaveAttachments" android:id="@+id/btnSaveAttachments"
@ -609,7 +618,7 @@
android:minHeight="0dp" android:minHeight="0dp"
android:text="@string/title_save_all" android:text="@string/title_save_all"
app:layout_constraintEnd_toEndOf="@id/rvAttachment" app:layout_constraintEnd_toEndOf="@id/rvAttachment"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> app:layout_constraintTop_toBottomOf="@id/cbInline" />
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier_internet" android:id="@+id/barrier_internet"

@ -280,6 +280,7 @@
<string name="title_raw_save">Save raw message</string> <string name="title_raw_save">Save raw message</string>
<string name="title_manage_keywords">Manage keywords</string> <string name="title_manage_keywords">Manage keywords</string>
<string name="title_add_keyword">Add keyword</string> <string name="title_add_keyword">Add keyword</string>
<string name="title_show_inline">Show inline attachments</string>
<string name="title_download_all">Download all</string> <string name="title_download_all">Download all</string>
<string name="title_save_all">Save all</string> <string name="title_save_all">Save all</string>
<string name="title_show_html">Show original</string> <string name="title_show_html">Show original</string>

Loading…
Cancel
Save