Make caption text copyable with long press

Use native way to theme ViewRedditGalleryActivity
This commit is contained in:
scria1000 2021-11-27 20:04:45 +03:00
parent 17df9d41ca
commit 90a9b1033f
6 changed files with 87 additions and 49 deletions

View File

@ -59,7 +59,6 @@ public abstract class BaseActivity extends AppCompatActivity {
private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarExpanded = 0;
private int systemVisibilityToolbarCollapsed = 0; private int systemVisibilityToolbarCollapsed = 0;
private CustomThemeWrapper customThemeWrapper; private CustomThemeWrapper customThemeWrapper;
private int appliedTheme;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -99,18 +98,15 @@ public abstract class BaseActivity extends AppCompatActivity {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
getTheme().applyStyle(R.style.Theme_Normal, true); getTheme().applyStyle(R.style.Theme_Normal, true);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT);
setAppliedTheme(R.style.Theme_Normal);
break; break;
case 1: case 1:
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED);
setAppliedTheme(R.style.Theme_Normal_AmoledDark);
} else { } else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK);
setAppliedTheme(R.style.Theme_Normal_NormalDark);
} }
break; break;
case 2: 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) { if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
getTheme().applyStyle(R.style.Theme_Normal, true); getTheme().applyStyle(R.style.Theme_Normal, true);
setAppliedTheme(R.style.Theme_Normal);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT);
} else { } else {
if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED);
setAppliedTheme(R.style.Theme_Normal_AmoledDark);
} else { } else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK);
setAppliedTheme(R.style.Theme_Normal_NormalDark);
} }
} }
} }
@ -234,8 +227,6 @@ public abstract class BaseActivity extends AppCompatActivity {
return systemVisibilityToolbarCollapsed; return systemVisibilityToolbarCollapsed;
} }
public int getAppliedTheme() { return appliedTheme; }
public boolean isImmersiveInterface() { public boolean isImmersiveInterface() {
return immersiveInterface; return immersiveInterface;
} }
@ -306,8 +297,6 @@ public abstract class BaseActivity extends AppCompatActivity {
isImmersiveInterfaceApplicable = false; isImmersiveInterfaceApplicable = false;
} }
public void setAppliedTheme(int appliedStyle) { this.appliedTheme = appliedStyle; }
protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) { protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) {
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true);
} }

View File

@ -1,8 +1,15 @@
package ml.docilealligator.infinityforreddit.activities; 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.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Html; import android.text.Html;
@ -13,6 +20,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter;
@ -32,6 +40,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
import ml.docilealligator.infinityforreddit.WallpaperSetter; import ml.docilealligator.infinityforreddit.WallpaperSetter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle; 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_REDDIT_GALLERY = "ERG";
public static final String EXTRA_SUBREDDIT_NAME = "ESN"; 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) @BindView(R.id.hauler_view_view_reddit_gallery_activity)
HaulerView haulerView; HaulerView haulerView;
@BindView(R.id.view_pager_view_reddit_gallery_activity) @BindView(R.id.view_pager_view_reddit_gallery_activity)
ViewPagerBugFixed viewPager; ViewPagerBugFixed viewPager;
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<Post.Gallery> gallery;
private String subredditName;
private boolean useBottomAppBar;
@Inject @Inject
@Named("default") @Named("default")
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
@Inject @Inject
Executor executor; Executor executor;
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<Post.Gallery> gallery;
private String subredditName;
private boolean useBottomAppBar;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -70,8 +78,37 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
int theme = getIntent().getIntExtra(EXTRA_APPLIED_THEME, R.style.Theme_Normal); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
getTheme().applyStyle(theme <= 0 ? R.style.Theme_Normal : theme, true); 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 getTheme().applyStyle(FontStyle.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);

View File

