Refactoring

pull/214/head
M66B 12 months ago
parent b770a39f17
commit 0474a73b4a

@ -55,7 +55,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder> { public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder> {
private Fragment parentFragment; private Fragment parentFragment;
private final Context context; private final Context context;
private final LayoutInflater inflater; private final LayoutInflater inflater;
@ -293,9 +293,9 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
} }
if (reload == null) if (reload == null)
ServiceSynchronize.eval(context, "image"); ServiceSynchronize.eval(context, "media");
else else
ServiceSynchronize.reload(context, reload, false, "image"); ServiceSynchronize.reload(context, reload, false, "media");
return null; return null;
} }
@ -304,7 +304,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), 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.parentFragment = parentFragment;
this.context = parentFragment.getContext(); this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner(); this.owner = parentFragment.getViewLifecycleOwner();
@ -336,15 +336,15 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
owner.getLifecycle().addObserver(new LifecycleObserver() { owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() { public void onDestroyed() {
Log.d(AdapterImage.this + " parent destroyed"); Log.d(AdapterMedia.this + " parent destroyed");
AdapterImage.this.parentFragment = null; AdapterMedia.this.parentFragment = null;
owner.getLifecycle().removeObserver(this); owner.getLifecycle().removeObserver(this);
} }
}); });
} }
public void set(@NonNull List<EntityAttachment> attachments) { 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>() { Collections.sort(attachments, new Comparator<EntityAttachment>() {
@Override @Override
@ -433,7 +433,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
@Override @Override
@NonNull @NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 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 @Override
@ -447,7 +447,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
} }
@Override @Override
public void onViewRecycled(@NonNull AdapterImage.ViewHolder holder) { public void onViewRecycled(@NonNull AdapterMedia.ViewHolder holder) {
holder.ivImage.setImageDrawable(null); holder.ivImage.setImageDrawable(null);
} }
} }

@ -526,17 +526,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private ImageButton ibStoreMedia; private ImageButton ibStoreMedia;
private ImageButton ibShareImages; private ImageButton ibShareImages;
private RecyclerView rvImage; private RecyclerView rvMedia;
private Group grpAddresses; private Group grpAddresses;
private Group grpHeaders; private Group grpHeaders;
private Group grpAction; private Group grpAction;
private Group grpCalendar; private Group grpCalendar;
private Group grpCalendarResponse; private Group grpCalendarResponse;
private Group grpImages; private Group grpMedia;
private AdapterAttachment adapterAttachment; private AdapterAttachment adapterAttachment;
private AdapterImage adapterImage; private AdapterMedia adapterMedia;
private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments"); private TwoStateOwner cowner = new TwoStateOwner(owner, "MessageAttachments");
private TwoStateOwner powner = new TwoStateOwner(owner, "MessagePopup"); 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); ibStoreMedia = vsBody.findViewById(R.id.ibStoreMedia);
ibShareImages = vsBody.findViewById(R.id.ibShareImages); ibShareImages = vsBody.findViewById(R.id.ibShareImages);
rvImage = vsBody.findViewById(R.id.rvImage); rvMedia = vsBody.findViewById(R.id.rvMedia);
rvImage.setHasFixedSize(false); rvMedia.setHasFixedSize(false);
StaggeredGridLayoutManager sglm = StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
rvImage.setLayoutManager(sglm); rvMedia.setLayoutManager(sglm);
adapterImage = new AdapterImage(parentFragment); adapterMedia = new AdapterMedia(parentFragment);
rvImage.setAdapter(adapterImage); rvMedia.setAdapter(adapterMedia);
grpAddresses = vsBody.findViewById(R.id.grpAddresses); grpAddresses = vsBody.findViewById(R.id.grpAddresses);
grpHeaders = vsBody.findViewById(R.id.grpHeaders); grpHeaders = vsBody.findViewById(R.id.grpHeaders);
grpAction = vsBody.findViewById(R.id.grpAction); grpAction = vsBody.findViewById(R.id.grpAction);
grpCalendar = vsBody.findViewById(R.id.grpCalendar); grpCalendar = vsBody.findViewById(R.id.grpCalendar);
grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse); grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
grpImages = vsBody.findViewById(R.id.grpImages); grpMedia = vsBody.findViewById(R.id.grpMedia);
if (large_buttons) { if (large_buttons) {
int dp36 = Helper.dp2pixels(context, 42); int dp36 = Helper.dp2pixels(context, 42);
@ -1734,7 +1734,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
grpAction.setVisibility(View.GONE); grpAction.setVisibility(View.GONE);
grpCalendar.setVisibility(View.GONE); grpCalendar.setVisibility(View.GONE);
grpCalendarResponse.setVisibility(View.GONE); grpCalendarResponse.setVisibility(View.GONE);
grpImages.setVisibility(View.GONE); grpMedia.setVisibility(View.GONE);
ivPlain.setVisibility(View.GONE); ivPlain.setVisibility(View.GONE);
ibReceipt.setVisibility(View.GONE); ibReceipt.setVisibility(View.GONE);
@ -3682,18 +3682,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
bindCalendar(message, calendar); bindCalendar(message, calendar);
int iavailable = 0; int iavailable = 0;
List<EntityAttachment> images = new ArrayList<>(); List<EntityAttachment> media = new ArrayList<>();
if (thumbnails && bind_extras) { if (thumbnails && bind_extras) {
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if ((pdf_preview && attachment.isPDF()) || if ((pdf_preview && attachment.isPDF()) ||
(attachment.isAttachment() && attachment.isImage())) { (attachment.isAttachment() && attachment.isImage())) {
images.add(attachment); media.add(attachment);
if (attachment.available && !attachment.isPDF()) if (attachment.available && !attachment.isPDF())
iavailable++; iavailable++;
} }
} }
adapterImage.set(images); adapterMedia.set(media);
grpImages.setVisibility(images.size() > 0 ? View.VISIBLE : View.GONE); grpMedia.setVisibility(media.size() > 0 ? View.VISIBLE : View.GONE);
ibStoreMedia.setVisibility( ibStoreMedia.setVisibility(
iavailable > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q iavailable > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q

@ -5,7 +5,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<View <View
android:id="@+id/vSeparatorImages" android:id="@+id/vSeparatorMedia"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
@ -25,7 +25,7 @@
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:tooltipText="@string/title_save_all" android:tooltipText="@string/title_save_all"
app:layout_constraintEnd_toStartOf="@id/ibShareImages" 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" /> app:srcCompat="@drawable/twotone_photo_library_24" />
<ImageButton <ImageButton
@ -38,11 +38,11 @@
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:tooltipText="@string/title_share" android:tooltipText="@string/title_share"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorImages" app:layout_constraintTop_toBottomOf="@+id/vSeparatorMedia"
app:srcCompat="@drawable/twotone_share_24" /> app:srcCompat="@drawable/twotone_share_24" />
<eu.faircode.email.FixedRecyclerView <eu.faircode.email.FixedRecyclerView
android:id="@+id/rvImage" android:id="@+id/rvMedia"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -50,8 +50,8 @@
app:layout_constraintTop_toBottomOf="@id/ibShareImages" /> app:layout_constraintTop_toBottomOf="@id/ibShareImages" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpImages" android:id="@+id/grpMedia"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorImages,rvImage" /> app:constraint_referenced_ids="vSeparatorMedia,rvMedia" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save