mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
b770a39f17
commit
0474a73b4a
|
@ -55,7 +55,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder> {
|
||||
public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder> {
|
||||
private Fragment parentFragment;
|
||||
private final Context context;
|
||||
private final LayoutInflater inflater;
|
||||
|
@ -293,9 +293,9 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
}
|
||||
|
||||
if (reload == null)
|
||||
ServiceSynchronize.eval(context, "image");
|
||||
ServiceSynchronize.eval(context, "media");
|
||||
else
|
||||
ServiceSynchronize.reload(context, reload, false, "image");
|
||||
ServiceSynchronize.reload(context, reload, false, "media");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(context, owner, args, "image:fetch");
|
||||
}.execute(context, owner, args, "media:fetch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
}
|
||||
}
|
||||
|
||||
AdapterImage(Fragment parentFragment) {
|
||||
AdapterMedia(Fragment parentFragment) {
|
||||
this.parentFragment = parentFragment;
|
||||
this.context = parentFragment.getContext();
|
||||
this.owner = parentFragment.getViewLifecycleOwner();
|
||||
|
@ -336,15 +336,15 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroyed() {
|
||||
Log.d(AdapterImage.this + " parent destroyed");
|
||||
AdapterImage.this.parentFragment = null;
|
||||
Log.d(AdapterMedia.this + " parent destroyed");
|
||||
AdapterMedia.this.parentFragment = null;
|
||||
owner.getLifecycle().removeObserver(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void set(@NonNull List<EntityAttachment> attachments) {
|
||||
Log.i("Set images=" + attachments.size());
|
||||
Log.i("Set media=" + attachments.size());
|
||||
|
||||
Collections.sort(attachments, new Comparator<EntityAttachment>() {
|
||||
@Override
|
||||
|
@ -433,7 +433,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
@Override
|
||||
@NonNull
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(inflater.inflate(R.layout.item_image, parent, false));
|
||||
return new ViewHolder(inflater.inflate(R.layout.item_media, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -447,7 +447,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull AdapterImage.ViewHolder holder) {
|
||||
public void onViewRecycled(@NonNull AdapterMedia.ViewHolder holder) {
|
||||
holder.ivImage.setImageDrawable(null);
|
||||
}
|
||||
}
|
|
@ -526,17 +526,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
private ImageButton ibStoreMedia;
|
||||
private ImageButton ibShareImages;
|
||||
private RecyclerView rvImage;
|
||||
private RecyclerView rvMedia;
|
||||
|
||||
private Group grpAddresses;
|
||||
private Group grpHeaders;
|
||||
private Group grpAction;
|
||||
private Group grpCalendar;
|
||||
private Group grpCalendarResponse;
|
||||
private Group grpImages;
|
||||
private Group grpMedia;
|
||||
|
||||
private AdapterAttachment adapterAttachment;
|
||||
private AdapterImage adapterImage;
|
||||
private AdapterMedia adapterMedia;
|
||||
|
||||
private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments");
|
||||
private TwoStateOwner powner = new TwoStateOwner(owner, "MessagePopup");
|
||||
|
@ -956,20 +956,20 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
|
||||
ibStoreMedia = vsBody.findViewById(R.id.ibStoreMedia);
|
||||
ibShareImages = vsBody.findViewById(R.id.ibShareImages);
|
||||
rvImage = vsBody.findViewById(R.id.rvImage);
|
||||
rvImage.setHasFixedSize(false);
|
||||
rvMedia = vsBody.findViewById(R.id.rvMedia);
|
||||
rvMedia.setHasFixedSize(false);
|
||||
StaggeredGridLayoutManager sglm =
|
||||
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
|
||||
rvImage.setLayoutManager(sglm);
|
||||
adapterImage = new AdapterImage(parentFragment);
|
||||
rvImage.setAdapter(adapterImage);
|
||||
rvMedia.setLayoutManager(sglm);
|
||||
adapterMedia = new AdapterMedia(parentFragment);
|
||||
rvMedia.setAdapter(adapterMedia);
|
||||
|
||||
grpAddresses = vsBody.findViewById(R.id.grpAddresses);
|
||||
grpHeaders = vsBody.findViewById(R.id.grpHeaders);
|
||||
grpAction = vsBody.findViewById(R.id.grpAction);
|
||||
grpCalendar = vsBody.findViewById(R.id.grpCalendar);
|
||||
grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
|
||||
grpImages = vsBody.findViewById(R.id.grpImages);
|
||||
grpMedia = vsBody.findViewById(R.id.grpMedia);
|
||||
|
||||
if (large_buttons) {
|
||||
int dp36 = Helper.dp2pixels(context, 42);
|
||||
|
@ -1734,7 +1734,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
grpAction.setVisibility(View.GONE);
|
||||
grpCalendar.setVisibility(View.GONE);
|
||||
grpCalendarResponse.setVisibility(View.GONE);
|
||||
grpImages.setVisibility(View.GONE);
|
||||
grpMedia.setVisibility(View.GONE);
|
||||
|
||||
ivPlain.setVisibility(View.GONE);
|
||||
ibReceipt.setVisibility(View.GONE);
|
||||
|
@ -3682,18 +3682,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
bindCalendar(message, calendar);
|
||||
|
||||
int iavailable = 0;
|
||||
List<EntityAttachment> images = new ArrayList<>();
|
||||
List<EntityAttachment> media = new ArrayList<>();
|
||||
if (thumbnails && bind_extras) {
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if ((pdf_preview && attachment.isPDF()) ||
|
||||
(attachment.isAttachment() && attachment.isImage())) {
|
||||
images.add(attachment);
|
||||
media.add(attachment);
|
||||
if (attachment.available && !attachment.isPDF())
|
||||
iavailable++;
|
||||
}
|
||||
}
|
||||
adapterImage.set(images);
|
||||
grpImages.setVisibility(images.size() > 0 ? View.VISIBLE : View.GONE);
|
||||
adapterMedia.set(media);
|
||||
grpMedia.setVisibility(media.size() > 0 ? View.VISIBLE : View.GONE);
|
||||
|
||||
ibStoreMedia.setVisibility(
|
||||
iavailable > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="wrap_content">
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorImages"
|
||||
android:id="@+id/vSeparatorMedia"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="3dp"
|
||||
|
@ -25,7 +25,7 @@
|
|||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@string/title_save_all"
|
||||
app:layout_constraintEnd_toStartOf="@id/ibShareImages"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorImages"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorMedia"
|
||||
app:srcCompat="@drawable/twotone_photo_library_24" />
|
||||
|
||||
<ImageButton
|
||||
|
@ -38,11 +38,11 @@
|
|||
android:scaleType="fitCenter"
|
||||
android:tooltipText="@string/title_share"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorImages"
|
||||
app:layout_constraintTop_toBottomOf="@+id/vSeparatorMedia"
|
||||
app:srcCompat="@drawable/twotone_share_24" />
|
||||
|
||||
<eu.faircode.email.FixedRecyclerView
|
||||
android:id="@+id/rvImage"
|
||||
android:id="@+id/rvMedia"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -50,8 +50,8 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/ibShareImages" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpImages"
|
||||
android:id="@+id/grpMedia"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="vSeparatorImages,rvImage" />
|
||||
app:constraint_referenced_ids="vSeparatorMedia,rvMedia" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Reference in New Issue