@ -87,7 +87,6 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.VoteThing; import ml.docilealligator.infinityforreddit.VoteThing;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
@ -124,7 +123,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6; private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6;
private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7; private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7;
private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8; private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8;
private final MarkwonAdapter mMarkwonAdapter;
private AppCompatActivity mActivity; private AppCompatActivity mActivity;
private ViewPostDetailFragment mFragment; private ViewPostDetailFragment mFragment;
private Executor mExecutor; private Executor mExecutor;
@ -135,7 +134,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private RedditDataRoomDatabase mRedditDataRoomDatabase; private RedditDataRoomDatabase mRedditDataRoomDatabase;
private RequestManager mGlide; private RequestManager mGlide;
private Markwon mPostDetailMarkwon; private Markwon mPostDetailMarkwon;
private final MarkwonAdapter mMarkwonAdapter;
private int mImageViewWidth; private int mImageViewWidth;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
@ -196,6 +194,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private int mDownvotedColor; private int mDownvotedColor;
private int mVoteAndReplyUnavailableVoteButtonColor; private int mVoteAndReplyUnavailableVoteButtonColor;
private int mPostIconAndInfoColor; private int mPostIconAndInfoColor;
private int mCommentColor;
private Drawable mCommentIcon; private Drawable mCommentIcon;
private float mScale; private float mScale;
@ -264,6 +263,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2);
ClickableSpan clickableSpan = new ClickableSpan() { ClickableSpan clickableSpan = new ClickableSpan() {
private boolean isShowing = false; private boolean isShowing = false;
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
if (isShowing) { if (isShowing) {
@ -422,6 +422,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mDownvotedColor = customThemeWrapper.getDownvoted(); mDownvotedColor = customThemeWrapper.getDownvoted();
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor(); mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor(); mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor();
mCommentColor = customThemeWrapper.getCommentColor();
mCommentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp); mCommentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp);
if (mCommentIcon != null) { if (mCommentIcon != null) {
@ -820,14 +821,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
boolean previewCaptionIsEmpty = android.text.TextUtils.isEmpty(previewCaption); boolean previewCaptionIsEmpty = android.text.TextUtils.isEmpty(previewCaption);
boolean previewCaptionUrlIsEmpty = android.text.TextUtils.isEmpty(previewCaptionUrl); boolean previewCaptionUrlIsEmpty = android.text.TextUtils.isEmpty(previewCaptionUrl);
if (!previewCaptionIsEmpty || !previewCaptionUrlIsEmpty) { if (!previewCaptionIsEmpty || !previewCaptionUrlIsEmpty) {
((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setBackgroundColor(mCardViewColor & 0x0D000000); // Make 10% darker than CardViewColor
((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE); ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE);
} }
if (!previewCaptionIsEmpty) { if (!previewCaptionIsEmpty) {
((PostDetailGalleryViewHolder) holder).mCaption.setTextColor(mCommentColor);
((PostDetailGalleryViewHolder) holder).mCaption.setText(previewCaption); ((PostDetailGalleryViewHolder) holder).mCaption.setText(previewCaption);
((PostDetailGalleryViewHolder) holder).mCaption.setSelected(true); ((PostDetailGalleryViewHolder) holder).mCaption.setSelected(true);
} }
if(!previewCaptionUrlIsEmpty) if (!previewCaptionUrlIsEmpty) {
{
String domain = Uri.parse(previewCaptionUrl).getHost(); String domain = Uri.parse(previewCaptionUrl).getHost();
domain = domain.startsWith("www.") ? domain.substring(4) : domain; domain = domain.startsWith("www.") ? domain.substring(4) : domain;
mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrl, String.format("[%s](%s)", domain, previewCaptionUrl)); mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrl, String.format("[%s](%s)", domain, previewCaptionUrl));
@ -1583,6 +1585,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} }
class PostDetailVideoAutoplayViewHolder extends PostDetailBaseViewHolder implements ToroPlayer { class PostDetailVideoAutoplayViewHolder extends PostDetailBaseViewHolder implements ToroPlayer {
public FetchGfycatOrRedgifsVideoLinks fetchGfycatOrRedgifsVideoLinks;
@BindView(R.id.icon_gif_image_view_item_post_detail_video_autoplay) @BindView(R.id.icon_gif_image_view_item_post_detail_video_autoplay)
AspectRatioGifImageView mIconGifImageView; AspectRatioGifImageView mIconGifImageView;
@BindView(R.id.subreddit_text_view_item_post_detail_video_autoplay) @BindView(R.id.subreddit_text_view_item_post_detail_video_autoplay)
@ -1639,12 +1642,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
ImageView mSaveButton; ImageView mSaveButton;
@BindView(R.id.share_button_item_post_detail_video_autoplay) @BindView(R.id.share_button_item_post_detail_video_autoplay)
ImageView mShareButton; ImageView mShareButton;
@Nullable @Nullable
ExoPlayerViewHelper helper; ExoPlayerViewHelper helper;
private Uri mediaUri; private Uri mediaUri;
private float volume; private float volume;
public FetchGfycatOrRedgifsVideoLinks fetchGfycatOrRedgifsVideoLinks;
public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) { public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -2269,7 +2270,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, mPost.getGallery()); intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, mPost.getGallery());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName()); intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_APPLIED_THEME, ((BaseActivity)mActivity).getAppliedTheme());
mActivity.startActivity(intent); mActivity.startActivity(intent);
} }
} }
@ -2380,7 +2380,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, mPost.getGallery()); intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, mPost.getGallery());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName()); intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_APPLIED_THEME, ((BaseActivity)mActivity).getAppliedTheme());
mActivity.startActivity(intent); mActivity.startActivity(intent);
}); });

