Added collapsing attachments

This commit is contained in:
M66B 2023-07-08 21:16:32 +02:00
parent 2d4d5b579c
commit e6f95ee913
3 changed files with 68 additions and 18 deletions

View File

@ -446,6 +446,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private TextView tvNoInternetHeaders;
private RecyclerView rvAttachment;
private View vSeparatorAttachments;
private ImageButton ibExpanderAttachments;
private TextView tvAttachments;
private CheckBox cbInline;
private ImageButton ibSaveAttachments;
private ImageButton ibDownloadAttachments;
@ -528,7 +531,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private Group grpAction;
private Group grpCalendar;
private Group grpCalendarResponse;
private Group grpAttachments;
private Group grpImages;
private AdapterAttachment adapterAttachment;
@ -875,6 +877,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
adapterAttachment = new AdapterAttachment(parentFragment, true, properties);
rvAttachment.setAdapter(adapterAttachment);
vSeparatorAttachments = attachments.findViewById(R.id.vSeparatorAttachments);
ibExpanderAttachments = attachments.findViewById(R.id.ibExpanderAttachments);
tvAttachments = attachments.findViewById(R.id.tvAttachments);
cbInline = attachments.findViewById(R.id.cbInline);
ibSaveAttachments = attachments.findViewById(R.id.ibSaveAttachments);
ibDownloadAttachments = attachments.findViewById(R.id.ibDownloadAttachments);
@ -962,7 +967,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
grpAction = vsBody.findViewById(R.id.grpAction);
grpCalendar = vsBody.findViewById(R.id.grpCalendar);
grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
grpAttachments = attachments.findViewById(R.id.grpAttachments);
grpImages = vsBody.findViewById(R.id.grpImages);
if (large_buttons) {
@ -1691,7 +1695,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
grpAction.setVisibility(View.GONE);
grpCalendar.setVisibility(View.GONE);
grpCalendarResponse.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
grpImages.setVisibility(View.GONE);
ivPlain.setVisibility(View.GONE);
@ -1748,6 +1751,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
clearCalendar();
rvAttachment.setVisibility(View.GONE);
vSeparatorAttachments.setVisibility(View.GONE);
ibExpanderAttachments.setVisibility(View.GONE);
tvAttachments.setVisibility(View.GONE);
cbInline.setVisibility(View.GONE);
ibSaveAttachments.setVisibility(View.GONE);
ibDownloadAttachments.setVisibility(View.GONE);
@ -3489,6 +3496,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
attachments = new ArrayList<>();
properties.setAttachments(message.id, attachments);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean hide_attachments = prefs.getBoolean("hide_attachments", false);
boolean show_inline = properties.getValue("inline", message.id);
Log.i("Show inline=" + show_inline);
@ -3528,13 +3538,32 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
calendar = attachment;
}
rvAttachment.setVisibility(show.size() > 0 && !hide_attachments ? View.VISIBLE : View.GONE);
vSeparatorAttachments.setVisibility(show.size() > 0 ? View.VISIBLE : View.GONE);
tvAttachments.setText(context.getResources()
.getQuantityString(R.plurals.title_attachments, show.size(), show.size()));
tvAttachments.setVisibility(show.size() > 0 && hide_attachments ? View.VISIBLE : View.GONE);
ibExpanderAttachments.setImageLevel(hide_attachments ? 1 /* more */ : 0 /* less */);
ibExpanderAttachments.setVisibility(show.size() > 0 ? View.VISIBLE : View.GONE);
ibExpanderAttachments.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
prefs.edit().putBoolean("hide_attachments", !hide_attachments).apply();
cowner.restart();
bindAttachments(message, properties.getAttachments(message.id), false);
}
});
cbInline.setOnCheckedChangeListener(null);
cbInline.setChecked(show_inline);
cbInline.setVisibility(has_inline ? View.VISIBLE : View.GONE);
cbInline.setVisibility(has_inline && !hide_attachments ? View.VISIBLE : View.GONE);
ibSaveAttachments.setVisibility(available > 1 && unavailable == 0 ? View.VISIBLE : View.GONE);
ibDownloadAttachments.setVisibility(downloadable > 1 && suitable ? View.VISIBLE : View.GONE);
tvNoInternetAttachments.setVisibility(downloading && !suitable ? View.VISIBLE : View.GONE);
ibSaveAttachments.setVisibility(available > 1 && unavailable == 0 && !hide_attachments ? View.VISIBLE : View.GONE);
ibDownloadAttachments.setVisibility(downloadable > 1 && suitable && !hide_attachments ? View.VISIBLE : View.GONE);
tvNoInternetAttachments.setVisibility(downloading && !suitable && !hide_attachments ? View.VISIBLE : View.GONE);
cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@ -3556,8 +3585,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
});
grpAttachments.setVisibility(show.size() > 0 ? View.VISIBLE : View.GONE);
if (calendar != null && bind_extras)
bindCalendar(message, calendar);

View File

@ -14,6 +14,30 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/ibExpanderAttachments"
android:layout_width="0dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/title_legend_expander"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorAttachments"
app:srcCompat="@drawable/expander" />
<TextView
android:id="@+id/tvAttachments"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:text="10 attachments"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibExpanderAttachments" />
<CheckBox
android:id="@+id/cbInline"
android:layout_width="0dp"
@ -23,7 +47,7 @@
android:text="@string/title_show_inline"
app:layout_constraintEnd_toStartOf="@+id/ibDownloadAttachments"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments" />
app:layout_constraintTop_toBottomOf="@+id/tvAttachments" />
<ImageButton
android:id="@+id/ibDownloadAttachments"
@ -35,7 +59,7 @@
android:scaleType="fitCenter"
android:tooltipText="@string/title_download_all"
app:layout_constraintEnd_toStartOf="@id/ibSaveAttachments"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments"
app:layout_constraintTop_toBottomOf="@+id/tvAttachments"
app:srcCompat="@drawable/twotone_cloud_download_24" />
<ImageButton
@ -48,7 +72,7 @@
android:scaleType="fitCenter"
android:tooltipText="@string/title_save_all"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAttachments"
app:layout_constraintTop_toBottomOf="@+id/tvAttachments"
app:srcCompat="@drawable/twotone_save_alt_24" />
<androidx.constraintlayout.widget.Barrier
@ -80,10 +104,4 @@
app:layout_constraintEnd_toEndOf="@id/rvAttachment"
app:layout_constraintStart_toStartOf="@id/rvAttachment"
app:layout_constraintTop_toBottomOf="@id/rvAttachment" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAttachments"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -91,6 +91,11 @@
<item quantity="other">Delete %1$d messages permanently?</item>
</plurals>
<plurals name="title_attachments">
<item quantity="one">One attachment</item>
<item quantity="other">%1$d attachments</item>
</plurals>
<plurals name="title_ask_spam">
<item quantity="one">Treat %1$d message as spam?</item>
<item quantity="other">Treat %1$d messages as spam?</item>