@@ -690,8 +690,8 @@ private void bindMultiImagePost(FeedPost post) {
690690 mediaItems = post .getMedia ();
691691
692692
693- // For posts with 1-2 images , use grid layout
694- if (mediaItems .size () <= 2 ) {
693+ // For posts with 1 image , use grid layout
694+ if (mediaItems .size () <= 1 ) {
695695 imageGridLayout .setVisibility (View .VISIBLE );
696696 imageViewPager .setVisibility (View .GONE );
697697 imageCounterTextView .setVisibility (View .GONE );
@@ -706,7 +706,7 @@ private void bindMultiImagePost(FeedPost post) {
706706 imageGridLayout .invalidate ();
707707 mediaGalleryContainer .setVisibility (View .VISIBLE );
708708 } else {
709- // For 3 + images, use the ViewPager
709+ // For 2 + images, use the ViewPager
710710 imageGridLayout .setVisibility (View .GONE );
711711 imageViewPager .setVisibility (View .VISIBLE );
712712 imageCounterTextView .setVisibility (View .VISIBLE );
@@ -761,7 +761,7 @@ public void onPageSelected(int position) {
761761 }
762762
763763 /**
764- * Set up the grid layout for 1-3 images
764+ * Set up the grid layout for single image
765765 *
766766 * @param post The post containing the media items
767767 * @param mediaItems The list of media items
@@ -791,53 +791,6 @@ private void setupImageGrid(FeedPost post, List<FeedPostMediaItem> mediaItems) {
791791 params .width = GridLayout .LayoutParams .MATCH_PARENT ;
792792 params .height = GridLayout .LayoutParams .MATCH_PARENT ;
793793 imageGridLayout .addView (imageView , params );
794- } else if (count == 2 ) {
795- // Pre-calculate total height for two stacked images
796- int totalHeight = 0 ;
797- for (int i = 0 ; i < count ; i ++) {
798- FeedPostMediaItem mediaItem = mediaItems .get (i );
799- if (mediaItem .getSizes () != null && !mediaItem .getSizes ().isEmpty ()) {
800- FeedPostMediaItemAsset bestAsset = selectBestImageSize (mediaItem .getSizes ());
801- if (bestAsset != null ) {
802- int imageHeight = calculateImageHeight (bestAsset , screenWidth );
803- totalHeight += imageHeight ;
804- if (i > 0 ) totalHeight += 4 ; // Add margin between images
805- }
806- }
807- }
808-
809- // Set grid height to prevent layout shifts
810- if (totalHeight > 0 ) {
811- imageGridLayout .getLayoutParams ().height = totalHeight ;
812- imageGridLayout .requestLayout ();
813- }
814-
815- // Set up GridLayout configuration for 2 rows, 1 column
816- imageGridLayout .setRowCount (2 );
817- imageGridLayout .setColumnCount (1 );
818-
819- // Two images stacked vertically
820- for (int i = 0 ; i < count ; i ++) {
821- FeedPostMediaItem mediaItem = mediaItems .get (i );
822- ImageView imageView = createImageView (post , mediaItem , i );
823-
824- // Calculate individual image height for proper layout
825- int individualHeight = getHalfImageHeight (); // Default fallback
826- if (mediaItem .getSizes () != null && !mediaItem .getSizes ().isEmpty ()) {
827- FeedPostMediaItemAsset bestAsset = selectBestImageSize (mediaItem .getSizes ());
828- if (bestAsset != null ) {
829- individualHeight = calculateImageHeight (bestAsset , screenWidth );
830- }
831- }
832-
833- GridLayout .LayoutParams params = new GridLayout .LayoutParams (
834- GridLayout .spec (i , 1 ), // i'th row, span 1 row
835- GridLayout .spec (0 , 1 )); // column 0, span 1 column
836- params .width = GridLayout .LayoutParams .MATCH_PARENT ;
837- params .height = GridLayout .LayoutParams .WRAP_CONTENT ;
838- params .setMargins (0 , i > 0 ? 4 : 0 , 0 , i < count - 1 ? 4 : 0 ); // Vertical margins between images
839- imageGridLayout .addView (imageView , params );
840- }
841794 }
842795 }
843796
0 commit comments