diff options
Diffstat (limited to 'app/src/main/java/ml')
2 files changed, 52 insertions, 32 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<Recycler ((PostDetailGalleryViewHolder) holder).mImageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - String previewCaption = preview.getPreviewCaption(); - String previewCaptionUrl = preview.getPreviewCaptionUrl(); - boolean previewCaptionIsEmpty = android.text.TextUtils.isEmpty(previewCaption); - boolean previewCaptionUrlIsEmpty = android.text.TextUtils.isEmpty(previewCaptionUrl); - if (!previewCaptionIsEmpty || !previewCaptionUrlIsEmpty) { - ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setBackgroundColor(mCardViewColor & 0x0D000000); // Make 10% darker than CardViewColor - ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE); - } - if (!previewCaptionIsEmpty) { - ((PostDetailGalleryViewHolder) holder).mCaption.setTextColor(mCommentColor); - ((PostDetailGalleryViewHolder) holder).mCaption.setText(previewCaption); - ((PostDetailGalleryViewHolder) holder).mCaption.setSelected(true); - } - if (!previewCaptionUrlIsEmpty) { - String domain = Uri.parse(previewCaptionUrl).getHost(); - domain = domain.startsWith("www.") ? domain.substring(4) : domain; - mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrl, String.format("[%s](%s)", domain, previewCaptionUrl)); - } - loadImage((PostDetailGalleryViewHolder) holder, preview); + + loadCaptionPreview((PostDetailGalleryViewHolder) holder, preview); } else { ((PostDetailGalleryViewHolder) holder).mNoPreviewPostTypeImageView.setVisibility(View.VISIBLE); } @@ -814,6 +797,29 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } } + private void loadCaptionPreview(PostDetailBaseViewHolder holder, Post.Preview preview) { + if (holder instanceof PostDetailGalleryViewHolder) { + String previewCaption = preview.getPreviewCaption(); + String previewCaptionUrl = preview.getPreviewCaptionUrl(); + boolean previewCaptionIsEmpty = android.text.TextUtils.isEmpty(previewCaption); + boolean previewCaptionUrlIsEmpty = android.text.TextUtils.isEmpty(previewCaptionUrl); + if (!previewCaptionIsEmpty || !previewCaptionUrlIsEmpty) { + ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setBackgroundColor(mCardViewColor & 0x0D000000); // Make 10% darker than CardViewColor + ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE); + } + if (!previewCaptionIsEmpty) { + ((PostDetailGalleryViewHolder) holder).mCaption.setTextColor(mCommentColor); + ((PostDetailGalleryViewHolder) holder).mCaption.setText(previewCaption); + ((PostDetailGalleryViewHolder) holder).mCaption.setSelected(true); + } + if (!previewCaptionUrlIsEmpty) { + String domain = Uri.parse(previewCaptionUrl).getHost(); + domain = domain.startsWith("www.") ? domain.substring(4) : domain; + mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrl, String.format("[%s](%s)", domain, previewCaptionUrl)); + } + } + } + @Nullable private Post.Preview getSuitablePreview(ArrayList<Post.Preview> 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)); } |