diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-10-26 15:43:52 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-10-26 15:43:52 +0000 |
commit | e1b0b568ec21be256318d387ed2809ed3dc45b63 (patch) | |
tree | e0a25850b1cc2eff53ea9ce1639dba95baf66ced /app/src/main/java/ml/docilealligator | |
parent | 6710c44ff9e2d2a57d8f4e883be49ffca531779e (diff) | |
download | infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar.gz infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar.bz2 infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar.lz infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar.xz infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.tar.zst infinity-for-reddit-e1b0b568ec21be256318d387ed2809ed3dc45b63.zip |
Giving awards to comments. Fix some bugs.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
10 files changed, 126 insertions, 32 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/GiveAwardActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/GiveAwardActivity.java index 03bf88cd..803743aa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/GiveAwardActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/GiveAwardActivity.java @@ -139,7 +139,7 @@ public class GiveAwardActivity extends BaseActivity { @Override public void success(String awardsHTML, int awardCount) { Intent data = new Intent(); - data.putExtra(EXTRA_ITEM_POSITION, itemPosition); + data.putExtra(EXTRA_RETURN_ITEM_POSITION, itemPosition); data.putExtra(EXTRA_RETURN_NEW_AWARDS, awardsHTML); data.putExtra(EXTRA_RETURN_NEW_AWARDS_COUNT, awardCount); setResult(RESULT_OK, data); 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 448d3d64..0826ce6d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -1228,7 +1228,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) + .setTitle(R.string.go_to_subreddit) .setView(thingEditText) .setPositiveButton(R.string.ok, (dialogInterface, i) -> { 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 1e233c35..e8bc769a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -124,8 +124,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS public static final String EXTRA_MESSAGE_FULLNAME = "ENI"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; public static final int EDIT_COMMENT_REQUEST_CODE = 3; + public static final int GIVE_AWARD_REQUEST_CODE = 100; private static final int EDIT_POST_REQUEST_CODE = 2; - private static final int GIVE_AWARD_REQUEST_CODE = 100; @State boolean mNullAccessToken = false; @State diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index b34ba388..2492b7ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -1112,7 +1112,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.go_to_user) + .setTitle(R.string.go_to_subreddit) .setView(thingEditText) .setPositiveButton(R.string.ok, (dialogInterface, i) -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index a00bf56d..c309e899 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -94,6 +94,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele public static final String EXTRA_USER_NAME_KEY = "EUNK"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; + public static final int GIVE_AWARD_REQUEST_CODE = 200; + public static final int EDIT_COMMENT_REQUEST_CODE = 300; private static final String FETCH_USER_INFO_STATE = "FSIS"; private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; @@ -580,7 +582,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele FetchUserData.fetchUserData(mRetrofit, username, new FetchUserData.FetchUserDataListener() { @Override public void onFetchUserDataSuccess(UserData userData) { - new InsertUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), userData, + new ViewUserDetailActivity.InsertUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), userData, () -> mFetchUserInfoSuccess = true).execute(); } @@ -734,6 +736,29 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { + if (requestCode == GIVE_AWARD_REQUEST_CODE) { + Toast.makeText(this, R.string.give_award_success, Toast.LENGTH_SHORT).show(); + int position = data.getIntExtra(GiveAwardActivity.EXTRA_RETURN_ITEM_POSITION, 0); + String newAwardsHTML = data.getStringExtra(GiveAwardActivity.EXTRA_RETURN_NEW_AWARDS); + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.giveAward(newAwardsHTML, position); + } + } else if (requestCode == EDIT_COMMENT_REQUEST_CODE) { + if (data != null) { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.editComment( + data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT), + data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION)); + } + } + } + } + } + + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess); @@ -964,6 +989,24 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } } + + void giveAward(String awardsHTML, int position) { + if (fragmentManager != null) { + Fragment fragment = fragmentManager.findFragmentByTag("f1"); + if (fragment instanceof CommentsListingFragment) { + ((CommentsListingFragment) fragment).giveAward(awardsHTML, position); + } + } + } + + void editComment(String commentMarkdown, int position) { + if (fragmentManager != null) { + Fragment fragment = fragmentManager.findFragmentByTag("f1"); + if (fragment instanceof CommentsListingFragment) { + ((CommentsListingFragment) fragment).editComment(commentMarkdown, position); + } + } + } } private void lockSwipeRightToGoBack() { 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 3ae368c9..0e6fabdb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1878,6 +1878,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy notifyItemChanged(0); } } else { + position = mIsSingleCommentThreadMode ? position + 2 : position + 1; Comment comment = getCurrentComment(position); if (comment != null) { comment.addAwards(awardsHTML); @@ -3300,8 +3301,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy if (comment != null) { Bundle bundle = new Bundle(); if (!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { - bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_EDIT_AND_DELETE_AVAILABLE, true); } + bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment); if (mIsSingleCommentThreadMode) { bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition() - 2); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java index 4f4b9963..508d22aa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -265,6 +265,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } if (comment.getAwards() != null && !comment.getAwards().equals("")) { + ((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE); Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards()); } @@ -362,6 +363,24 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } } + public void giveAward(String awardsHTML, int position) { + if (position >= 0 && position < getItemCount()) { + Comment comment = getItem(position); + if (comment != null) { + comment.addAwards(awardsHTML); + notifyItemChanged(position); + } + } + } + + public void editComment(String commentContentMarkdown, int position) { + Comment comment = getItem(position); + if (comment != null) { + comment.setCommentMarkdown(commentContentMarkdown); + notifyItemChanged(position); + } + } + public interface RetryLoadingMoreCallback { void retryLoadingMore(); } @@ -475,10 +494,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment if (comment != null) { Bundle bundle = new Bundle(); if (comment.getAuthor().equals(mAccountName)) { - bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_EDIT_AND_DELETE_AVAILABLE, true); } + bundle.putString(CommentMoreBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment); - bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition() - 1); + bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getAdapterPosition()); bundle.putString(CommentMoreBottomSheetFragment.EXTRA_COMMENT_MARKDOWN, comment.getCommentMarkdown()); CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment(); commentMoreBottomSheetFragment.setArguments(bundle); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java index 34ef1bfe..e105ff80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java @@ -23,6 +23,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Activity.CommentFullMarkdownActivity; import ml.docilealligator.infinityforreddit.Activity.EditCommentActivity; +import ml.docilealligator.infinityforreddit.Activity.GiveAwardActivity; import ml.docilealligator.infinityforreddit.Activity.ReportActivity; import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; @@ -37,6 +38,7 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag public static final String EXTRA_COMMENT = "ECF"; 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_COMMENT_MARKDOWN = "ECM"; public static final String EXTRA_IS_NSFW = "EIN"; @@ -48,6 +50,8 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag TextView shareTextView; @BindView(R.id.copy_text_view_comment_more_bottom_sheet_fragment) TextView copyTextView; + @BindView(R.id.give_award_text_view_comment_more_bottom_sheet_fragment) + TextView giveAwardTextView; @BindView(R.id.view_full_markdown_text_view_comment_more_bottom_sheet_fragment) TextView viewFullMarkdownTextView; @BindView(R.id.report_view_comment_more_bottom_sheet_fragment) @@ -82,34 +86,50 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag return rootView; } String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN); + boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false); if (accessToken != null && !accessToken.equals("")) { - editTextView.setVisibility(View.VISIBLE); - deleteTextView.setVisibility(View.VISIBLE); - - editTextView.setOnClickListener(view -> { - Intent intent = new Intent(activity, EditCommentActivity.class); - intent.putExtra(EditCommentActivity.EXTRA_ACCESS_TOKEN, accessToken); - intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getFullName()); - intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown()); - intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION)); + giveAwardTextView.setVisibility(View.VISIBLE); + giveAwardTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, GiveAwardActivity.class); + intent.putExtra(GiveAwardActivity.EXTRA_THING_FULLNAME, comment.getFullName()); + intent.putExtra(GiveAwardActivity.EXTRA_ITEM_POSITION, bundle.getInt(EXTRA_POSITION)); if (activity instanceof ViewPostDetailActivity) { - activity.startActivityForResult(intent, ViewPostDetailActivity.EDIT_COMMENT_REQUEST_CODE); - } else { - startActivity(intent); + activity.startActivityForResult(intent, ViewPostDetailActivity.GIVE_AWARD_REQUEST_CODE); + } else if (activity instanceof ViewUserDetailActivity) { + activity.startActivityForResult(intent, ViewUserDetailActivity.GIVE_AWARD_REQUEST_CODE); } - dismiss(); }); - deleteTextView.setOnClickListener(view -> { - dismiss(); - if (activity instanceof ViewPostDetailActivity) { - ((ViewPostDetailActivity) activity).deleteComment(comment.getFullName(), bundle.getInt(EXTRA_POSITION)); - } else if (activity instanceof ViewUserDetailActivity) { - ((ViewUserDetailActivity) activity).deleteComment(comment.getFullName()); - } - }); + if (editAndDeleteAvailable) { + editTextView.setVisibility(View.VISIBLE); + deleteTextView.setVisibility(View.VISIBLE); + + editTextView.setOnClickListener(view -> { + Intent intent = new Intent(activity, EditCommentActivity.class); + intent.putExtra(EditCommentActivity.EXTRA_ACCESS_TOKEN, accessToken); + intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getFullName()); + intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown()); + intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION)); + if (activity instanceof ViewPostDetailActivity) { + activity.startActivityForResult(intent, ViewPostDetailActivity.EDIT_COMMENT_REQUEST_CODE); + } else { + activity.startActivityForResult(intent, ViewUserDetailActivity.EDIT_COMMENT_REQUEST_CODE); + } + + dismiss(); + }); + + deleteTextView.setOnClickListener(view -> { + dismiss(); + if (activity instanceof ViewPostDetailActivity) { + ((ViewPostDetailActivity) activity).deleteComment(comment.getFullName(), bundle.getInt(EXTRA_POSITION)); + } else if (activity instanceof ViewUserDetailActivity) { + ((ViewUserDetailActivity) activity).deleteComment(comment.getFullName()); + } + }); + } } shareTextView.setOnClickListener(view -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index bbd5fda3..5f0f0ba7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -391,4 +391,16 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni public SortType getSortType() { return sortType; } + + public void giveAward(String awardsHTML, int position) { + if (mAdapter != null) { + mAdapter.giveAward(awardsHTML, position); + } + } + + public void editComment(String commentMarkdown, int position) { + if (mAdapter != null) { + mAdapter.editComment(commentMarkdown, position); + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchPost.java index ccfc40eb..2d5ec30e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchPost.java @@ -1,7 +1,5 @@ package ml.docilealligator.infinityforreddit.Post; -import android.util.Log; - import androidx.annotation.NonNull; import java.util.Locale; @@ -60,7 +58,6 @@ public class FetchPost { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { - Log.i("asdasdf", "s " + response.body()); new ParsePost.ParseRandomPostAsyncTask(response.body(), isNSFW, new ParsePost.ParseRandomPostListener() { @Override |