diff options
Diffstat (limited to 'app/src/main/java')
4 files changed, 144 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 4577cb96..41a09c37 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -48,6 +48,7 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount; @@ -59,6 +60,9 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import retrofit2.Retrofit; + +import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY; public class ViewPostDetailActivity extends BaseActivity implements SortTypeSelectionCallback, ActivityToolbarInterface { @@ -73,8 +77,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele public static final int EDIT_COMMENT_REQUEST_CODE = 3; public static final int GIVE_AWARD_REQUEST_CODE = 100; @State - String mAccountName; - @State String mNewAccountName; @BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout; @@ -87,6 +89,9 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele @BindView(R.id.fab_view_post_detail_activity) FloatingActionButton fab; @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @Named("default") @@ -105,6 +110,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele private FragmentManager fragmentManager; private SlidrInterface mSlidrInterface; private SectionsPagerAdapter sectionsPagerAdapter; + private String mAccessToken; + private String mAccountName; private long postFragmentId; private int postListPosition = -1; private int orientation; @@ -183,6 +190,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); } + mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false); @@ -302,6 +310,52 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } + public void saveComment(@NonNull Comment comment, int position) { + if (comment.isSaved()) { + comment.setSaved(false); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + fragment.saveComment(position, false); + } + Toast.makeText(ViewPostDetailActivity.this, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + fragment.saveComment(position, true); + } + Toast.makeText(ViewPostDetailActivity.this, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } else { + comment.setSaved(true); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { + @Override + public void success() { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + fragment.saveComment(position, true); + } + Toast.makeText(ViewPostDetailActivity.this, R.string.comment_saved_success, Toast.LENGTH_SHORT).show(); + } + + @Override + public void failed() { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + fragment.saveComment(position, false); + } + Toast.makeText(ViewPostDetailActivity.this, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { if (!getClass().getName().equals(event.excludeActivityClassName)) { @@ -346,6 +400,26 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele int newAwardsCount = data.getIntExtra(GiveAwardActivity.EXTRA_RETURN_NEW_AWARDS_COUNT, 0); awardGiven(newAwardsHTML, newAwardsCount, position); } + } else if (requestCode == CommentActivity.WRITE_COMMENT_REQUEST_CODE) { + if (data != null && resultCode == Activity.RESULT_OK) { + if (data.hasExtra(RETURN_EXTRA_COMMENT_DATA_KEY)) { + ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); + if (fragment != null) { + Comment comment = data.getParcelableExtra(RETURN_EXTRA_COMMENT_DATA_KEY); + if (comment != null && comment.getDepth() == 0) { + fragment.addComment(comment); + } else { + String parentFullname = data.getStringExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY); + int parentPosition = data.getIntExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, -1); + if (parentFullname != null && parentPosition >= 0) { + fragment.addChildComment(comment, parentFullname, parentPosition); + } + } + } + } else { + Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show(); + } + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index f463ed31..2aa5b555 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -192,6 +192,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private boolean mHasMoreComments; private boolean loadMoreCommentsFailed; + private int depthThreshold = 5; private int mColorPrimaryLightTheme; private int mColorAccent; private int mCircularProgressBarBackgroundColor; @@ -224,13 +225,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private int mNoPreviewPostTypeIconTint; private int mUpvotedColor; private int mDownvotedColor; - private int mCommentVerticalBarColor1; - private int mCommentVerticalBarColor2; - private int mCommentVerticalBarColor3; - private int mCommentVerticalBarColor4; - private int mCommentVerticalBarColor5; - private int mCommentVerticalBarColor6; - private int mCommentVerticalBarColor7; private int mSingleCommentThreadBackgroundColor; private int mVoteAndReplyUnavailableVoteButtonColor; private int mButtonTextColor; @@ -485,8 +479,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE); mExpandChildren = !sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); - //mCommentToolbarHidden = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false); - mCommentToolbarHidden = true; + mCommentToolbarHidden = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false); + //mCommentToolbarHidden = true; mCommentToolbarHideOnClick = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true); mSwapTapAndLong = sharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false); mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); @@ -557,13 +551,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mUsernameColor = customThemeWrapper.getUsername(); mUpvotedColor = customThemeWrapper.getUpvoted(); mDownvotedColor = customThemeWrapper.getDownvoted(); - mCommentVerticalBarColor1 = customThemeWrapper.getCommentVerticalBarColor1(); - mCommentVerticalBarColor2 = customThemeWrapper.getCommentVerticalBarColor2(); - mCommentVerticalBarColor3 = customThemeWrapper.getCommentVerticalBarColor3(); - mCommentVerticalBarColor4 = customThemeWrapper.getCommentVerticalBarColor4(); - mCommentVerticalBarColor5 = customThemeWrapper.getCommentVerticalBarColor5(); - mCommentVerticalBarColor6 = customThemeWrapper.getCommentVerticalBarColor6(); - mCommentVerticalBarColor7 = customThemeWrapper.getCommentVerticalBarColor7(); mSingleCommentThreadBackgroundColor = customThemeWrapper.getSingleCommentThreadBackgroundColor(); mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor(); mButtonTextColor = customThemeWrapper.getButtonTextColor(); @@ -1118,6 +1105,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy comment.getScore() + comment.getVoteType()))); ((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors); + if (comment.getDepth() > depthThreshold) { + ((CommentViewHolder) holder).saveButton.setVisibility(View.GONE); + ((CommentViewHolder) holder).replyButton.setVisibility(View.GONE); + } else { + ((CommentViewHolder) holder).saveButton.setVisibility(View.VISIBLE); + ((CommentViewHolder) holder).replyButton.setVisibility(View.VISIBLE); + } if (comment.hasReply()) { if (comment.isExpanded()) { @@ -1882,6 +1876,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } } + public void setSaveComment(int position, boolean isSaved) { + Comment comment = getCurrentComment(position); + if (comment != null) { + comment.setSaved(isSaved); + } + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof CommentViewHolder) { @@ -3365,6 +3366,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } bundle.putString(CommentMoreBottomSheetFragment.EXTRA_COMMENT_MARKDOWN, comment.getCommentMarkdown()); bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_IS_NSFW, mPost.isNSFW()); + if (comment.getDepth() > depthThreshold) { + bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_SHOW_REPLY_AND_SAVE_OPTION, true); + } CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment(); commentMoreBottomSheetFragment.setArguments(bundle); commentMoreBottomSheetFragment.show(mActivity.getSupportFragmentManager(), commentMoreBottomSheetFragment.getTag()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index d1826cf2..6774b205 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -15,20 +15,22 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.activities.FullMarkdownActivity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.EditCommentActivity; +import ml.docilealligator.infinityforreddit.activities.FullMarkdownActivity; import ml.docilealligator.infinityforreddit.activities.GiveAwardActivity; import ml.docilealligator.infinityforreddit.activities.ReportActivity; import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.comment.Comment; -import ml.docilealligator.infinityforreddit.R; /** @@ -40,13 +42,18 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag public static final String EXTRA_ACCESS_TOKEN = "EAT"; public static final String EXTRA_EDIT_AND_DELETE_AVAILABLE = "EEADA"; public static final String EXTRA_POSITION = "EP"; + public static final String EXTRA_SHOW_REPLY_AND_SAVE_OPTION = "ESSARO"; public static final String EXTRA_COMMENT_MARKDOWN = "ECM"; public static final String EXTRA_IS_NSFW = "EIN"; @BindView(R.id.edit_text_view_comment_more_bottom_sheet_fragment) TextView editTextView; @BindView(R.id.delete_text_view_comment_more_bottom_sheet_fragment) TextView deleteTextView; + @BindView(R.id.reply_text_view_comment_more_bottom_sheet_fragment) + TextView replyTextView; @BindView(R.id.save_text_view_comment_more_bottom_sheet_fragment) + TextView saveTextView; + @BindView(R.id.share_text_view_comment_more_bottom_sheet_fragment) TextView shareTextView; @BindView(R.id.copy_text_view_comment_more_bottom_sheet_fragment) TextView copyTextView; @@ -87,6 +94,7 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag } String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false); + boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false); if (accessToken != null && !accessToken.equals("")) { giveAwardTextView.setVisibility(View.VISIBLE); @@ -131,6 +139,38 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag } } + if (showReplyAndSaveOption) { + replyTextView.setVisibility(View.VISIBLE); + saveTextView.setVisibility(View.VISIBLE); + if (comment.isSaved()) { + saveTextView.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_24dp), null, null, null); + saveTextView.setText(R.string.unsave_comment); + } else { + saveTextView.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(activity, R.drawable.ic_bookmark_border_24dp), null, null, null); + saveTextView.setText(R.string.save_comment); + } + replyTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, CommentActivity.class); + intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, comment.getDepth() + 1); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, comment.getCommentMarkdown()); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentRawText()); + intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); + intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); + + intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, bundle.getInt(EXTRA_POSITION)); + activity.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); + + dismiss(); + }); + + saveTextView.setOnClickListener(view -> { + if (activity instanceof ViewPostDetailActivity) { + ((ViewPostDetailActivity) activity).saveComment(comment, bundle.getInt(EXTRA_POSITION)); + } + dismiss(); + }); + } + shareTextView.setOnClickListener(view -> { dismiss(); try { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 5f41dc1d..86cc6c4a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -729,6 +729,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } } + public void saveComment(int position, boolean isSaved) { + if (mAdapter != null) { + mAdapter.setSaveComment(position, isSaved); + } + } + @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_post_detail_fragment, menu); |