From b8e2d44638b0ecb213fb0fa74c17da0060f4fd31 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:11:02 +0300 Subject: Initial support for gallery captions --- .../adapters/PostDetailRecyclerViewAdapter.java | 24 +++++ .../ViewRedditGalleryImageOrGifFragment.java | 52 +++++++++- .../infinityforreddit/post/FetchRemovedPost.java | 2 +- .../infinityforreddit/post/ParsePost.java | 31 ++++-- .../infinityforreddit/post/Post.java | 32 +++++- .../infinityforreddit/utils/JSONUtils.java | 2 + .../fragment_view_reddit_gallery_image_or_gif.xml | 113 ++++++++++++++------- .../main/res/layout/item_post_detail_gallery.xml | 54 ++++++++++ 8 files changed, 261 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 789ce798..3d481524 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -810,6 +810,24 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { + UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, captionUrl); + urlMenuBottomSheetFragment.setArguments(bundle); + urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); + return true; + }); + + captionUrlTextView.setVisibility(View.VISIBLE); + captionUrlTextView.setText(captionUrl); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java index 8ae15029..e49ffa7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java @@ -98,7 +98,7 @@ public class FetchRemovedPost { previews.set(0, preview); } } else { - Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1); + Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1, "", ""); preview.setPreviewUrl(result.getString("thumbnail")); ArrayList newPreviews = new ArrayList<>(); newPreviews.add(preview); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index ff341041..860feaf2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -209,7 +209,7 @@ public class ParsePost { String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY); int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight)); + previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight, "", "")); JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY); for (int i = 0; i < thumbnailPreviews.length(); i++) { @@ -218,7 +218,7 @@ public class ParsePost { int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY); int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight)); + previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight, "", "")); } } if (data.has(JSONUtils.CROSSPOST_PARENT_LIST)) { @@ -301,7 +301,7 @@ public class ParsePost { spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else { @@ -341,7 +341,7 @@ public class ParsePost { String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY); int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight)); + previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight, "", "")); JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY); for (int i = 0; i < thumbnailPreviews.length(); i++) { @@ -350,7 +350,7 @@ public class ParsePost { int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY); int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight)); + previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight, "", "")); } } } @@ -397,7 +397,7 @@ public class ParsePost { hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else if (url.endsWith("gif")){ @@ -490,7 +490,7 @@ public class ParsePost { spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else if (url.endsWith("mp4")) { @@ -559,11 +559,24 @@ public class ParsePost { galleryItemUrl = sourceObject.getString(JSONUtils.MP4_KEY); } } + + JSONObject galleryItem = galleryIdsArray.getJSONObject(i); + String galleryItemCaption = ""; + String galleryItemCaptionUrl = ""; + if(galleryItem.has(JSONUtils.CAPTION_KEY)){ + galleryItemCaption = galleryItem.getString(JSONUtils.CAPTION_KEY).trim(); + } + + if(galleryItem.has(JSONUtils.CAPTION_URL_KEY)){ + galleryItemCaptionUrl = galleryItem.getString(JSONUtils.CAPTION_URL_KEY).trim(); + } + if ((previews.isEmpty()) && mimeType.contains("jpg") || mimeType.contains("png")) { previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY), - singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY))); + singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY), galleryItemCaption, galleryItemCaptionUrl)); } - gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1))); + + gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl)); } if (!gallery.isEmpty()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index 6a0173c1..e19696a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -582,8 +582,10 @@ public class Post implements Parcelable { public String url; public String fileName; public int mediaType; + public String caption; + public String captionUrl; - public Gallery(String mimeType, String url, String fileName) { + public Gallery(String mimeType, String url, String fileName, String caption, String captionUrl) { this.mimeType = mimeType; this.url = url; this.fileName = fileName; @@ -594,6 +596,8 @@ public class Post implements Parcelable { } else { mediaType = TYPE_VIDEO; } + this.caption = caption; + this.captionUrl = captionUrl; } protected Gallery(Parcel in) { @@ -601,6 +605,8 @@ public class Post implements Parcelable { url = in.readString(); fileName = in.readString(); mediaType = in.readInt(); + caption = in.readString(); + captionUrl = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -626,6 +632,8 @@ public class Post implements Parcelable { parcel.writeString(url); parcel.writeString(fileName); parcel.writeInt(mediaType); + parcel.writeString(caption); + parcel.writeString(captionUrl); } } @@ -633,17 +641,23 @@ public class Post implements Parcelable { private String previewUrl; private int previewWidth; private int previewHeight; + private String previewCaption; + private String previewCaptionUrl; - public Preview(String previewUrl, int previewWidth, int previewHeight) { + public Preview(String previewUrl, int previewWidth, int previewHeight, String previewCaption, String previewCaptionUrl) { this.previewUrl = previewUrl; this.previewWidth = previewWidth; this.previewHeight = previewHeight; + this.previewCaption = previewCaption; + this.previewCaptionUrl = previewCaptionUrl; } protected Preview(Parcel in) { previewUrl = in.readString(); previewWidth = in.readInt(); previewHeight = in.readInt(); + previewCaption = in.readString(); + previewCaptionUrl = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -682,6 +696,18 @@ public class Post implements Parcelable { this.previewHeight = previewHeight; } + public String getPreviewCaption() { + return previewCaption; + } + + public void setPreviewCaption(String previewCaption) { this.previewCaption = previewCaption; } + + public String getPreviewCaptionUrl() { + return previewCaptionUrl; + } + + public void setPreviewCaptionUrl(String previewCaptionUrl) { this.previewCaptionUrl = previewCaptionUrl; } + @Override public int describeContents() { return 0; @@ -692,6 +718,8 @@ public class Post implements Parcelable { parcel.writeString(previewUrl); parcel.writeInt(previewWidth); parcel.writeInt(previewHeight); + parcel.writeString(previewCaption); + parcel.writeString(previewCaptionUrl); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java index b76f198e..19ea43cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java @@ -171,4 +171,6 @@ public class JSONUtils { public static final String DISPLAY_STRING_KEY = "display_string"; public static final String RESULTS_KEY = "results"; public static final String CONTENT_MD_KEY = "content_md"; + public static final String CAPTION_KEY = "caption"; + public static final String CAPTION_URL_KEY = "outbound_url"; } diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index b41c5600..986b86c6 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -50,47 +50,90 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> - - - + android:gravity="center_vertical" + android:orientation="vertical" + android:visibility="gone"> - + - + + + + android:layout_height="wrap_content"> + + + + + + + + + diff --git a/app/src/main/res/layout/item_post_detail_gallery.xml b/app/src/main/res/layout/item_post_detail_gallery.xml index 6a5d2a51..e9044418 100644 --- a/app/src/main/res/layout/item_post_detail_gallery.xml +++ b/app/src/main/res/layout/item_post_detail_gallery.xml @@ -267,6 +267,60 @@ android:src="@drawable/ic_link" android:visibility="gone" /> + + + + + + + + + + Date: Wed, 10 Nov 2021 15:37:11 +0300 Subject: Fix bottom url menu not being themed accordingly Use linkify for in-gallery caption url --- .../infinityforreddit/activities/BaseActivity.java | 11 ++++++++++ .../activities/ViewRedditGalleryActivity.java | 4 +++- .../adapters/PostDetailRecyclerViewAdapter.java | 3 +++ .../adapters/PostRecyclerViewAdapter.java | 3 +++ .../ViewRedditGalleryImageOrGifFragment.java | 24 +++++++++++++--------- .../fragment_view_reddit_gallery_image_or_gif.xml | 2 -- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 13f40f63..636e4615 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -59,6 +59,7 @@ public abstract class BaseActivity extends AppCompatActivity { private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; private CustomThemeWrapper customThemeWrapper; + private int appliedTheme; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -98,15 +99,18 @@ public abstract class BaseActivity extends AppCompatActivity { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Normal, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); + setAppliedTheme(R.style.Theme_Normal); break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + setAppliedTheme(R.style.Theme_Normal_NormalDark); } break; case 2: @@ -117,14 +121,17 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Normal, true); + setAppliedTheme(R.style.Theme_Normal); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + setAppliedTheme(R.style.Theme_Normal_NormalDark); } } } @@ -227,6 +234,8 @@ public abstract class BaseActivity extends AppCompatActivity { return systemVisibilityToolbarCollapsed; } + public int getAppliedTheme() { return appliedTheme; } + public boolean isImmersiveInterface() { return immersiveInterface; } @@ -297,6 +306,8 @@ public abstract class BaseActivity extends AppCompatActivity { isImmersiveInterfaceApplicable = false; } + public void setAppliedTheme(int appliedStyle) { this.appliedTheme = appliedStyle; } + protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) { applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 8b477c34..3c016a2c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -48,6 +48,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA public static final String EXTRA_REDDIT_GALLERY = "ERG"; public static final String EXTRA_SUBREDDIT_NAME = "ESN"; + public static final String EXTRA_APPLIED_THEME = "EAS"; @BindView(R.id.hauler_view_view_reddit_gallery_activity) HaulerView haulerView; @@ -69,7 +70,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(R.style.Theme_Normal, true); + int theme = getIntent().getIntExtra(EXTRA_APPLIED_THEME, R.style.Theme_Normal); + getTheme().applyStyle(theme <= 0 ? R.style.Theme_Normal : theme, true); getTheme().applyStyle(FontStyle.valueOf(sharedPreferences .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 9857e421..dba26de7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -87,6 +87,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -2268,6 +2269,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { - UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, captionUrl); - urlMenuBottomSheetFragment.setArguments(bundle); - urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); - return true; - }); - - captionUrlTextView.setVisibility(View.VISIBLE); captionUrlTextView.setText(captionUrl); + if (!activity.isDestroyed() && !activity.isFinishing()) { + BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { + UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); + urlMenuBottomSheetFragment.setArguments(bundle); + urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); + return true; + }); + } + captionUrlTextView.setVisibility(View.VISIBLE); } } diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index 986b86c6..23fc50b0 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -77,11 +77,9 @@ android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" - android:autoLink="web" android:ellipsize="end" android:fontFamily="?attr/content_font_family" android:gravity="center_vertical" - android:nestedScrollingEnabled="false" android:textColor="#FFFFFF" android:textColorLink="#FFFFFF" android:textSize="?attr/content_font_default" -- cgit v1.2.3 From 90a9b1033f36087ce302e06304cbf3581921748b Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 27 Nov 2021 20:04:45 +0300 Subject: Make caption text copyable with long press Use native way to theme ViewRedditGalleryActivity --- .../infinityforreddit/activities/BaseActivity.java | 11 ----- .../activities/ViewRedditGalleryActivity.java | 51 +++++++++++++++++++--- .../adapters/PostDetailRecyclerViewAdapter.java | 23 +++++----- .../adapters/PostRecyclerViewAdapter.java | 1 - .../ViewRedditGalleryImageOrGifFragment.java | 47 ++++++++++++-------- .../fragment_view_reddit_gallery_image_or_gif.xml | 3 +- 6 files changed, 87 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 636e4615..13f40f63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -59,7 +59,6 @@ public abstract class BaseActivity extends AppCompatActivity { private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; private CustomThemeWrapper customThemeWrapper; - private int appliedTheme; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -99,18 +98,15 @@ public abstract class BaseActivity extends AppCompatActivity { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Normal, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); - setAppliedTheme(R.style.Theme_Normal); break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); - setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); - setAppliedTheme(R.style.Theme_Normal_NormalDark); } break; case 2: @@ -121,17 +117,14 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Normal, true); - setAppliedTheme(R.style.Theme_Normal); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); - setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); - setAppliedTheme(R.style.Theme_Normal_NormalDark); } } } @@ -234,8 +227,6 @@ public abstract class BaseActivity extends AppCompatActivity { return systemVisibilityToolbarCollapsed; } - public int getAppliedTheme() { return appliedTheme; } - public boolean isImmersiveInterface() { return immersiveInterface; } @@ -306,8 +297,6 @@ public abstract class BaseActivity extends AppCompatActivity { isImmersiveInterfaceApplicable = false; } - public void setAppliedTheme(int appliedStyle) { this.appliedTheme = appliedStyle; } - protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) { applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 3c016a2c..aadf344d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -1,8 +1,15 @@ package ml.docilealligator.infinityforreddit.activities; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + import android.content.SharedPreferences; +import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.Html; @@ -13,6 +20,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; @@ -32,6 +40,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; import ml.docilealligator.infinityforreddit.WallpaperSetter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed; import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontStyle; @@ -48,21 +57,20 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA public static final String EXTRA_REDDIT_GALLERY = "ERG"; public static final String EXTRA_SUBREDDIT_NAME = "ESN"; - public static final String EXTRA_APPLIED_THEME = "EAS"; @BindView(R.id.hauler_view_view_reddit_gallery_activity) HaulerView haulerView; @BindView(R.id.view_pager_view_reddit_gallery_activity) ViewPagerBugFixed viewPager; - private SectionsPagerAdapter sectionsPagerAdapter; - private ArrayList gallery; - private String subredditName; - private boolean useBottomAppBar; @Inject @Named("default") SharedPreferences sharedPreferences; @Inject Executor executor; + private SectionsPagerAdapter sectionsPagerAdapter; + private ArrayList gallery; + private String subredditName; + private boolean useBottomAppBar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -70,8 +78,37 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA ((Infinity) getApplication()).getAppComponent().inject(this); - int theme = getIntent().getIntExtra(EXTRA_APPLIED_THEME, R.style.Theme_Normal); - getTheme().applyStyle(theme <= 0 ? R.style.Theme_Normal : theme, true); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int systemThemeType = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (systemThemeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + getTheme().applyStyle(R.style.Theme_Normal, true); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); + } + break; + case 2: + if (systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + getTheme().applyStyle(R.style.Theme_Normal, true); + } else { + if (sharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); + } + } + } getTheme().applyStyle(FontStyle.valueOf(sharedPreferences .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index dba26de7..d99db605 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -87,7 +87,6 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; -import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -124,7 +123,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { + if (activity != null + && !activity.isDestroyed() + && !activity.isFinishing() + && captionTextView.getSelectionStart() == -1 + && captionTextView.getSelectionEnd() == -1) { + Bundle bundle = new Bundle(); + bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, caption); + CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment(); + copyTextBottomSheetFragment.setArguments(bundle); + copyTextBottomSheetFragment.show(activity.getSupportFragmentManager(), copyTextBottomSheetFragment.getTag()); + } + return true; + }); } - if(!captionUrlIsEmpty) - { + if (!captionUrlIsEmpty) { captionUrlTextView.setText(captionUrl); - if (!activity.isDestroyed() && !activity.isFinishing()) { - BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { + BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { + if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); urlMenuBottomSheetFragment.setArguments(bundle); urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); - return true; - }); - } + } + return true; + }); captionUrlTextView.setVisibility(View.VISIBLE); } } @@ -348,7 +361,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { Intent intent = new Intent(activity, DownloadMediaService.class); intent.putExtra(DownloadMediaService.EXTRA_URL, media.url); - intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF: DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); + intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); ContextCompat.startForegroundService(activity, intent); diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index 23fc50b0..54d64069 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -59,7 +59,8 @@ android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="vertical" - android:visibility="gone"> + android:visibility="gone" + android:paddingTop="8dp"> Date: Sat, 27 Nov 2021 21:28:49 +0300 Subject: Fix conflict --- .../infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 853ce598..5ab227a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -131,7 +131,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter Date: Sun, 28 Nov 2021 19:15:47 +0300 Subject: Adjust caption layout Set caption max length Set link ellipsis --- .../adapters/PostDetailRecyclerViewAdapter.java | 44 ++++--- .../ViewRedditGalleryImageOrGifFragment.java | 40 ++++-- .../fragment_view_reddit_gallery_image_or_gif.xml | 50 +++---- .../main/res/layout/item_post_detail_gallery.xml | 146 +++++++++++---------- 4 files changed, 151 insertions(+), 129 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 5ab227a1..17bd2e8a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -768,26 +768,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter previews) { Post.Preview preview; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 97330c13..df3d88ae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -201,20 +201,12 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { bottomAppBar.setVisibility(View.VISIBLE); } } else { - activity.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_IMMERSIVE); - isActionBarHidden = true; - if (activity.isUseBottomAppBar() || isUseBottomCaption) { - bottomAppBar.setVisibility(View.GONE); - } + hideAppBar(); } }); + captionLayout.setOnClickListener(view -> hideAppBar()); + errorLinearLayout.setOnClickListener(view -> { progressBar.setVisibility(View.VISIBLE); errorLinearLayout.setVisibility(View.GONE); @@ -268,6 +260,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { if (!captionIsEmpty) { captionTextView.setVisibility(View.VISIBLE); captionTextView.setText(caption); + captionTextView.setOnClickListener(view -> hideAppBar()); captionTextView.setOnLongClickListener(view -> { if (activity != null && !activity.isDestroyed() @@ -284,12 +277,19 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { }); } if (!captionUrlIsEmpty) { - captionUrlTextView.setText(captionUrl); + String scheme = Uri.parse(captionUrl).getScheme(); + String urlWithoutScheme = ""; + if(!TextUtils.isEmpty(scheme)){ + urlWithoutScheme = captionUrl.substring(scheme.length() + 3); + } + + captionUrlTextView.setText(TextUtils.isEmpty(urlWithoutScheme) ? captionUrl : urlWithoutScheme); + BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); Bundle bundle = new Bundle(); - bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, captionUrl); urlMenuBottomSheetFragment.setArguments(bundle); urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); } @@ -302,6 +302,20 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { return rootView; } + private void hideAppBar() { + activity.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE); + isActionBarHidden = true; + if (activity.isUseBottomAppBar() || isUseBottomCaption) { + bottomAppBar.setVisibility(View.GONE); + } + } + private void loadImage() { imageView.showImage(Uri.parse(media.url)); } diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index 54d64069..4cfdf858 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -1,7 +1,7 @@ + android:textColor="@android:color/white" + android:textSize="?attr/font_default" /> + android:visibility="gone"> + android:paddingTop="8dp" + android:visibility="gone"> @@ -80,7 +80,7 @@ android:layout_weight="1" android:ellipsize="end" android:fontFamily="?attr/content_font_family" - android:gravity="center_vertical" + android:maxLength="180" android:textColor="#FFFFFF" android:textColorLink="#FFFFFF" android:textSize="?attr/content_font_default" @@ -97,41 +97,41 @@ android:id="@+id/title_text_view_view_reddit_gallery_image_or_gif_fragment" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_weight="1" android:layout_gravity="center_vertical" + android:layout_weight="1" + android:ellipsize="end" + android:fontFamily="?attr/font_family" android:gravity="center_vertical" + android:maxLines="1" android:paddingTop="8dp" android:paddingBottom="8dp" android:textColor="#FFFFFF" - android:textSize="?attr/font_20" - android:fontFamily="?attr/font_family" - android:maxLines="1" - android:ellipsize="end" /> + android:textSize="?attr/font_20" /> + android:src="@drawable/ic_file_download_toolbar_white_24dp" /> + android:src="@drawable/ic_share_toolbar_white_24dp" /> + android:src="@drawable/ic_wallpaper_white_24dp" /> diff --git a/app/src/main/res/layout/item_post_detail_gallery.xml b/app/src/main/res/layout/item_post_detail_gallery.xml index e9044418..0cf6a484 100644 --- a/app/src/main/res/layout/item_post_detail_gallery.xml +++ b/app/src/main/res/layout/item_post_detail_gallery.xml @@ -1,11 +1,11 @@ + android:background="?attr/cardViewBackgroundColor" + android:orientation="vertical"> + app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post_detail_gallery" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post_detail_gallery" + app:layout_constraintTop_toBottomOf="@+id/subreddit_text_view_item_post_detail_gallery" /> + android:textSize="?attr/title_font_18" /> @@ -129,10 +129,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:text="@string/spoiler" - android:textSize="?attr/font_12" android:fontFamily="?attr/font_family" android:padding="4dp" + android:text="@string/spoiler" + android:textSize="?attr/font_12" android:visibility="gone" app:lib_setRadius="6dp" app:lib_setRoundedView="true" @@ -142,10 +142,10 @@ android:id="@+id/nsfw_text_view_item_post_detail_gallery" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:fontFamily="?attr/font_family" android:padding="4dp" android:text="@string/nsfw" android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" android:visibility="gone" app:lib_setRadius="6dp" app:lib_setRoundedView="true" @@ -156,9 +156,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:fontFamily="?attr/font_family" android:padding="4dp" android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" android:visibility="gone" app:lib_setRadius="6dp" app:lib_setRoundedView="true" @@ -168,8 +168,8 @@ android:id="@+id/upvote_ratio_text_view_item_post_detail_gallery" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" /> + android:fontFamily="?attr/font_family" + android:textSize="?attr/font_12" /> @@ -223,10 +223,10 @@ android:id="@+id/video_or_gif_indicator_image_view_item_post_detail" android:layout_width="36dp" android:layout_height="36dp" - android:layout_margin="16dp" android:layout_gravity="start" - android:scaleType="center" + android:layout_margin="16dp" android:background="@drawable/play_button_round_background" + android:scaleType="center" android:src="@drawable/ic_gallery_24dp" /> @@ -247,12 +247,12 @@ android:id="@+id/load_image_error_text_view_item_post_detail_gallery" android:layout_width="match_parent" android:layout_height="wrap_content" - android:drawableTop="@drawable/ic_error_outline_black_24dp" android:layout_centerInParent="true" + android:drawableTop="@drawable/ic_error_outline_black_24dp" + android:fontFamily="?attr/font_family" android:gravity="center" android:text="@string/error_loading_image_tap_to_retry" android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" android:visibility="gone" /> @@ -279,42 +279,44 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:ellipsize="marquee" + android:focusable="true" + android:focusableInTouchMode="true" android:fontFamily="?attr/content_font_family" android:gravity="start" android:marqueeRepeatLimit="marquee_forever" - android:paddingLeft="8dp" - android:paddingRight="8dp" - android:singleLine="true" + android:paddingHorizontal="8dp" android:scrollHorizontally="true" - android:focusable="true" - android:focusableInTouchMode="true" + android:singleLine="true" android:textColor="?attr/primaryTextColor" android:textSize="?attr/content_font_default" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@id/guideline4" + app:layout_constraintEnd_toStartOf="@id/caption_url_text_view_item_post_detail_gallery" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -322,89 +324,89 @@ + android:layout_height="wrap_content"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintStart_toEndOf="@id/plus_button_item_post_detail_gallery" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintStart_toEndOf="@id/score_text_view_item_post_detail_gallery" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintStart_toEndOf="@id/minus_button_item_post_detail_gallery" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> -- cgit v1.2.3 From 886eb68341579634090e73fd3306ec5019eb9f9a Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:10:31 +0300 Subject: Download unprocessed gallery picture Resolves #558 --- .../ViewRedditGalleryImageOrGifFragment.java | 33 ++++++++++++++++++---- .../infinityforreddit/post/ParsePost.java | 12 +++++++- .../infinityforreddit/post/Post.java | 15 +++++++++- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index df3d88ae..51af89cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -111,6 +111,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { private boolean isDownloading = false; private boolean isActionBarHidden = false; private boolean isUseBottomCaption = false; + private boolean isFallback = false; public ViewRedditGalleryImageOrGifFragment() { // Required empty public constructor @@ -177,6 +178,21 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { view.setQuickScaleEnabled(true); view.resetScaleAndCenter(); } + + @Override + public void onImageLoadError(Exception e) { + e.printStackTrace(); + // For issue #558 + // Make sure it's not stuck in a loop if it comes to that + // Fallback url should be empty if it's not an album item + if (!isFallback && media.hasFallback()) { + imageView.cancel(); + isFallback = true; + loadImage(); + } else { + isFallback = false; + } + } }); } } @@ -210,7 +226,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { errorLinearLayout.setOnClickListener(view -> { progressBar.setVisibility(View.VISIBLE); errorLinearLayout.setVisibility(View.GONE); - loadImage(); }); if (activity.isUseBottomAppBar()) { @@ -317,7 +332,12 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { } private void loadImage() { - imageView.showImage(Uri.parse(media.url)); + if(isFallback) { + imageView.showImage(Uri.parse(media.fallbackUrl)); + } + else{ + imageView.showImage(Uri.parse(media.url)); + } } @Override @@ -374,7 +394,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isDownloading = false; Intent intent = new Intent(activity, DownloadMediaService.class); - intent.putExtra(DownloadMediaService.EXTRA_URL, media.url); + intent.putExtra(DownloadMediaService.EXTRA_URL, media.hasFallback() ? media.fallbackUrl : media.url); // Retrieve original instead of the one additionally compressed by reddit intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); @@ -382,8 +402,10 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } + //TODO: Find a way to share original image, Glide messes with the size and quality, + // compression should be up to the app being shared with (WhatsApp for example) private void shareImage() { - glide.asBitmap().load(media.url).into(new CustomTarget() { + glide.asBitmap().load(media.hasFallback() ? media.fallbackUrl : media.url).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { if (activity.getExternalCacheDir() != null) { @@ -499,7 +521,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { super.onResume(); SubsamplingScaleImageView ssiv = imageView.getSSIV(); if (ssiv == null || !ssiv.hasImage()) { - imageView.showImage(Uri.parse(media.url)); + loadImage(); } } @@ -507,6 +529,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { public void onDestroyView() { super.onDestroyView(); imageView.cancel(); + isFallback = false; SubsamplingScaleImageView subsamplingScaleImageView = imageView.getSSIV(); if (subsamplingScaleImageView != null) { subsamplingScaleImageView.recycle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 860feaf2..cf070e4e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.post; import android.net.Uri; import android.os.Handler; import android.text.Html; +import android.text.TextUtils; import org.json.JSONArray; import org.json.JSONException; @@ -575,8 +576,17 @@ public class ParsePost { previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY), singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY), galleryItemCaption, galleryItemCaptionUrl)); } + + Post.Gallery postGalleryItem = new Post.Gallery(mimeType, galleryItemUrl, "", subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl); + + // For issue #558 + // Construct a fallback image url + if(!TextUtils.isEmpty(galleryItemUrl) && !TextUtils.isEmpty(mimeType) && (mimeType.contains("jpg") || mimeType.contains("png"))) { + postGalleryItem.setFallbackUrl("https://i.redd.it/" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1)); + postGalleryItem.setHasFallback(true); + } - gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl)); + gallery.add(postGalleryItem); } if (!gallery.isEmpty()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index e19696a3..ce096362 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -580,14 +580,17 @@ public class Post implements Parcelable { public String mimeType; public String url; + public String fallbackUrl; + private boolean hasFallback; public String fileName; public int mediaType; public String caption; public String captionUrl; - public Gallery(String mimeType, String url, String fileName, String caption, String captionUrl) { + public Gallery(String mimeType, String url, String fallbackUrl, String fileName, String caption, String captionUrl) { this.mimeType = mimeType; this.url = url; + this.fallbackUrl = fallbackUrl; this.fileName = fileName; if (mimeType.contains("gif")) { mediaType = TYPE_GIF; @@ -603,6 +606,8 @@ public class Post implements Parcelable { protected Gallery(Parcel in) { mimeType = in.readString(); url = in.readString(); + fallbackUrl = in.readString(); + hasFallback = in.readByte() != 0; fileName = in.readString(); mediaType = in.readInt(); caption = in.readString(); @@ -630,11 +635,19 @@ public class Post implements Parcelable { public void writeToParcel(Parcel parcel, int i) { parcel.writeString(mimeType); parcel.writeString(url); + parcel.writeString(fallbackUrl); + parcel.writeByte((byte) (hasFallback ? 1 : 0)); parcel.writeString(fileName); parcel.writeInt(mediaType); parcel.writeString(caption); parcel.writeString(captionUrl); } + + public void setFallbackUrl(String fallbackUrl) { this.fallbackUrl = fallbackUrl; } + + public void setHasFallback(boolean hasFallback) { this.hasFallback = hasFallback; } + + public boolean hasFallback() { return this.hasFallback; } } public static class Preview implements Parcelable { -- cgit v1.2.3 From a663359f9aedad2b8cbbbf31ecbd95137c241846 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:13:08 +0300 Subject: Revert "Download unprocessed gallery picture" This reverts commit 886eb68341579634090e73fd3306ec5019eb9f9a. --- .../ViewRedditGalleryImageOrGifFragment.java | 33 ++++------------------ .../infinityforreddit/post/ParsePost.java | 12 +------- .../infinityforreddit/post/Post.java | 15 +--------- 3 files changed, 7 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 51af89cb..df3d88ae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -111,7 +111,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { private boolean isDownloading = false; private boolean isActionBarHidden = false; private boolean isUseBottomCaption = false; - private boolean isFallback = false; public ViewRedditGalleryImageOrGifFragment() { // Required empty public constructor @@ -178,21 +177,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { view.setQuickScaleEnabled(true); view.resetScaleAndCenter(); } - - @Override - public void onImageLoadError(Exception e) { - e.printStackTrace(); - // For issue #558 - // Make sure it's not stuck in a loop if it comes to that - // Fallback url should be empty if it's not an album item - if (!isFallback && media.hasFallback()) { - imageView.cancel(); - isFallback = true; - loadImage(); - } else { - isFallback = false; - } - } }); } } @@ -226,6 +210,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { errorLinearLayout.setOnClickListener(view -> { progressBar.setVisibility(View.VISIBLE); errorLinearLayout.setVisibility(View.GONE); + loadImage(); }); if (activity.isUseBottomAppBar()) { @@ -332,12 +317,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { } private void loadImage() { - if(isFallback) { - imageView.showImage(Uri.parse(media.fallbackUrl)); - } - else{ - imageView.showImage(Uri.parse(media.url)); - } + imageView.showImage(Uri.parse(media.url)); } @Override @@ -394,7 +374,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isDownloading = false; Intent intent = new Intent(activity, DownloadMediaService.class); - intent.putExtra(DownloadMediaService.EXTRA_URL, media.hasFallback() ? media.fallbackUrl : media.url); // Retrieve original instead of the one additionally compressed by reddit + intent.putExtra(DownloadMediaService.EXTRA_URL, media.url); intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName); intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName); @@ -402,10 +382,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); } - //TODO: Find a way to share original image, Glide messes with the size and quality, - // compression should be up to the app being shared with (WhatsApp for example) private void shareImage() { - glide.asBitmap().load(media.hasFallback() ? media.fallbackUrl : media.url).into(new CustomTarget() { + glide.asBitmap().load(media.url).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { if (activity.getExternalCacheDir() != null) { @@ -521,7 +499,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { super.onResume(); SubsamplingScaleImageView ssiv = imageView.getSSIV(); if (ssiv == null || !ssiv.hasImage()) { - loadImage(); + imageView.showImage(Uri.parse(media.url)); } } @@ -529,7 +507,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { public void onDestroyView() { super.onDestroyView(); imageView.cancel(); - isFallback = false; SubsamplingScaleImageView subsamplingScaleImageView = imageView.getSSIV(); if (subsamplingScaleImageView != null) { subsamplingScaleImageView.recycle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index cf070e4e..860feaf2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.post; import android.net.Uri; import android.os.Handler; import android.text.Html; -import android.text.TextUtils; import org.json.JSONArray; import org.json.JSONException; @@ -576,17 +575,8 @@ public class ParsePost { previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY), singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY), galleryItemCaption, galleryItemCaptionUrl)); } - - Post.Gallery postGalleryItem = new Post.Gallery(mimeType, galleryItemUrl, "", subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl); - - // For issue #558 - // Construct a fallback image url - if(!TextUtils.isEmpty(galleryItemUrl) && !TextUtils.isEmpty(mimeType) && (mimeType.contains("jpg") || mimeType.contains("png"))) { - postGalleryItem.setFallbackUrl("https://i.redd.it/" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1)); - postGalleryItem.setHasFallback(true); - } - gallery.add(postGalleryItem); + gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl)); } if (!gallery.isEmpty()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index ce096362..e19696a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -580,17 +580,14 @@ public class Post implements Parcelable { public String mimeType; public String url; - public String fallbackUrl; - private boolean hasFallback; public String fileName; public int mediaType; public String caption; public String captionUrl; - public Gallery(String mimeType, String url, String fallbackUrl, String fileName, String caption, String captionUrl) { + public Gallery(String mimeType, String url, String fileName, String caption, String captionUrl) { this.mimeType = mimeType; this.url = url; - this.fallbackUrl = fallbackUrl; this.fileName = fileName; if (mimeType.contains("gif")) { mediaType = TYPE_GIF; @@ -606,8 +603,6 @@ public class Post implements Parcelable { protected Gallery(Parcel in) { mimeType = in.readString(); url = in.readString(); - fallbackUrl = in.readString(); - hasFallback = in.readByte() != 0; fileName = in.readString(); mediaType = in.readInt(); caption = in.readString(); @@ -635,19 +630,11 @@ public class Post implements Parcelable { public void writeToParcel(Parcel parcel, int i) { parcel.writeString(mimeType); parcel.writeString(url); - parcel.writeString(fallbackUrl); - parcel.writeByte((byte) (hasFallback ? 1 : 0)); parcel.writeString(fileName); parcel.writeInt(mediaType); parcel.writeString(caption); parcel.writeString(captionUrl); } - - public void setFallbackUrl(String fallbackUrl) { this.fallbackUrl = fallbackUrl; } - - public void setHasFallback(boolean hasFallback) { this.hasFallback = hasFallback; } - - public boolean hasFallback() { return this.hasFallback; } } public static class Preview implements Parcelable { -- cgit v1.2.3