From 99a8e035789bed0070f3e49373f97d4a69460ead Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 26 Sep 2020 14:42:35 -0400 Subject: [PATCH] dm media layout finalization --- .../DirectMessageMediaShareViewHolder.java | 31 +------------------ .../fragments/main/ProfileFragment.java | 1 - .../awais/instagrabber/utils/NumberUtils.java | 4 +-- .../fragment_direct_messages_thread.xml | 1 - app/src/main/res/layout/layout_dm_media.xml | 1 + .../main/res/layout/layout_dm_media_share.xml | 1 + .../main/res/layout/layout_dm_raven_media.xml | 1 + .../main/res/layout/layout_dm_story_share.xml | 1 + 8 files changed, 7 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageMediaShareViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageMediaShareViewHolder.java index 9648b82d..02a79cff 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageMediaShareViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageMediaShareViewHolder.java @@ -53,41 +53,12 @@ public class DirectMessageMediaShareViewHolder extends DirectMessageItemViewHold maxWidth ); final ViewGroup.LayoutParams layoutParams = binding.ivMediaPreview.getLayoutParams(); - layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; layoutParams.height = widthHeight.second != null ? widthHeight.second : 0; + layoutParams.width = widthHeight.first != null ? widthHeight.first : 0; binding.ivMediaPreview.requestLayout(); binding.ivMediaPreview.setImageURI(mediaModel.getThumbUrl()); final MediaItemType modelMediaType = mediaModel.getMediaType(); binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO || modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER ? View.VISIBLE : View.GONE); } - - private class WidthHeight { - private final DirectItemMediaModel mediaModel; - private int height; - private int width; - - public WidthHeight(final DirectItemMediaModel mediaModel) {this.mediaModel = mediaModel;} - - public int getHeight() { - return height; - } - - public int getWidth() { - return width; - } - - public WidthHeight invoke() { - height = mediaModel.getHeight(); - width = mediaModel.getWidth(); - // make height 500dp regardless - width = NumberUtils.getResultingWidth(maxHeight, height, width); - height = maxHeight; - if (width > maxWidth) { - height = NumberUtils.getResultingHeight(maxWidth, height, width); - width = maxWidth; - } - return this; - } - } } diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 75ddef44..21aed661 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -841,7 +841,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } private void fetchPosts() { - Log.d("austin_debug", "fp"); stopCurrentExecutor(); binding.swipeRefreshLayout.setRefreshing(true); currentlyExecuting = new PostsFetcher(profileModel.getId(), PostItemType.MAIN, endCursor, postsFetchListener) diff --git a/app/src/main/java/awais/instagrabber/utils/NumberUtils.java b/app/src/main/java/awais/instagrabber/utils/NumberUtils.java index 69db8011..1c8db120 100644 --- a/app/src/main/java/awais/instagrabber/utils/NumberUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/NumberUtils.java @@ -57,8 +57,8 @@ public final class NumberUtils { @NonNull public static Pair calculateWidthHeight(final int height, final int width, final int maxHeight, final int maxWidth) { - int tempWidth = NumberUtils.getResultingWidth(maxHeight, height, width); - int tempHeight = maxHeight; + int tempWidth = width; + int tempHeight = height > maxHeight ? maxHeight : height; if (tempWidth > maxWidth) { tempHeight = NumberUtils.getResultingHeight(maxWidth, height, width); tempWidth = maxWidth; diff --git a/app/src/main/res/layout/fragment_direct_messages_thread.xml b/app/src/main/res/layout/fragment_direct_messages_thread.xml index 3ea8bd66..23f34465 100644 --- a/app/src/main/res/layout/fragment_direct_messages_thread.xml +++ b/app/src/main/res/layout/fragment_direct_messages_thread.xml @@ -11,7 +11,6 @@ android:id="@+id/swipeRefreshLayout" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_weight="1"> diff --git a/app/src/main/res/layout/layout_dm_media_share.xml b/app/src/main/res/layout/layout_dm_media_share.xml index 02c082bc..867f2526 100644 --- a/app/src/main/res/layout/layout_dm_media_share.xml +++ b/app/src/main/res/layout/layout_dm_media_share.xml @@ -22,6 +22,7 @@ android:id="@+id/ivMediaPreview" android:layout_width="match_parent" android:layout_height="match_parent" + android:layout_gravity="center" android:adjustViewBounds="true" android:maxHeight="@dimen/dm_media_img_max_height" app:actualImageScaleType="fitCenter" /> diff --git a/app/src/main/res/layout/layout_dm_raven_media.xml b/app/src/main/res/layout/layout_dm_raven_media.xml index b5aa10a3..7fae919a 100644 --- a/app/src/main/res/layout/layout_dm_raven_media.xml +++ b/app/src/main/res/layout/layout_dm_raven_media.xml @@ -20,6 +20,7 @@ android:id="@+id/ivMediaPreview" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" android:adjustViewBounds="true" android:maxHeight="@dimen/dm_media_img_max_height" /> diff --git a/app/src/main/res/layout/layout_dm_story_share.xml b/app/src/main/res/layout/layout_dm_story_share.xml index beaf49f8..3aa5ebc9 100644 --- a/app/src/main/res/layout/layout_dm_story_share.xml +++ b/app/src/main/res/layout/layout_dm_story_share.xml @@ -13,6 +13,7 @@ android:id="@+id/ivMediaPreview" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" android:adjustViewBounds="true" android:maxHeight="@dimen/dm_media_img_max_height" />