View File

@ -1972,7 +1972,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery()); intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName()); intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
intent.putExtra(ViewRedditGalleryActivity.EXTRA_APPLIED_THEME, ((BaseActivity)mActivity).getAppliedTheme());
mActivity.startActivity(intent); mActivity.startActivity(intent);
} }
} }

View File

@ -4,13 +4,13 @@ import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -62,10 +62,12 @@ import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile;
import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFile; import ml.docilealligator.infinityforreddit.asynctasks.SaveGIFToFile;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class ViewRedditGalleryImageOrGifFragment extends Fragment { public class ViewRedditGalleryImageOrGifFragment extends Fragment {
@ -249,18 +251,16 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
String caption = media.caption; String caption = media.caption;
String captionUrl = media.captionUrl; String captionUrl = media.captionUrl;
boolean captionIsEmpty = android.text.TextUtils.isEmpty(caption); boolean captionIsEmpty = TextUtils.isEmpty(caption);
boolean captionUrlIsEmpty = android.text.TextUtils.isEmpty(captionUrl); boolean captionUrlIsEmpty = TextUtils.isEmpty(captionUrl);
if (!captionIsEmpty || !captionUrlIsEmpty) { if (!captionIsEmpty || !captionUrlIsEmpty) {
isUseBottomCaption = true; isUseBottomCaption = true;
if (!activity.isUseBottomAppBar()) { if (!activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE); bottomAppBar.setVisibility(View.VISIBLE);
bottomAppBarMenu.setVisibility(View.GONE); bottomAppBarMenu.setVisibility(View.GONE);
//Add bottom margin so that caption doesn't disappear to the bottom in some screens with rounded corners
//I couldn't get binding expressions to work so I did it here captionLayout.setPadding(0, captionLayout.getPaddingTop(), 0, (int) Utils.convertDpToPixel(16, activity));
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)captionLayout.getLayoutParams();
layoutParams.setMargins(0, 0, 0, (int) (16 * getResources().getDisplayMetrics().density));
} }
captionLayout.setVisibility(View.VISIBLE); captionLayout.setVisibility(View.VISIBLE);
@ -268,20 +268,33 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
if (!captionIsEmpty) { if (!captionIsEmpty) {
captionTextView.setVisibility(View.VISIBLE); captionTextView.setVisibility(View.VISIBLE);
captionTextView.setText(caption); captionTextView.setText(caption);
captionTextView.setOnLongClickListener(view -> {
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());
} }
if(!captionUrlIsEmpty) return true;
{ });
}
if (!captionUrlIsEmpty) {
captionUrlTextView.setText(captionUrl); 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(); UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
urlMenuBottomSheetFragment.setArguments(bundle); urlMenuBottomSheetFragment.setArguments(bundle);
urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
}
return true; return true;
}); });
}
captionUrlTextView.setVisibility(View.VISIBLE); captionUrlTextView.setVisibility(View.VISIBLE);
} }
} }

View File

@ -59,7 +59,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone"> android:visibility="gone"
android:paddingTop="8dp">
<TextView <TextView
android:id="@+id/caption_text_view_view_reddit_gallery_image_or_gif_fragment" android:id="@+id/caption_text_view_view_reddit_gallery_image_or_gif_fragment"