From e439b840957030cdce7b310b595cfa9add844422 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 7 May 2020 14:05:33 +0800 Subject: Video autoplay in ViewPostDetailActivity. Optimize CommentAndPostRecyclerViewAdapter. --- .../Activity/ViewPostDetailActivity.java | 42 +- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 1582 +++++++++++++++----- .../Adapter/PostRecyclerViewAdapter.java | 296 ++-- .../main/res/layout/activity_view_post_detail.xml | 2 +- app/src/main/res/layout/item_post.xml | 361 ----- app/src/main/res/layout/item_post_compact.xml | 8 +- app/src/main/res/layout/item_post_detail.xml | 362 ----- .../item_post_detail_image_and_gif_autoplay.xml | 317 ++++ app/src/main/res/layout/item_post_detail_link.xml | 327 ++++ .../layout/item_post_detail_no_preview_link.xml | 305 ++++ app/src/main/res/layout/item_post_detail_text.xml | 288 ++++ .../item_post_detail_video_and_gif_preview.xml | 330 ++++ .../res/layout/item_post_detail_video_autoplay.xml | 294 ++++ .../layout/item_post_image_and_gif_autoplay.xml | 313 ++++ .../item_post_image_and_gif_autoplay_type.xml | 313 ---- app/src/main/res/layout/item_post_link.xml | 324 ++++ app/src/main/res/layout/item_post_link_type.xml | 324 ---- .../main/res/layout/item_post_no_preview_link.xml | 293 ++++ .../res/layout/item_post_no_preview_link_type.xml | 293 ---- app/src/main/res/layout/item_post_text.xml | 288 ++++ app/src/main/res/layout/item_post_text_type.xml | 288 ---- .../res/layout/item_post_video_and_gif_preview.xml | 328 ++++ .../item_post_video_and_gif_preview_type.xml | 328 ---- .../res/layout/item_post_video_type_autoplay.xml | 6 +- 24 files changed, 4752 insertions(+), 2860 deletions(-) delete mode 100644 app/src/main/res/layout/item_post.xml delete mode 100644 app/src/main/res/layout/item_post_detail.xml create mode 100644 app/src/main/res/layout/item_post_detail_image_and_gif_autoplay.xml create mode 100644 app/src/main/res/layout/item_post_detail_link.xml create mode 100644 app/src/main/res/layout/item_post_detail_no_preview_link.xml create mode 100644 app/src/main/res/layout/item_post_detail_text.xml create mode 100644 app/src/main/res/layout/item_post_detail_video_and_gif_preview.xml create mode 100644 app/src/main/res/layout/item_post_detail_video_autoplay.xml create mode 100644 app/src/main/res/layout/item_post_image_and_gif_autoplay.xml delete mode 100644 app/src/main/res/layout/item_post_image_and_gif_autoplay_type.xml create mode 100644 app/src/main/res/layout/item_post_link.xml delete mode 100644 app/src/main/res/layout/item_post_link_type.xml create mode 100644 app/src/main/res/layout/item_post_no_preview_link.xml delete mode 100644 app/src/main/res/layout/item_post_no_preview_link_type.xml create mode 100644 app/src/main/res/layout/item_post_text.xml delete mode 100644 app/src/main/res/layout/item_post_text_type.xml create mode 100644 app/src/main/res/layout/item_post_video_and_gif_preview.xml delete mode 100644 app/src/main/res/layout/item_post_video_and_gif_preview_type.xml (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index f3e4d0aa..764ede0d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -52,11 +52,15 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import im.ene.toro.exoplayer.ExoCreator; +import im.ene.toro.media.PlaybackInfo; +import im.ene.toro.media.VolumeInfo; import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.CommentData; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer; import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; @@ -64,13 +68,13 @@ import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivit import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchComment; -import ml.docilealligator.infinityforreddit.Post.FetchPost; import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.PostCommentSortTypeBottomSheetFragment; -import ml.docilealligator.infinityforreddit.Post.HidePost; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.ParseComment; +import ml.docilealligator.infinityforreddit.Post.FetchPost; +import ml.docilealligator.infinityforreddit.Post.HidePost; import ml.docilealligator.infinityforreddit.Post.ParsePost; import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.R; @@ -87,6 +91,8 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET; +import static im.ene.toro.media.PlaybackInfo.TIME_UNSET; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE; @@ -140,7 +146,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @BindView(R.id.swipe_refresh_layout_view_post_detail_activity) SwipeRefreshLayout mSwipeRefreshLayout; @BindView(R.id.recycler_view_view_post_detail) - RecyclerView mRecyclerView; + CustomToroContainer mRecyclerView; @BindView(R.id.fetch_post_info_linear_layout_view_post_detail_activity) LinearLayout mFetchPostInfoLinearLayout; @BindView(R.id.fetch_post_info_image_view_view_post_detail_activity) @@ -165,16 +171,14 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS SharedPreferences mSortTypeSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + ExoCreator mExoCreator; private RequestManager mGlide; private Locale mLocale; private Menu mMenu; private int orientation; private int postListPosition = -1; private String mSingleCommentId; - private boolean mNeedBlurNsfw; - private boolean mNeedBlurSpoiler; - private boolean mVoteButtonsOnTheRight; - private boolean mShowElapsedTime; private boolean showToast = false; private boolean isSortingComments = false; private boolean mVolumeKeysNavigateComments; @@ -182,10 +186,6 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private boolean mLockFab; private boolean mSwipeUpToHideFab; private boolean mExpandChildren; - private boolean mCommentToolbarHidden; - private boolean mCommentToolbarHideOnClick; - private boolean mShowCommentDivider; - private boolean mShowAbsoluteNumberOfVotes; private LinearLayoutManager mLinearLayoutManager; private CommentAndPostRecyclerViewAdapter mAdapter; private RecyclerView.SmoothScroller mSmoothScroller; @@ -242,18 +242,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mToolbar.setTitle(""); setSupportActionBar(mToolbar); - mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); - mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); - mVoteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); - mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false); mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); - mCommentToolbarHidden = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false); - mCommentToolbarHideOnClick= mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true); - mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); - mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true); mGlide = Glide.with(this); mLocale = getResources().getConfiguration().locale; @@ -511,8 +503,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, - mNeedBlurNsfw, mNeedBlurSpoiler, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, - mCommentToolbarHidden, mCommentToolbarHideOnClick, mShowCommentDivider,mShowAbsoluteNumberOfVotes, + mSharedPreferences, mExoCreator, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -552,6 +543,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } } + mRecyclerView.setCacheManager(mAdapter); + mRecyclerView.setPlayerInitializer(order -> { + VolumeInfo volumeInfo = new VolumeInfo(true, 0f); + return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); + }); + fab.setOnClickListener(view -> scrollToNextParentComment()); } @@ -644,8 +641,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, - mNeedBlurNsfw, mNeedBlurSpoiler, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, - mCommentToolbarHidden, mCommentToolbarHideOnClick, mShowCommentDivider, mShowAbsoluteNumberOfVotes, + mSharedPreferences, mExoCreator, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index eb2ba7ae..14d6686b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.Adapter; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.ColorFilter; import android.graphics.PorterDuff; @@ -39,6 +40,12 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; +import com.google.android.exoplayer2.metadata.Metadata; +import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.text.Cue; +import com.google.android.exoplayer2.trackselection.TrackSelectionArray; +import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.PlayerView; import com.libRG.CustomTextView; import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import com.santalu.aspectratioimageview.AspectRatioImageView; @@ -46,10 +53,19 @@ import com.santalu.aspectratioimageview.AspectRatioImageView; import org.commonmark.ext.gfm.tables.TableBlock; import java.util.ArrayList; +import java.util.List; import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; +import im.ene.toro.CacheManager; +import im.ene.toro.ToroPlayer; +import im.ene.toro.ToroUtil; +import im.ene.toro.exoplayer.ExoCreator; +import im.ene.toro.exoplayer.ExoPlayerViewHelper; +import im.ene.toro.exoplayer.Playable; +import im.ene.toro.media.PlaybackInfo; +import im.ene.toro.widget.Container; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; @@ -88,22 +104,28 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.Utils.GlideImageGetter; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.VoteThing; import retrofit2.Retrofit; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE; -public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - private static final int VIEW_TYPE_POST_DETAIL = 0; - private static final int VIEW_TYPE_FIRST_LOADING = 1; - private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 2; - private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 3; - private static final int VIEW_TYPE_COMMENT = 4; - private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 5; - private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 6; - private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 7; - private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 8; +public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter implements CacheManager { + private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY = 1; + private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW = 2; + private static final int VIEW_TYPE_POST_DETAIL_IMAGE_AND_GIF_AUTOPLAY = 3; + private static final int VIEW_TYPE_POST_DETAIL_LINK = 4; + private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 5; + private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 6; + private static final int VIEW_TYPE_FIRST_LOADING = 7; + private static final int VIEW_TYPE_FIRST_LOADING_FAILED = 8; + private static final int VIEW_TYPE_NO_COMMENT_PLACEHOLDER = 9; + private static final int VIEW_TYPE_COMMENT = 10; + private static final int VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS = 11; + private static final int VIEW_TYPE_IS_LOADING_MORE_COMMENTS = 12; + private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 13; + private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 14; private AppCompatActivity mActivity; private Retrofit mRetrofit; @@ -121,7 +143,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0) { @@ -454,11 +517,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter ((PostDetailViewHolder) holder).mUserTextView.performClick()); + ((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE); + Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAuthorFlairTextView, mPost.getAuthorFlairHTML()); } else if (mPost.getAuthorFlair() != null && !mPost.getAuthorFlair().equals("")) { - ((PostDetailViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE); - ((PostDetailViewHolder) holder).mAuthorFlairTextView.setText(mPost.getAuthorFlair()); + ((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setText(mPost.getAuthorFlair()); } switch (mPost.getVoteType()) { case 1: //Upvote - ((PostDetailViewHolder) holder).mUpvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mUpvotedColor); + ((PostDetailBaseViewHolder) holder).mUpvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN); + ((PostDetailBaseViewHolder) holder).mScoreTextView.setTextColor(mUpvotedColor); break; case -1: //Downvote - ((PostDetailViewHolder) holder).mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mDownvotedColor); + ((PostDetailBaseViewHolder) holder).mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN); + ((PostDetailBaseViewHolder) holder).mScoreTextView.setTextColor(mDownvotedColor); break; case 0: - ((PostDetailViewHolder) holder).mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mPostIconAndInfoColor); - } - - if (mPost.getPostType() != Post.TEXT_TYPE && mPost.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { - ((PostDetailViewHolder) holder).mRelativeLayout.setVisibility(View.VISIBLE); - ((PostDetailViewHolder) holder).mImageView.setVisibility(View.VISIBLE); - ((PostDetailViewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth()); - loadImage((PostDetailViewHolder) holder); - } else { - ((PostDetailViewHolder) holder).mRelativeLayout.setVisibility(View.GONE); - ((PostDetailViewHolder) holder).mImageView.setVisibility(View.GONE); + ((PostDetailBaseViewHolder) holder).mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostDetailBaseViewHolder) holder).mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostDetailBaseViewHolder) holder).mScoreTextView.setTextColor(mPostIconAndInfoColor); } if (mPost.isArchived()) { - ((PostDetailViewHolder) holder).mUpvoteButton + ((PostDetailBaseViewHolder) holder).mUpvoteButton .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mDownvoteButton + ((PostDetailBaseViewHolder) holder).mDownvoteButton .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } if (mPost.isCrosspost()) { - ((PostDetailViewHolder) holder).mCrosspostImageView.setOnClickListener(view -> { - Intent crosspostIntent = new Intent(mActivity, ViewPostDetailActivity.class); - crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); - mActivity.startActivity(crosspostIntent); - }); - ((PostDetailViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE); } - ((PostDetailViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed()); - ((PostDetailViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed()); + ((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed()); + ((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed()); if (mShowElapsedTime) { - ((PostDetailViewHolder) holder).mPostTimeTextView.setText( + ((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText( Utils.getElapsedTime(mActivity, mPost.getPostTimeMillis())); } else { - ((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime()); + ((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime()); } if (mPost.isArchived()) { - ((PostDetailViewHolder) holder).mArchivedImageView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mArchivedImageView.setVisibility(View.VISIBLE); } if (mPost.isLocked()) { - ((PostDetailViewHolder) holder).mLockedImageView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mLockedImageView.setVisibility(View.VISIBLE); } if (mPost.isSpoiler()) { - ((PostDetailViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE); } if (mPost.getFlair() != null && !mPost.getFlair().equals("")) { - ((PostDetailViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE); Spannable flairHTML; - GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailViewHolder) holder).mFlairTextView); + GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailBaseViewHolder) holder).mFlairTextView); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { flairHTML = (Spannable) Html.fromHtml(mPost.getFlair(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); } else { flairHTML = (Spannable) Html.fromHtml(mPost.getFlair(), glideImageGetter, null); } - ((PostDetailViewHolder) holder).mFlairTextView.setText(flairHTML); + ((PostDetailBaseViewHolder) holder).mFlairTextView.setText(flairHTML); } if (mPost.getAwards() != null && !mPost.getAwards().equals("")) { - ((PostDetailViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE); - Utils.setHTMLWithImageToTextView(((PostDetailViewHolder) holder).mAwardsTextView, mPost.getAwards()); + ((PostDetailBaseViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE); + Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards()); } if (mPost.isNSFW()) { - ((PostDetailViewHolder) holder).mNSFWTextView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, FilteredThingActivity.class); - intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); - intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE); - mActivity.startActivity(intent); - }); - ((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.VISIBLE); + ((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.VISIBLE); } else { - ((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.GONE); + ((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE); } - ((PostDetailViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType())); - - ((PostDetailViewHolder) holder).mTypeTextView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, FilteredThingActivity.class); - intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); - intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType()); - mActivity.startActivity(intent); - - }); - - switch (mPost.getPostType()) { - case Post.IMAGE_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("IMAGE"); - - ((PostDetailViewHolder) holder).mImageView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, ViewImageActivity.class); - intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPost.getUrl()); - intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2) - + "-" + mPost.getId().substring(3) + ".jpg"); - intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle()); - mActivity.startActivity(intent); - }); - - if (mPost.getPreviewWidth() <= 0 || mPost.getPreviewHeight() <= 0) { - ((PostDetailViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostDetailViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale); - } - break; - case Post.LINK_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("LINK"); - - ((PostDetailViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE); - String domain = Uri.parse(mPost.getUrl()).getHost(); - ((PostDetailViewHolder) holder).mLinkTextView.setText(domain); - - ((PostDetailViewHolder) holder).mImageView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, LinkResolverActivity.class); - Uri uri = Uri.parse(mPost.getUrl()); - if (uri.getScheme() == null && uri.getHost() == null) { - intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); - } else { - intent.setData(uri); - } - mActivity.startActivity(intent); - }); - break; - case Post.GIF_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("GIF"); - - ((PostDetailViewHolder) holder).mImageView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, ViewGIFActivity.class); - intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName() - + "-" + mPost.getId() + ".gif"); - intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl()); - intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle()); - mActivity.startActivity(intent); - }); - - ((PostDetailViewHolder) holder).mPlayButtonImageView.setVisibility(View.VISIBLE); - break; - case Post.VIDEO_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("VIDEO"); - - final Uri videoUri = Uri.parse(mPost.getVideoUrl()); - ((PostDetailViewHolder) holder).mImageView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, ViewVideoActivity.class); - intent.setData(videoUri); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); - intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle()); - mActivity.startActivity(intent); - }); - - ((PostDetailViewHolder) holder).mPlayButtonImageView.setVisibility(View.VISIBLE); - break; - case Post.NO_PREVIEW_LINK_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("LINK"); - - ((PostDetailViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE); - String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost(); - ((PostDetailViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain); - - if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) { - ((PostDetailViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE); - LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { - @Override - public void onScrolledLeft() { - ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); - } - - @Override - public void onScrolledRight() { - ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack(); - } - }); - ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager); - ((PostDetailViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter); - mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText()); - mMarkwonAdapter.notifyDataSetChanged(); - } + ((PostDetailBaseViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType())); - ((PostDetailViewHolder) holder).mNoPreviewLinkImageView.setVisibility(View.VISIBLE); - ((PostDetailViewHolder) holder).mNoPreviewLinkImageView.setOnClickListener(view -> { - Intent intent = new Intent(mActivity, LinkResolverActivity.class); - Uri uri = Uri.parse(mPost.getUrl()); - if (uri.getScheme() == null && uri.getHost() == null) { - intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); - } else { - intent.setData(uri); - } - mActivity.startActivity(intent); - }); - break; - case Post.TEXT_TYPE: - ((PostDetailViewHolder) holder).mTypeTextView.setText("TEXT"); - - if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) { - ((PostDetailViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE); - LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { - @Override - public void onScrolledLeft() { - ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); - } + ((PostDetailBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getNComments())); - @Override - public void onScrolledRight() { - ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack(); - } - }); - ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager); - ((PostDetailViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter); - mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText()); - mMarkwonAdapter.notifyDataSetChanged(); - } - break; + if (mPost.isSaved()) { + ((PostDetailBaseViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); + } else { + ((PostDetailBaseViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); } - ((PostDetailViewHolder) holder).commentsCountTextView.setOnClickListener(view -> { - if (mPost.isArchived()) { - Toast.makeText(mActivity, R.string.archived_post_reply_unavailable, Toast.LENGTH_SHORT).show(); - return; + if (holder instanceof PostDetailVideoAutoplayViewHolder) { + ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) mPost.getPreviewWidth() / mPost.getPreviewHeight()); + ((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl())); + } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { + if (mPost.getPostType() == Post.GIF_TYPE) { + ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif)); + } else { + ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video)); } - - if (mPost.isLocked()) { - Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show(); - return; + ((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth()); + loadImage((PostDetailVideoAndGifPreviewHolder) holder); + } else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) { + if (mPost.getPostType() == Post.GIF_TYPE) { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif)); + } else { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.image)); } - if (mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; + if (mPost.getPreviewWidth() <= 0 || mPost.getPreviewHeight() <= 0) { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale); } - Intent intent = new Intent(mActivity, CommentActivity.class); - intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle()); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText()); - intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); - intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); - mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); - }); - - ((PostDetailViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getNComments())); - - if (mPost.isSaved()) { - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); - } else { - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); - } + ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth()); + loadImage((PostDetailImageAndGifAutoplayViewHolder) holder); + } else if (holder instanceof PostDetailLinkViewHolder) { + String domain = Uri.parse(mPost.getUrl()).getHost(); + ((PostDetailLinkViewHolder) holder).mLinkTextView.setText(domain); + ((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth()); + loadImage((PostDetailLinkViewHolder) holder); + } else if (holder instanceof PostDetailNoPreviewLinkViewHolder) { + String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost(); + ((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain); + + if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) { + ((PostDetailNoPreviewLinkViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE); + LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + @Override + public void onScrolledLeft() { + ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); + } - ((PostDetailViewHolder) holder).mSaveButton.setOnClickListener(view -> { - if (mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; + @Override + public void onScrolledRight() { + ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack(); + } + }); + ((PostDetailNoPreviewLinkViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager); + ((PostDetailNoPreviewLinkViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter); + mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText()); + mMarkwonAdapter.notifyDataSetChanged(); } + } else if (holder instanceof PostDetailTextViewHolder) { + if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) { + ((PostDetailTextViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE); + LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + @Override + public void onScrolledLeft() { + ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); + } - if (mPost.isSaved()) { - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); - SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), - new SaveThing.SaveThingListener() { - @Override - public void success() { - mPost.setSaved(false); - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); - Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); - mCommentRecyclerViewAdapterCallback.updatePost(mPost); - } - - @Override - public void failed() { - mPost.setSaved(true); - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); - Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); - mCommentRecyclerViewAdapterCallback.updatePost(mPost); - } - }); - } else { - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); - SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), - new SaveThing.SaveThingListener() { - @Override - public void success() { - mPost.setSaved(true); - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); - Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); - mCommentRecyclerViewAdapterCallback.updatePost(mPost); - } - - @Override - public void failed() { - mPost.setSaved(false); - ((PostDetailViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); - Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); - mCommentRecyclerViewAdapterCallback.updatePost(mPost); - } - }); + @Override + public void onScrolledRight() { + ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack(); + } + }); + ((PostDetailTextViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager); + ((PostDetailTextViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter); + mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText()); + mMarkwonAdapter.notifyDataSetChanged(); } - }); + } } else if (holder instanceof CommentViewHolder) { CommentData comment; if (mIsSingleCommentThreadMode) { @@ -1202,33 +1104,92 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - holder.mLoadImageProgressBar.setVisibility(View.GONE); - holder.mLoadImageErrorTextView.setVisibility(View.VISIBLE); - holder.mLoadImageErrorTextView.setOnClickListener(view -> { - holder.mLoadImageProgressBar.setVisibility(View.VISIBLE); - holder.mLoadImageErrorTextView.setVisibility(View.GONE); - loadImage(holder); - }); - return false; - } + private void loadImage(PostDetailBaseViewHolder holder) { + if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) { + String url = mAutoplay && mPost.getPostType() == Post.GIF_TYPE ? mPost.getUrl() : mPost.getPreviewUrl(); + RequestBuilder imageRequestBuilder = mGlide.load(url) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.VISIBLE); + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE); + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE); + loadImage(holder); + }); + return false; + } - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - holder.mLoadWrapper.setVisibility(View.GONE); - return false; - } - }); + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadWrapper.setVisibility(View.GONE); + return false; + } + }); - if ((mPost.isNSFW() && mNeedBlurNSFW) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(holder.mImageView); - } else { - imageRequestBuilder.into(holder.mImageView); + if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); + } else { + imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); + } + } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { + RequestBuilder imageRequestBuilder = mGlide.load(mPost.getPreviewUrl()) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageErrorTextView.setVisibility(View.VISIBLE); + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> { + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE); + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE); + loadImage(holder); + }); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + ((PostDetailVideoAndGifPreviewHolder) holder).mLoadWrapper.setVisibility(View.GONE); + return false; + } + }); + + if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); + } else { + imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); + } + } else if(holder instanceof PostDetailLinkViewHolder) { + RequestBuilder imageRequestBuilder = mGlide.load(mPost.getPreviewUrl()) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + ((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); + ((PostDetailLinkViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.VISIBLE); + ((PostDetailLinkViewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> { + ((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE); + ((PostDetailLinkViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE); + loadImage(holder); + }); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + ((PostDetailLinkViewHolder) holder).mLoadWrapper.setVisibility(View.GONE); + return false; + } + }); + + if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostDetailLinkViewHolder) holder).mImageView); + } else { + imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView); + } } } @@ -1445,7 +1406,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mSubredditTextView.performClick()); @@ -1640,25 +1628,28 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - Bundle bundle = new Bundle(); - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, mPost.getPermalink()); - if (mPost.getPostType() != Post.TEXT_TYPE) { - bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, mPost.getPostType()); - switch (mPost.getPostType()) { - case Post.IMAGE_TYPE: - case Post.GIF_TYPE: - case Post.LINK_TYPE: - case Post.NO_PREVIEW_LINK_TYPE: - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, mPost.getUrl()); - break; - case Post.VIDEO_TYPE: - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, mPost.getVideoDownloadUrl()); - break; - } - } - mShareLinkBottomSheetFragment.setArguments(bundle); - mShareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), mShareLinkBottomSheetFragment.getTag()); + mAuthorFlairTextView.setOnClickListener(view -> mUserTextView.performClick()); + + mCrosspostImageView.setOnClickListener(view -> { + Intent crosspostIntent = new Intent(mActivity, ViewPostDetailActivity.class); + crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); + mActivity.startActivity(crosspostIntent); + }); + + mTypeTextView.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType()); + mActivity.startActivity(intent); + }); + + mNSFWTextView.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE); + mActivity.startActivity(intent); }); mUpvoteButton.setOnClickListener(view -> { @@ -1809,30 +1800,125 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if (mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_reply_unavailable, Toast.LENGTH_SHORT).show(); + return; + } - itemView.setBackgroundColor(mCardViewColor); - mSubredditTextView.setTextColor(mSubredditColor); - mUserTextView.setTextColor(mUsernameColor); - mAuthorFlairTextView.setTextColor(mAuthorFlairTextColor); - mPostTimeTextView.setTextColor(mSecondaryTextColor); + if (mPost.isLocked()) { + Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + if (mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + Intent intent = new Intent(mActivity, CommentActivity.class); + intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText()); + intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); + intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); + mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); + }); + + mSaveButton.setOnClickListener(view -> { + if (mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + if (mPost.isSaved()) { + mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + mPost.setSaved(false); + mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); + Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + + @Override + public void failed() { + mPost.setSaved(true); + mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); + Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + }); + } else { + mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + mPost.setSaved(true); + mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); + Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + + @Override + public void failed() { + mPost.setSaved(false); + mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); + Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); + mCommentRecyclerViewAdapterCallback.updatePost(mPost); + } + }); + } + }); + + mShareButton.setOnClickListener(view -> { + Bundle bundle = new Bundle(); + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, mPost.getPermalink()); + if (mPost.getPostType() != Post.TEXT_TYPE) { + bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, mPost.getPostType()); + switch (mPost.getPostType()) { + case Post.IMAGE_TYPE: + case Post.GIF_TYPE: + case Post.LINK_TYPE: + case Post.NO_PREVIEW_LINK_TYPE: + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, mPost.getUrl()); + break; + case Post.VIDEO_TYPE: + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, mPost.getVideoDownloadUrl()); + break; + } + } + mShareLinkBottomSheetFragment.setArguments(bundle); + mShareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), mShareLinkBottomSheetFragment.getTag()); + }); + + if (mVoteButtonsOnTheRight) { + ConstraintSet constraintSet = new ConstraintSet(); + constraintSet.clone(mBottomConstraintLayout); + constraintSet.clear(mUpvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(mScoreTextView.getId(), ConstraintSet.START); + constraintSet.clear(mDownvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(mSaveButton.getId(), ConstraintSet.END); + constraintSet.clear(mShareButton.getId(), ConstraintSet.END); + constraintSet.connect(mUpvoteButton.getId(), ConstraintSet.END, mScoreTextView.getId(), ConstraintSet.START); + constraintSet.connect(mScoreTextView.getId(), ConstraintSet.END, mDownvoteButton.getId(), ConstraintSet.START); + constraintSet.connect(mDownvoteButton.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); + constraintSet.connect(commentsCountTextView.getId(), ConstraintSet.START, mSaveButton.getId(), ConstraintSet.END); + constraintSet.connect(commentsCountTextView.getId(), ConstraintSet.END, mUpvoteButton.getId(), ConstraintSet.START); + constraintSet.connect(mSaveButton.getId(), ConstraintSet.START, mShareButton.getId(), ConstraintSet.END); + constraintSet.connect(mShareButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.setHorizontalBias(commentsCountTextView.getId(), 0); + constraintSet.applyTo(mBottomConstraintLayout); + } + + itemView.setBackgroundColor(mCardViewColor); + mSubredditTextView.setTextColor(mSubredditColor); + mUserTextView.setTextColor(mUsernameColor); + mAuthorFlairTextView.setTextColor(mAuthorFlairTextColor); + mPostTimeTextView.setTextColor(mSecondaryTextColor); mTitleTextView.setTextColor(mPostTitleColor); mTypeTextView.setBackgroundColor(mPostTypeBackgroundColor); mTypeTextView.setBorderColor(mPostTypeBackgroundColor); @@ -1850,10 +1936,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if (helper != null) { + if (helper.getVolume() != 0) { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp)); + helper.setVolume(0f); + volume = 0f; + } else { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp)); + helper.setVolume(1f); + volume = 1f; + } + } + }); + + fullscreenButton.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, ViewVideoActivity.class); + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle()); + mActivity.startActivity(intent); + }); + } + + void bindVideoUri(Uri videoUri) { + mediaUri = videoUri; + } + + void resetVolume() { + volume = 0f; + } + + @NonNull + @Override + public View getPlayerView() { + return playerView; + } + + @NonNull + @Override + public PlaybackInfo getCurrentPlaybackInfo() { + return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo(); + } + + @Override + public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) { + if (helper == null) { + helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); + helper.addEventListener(new Playable.EventListener() { + @Override + public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { + if (!trackGroups.isEmpty()) { + for (int i = 0; i < trackGroups.length; i++) { + String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType; + if (mimeType != null && mimeType.contains("audio")) { + helper.setVolume(volume); + muteButton.setVisibility(View.VISIBLE); + if (volume != 0f) { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp)); + } else { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp)); + } + break; + } + } + } else { + muteButton.setVisibility(View.GONE); + } + } + + @Override + public void onMetadata(Metadata metadata) { + + } + + @Override + public void onCues(List cues) { + + } + }); + } + helper.initialize(container, playbackInfo); + } + + @Override + public void play() { + if (helper != null) helper.play(); + } + + @Override + public void pause() { + if (helper != null) helper.pause(); + } + + @Override + public boolean isPlaying() { + return helper != null && helper.isPlaying(); + } + + @Override + public void release() { + if (helper != null) { + helper.release(); + helper = null; + } + } + + @Override + public boolean wantsToPlay() { + return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85; + } + + @Override + public int getPlayerOrder() { + return getAdapterPosition(); + } + } + + class PostDetailVideoAndGifPreviewHolder extends PostDetailBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_detail_video_and_gif_preview) + AspectRatioGifImageView mIconGifImageView; + @BindView(R.id.subreddit_text_view_item_post_detail_video_and_gif_preview) + TextView mSubredditTextView; + @BindView(R.id.user_text_view_item_post_detail_video_and_gif_preview) + TextView mUserTextView; + @BindView(R.id.author_flair_text_view_item_post_detail_video_and_gif_preview) + TextView mAuthorFlairTextView; + @BindView(R.id.post_time_text_view_item_post_detail_video_and_gif_preview) + TextView mPostTimeTextView; + @BindView(R.id.title_text_view_item_post_detail_video_and_gif_preview) + TextView mTitleTextView; + @BindView(R.id.type_text_view_item_post_detail_video_and_gif_preview) + CustomTextView mTypeTextView; + @BindView(R.id.crosspost_image_view_item_post_detail_video_and_gif_preview) + ImageView mCrosspostImageView; + @BindView(R.id.archived_image_view_item_post_detail_video_and_gif_preview) + ImageView mArchivedImageView; + @BindView(R.id.locked_image_view_item_post_detail_video_and_gif_preview) + ImageView mLockedImageView; + @BindView(R.id.nsfw_text_view_item_post_detail_video_and_gif_preview) + CustomTextView mNSFWTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_detail_video_and_gif_preview) + CustomTextView mSpoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_detail_video_and_gif_preview) + CustomTextView mFlairTextView; + @BindView(R.id.awards_text_view_item_post_detail_video_and_gif_preview) + TextView mAwardsTextView; + @BindView(R.id.load_wrapper_item_post_detail_video_and_gif_preview) + RelativeLayout mLoadWrapper; + @BindView(R.id.progress_bar_item_post_detail_video_and_gif_preview) + ProgressBar mLoadImageProgressBar; + @BindView(R.id.load_image_error_text_view_item_post_detail_video_and_gif_preview) + TextView mLoadImageErrorTextView; + @BindView(R.id.image_view_item_post_detail_video_and_gif_preview) + AspectRatioImageView mImageView; + @BindView(R.id.bottom_constraint_layout_item_post_detail_video_and_gif_preview) + ConstraintLayout mBottomConstraintLayout; + @BindView(R.id.plus_button_item_post_detail_video_and_gif_preview) + ImageView mUpvoteButton; + @BindView(R.id.score_text_view_item_post_detail_video_and_gif_preview) + TextView mScoreTextView; + @BindView(R.id.minus_button_item_post_detail_video_and_gif_preview) + ImageView mDownvoteButton; + @BindView(R.id.comments_count_item_post_detail_video_and_gif_preview) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_detail_video_and_gif_preview) + ImageView mSaveButton; + @BindView(R.id.share_button_item_post_detail_video_and_gif_preview) + ImageView mShareButton; + + PostDetailVideoAndGifPreviewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView(mIconGifImageView, + mSubredditTextView, + mUserTextView, + mAuthorFlairTextView, + mPostTimeTextView, + mTitleTextView, + mTypeTextView, + mCrosspostImageView, + mArchivedImageView, + mLockedImageView, + mNSFWTextView, + mSpoilerTextView, + mFlairTextView, + mAwardsTextView, + mBottomConstraintLayout, + mUpvoteButton, + mScoreTextView, + mDownvoteButton, + commentsCountTextView, + mSaveButton, + mShareButton); + + mLoadImageProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + mLoadImageErrorTextView.setTextColor(mPrimaryTextColor); + + mImageView.setOnClickListener(view -> { + if (mPost.getPostType() == Post.VIDEO_TYPE) { + Intent intent = new Intent(mActivity, ViewVideoActivity.class); + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle()); + mActivity.startActivity(intent); + } else if (mPost.getPostType() == Post.GIF_TYPE) { + Intent intent = new Intent(mActivity, ViewGIFActivity.class); + intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName() + + "-" + mPost.getId() + ".gif"); + intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl()); + intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle()); + mActivity.startActivity(intent); + } + }); + } + } + + class PostDetailImageAndGifAutoplayViewHolder extends PostDetailBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_detail_image_and_gif_autoplay) + AspectRatioGifImageView mIconGifImageView; + @BindView(R.id.subreddit_text_view_item_post_detail_image_and_gif_autoplay) + TextView mSubredditTextView; + @BindView(R.id.user_text_view_item_post_detail_image_and_gif_autoplay) + TextView mUserTextView; + @BindView(R.id.author_flair_text_view_item_post_detail_image_and_gif_autoplay) + TextView mAuthorFlairTextView; + @BindView(R.id.post_time_text_view_item_post_detail_image_and_gif_autoplay) + TextView mPostTimeTextView; + @BindView(R.id.title_text_view_item_post_detail_image_and_gif_autoplay) + TextView mTitleTextView; + @BindView(R.id.type_text_view_item_post_detail_image_and_gif_autoplay) + CustomTextView mTypeTextView; + @BindView(R.id.crosspost_image_view_item_post_detail_image_and_gif_autoplay) + ImageView mCrosspostImageView; + @BindView(R.id.archived_image_view_item_post_detail_image_and_gif_autoplay) + ImageView mArchivedImageView; + @BindView(R.id.locked_image_view_item_post_detail_image_and_gif_autoplay) + ImageView mLockedImageView; + @BindView(R.id.nsfw_text_view_item_post_detail_image_and_gif_autoplay) + CustomTextView mNSFWTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_detail_image_and_gif_autoplay) + CustomTextView mSpoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_detail_image_and_gif_autoplay) + CustomTextView mFlairTextView; + @BindView(R.id.awards_text_view_item_post_detail_image_and_gif_autoplay) + TextView mAwardsTextView; + @BindView(R.id.image_view_wrapper_item_post_detail_image_and_gif_autoplay) + RelativeLayout mRelativeLayout; + @BindView(R.id.load_wrapper_item_post_detail_image_and_gif_autoplay) + RelativeLayout mLoadWrapper; + @BindView(R.id.progress_bar_item_post_detail_image_and_gif_autoplay) + ProgressBar mLoadImageProgressBar; + @BindView(R.id.load_image_error_text_view_item_post_detail_image_and_gif_autoplay) + TextView mLoadImageErrorTextView; + @BindView(R.id.image_view_item_post_detail_image_and_gif_autoplay) + AspectRatioImageView mImageView; + @BindView(R.id.bottom_constraint_layout_item_post_detail_image_and_gif_autoplay) + ConstraintLayout mBottomConstraintLayout; + @BindView(R.id.plus_button_item_post_detail_image_and_gif_autoplay) + ImageView mUpvoteButton; + @BindView(R.id.score_text_view_item_post_detail_image_and_gif_autoplay) + TextView mScoreTextView; + @BindView(R.id.minus_button_item_post_detail_image_and_gif_autoplay) + ImageView mDownvoteButton; + @BindView(R.id.comments_count_item_post_detail_image_and_gif_autoplay) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_detail_image_and_gif_autoplay) + ImageView mSaveButton; + @BindView(R.id.share_button_item_post_detail_image_and_gif_autoplay) + ImageView mShareButton; + + PostDetailImageAndGifAutoplayViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView(mIconGifImageView, + mSubredditTextView, + mUserTextView, + mAuthorFlairTextView, + mPostTimeTextView, + mTitleTextView, + mTypeTextView, + mCrosspostImageView, + mArchivedImageView, + mLockedImageView, + mNSFWTextView, + mSpoilerTextView, + mFlairTextView, + mAwardsTextView, + mBottomConstraintLayout, + mUpvoteButton, + mScoreTextView, + mDownvoteButton, + commentsCountTextView, + mSaveButton, + mShareButton); + + mLoadImageProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + mLoadImageErrorTextView.setTextColor(mPrimaryTextColor); + + mImageView.setOnClickListener(view -> { + if (mPost.getPostType() == Post.IMAGE_TYPE) { + Intent intent = new Intent(mActivity, ViewImageActivity.class); + intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPost.getUrl()); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2) + + "-" + mPost.getId().substring(3) + ".jpg"); + intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle()); + mActivity.startActivity(intent); + } else if (mPost.getPostType() == Post.GIF_TYPE) { + Intent intent = new Intent(mActivity, ViewGIFActivity.class); + intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName() + + "-" + mPost.getId() + ".gif"); + intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl()); + intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle()); + mActivity.startActivity(intent); + } + }); + } + } + + class PostDetailLinkViewHolder extends PostDetailBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_detail_link) + AspectRatioGifImageView mIconGifImageView; + @BindView(R.id.subreddit_text_view_item_post_detail_link) + TextView mSubredditTextView; + @BindView(R.id.user_text_view_item_post_detail_link) + TextView mUserTextView; + @BindView(R.id.author_flair_text_view_item_post_detail_link) + TextView mAuthorFlairTextView; + @BindView(R.id.post_time_text_view_item_post_detail_link) + TextView mPostTimeTextView; + @BindView(R.id.title_text_view_item_post_detail_link) + TextView mTitleTextView; + @BindView(R.id.type_text_view_item_post_detail_link) + CustomTextView mTypeTextView; + @BindView(R.id.crosspost_image_view_item_post_detail_link) + ImageView mCrosspostImageView; + @BindView(R.id.archived_image_view_item_post_detail_link) + ImageView mArchivedImageView; + @BindView(R.id.locked_image_view_item_post_detail_link) + ImageView mLockedImageView; + @BindView(R.id.nsfw_text_view_item_post_detail_link) + CustomTextView mNSFWTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_detail_link) + CustomTextView mSpoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_detail_link) + CustomTextView mFlairTextView; + @BindView(R.id.awards_text_view_item_post_detail_link) + TextView mAwardsTextView; + @BindView(R.id.link_text_view_item_post_detail_link) + TextView mLinkTextView; + @BindView(R.id.image_view_wrapper_item_post_detail_link) + RelativeLayout mRelativeLayout; + @BindView(R.id.load_wrapper_item_post_detail_link) + RelativeLayout mLoadWrapper; + @BindView(R.id.progress_bar_item_post_detail_link) + ProgressBar mLoadImageProgressBar; + @BindView(R.id.load_image_error_text_view_item_post_detail_link) + TextView mLoadImageErrorTextView; + @BindView(R.id.image_view_item_post_detail_link) + AspectRatioImageView mImageView; + @BindView(R.id.bottom_constraint_layout_item_post_detail_link) + ConstraintLayout mBottomConstraintLayout; + @BindView(R.id.plus_button_item_post_detail_link) + ImageView mUpvoteButton; + @BindView(R.id.score_text_view_item_post_detail_link) + TextView mScoreTextView; + @BindView(R.id.minus_button_item_post_detail_link) + ImageView mDownvoteButton; + @BindView(R.id.comments_count_item_post_detail_link) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_detail_link) + ImageView mSaveButton; + @BindView(R.id.share_button_item_post_detail_link) + ImageView mShareButton; + + PostDetailLinkViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView(mIconGifImageView, + mSubredditTextView, + mUserTextView, + mAuthorFlairTextView, + mPostTimeTextView, + mTitleTextView, + mTypeTextView, + mCrosspostImageView, + mArchivedImageView, + mLockedImageView, + mNSFWTextView, + mSpoilerTextView, + mFlairTextView, + mAwardsTextView, + mBottomConstraintLayout, + mUpvoteButton, + mScoreTextView, + mDownvoteButton, + commentsCountTextView, + mSaveButton, + mShareButton); + + mLinkTextView.setTextColor(mSecondaryTextColor); + mLoadImageProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + mLoadImageErrorTextView.setTextColor(mPrimaryTextColor); + + mImageView.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, LinkResolverActivity.class); + Uri uri = Uri.parse(mPost.getUrl()); + if (uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); + } else { + intent.setData(uri); + } + mActivity.startActivity(intent); + }); + } + } + + class PostDetailNoPreviewLinkViewHolder extends PostDetailBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_detail_no_preview_link) + AspectRatioGifImageView mIconGifImageView; + @BindView(R.id.subreddit_text_view_item_post_detail_no_preview_link) + TextView mSubredditTextView; + @BindView(R.id.user_text_view_item_post_detail_no_preview_link) + TextView mUserTextView; + @BindView(R.id.author_flair_text_view_item_post_detail_no_preview_link) + TextView mAuthorFlairTextView; + @BindView(R.id.post_time_text_view_item_post_detail_no_preview_link) + TextView mPostTimeTextView; + @BindView(R.id.title_text_view_item_post_detail_no_preview_link) + TextView mTitleTextView; + @BindView(R.id.content_markdown_view_item_post_detail_no_preview_link) + RecyclerView mContentMarkdownView; + @BindView(R.id.type_text_view_item_post_detail_no_preview_link) + CustomTextView mTypeTextView; + @BindView(R.id.crosspost_image_view_item_post_detail_no_preview_link) + ImageView mCrosspostImageView; + @BindView(R.id.archived_image_view_item_post_detail_no_preview_link) + ImageView mArchivedImageView; + @BindView(R.id.locked_image_view_item_post_detail_no_preview_link) + ImageView mLockedImageView; + @BindView(R.id.nsfw_text_view_item_post_detail_no_preview_link) + CustomTextView mNSFWTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_detail_no_preview_link) + CustomTextView mSpoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_detail_no_preview_link) + CustomTextView mFlairTextView; + @BindView(R.id.awards_text_view_item_post_detail_no_preview_link) + TextView mAwardsTextView; + @BindView(R.id.link_text_view_item_post_detail_no_preview_link) + TextView mLinkTextView; + @BindView(R.id.image_view_no_preview_link_item_post_detail_no_preview_link) + ImageView mNoPreviewLinkImageView; + @BindView(R.id.bottom_constraint_layout_item_post_detail_no_preview_link) + ConstraintLayout mBottomConstraintLayout; + @BindView(R.id.plus_button_item_post_detail_no_preview_link) + ImageView mUpvoteButton; + @BindView(R.id.score_text_view_item_post_detail_no_preview_link) + TextView mScoreTextView; + @BindView(R.id.minus_button_item_post_detail_no_preview_link) + ImageView mDownvoteButton; + @BindView(R.id.comments_count_item_post_detail_no_preview_link) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_detail_no_preview_link) + ImageView mSaveButton; + @BindView(R.id.share_button_item_post_detail_no_preview_link) + ImageView mShareButton; + + PostDetailNoPreviewLinkViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView(mIconGifImageView, + mSubredditTextView, + mUserTextView, + mAuthorFlairTextView, + mPostTimeTextView, + mTitleTextView, + mTypeTextView, + mCrosspostImageView, + mArchivedImageView, + mLockedImageView, + mNSFWTextView, + mSpoilerTextView, + mFlairTextView, + mAwardsTextView, + mBottomConstraintLayout, + mUpvoteButton, + mScoreTextView, + mDownvoteButton, + commentsCountTextView, + mSaveButton, + mShareButton); + + mLinkTextView.setTextColor(mSecondaryTextColor); + mNoPreviewLinkImageView.setBackgroundColor(mNoPreviewLinkBackgroundColor); + + mNoPreviewLinkImageView.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, LinkResolverActivity.class); + Uri uri = Uri.parse(mPost.getUrl()); + if (uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); + } else { + intent.setData(uri); + } + mActivity.startActivity(intent); + }); + } + } + + class PostDetailTextViewHolder extends PostDetailBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_detail_text) + AspectRatioGifImageView mIconGifImageView; + @BindView(R.id.subreddit_text_view_item_post_detail_text) + TextView mSubredditTextView; + @BindView(R.id.user_text_view_item_post_detail_text) + TextView mUserTextView; + @BindView(R.id.author_flair_text_view_item_post_detail_text) + TextView mAuthorFlairTextView; + @BindView(R.id.post_time_text_view_item_post_detail_text) + TextView mPostTimeTextView; + @BindView(R.id.title_text_view_item_post_detail_text) + TextView mTitleTextView; + @BindView(R.id.content_markdown_view_item_post_detail_text) + RecyclerView mContentMarkdownView; + @BindView(R.id.type_text_view_item_post_detail_text) + CustomTextView mTypeTextView; + @BindView(R.id.crosspost_image_view_item_post_detail_text) + ImageView mCrosspostImageView; + @BindView(R.id.archived_image_view_item_post_detail_text) + ImageView mArchivedImageView; + @BindView(R.id.locked_image_view_item_post_detail_text) + ImageView mLockedImageView; + @BindView(R.id.nsfw_text_view_item_post_detail_text) + CustomTextView mNSFWTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_detail_text) + CustomTextView mSpoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_detail_text) + CustomTextView mFlairTextView; + @BindView(R.id.awards_text_view_item_post_detail_text) + TextView mAwardsTextView; + @BindView(R.id.bottom_constraint_layout_item_post_detail_text) + ConstraintLayout mBottomConstraintLayout; + @BindView(R.id.plus_button_item_post_detail_text) + ImageView mUpvoteButton; + @BindView(R.id.score_text_view_item_post_detail_text) + TextView mScoreTextView; + @BindView(R.id.minus_button_item_post_detail_text) + ImageView mDownvoteButton; + @BindView(R.id.comments_count_item_post_detail_text) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_detail_text) + ImageView mSaveButton; + @BindView(R.id.share_button_item_post_detail_text) + ImageView mShareButton; + + PostDetailTextViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView(mIconGifImageView, + mSubredditTextView, + mUserTextView, + mAuthorFlairTextView, + mPostTimeTextView, + mTitleTextView, + mTypeTextView, + mCrosspostImageView, + mArchivedImageView, + mLockedImageView, + mNSFWTextView, + mSpoilerTextView, + mFlairTextView, + mAwardsTextView, + mBottomConstraintLayout, + mUpvoteButton, + mScoreTextView, + mDownvoteButton, + commentsCountTextView, + mSaveButton, + mShareButton); + } + } + class CommentViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.linear_layout_item_comment) LinearLayout linearLayout; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 3623fb54..2d89858a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -127,6 +127,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter imageRequestBuilder = mGlide.load(url).listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - ((PostImageAndGifAutoplayTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostImageAndGifAutoplayTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostImageAndGifAutoplayTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostImageAndGifAutoplayTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostImageAndGifAutoplayTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); + ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { + ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); loadImage(holder, post); }); return false; @@ -1121,27 +1122,27 @@ public class PostRecyclerViewAdapter extends PagedListAdapter target, DataSource dataSource, boolean isFirstResource) { - ((PostImageAndGifAutoplayTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostImageAndGifAutoplayTypeViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE); return false; } }); if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostImageAndGifAutoplayTypeViewHolder) holder).imageView); + .into(((PostImageAndGifAutoplayViewHolder) holder).imageView); } else { - imageRequestBuilder.into(((PostImageAndGifAutoplayTypeViewHolder) holder).imageView); + imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView); } - } else if (holder instanceof PostGifAndVideoPreviewViewHolder) { + } else if (holder instanceof PostVideoAndGifPreviewViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - ((PostGifAndVideoPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostGifAndVideoPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostGifAndVideoPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostGifAndVideoPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGifAndVideoPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); + ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { + ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); loadImage(holder, post); }); return false; @@ -1149,17 +1150,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter target, DataSource dataSource, boolean isFirstResource) { - ((PostGifAndVideoPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostGifAndVideoPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); return false; } }); if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostGifAndVideoPreviewViewHolder) holder).imageView); + .into(((PostVideoAndGifPreviewViewHolder) holder).imageView); } else { - imageRequestBuilder.into(((PostGifAndVideoPreviewViewHolder) holder).imageView); + imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView); } } else if (holder instanceof PostLinkTypeViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener() { @@ -1309,13 +1310,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { Post post = getItem(getAdapterPosition()); @@ -2123,61 +2129,61 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { Post post = getItem(getAdapterPosition()); @@ -2220,59 +2227,59 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { Post post = getItem(getAdapterPosition()); @@ -2331,9 +2339,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_compact.xml b/app/src/main/res/layout/item_post_compact.xml index 8b65f934..d81a2bdc 100644 --- a/app/src/main/res/layout/item_post_compact.xml +++ b/app/src/main/res/layout/item_post_compact.xml @@ -54,7 +54,7 @@ app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml deleted file mode 100644 index ce515feb..00000000 --- a/app/src/main/res/layout/item_post_detail.xml +++ /dev/null @@ -1,362 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_image_and_gif_autoplay.xml b/app/src/main/res/layout/item_post_detail_image_and_gif_autoplay.xml new file mode 100644 index 00000000..3667d7b5 --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_image_and_gif_autoplay.xml @@ -0,0 +1,317 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_link.xml b/app/src/main/res/layout/item_post_detail_link.xml new file mode 100644 index 00000000..1b8570da --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_link.xml @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_no_preview_link.xml b/app/src/main/res/layout/item_post_detail_no_preview_link.xml new file mode 100644 index 00000000..01e887fb --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_no_preview_link.xml @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_text.xml b/app/src/main/res/layout/item_post_detail_text.xml new file mode 100644 index 00000000..00b81547 --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_text.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_video_and_gif_preview.xml b/app/src/main/res/layout/item_post_detail_video_and_gif_preview.xml new file mode 100644 index 00000000..5de14a3e --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_video_and_gif_preview.xml @@ -0,0 +1,330 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_detail_video_autoplay.xml b/app/src/main/res/layout/item_post_detail_video_autoplay.xml new file mode 100644 index 00000000..b73fae27 --- /dev/null +++ b/app/src/main/res/layout/item_post_detail_video_autoplay.xml @@ -0,0 +1,294 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_image_and_gif_autoplay.xml b/app/src/main/res/layout/item_post_image_and_gif_autoplay.xml new file mode 100644 index 00000000..e29f4287 --- /dev/null +++ b/app/src/main/res/layout/item_post_image_and_gif_autoplay.xml @@ -0,0 +1,313 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_image_and_gif_autoplay_type.xml b/app/src/main/res/layout/item_post_image_and_gif_autoplay_type.xml deleted file mode 100644 index b2fdf016..00000000 --- a/app/src/main/res/layout/item_post_image_and_gif_autoplay_type.xml +++ /dev/null @@ -1,313 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_link.xml b/app/src/main/res/layout/item_post_link.xml new file mode 100644 index 00000000..66c55908 --- /dev/null +++ b/app/src/main/res/layout/item_post_link.xml @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_link_type.xml b/app/src/main/res/layout/item_post_link_type.xml deleted file mode 100644 index 43f51b10..00000000 --- a/app/src/main/res/layout/item_post_link_type.xml +++ /dev/null @@ -1,324 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_no_preview_link.xml b/app/src/main/res/layout/item_post_no_preview_link.xml new file mode 100644 index 00000000..bf1ba331 --- /dev/null +++ b/app/src/main/res/layout/item_post_no_preview_link.xml @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_no_preview_link_type.xml b/app/src/main/res/layout/item_post_no_preview_link_type.xml deleted file mode 100644 index a6ef9eeb..00000000 --- a/app/src/main/res/layout/item_post_no_preview_link_type.xml +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_text.xml b/app/src/main/res/layout/item_post_text.xml new file mode 100644 index 00000000..39ea56f4 --- /dev/null +++ b/app/src/main/res/layout/item_post_text.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_text_type.xml b/app/src/main/res/layout/item_post_text_type.xml deleted file mode 100644 index cc7a3bb9..00000000 --- a/app/src/main/res/layout/item_post_text_type.xml +++ /dev/null @@ -1,288 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_video_and_gif_preview.xml b/app/src/main/res/layout/item_post_video_and_gif_preview.xml new file mode 100644 index 00000000..ad2e3b9d --- /dev/null +++ b/app/src/main/res/layout/item_post_video_and_gif_preview.xml @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_video_and_gif_preview_type.xml b/app/src/main/res/layout/item_post_video_and_gif_preview_type.xml deleted file mode 100644 index c3549df4..00000000 --- a/app/src/main/res/layout/item_post_video_and_gif_preview_type.xml +++ /dev/null @@ -1,328 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_video_type_autoplay.xml b/app/src/main/res/layout/item_post_video_type_autoplay.xml index 138090d8..bfbc7456 100644 --- a/app/src/main/res/layout/item_post_video_type_autoplay.xml +++ b/app/src/main/res/layout/item_post_video_type_autoplay.xml @@ -69,7 +69,7 @@ app:layout_constraintTop_toTopOf="parent"/> Date: Thu, 7 May 2020 14:10:41 +0800 Subject: Stop autoplay when wifi is lost in ViewPostDetailActivity if video autoplay is set to wifi only. --- .../infinityforreddit/Activity/ViewPostDetailActivity.java | 12 ++++++++++++ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 4 ++++ 2 files changed, 16 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 764ede0d..f7068f0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -64,6 +64,7 @@ import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer; import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -1238,6 +1239,17 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } } + @Subscribe + public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) { + if (mAdapter != null) { + String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER); + if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) { + mAdapter.setAutoplay(changeWifiStatusEvent.isConnectedToWifi); + refreshAdapter(); + } + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.view_post_detail_activity, menu); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 14d6686b..674dff72 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1451,6 +1451,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter Date: Fri, 8 May 2020 02:46:17 +0200 Subject: Fix image view with low resolution. --- .../infinityforreddit/Activity/ViewImageActivity.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java index 1ec2de8d..4533818d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java @@ -91,6 +91,7 @@ public class ViewImageActivity extends AppCompatActivity { private String mImageFileName; private float totalLengthY = 0.0f; private float touchY = -1.0f; + private float initialZoom = 1.0f; private float zoom = 1.0f; private boolean isSwiping = false; private RequestManager glide; @@ -327,7 +328,7 @@ public class ViewImageActivity extends AppCompatActivity { @Override public void onStateReset(State oldState, State newState) { - + initialZoom = newState.getZoom(); } }); @@ -367,7 +368,7 @@ public class ViewImageActivity extends AppCompatActivity { mProgressBar.setVisibility(View.GONE); return false; } - }).apply(new RequestOptions().fitCenter()).into(mImageView); + }).into(mImageView); } @Override @@ -455,7 +456,7 @@ public class ViewImageActivity extends AppCompatActivity { @Override public boolean dispatchTouchEvent(MotionEvent ev) { - if (zoom == 1.0) { + if (Math.abs(zoom - initialZoom) <= 0.000001) { swipe.dispatchTouchEvent(ev); } return super.dispatchTouchEvent(ev); -- cgit v1.2.3 From f27f7c12a8ae712d48623af87f1b8aff7fa61425 Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 01:16:31 +0200 Subject: Handle Reddit app links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index f932427f..ff39b7f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -56,6 +56,10 @@ public class LinkResolverActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); Uri uri = getIntent().getData(); + handleUri(uri); + } + + private void handleUri(Uri uri) { if (uri == null) { Toast.makeText(this, R.string.no_link_available, Toast.LENGTH_SHORT).show(); finish(); @@ -73,7 +77,10 @@ public class LinkResolverActivity extends AppCompatActivity { String authority = uri.getAuthority(); if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { - if (path.matches(POST_PATTERN)) { + if (authority.equals("reddit.app.link") && path.isEmpty()) { + String redirect = uri.getQueryParameter("$og_redirect"); + handleUri(Uri.parse(redirect)); + } else if (path.matches(POST_PATTERN)) { List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { -- cgit v1.2.3 From b31c96b2d9f35d622dd9415306296d46a194a0cb Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 01:17:14 +0200 Subject: Handle Reddit home links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index ff39b7f3..145e311e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -80,6 +80,9 @@ public class LinkResolverActivity extends AppCompatActivity { if (authority.equals("reddit.app.link") && path.isEmpty()) { String redirect = uri.getQueryParameter("$og_redirect"); handleUri(Uri.parse(redirect)); + } else if (path.isEmpty()) { + Intent intent = new Intent(this, MainActivity.class); + startActivity(intent); } else if (path.matches(POST_PATTERN)) { List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); -- cgit v1.2.3 From a2dc0b1c0d51d74ca5c3c5942af2b113ebbd27be Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 03:25:50 +0200 Subject: Handle other comment links. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 145e311e..76ed0e1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -31,7 +31,7 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; + private static final String COMMENT_PATTERN = "/(r|u|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; private static final String USER_PATTERN_1 = "/user/\\w+/{0,1}"; private static final String USER_PATTERN_2 = "/[uU]/\\w+/{0,1}"; @@ -76,6 +76,8 @@ public class LinkResolverActivity extends AppCompatActivity { String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); String authority = uri.getAuthority(); + List segments = uri.getPathSegments(); + if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { if (authority.equals("reddit.app.link") && path.isEmpty()) { String redirect = uri.getQueryParameter("$og_redirect"); @@ -84,7 +86,6 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } else if (path.matches(POST_PATTERN)) { - List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { Intent intent = new Intent(this, ViewPostDetailActivity.class); @@ -96,7 +97,6 @@ public class LinkResolverActivity extends AppCompatActivity { deepLinkError(uri); } } else if (path.matches(COMMENT_PATTERN)) { - List segments = uri.getPathSegments(); int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { Intent intent = new Intent(this, ViewPostDetailActivity.class); @@ -125,13 +125,13 @@ public class LinkResolverActivity extends AppCompatActivity { } } else if (path.matches(USER_PATTERN_1)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); } else if (path.matches(USER_PATTERN_2)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); -- cgit v1.2.3 From adf8fa4e6a859029ac2d17ee79296e2afcda5b7a Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 03:39:35 +0200 Subject: Improve some regex of link resolver. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 76ed0e1b..defe8e3a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -31,10 +31,9 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/(r|u|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; + private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; - private static final String USER_PATTERN_1 = "/user/\\w+/{0,1}"; - private static final String USER_PATTERN_2 = "/[uU]/\\w+/{0,1}"; + private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; @@ -123,13 +122,7 @@ public class LinkResolverActivity extends AppCompatActivity { intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); } - } else if (path.matches(USER_PATTERN_1)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(USER_PATTERN_2)) { + } else if (path.matches(USER_PATTERN)) { Intent intent = new Intent(this, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); -- cgit v1.2.3 From 3c32daaca2c3b3fbd826a927e60c87a57ef57ff2 Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Mon, 11 May 2020 21:26:55 +0200 Subject: Add swap tap and long click option. --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 65 +++++++++++++--------- .../Utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 1 + .../res/xml/gestures_and_buttons_preference.xml | 5 ++ 4 files changed, 47 insertions(+), 25 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 674dff72..f2a12781 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -150,6 +150,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter authorTextView.performClick()); - View.OnClickListener hideToolbarOnClickListener = view -> { - if (mCommentToolbarHideOnClick) { - if (bottomConstraintLayout.getLayoutParams().height == 0) { - bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT; - topScoreTextView.setVisibility(View.GONE); - ((ViewPostDetailActivity) mActivity).delayTransition(); - } else { - ((ViewPostDetailActivity) mActivity).delayTransition(); - bottomConstraintLayout.getLayoutParams().height = 0; - topScoreTextView.setVisibility(View.VISIBLE); - } - } - }; - linearLayout.setOnClickListener(hideToolbarOnClickListener); - commentMarkdownView.setOnClickListener(hideToolbarOnClickListener); - commentTimeTextView.setOnClickListener(hideToolbarOnClickListener); - moreButton.setOnClickListener(view -> { CommentData comment = getCurrentComment(); Bundle bundle = new Bundle(); @@ -2961,15 +2946,45 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { - expandButton.performClick(); - return true; - }); + if (mSwapTapAndLong) { + if (mCommentToolbarHideOnClick) { + View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar(); + linearLayout.setOnLongClickListener(hideToolbarOnLongClickListener); + commentMarkdownView.setOnLongClickListener(hideToolbarOnLongClickListener); + commentTimeTextView.setOnLongClickListener(hideToolbarOnLongClickListener); + } + View.OnClickListener expandCommentsOnClickListener = view -> expandComments(); + commentMarkdownView.setOnClickListener(expandCommentsOnClickListener); + itemView.setOnClickListener(expandCommentsOnClickListener); + } else { + if (mCommentToolbarHideOnClick) { + View.OnClickListener hideToolbarOnClickListener = view -> hideToolbar(); + linearLayout.setOnClickListener(hideToolbarOnClickListener); + commentMarkdownView.setOnClickListener(hideToolbarOnClickListener); + commentTimeTextView.setOnClickListener(hideToolbarOnClickListener); + } + View.OnLongClickListener expandsCommentsOnLongClickListener = view -> expandComments(); + commentMarkdownView.setOnLongClickListener(expandsCommentsOnLongClickListener); + itemView.setOnLongClickListener(expandsCommentsOnLongClickListener); + } + } - itemView.setOnLongClickListener(view -> { - expandButton.performClick(); - return true; - }); + private boolean expandComments() { + expandButton.performClick(); + return true; + } + + private boolean hideToolbar() { + if (bottomConstraintLayout.getLayoutParams().height == 0) { + bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT; + topScoreTextView.setVisibility(View.GONE); + ((ViewPostDetailActivity) mActivity).delayTransition(); + } else { + ((ViewPostDetailActivity) mActivity).delayTransition(); + bottomConstraintLayout.getLayoutParams().height = 0; + topScoreTextView.setVisibility(View.VISIBLE); + } + return true; } private CommentData getCurrentComment() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 63ab550e..538e5899 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -81,6 +81,7 @@ public class SharedPreferencesUtils { public static final String VIDEO_AUTOPLAY_VALUE_ON_WIFI = "1"; public static final String VIDEO_AUTOPLAY_VALUE_NEVER = "0"; public static final String LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "lock_jump_to_next_top_level_comment_button"; + public static final String SWAP_TAP_AND_LONG_COMMENTS = "swap_tap_and_long_in_comments"; public static final String SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "swipe_up_to_hide_jump_to_next_top_level_comments_button"; public static final String SHOW_TOP_LEVEL_COMMENTS_FIRST = "show_top_level_comments_first"; public static final String CONFIRM_TO_EXIT = "confirm_to_exit"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c12d7105..52ec8509 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -336,6 +336,7 @@ Show Elapsed Time in Posts and Comments Default Post Layout Show Divider in Compact Layout + Swap Tap and Long Press in Comments Swipe Right to Go Back From Comments Lock Jump to Next Top-level Comment Button Lock Bottom Navigation Bar diff --git a/app/src/main/res/xml/gestures_and_buttons_preference.xml b/app/src/main/res/xml/gestures_and_buttons_preference.xml index 4d111187..8cd307e0 100644 --- a/app/src/main/res/xml/gestures_and_buttons_preference.xml +++ b/app/src/main/res/xml/gestures_and_buttons_preference.xml @@ -33,4 +33,9 @@ app:key="volume_keys_navigate_posts" app:title="@string/settings_volume_keys_navigate_posts_title" /> + + \ No newline at end of file -- cgit v1.2.3 From ccecc2b511bffc9711bd41b15aabccc2d179b9cd Mon Sep 17 00:00:00 2001 From: Hermes Junior Date: Tue, 12 May 2020 00:27:53 +0200 Subject: Handle alternative multireddit URL. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index defe8e3a..bacb5a68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -36,6 +36,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; + private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; @Inject @@ -136,6 +137,13 @@ public class LinkResolverActivity extends AppCompatActivity { Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN_2)) { + String subredditName = path.substring(3); + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); -- cgit v1.2.3 From 8ddae6164978f7fa1a262dec6b57f230b727b3f8 Mon Sep 17 00:00:00 2001 From: OHermesJunior Date: Tue, 12 May 2020 00:46:42 +0200 Subject: More little improvements for regex. --- .../infinityforreddit/Activity/LinkResolverActivity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index bacb5a68..6719fe54 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -30,14 +30,14 @@ public class LinkResolverActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; - private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; - private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; - private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/{0,1}"; - private static final String USER_PATTERN = "/([uU]|user)/\\w+/{0,1}"; + private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/?\\w+/?"; + private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/?\\w+/\\w+/?"; + private static final String SUBREDDIT_PATTERN = "/[rR]/\\w+/?"; + private static final String USER_PATTERN = "/(u|U|user)/\\w+/?"; private static final String SIDEBAR_PATTERN = "/[rR]/\\w+/about/sidebar"; - private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; + private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/?"; private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; - private static final String REDD_IT_POST_PATTERN = "/\\w+/{0,1}"; + private static final String REDD_IT_POST_PATTERN = "/\\w+/?"; @Inject @Named("default") -- cgit v1.2.3 From 9490c37a09e4c7920a5129974da7a0f40a84d75a Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 12 May 2020 17:42:38 +0800 Subject: Resume video position when viewing it in fullscreen. --- .../infinityforreddit/Activity/ViewVideoActivity.java | 8 ++++++++ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 1 + .../infinityforreddit/Adapter/PostRecyclerViewAdapter.java | 1 + 3 files changed, 10 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 11e0d56d..00f9e848 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -69,6 +69,7 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_SUBREDDIT = "ES"; public static final String EXTRA_ID = "EI"; public static final String EXTRA_POST_TITLE = "EPT"; + public static final String EXTRA_PROGRESS_SECONDS = "EPS"; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; private static final String IS_MUTE_STATE = "IMS"; @BindView(R.id.relative_layout_view_video_activity) @@ -93,6 +94,7 @@ public class ViewVideoActivity extends AppCompatActivity { private float totalLengthY = 0.0f; private float touchY = -1.0f; private String postTitle; + private long resumePosition = -1; @Inject @Named("default") @@ -134,6 +136,9 @@ public class ViewVideoActivity extends AppCompatActivity { videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL); videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4"; postTitle = intent.getStringExtra(EXTRA_POST_TITLE); + if (savedInstanceState == null) { + resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1); + } if (postTitle != null) { setTitle(Html.fromHtml(String.format("%s", postTitle))); @@ -320,6 +325,9 @@ public class ViewVideoActivity extends AppCompatActivity { player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); player.setRepeatMode(Player.REPEAT_MODE_ALL); + if (resumePosition > 0) { + player.seekTo(resumePosition); + } player.setPlayWhenReady(true); wasPlaying = true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index f2a12781..64ab34ff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -2057,6 +2057,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter Date: Tue, 12 May 2020 20:22:29 +0800 Subject: Disable video autoply in lazy mode. --- .../Adapter/PostRecyclerViewAdapter.java | 4 ++++ .../infinityforreddit/Fragment/PostFragment.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 19df7a8c..9840d050 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1305,6 +1305,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter Date: Wed, 13 May 2020 12:51:44 +0800 Subject: Customize tabs in main page for logged-in users. --- .../infinityforreddit/Activity/MainActivity.java | 194 +++++++++++++-------- .../infinityforreddit/AppComponent.java | 3 + .../Settings/CustomizeMainPageTabsFragment.java | 174 ++++++++++++++++++ .../Utils/SharedPreferencesUtils.java | 15 ++ app/src/main/res/values/arrays.xml | 18 ++ app/src/main/res/values/strings.xml | 16 +- .../xml/customize_main_page_tabs_preferences.xml | 76 ++++++++ app/src/main/res/xml/interface_preference.xml | 5 + 8 files changed, 425 insertions(+), 76 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java create mode 100644 app/src/main/res/xml/customize_main_page_tabs_preferences.xml (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index ca7e42d2..8f773a69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -922,9 +922,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } private class SectionsPagerAdapter extends FragmentPagerAdapter { - private PostFragment frontPagePostFragment; - private PostFragment popularPostFragment; - private PostFragment allPostFragment; + private PostFragment tab1; + private PostFragment tab2; + private PostFragment tab3; SectionsPagerAdapter(FragmentManager fm) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); @@ -956,6 +956,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } if (position == 0) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, ""); + return generatePostFragment(postType, name); + } else if (position == 1) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, ""); + return generatePostFragment(postType, name); + } else { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, ""); + return generatePostFragment(postType, name); + } + } + + private Fragment generatePostFragment(String postType, String name) { + if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME)) { PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE); @@ -963,11 +979,39 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); return fragment; - } else if (position == 1) { + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL)) { PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - bundle.putString(PostFragment.EXTRA_NAME, "popular"); + bundle.putString(PostFragment.EXTRA_NAME, "all"); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + bundle.putString(PostFragment.EXTRA_NAME, name); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putString(PostFragment.EXTRA_NAME, name); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_MULTI_REDDIT); + bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); + bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + fragment.setArguments(bundle); + return fragment; + } else if (postType.equals(SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER)) { + PostFragment fragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER); + bundle.putString(PostFragment.EXTRA_USER_NAME, name); + bundle.putString(PostFragment.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_SUBMITTED); bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); @@ -976,7 +1020,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb PostFragment fragment = new PostFragment(); Bundle bundle = new Bundle(); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); - bundle.putString(PostFragment.EXTRA_NAME, "all"); + bundle.putString(PostFragment.EXTRA_NAME, "popular"); bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); fragment.setArguments(bundle); @@ -1004,11 +1048,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { switch (position) { case 0: - return "Home"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)); case 1: - return "Popular"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)); case 2: - return "All"; + return mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)); } } return null; @@ -1021,21 +1065,21 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (position) { case 0: - popularPostFragment = (PostFragment) fragment; + tab2 = (PostFragment) fragment; break; case 1: - allPostFragment = (PostFragment) fragment; + tab3 = (PostFragment) fragment; } } else { switch (position) { case 0: - frontPagePostFragment = (PostFragment) fragment; + tab1 = (PostFragment) fragment; break; case 1: - popularPostFragment = (PostFragment) fragment; + tab2 = (PostFragment) fragment; break; case 2: - allPostFragment = (PostFragment) fragment; + tab3 = (PostFragment) fragment; } } return fragment; @@ -1045,18 +1089,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (viewPager.getCurrentItem()) { case 0: - return popularPostFragment.handleKeyDown(keyCode); + return tab2.handleKeyDown(keyCode); case 1: - return allPostFragment.handleKeyDown(keyCode); + return tab3.handleKeyDown(keyCode); } } else { switch (viewPager.getCurrentItem()) { case 0: - return frontPagePostFragment.handleKeyDown(keyCode); + return tab1.handleKeyDown(keyCode); case 1: - return popularPostFragment.handleKeyDown(keyCode); + return tab2.handleKeyDown(keyCode); case 2: - return allPostFragment.handleKeyDown(keyCode); + return tab3.handleKeyDown(keyCode); } } return false; @@ -1066,18 +1110,18 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (viewPager.getCurrentItem()) { case 0: - return popularPostFragment.startLazyMode(); + return tab2.startLazyMode(); case 1: - return allPostFragment.startLazyMode(); + return tab3.startLazyMode(); } } else { switch (viewPager.getCurrentItem()) { case 0: - return frontPagePostFragment.startLazyMode(); + return tab1.startLazyMode(); case 1: - return popularPostFragment.startLazyMode(); + return tab2.startLazyMode(); case 2: - return allPostFragment.startLazyMode(); + return tab3.startLazyMode(); } } @@ -1088,22 +1132,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.stopLazyMode(); + tab2.stopLazyMode(); break; case 1: - allPostFragment.stopLazyMode(); + tab3.stopLazyMode(); break; } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.stopLazyMode(); + tab1.stopLazyMode(); break; case 1: - popularPostFragment.stopLazyMode(); + tab2.stopLazyMode(); break; case 2: - allPostFragment.stopLazyMode(); + tab3.stopLazyMode(); break; } } @@ -1113,22 +1157,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.resumeLazyMode(false); + tab2.resumeLazyMode(false); break; case 1: - allPostFragment.resumeLazyMode(false); + tab3.resumeLazyMode(false); break; } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.resumeLazyMode(false); + tab1.resumeLazyMode(false); break; case 1: - popularPostFragment.resumeLazyMode(false); + tab2.resumeLazyMode(false); break; case 2: - allPostFragment.resumeLazyMode(false); + tab3.resumeLazyMode(false); break; } } @@ -1138,21 +1182,21 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { switch (getCurrentLazyModeFragmentPosition()) { case 0: - popularPostFragment.pauseLazyMode(false); + tab2.pauseLazyMode(false); break; case 1: - allPostFragment.pauseLazyMode(false); + tab3.pauseLazyMode(false); } } else { switch (getCurrentLazyModeFragmentPosition()) { case 0: - frontPagePostFragment.pauseLazyMode(false); + tab1.pauseLazyMode(false); break; case 1: - popularPostFragment.pauseLazyMode(false); + tab2.pauseLazyMode(false); break; case 2: - allPostFragment.pauseLazyMode(false); + tab3.pauseLazyMode(false); } } } @@ -1161,9 +1205,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { if (!isInLazyMode) { return -1; - } else if (popularPostFragment != null && popularPostFragment.isInLazyMode()) { + } else if (tab2 != null && tab2.isInLazyMode()) { return 0; - } else if (allPostFragment != null && allPostFragment.isInLazyMode()) { + } else if (tab3 != null && tab3.isInLazyMode()) { return 1; } else { return -1; @@ -1171,11 +1215,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { if (!isInLazyMode) { return -1; - } else if (frontPagePostFragment != null && frontPagePostFragment.isInLazyMode()) { + } else if (tab1 != null && tab1.isInLazyMode()) { return 0; - } else if (popularPostFragment != null && popularPostFragment.isInLazyMode()) { + } else if (tab2 != null && tab2.isInLazyMode()) { return 1; - } else if (allPostFragment != null && allPostFragment.isInLazyMode()) { + } else if (tab3 != null && tab3.isInLazyMode()) { return 2; } else { return -1; @@ -1186,9 +1230,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb void changeSortType(SortType sortType) { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - popularPostFragment.changeSortType(sortType); + tab2.changeSortType(sortType); } else { - allPostFragment.changeSortType(sortType); + tab3.changeSortType(sortType); } } else { switch (viewPager.getCurrentItem()) { @@ -1198,7 +1242,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); } - frontPagePostFragment.changeSortType(sortType); + tab1.changeSortType(sortType); break; case 1: mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); @@ -1206,7 +1250,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); } - popularPostFragment.changeSortType(sortType); + tab2.changeSortType(sortType); break; case 2: mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); @@ -1214,7 +1258,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); } - allPostFragment.changeSortType(sortType); + tab3.changeSortType(sortType); } } } @@ -1222,77 +1266,77 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public void refresh() { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - if (popularPostFragment != null) { - popularPostFragment.refresh(); + if (tab2 != null) { + tab2.refresh(); } } else { - if (allPostFragment != null) { - allPostFragment.refresh(); + if (tab3 != null) { + tab3.refresh(); } } } else { switch (viewPager.getCurrentItem()) { case 0: - if (frontPagePostFragment != null) { - frontPagePostFragment.refresh(); + if (tab1 != null) { + tab1.refresh(); } break; case 1: - if (popularPostFragment != null) { - popularPostFragment.refresh(); + if (tab2 != null) { + tab2.refresh(); } break; case 2: - if (allPostFragment != null) { - allPostFragment.refresh(); + if (tab3 != null) { + tab3.refresh(); } } } } void changeNSFW(boolean nsfw) { - if (frontPagePostFragment != null) { - frontPagePostFragment.changeNSFW(nsfw); + if (tab1 != null) { + tab1.changeNSFW(nsfw); } - if (popularPostFragment != null) { - popularPostFragment.changeNSFW(nsfw); + if (tab2 != null) { + tab2.changeNSFW(nsfw); } - if (allPostFragment != null) { - allPostFragment.changeNSFW(nsfw); + if (tab3 != null) { + tab3.changeNSFW(nsfw); } } void changePostLayout(int postLayout) { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { - if (popularPostFragment != null) { + if (tab2 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); - popularPostFragment.changePostLayout(postLayout); + tab2.changePostLayout(postLayout); } } else { - if (allPostFragment != null) { + if (tab3 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); - allPostFragment.changePostLayout(postLayout); + tab3.changePostLayout(postLayout); } } } else { switch (viewPager.getCurrentItem()) { case 0: - if (frontPagePostFragment != null) { + if (tab1 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); - frontPagePostFragment.changePostLayout(postLayout); + tab1.changePostLayout(postLayout); } break; case 1: - if (popularPostFragment != null) { + if (tab2 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); - popularPostFragment.changePostLayout(postLayout); + tab2.changePostLayout(postLayout); } break; case 2: - if (allPostFragment != null) { + if (tab3 != null) { mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); - allPostFragment.changePostLayout(postLayout); + tab3.changePostLayout(postLayout); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 351ab8f8..5368f6f4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment; import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; @@ -164,4 +165,6 @@ public interface AppComponent { void inject(SelectedSubredditsActivity selectedSubredditsActivity); void inject(ReportActivity reportActivity); + + void inject(CustomizeMainPageTabsFragment customizeMainPageTabsFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java new file mode 100644 index 00000000..89e212dc --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java @@ -0,0 +1,174 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragmentCompat; + +import javax.inject.Inject; +import javax.inject.Named; + +import ml.docilealligator.infinityforreddit.Activity.SettingsActivity; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +/** + * A simple {@link Fragment} subclass. + */ +public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat { + + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper customThemeWrapper; + private SettingsActivity activity; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.customize_main_page_tabs_preferences, rootKey); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + EditTextPreference tab1TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE); + EditTextPreference tab2TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE); + EditTextPreference tab3TitlePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE); + ListPreference tab1PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE); + ListPreference tab2PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE); + ListPreference tab3PostTypePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE); + EditTextPreference tab1NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME); + EditTextPreference tab2NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME); + EditTextPreference tab3NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME); + + if (tab1TitlePreference != null && tab1PostTypePreference != null && tab1NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_username); + } + + tab1PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab1NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab1NamePreference.setVisible(true); + tab1NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + + if (tab2TitlePreference != null && tab2PostTypePreference != null && tab2NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_username); + } + + tab2PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab2NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab2NamePreference.setVisible(true); + tab2NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + + if (tab3TitlePreference != null && tab3PostTypePreference != null && tab3NamePreference != null) { + String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_username); + } + + tab3PostTypePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR: + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL: + tab3NamePreference.setVisible(false); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); + break; + case SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER: + tab3NamePreference.setVisible(true); + tab3NamePreference.setTitle(R.string.settings_tab_username); + } + return true; + }); + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (SettingsActivity) context; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 538e5899..7b12ef6c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -100,4 +100,19 @@ public class SharedPreferencesUtils { public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE = "delete_all_post_layout_data_in_database"; public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database"; public static final String RESET_ALL_SETTINGS = "reset_all_settings"; + public static final String MAIN_PAGE_TAB_1_TITLE = "main_page_tab_1_title"; + public static final String MAIN_PAGE_TAB_2_TITLE = "main_page_tab_2_title"; + public static final String MAIN_PAGE_TAB_3_TITLE = "main_page_tab_3_title"; + public static final String MAIN_PAGE_TAB_1_POST_TYPE = "main_page_tab_1_post_type"; + public static final String MAIN_PAGE_TAB_2_POST_TYPE = "main_page_tab_2_post_type"; + public static final String MAIN_PAGE_TAB_3_POST_TYPE = "main_page_tab_3_post_type"; + public static final String MAIN_PAGE_TAB_1_NAME = "main_page_tab_1_name"; + public static final String MAIN_PAGE_TAB_2_NAME = "main_page_tab_2_name"; + public static final String MAIN_PAGE_TAB_3_NAME = "main_page_tab_3_name"; + public static final String MAIN_PAGE_TAB_POST_TYPE_HOME = "0"; + public static final String MAIN_PAGE_TAB_POST_TYPE_POPULAR = "1"; + public static final String MAIN_PAGE_TAB_POST_TYPE_ALL = "2"; + public static final String MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT = "3"; + public static final String MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT = "4"; + public static final String MAIN_PAGE_TAB_POST_TYPE_USER = "5"; } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b415b0f5..5fce9e21 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -122,4 +122,22 @@ XLarge XXLarge + + + Home + Popular + All + Subreddit + MultiReddit + User + + + + 0 + 1 + 2 + 3 + 4 + 5 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52ec8509..5df67ecc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -321,6 +321,8 @@ Immersive Interface Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding + Customize Tabs in Main Page + Only for Logged-in User Enable Bottom Navigation Has No Effect in Anonymous Mode Vote Buttons on the Right @@ -393,6 +395,15 @@ Delete All Themes in Database Reset All Settings Clean the database and shared preferences + Restart the app to see the changes + Tab 1 + Tab 2 + Tab 3 + Title + Type + Subreddit Name + MultiReddit Name + Username Cannot get the link @@ -711,10 +722,13 @@ Reported Report failed You haven\'t selected a reason - + It Is Spam It Contains Copyright Issue It Contains Child Pornography It Contains Abusive Content + Home + Best + diff --git a/app/src/main/res/xml/customize_main_page_tabs_preferences.xml b/app/src/main/res/xml/customize_main_page_tabs_preferences.xml new file mode 100644 index 00000000..37e17d0c --- /dev/null +++ b/app/src/main/res/xml/customize_main_page_tabs_preferences.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml index 8b67a3bc..58de9ef4 100644 --- a/app/src/main/res/xml/interface_preference.xml +++ b/app/src/main/res/xml/interface_preference.xml @@ -20,6 +20,11 @@ app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" app:isPreferenceVisible="false" /> + + Date: Wed, 13 May 2020 23:09:22 +0800 Subject: Version 3.1.0. --- app/src/main/res/values/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/src') diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5df67ecc..6e614a3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -401,9 +401,9 @@ Tab 3 Title Type - Subreddit Name - MultiReddit Name - Username + Subreddit Name (Without r/ prefix) + MultiReddit Name (/user/yourusername/m/yourmultiredditname) + Username (Without u/ prefix) Cannot get the link -- cgit v1.2.3 From 2204b72484f9b143ff28e249f2eac3cc900ed3d0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 14 May 2020 10:27:35 +0800 Subject: Fix string value for popular. --- .../Settings/CustomizeMainPageTabsFragment.java | 28 +++++++++++----------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java index 89e212dc..01e2c28e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java @@ -55,15 +55,15 @@ public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat { EditTextPreference tab3NamePreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME); if (tab1TitlePreference != null && tab1PostTypePreference != null && tab1NamePreference != null) { - String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); - if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) { tab1NamePreference.setVisible(true); tab1NamePreference.setTitle(R.string.settings_tab_subreddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) { tab1NamePreference.setVisible(true); tab1NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) { tab1NamePreference.setVisible(true); tab1NamePreference.setTitle(R.string.settings_tab_username); } @@ -92,15 +92,15 @@ public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat { } if (tab2TitlePreference != null && tab2PostTypePreference != null && tab2NamePreference != null) { - String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, - SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); - if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) { tab2NamePreference.setVisible(true); tab2NamePreference.setTitle(R.string.settings_tab_subreddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) { tab2NamePreference.setVisible(true); tab2NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) { tab2NamePreference.setVisible(true); tab2NamePreference.setTitle(R.string.settings_tab_username); } @@ -129,15 +129,15 @@ public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat { } if (tab3TitlePreference != null && tab3PostTypePreference != null && tab3NamePreference != null) { - String string = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, - SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); - if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(string)) { + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, + SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL); + if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT.equals(postType)) { tab3NamePreference.setVisible(true); tab3NamePreference.setTitle(R.string.settings_tab_subreddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT.equals(postType)) { tab3NamePreference.setVisible(true); tab3NamePreference.setTitle(R.string.settings_tab_multi_reddit_name); - } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(string)) { + } else if (SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER.equals(postType)) { tab3NamePreference.setVisible(true); tab3NamePreference.setTitle(R.string.settings_tab_username); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e614a3b..b44a5157 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -729,6 +729,6 @@ It Contains Abusive Content Home - Best + Popular -- cgit v1.2.3 From 07710908ba44f3ada4d95c1fffd3cb708029a633 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 14 May 2020 10:41:59 +0800 Subject: Fix wrong tab type default value in MainActivity. --- .../ml/docilealligator/infinityforreddit/Activity/MainActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 8f773a69..6bc4189a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -960,11 +960,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, ""); return generatePostFragment(postType, name); } else if (position == 1) { - String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR); String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, ""); return generatePostFragment(postType, name); } else { - String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); + String postType = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL); String name = mSharedPreferences.getString(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, ""); return generatePostFragment(postType, name); } -- cgit v1.2.3