diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 954083c2..09304dd4 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -48,6 +48,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import android.widget.CheckBox; import android.widget.GridView; @@ -62,6 +63,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.PopupMenu; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; @@ -2113,6 +2115,35 @@ public class StatusAdapter extends RecyclerView.Adapter StatusViewHolder holder = (StatusViewHolder) viewHolder; MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account); if (status.art_attachment != null) { + + holder.bindingArt.artMedia.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + holder.bindingArt.artMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this); + float viewWidth = holder.bindingArt.artMedia.getWidth(); + ConstraintLayout.LayoutParams lp; + float mediaH = status.art_attachment.meta.small.height; + float mediaW = status.art_attachment.meta.small.width; + float ratio = 1.0f; + if (mediaW != 0) { + ratio = viewWidth / mediaW; + } + lp = new ConstraintLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio)); + holder.bindingArt.artMedia.setScaleType(ImageView.ScaleType.FIT_CENTER); + holder.bindingArt.artMedia.setLayoutParams(lp); + } + }); + float viewWidth = holder.bindingArt.artMedia.getWidth(); + ConstraintLayout.LayoutParams lp; + float mediaH = status.art_attachment.meta.small.height; + float mediaW = status.art_attachment.meta.small.width; + float ratio = 1.0f; + if (mediaW != 0) { + ratio = viewWidth / mediaW; + } + lp = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio)); + holder.bindingArt.artMedia.setScaleType(ImageView.ScaleType.FIT_CENTER); + holder.bindingArt.artMedia.setLayoutParams(lp); Glide.with(holder.bindingArt.artMedia.getContext()) .load(status.art_attachment.preview_url) .apply(new RequestOptions().transform(new RoundedCorners((int) Helper.convertDpToPixel(3, context)))) diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index e33d4ff7..6e3d55fb 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -342,19 +342,28 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. flagLoading = fetched_statuses.pagination.max_id == null; binding.noAction.setVisibility(View.GONE); + if (timelineType == Timeline.TimeLineEnum.ART) { //We have to split media in different statuses List mediaStatuses = new ArrayList<>(); for (Status status : fetched_statuses.statuses) { - if (status.media_attachments.size() > 1) { - for (Attachment attachment : status.media_attachments) { - status.media_attachments = new ArrayList<>(); - status.media_attachments.add(0, attachment); - mediaStatuses.add(status); + if (!tagTimeline.isNSFW && status.sensitive) { + continue; + } + for (Attachment attachment : status.media_attachments) { + try { + Status statusTmp = (Status) status.clone(); + statusTmp.art_attachment = attachment; + mediaStatuses.add(statusTmp); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); } + } } - fetched_statuses.statuses = mediaStatuses; + if (mediaStatuses.size() > 0) { + fetched_statuses.statuses = mediaStatuses; + } } //Update the timeline with new statuses int insertedStatus = updateStatusListWith(fetched_statuses.statuses); @@ -622,14 +631,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true); - /*Handler handler = new Handler(); - handler.postDelayed(() -> { - if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) { - getCachedStatus(direction, fetchingMissing, timelineParams); - } else { - getLiveStatus(direction, fetchingMissing, timelineParams, status); - } - }, slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 ? 0 : 1000);*/ if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) { getCachedStatus(direction, fetchingMissing, timelineParams); } else { diff --git a/app/src/main/res/layout/drawer_status_art.xml b/app/src/main/res/layout/drawer_status_art.xml index d14d14c4..c7d4d5b6 100644 --- a/app/src/main/res/layout/drawer_status_art.xml +++ b/app/src/main/res/layout/drawer_status_art.xml @@ -14,47 +14,32 @@ You should have received a copy of the GNU General Public License along with Fedilab; if not, see . --> - - - - - - - - - - - + android:layout_height="wrap_content" + android:adjustViewBounds="true" + android:scaleType="fitCenter" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:src="@tools:sample/backgrounds/scenic" /> @@ -88,4 +73,4 @@ android:textColor="@color/white" /> - \ No newline at end of file + \ No newline at end of file