diff options
Diffstat (limited to '')
8 files changed, 200 insertions, 86 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3679f066..8f7d4e15 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,11 +22,13 @@ android:usesCleartextTraffic="true"> <activity android:name=".EditCommentActivity" + android:label="@string/edit_comment_activity_label" android:parentActivityName=".MainActivity" android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="adjustResize" /> <activity android:name=".EditPostActivity" + android:label="@string/edit_post_activity_label" android:parentActivityName=".MainActivity" android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="adjustResize" /> diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 69e37c31..0e23d359 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -252,6 +252,10 @@ class Post implements Parcelable { return flair; } + void setFlair(String flair) { + this.flair = flair; + } + void setScore(int score) { this.score = score; } @@ -296,10 +300,18 @@ class Post implements Parcelable { return spoiler; } + void setSpoiler(boolean spoiler) { + this.spoiler = spoiler; + } + boolean isNSFW() { return nsfw; } + void setNSFW(boolean nsfw) { + this.nsfw = nsfw; + } + @Override public int describeContents() { return 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index 851d351a..cc1503ae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -423,6 +423,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { post.setTitle(event.post.getTitle()); post.setVoteType(event.post.getVoteType()); post.setScore(event.post.getScore()); + post.setNSFW(event.post.isNSFW()); + post.setSpoiler(event.post.isSpoiler()); + post.setFlair(event.post.getFlair()); mAdapter.notifyItemChanged(event.positionInList); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index 0412b99e..4deb3abd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -131,4 +131,20 @@ public interface RedditAPI { @FormUrlEncoded @POST("/api/editusertext") Call<String> editPostOrComment(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); + + @FormUrlEncoded + @POST("/api/marknsfw") + Call<String> markNSFW(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); + + @FormUrlEncoded + @POST("/api/unmarknsfw") + Call<String> unmarkNSFW(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); + + @FormUrlEncoded + @POST("/api/spoiler") + Call<String> markSpoiler(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); + + @FormUrlEncoded + @POST("/api/unspoiler") + Call<String> unmarkSpoiler(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 797c1834..964e1809 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -37,7 +37,9 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import javax.inject.Inject; import javax.inject.Named; @@ -223,6 +225,22 @@ public class ViewPostDetailActivity extends AppCompatActivity { mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true); } mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true); + + MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_activity); + nsfwItem.setVisible(true); + if(mPost.isNSFW()) { + nsfwItem.setTitle(R.string.action_unmark_nsfw); + } else { + nsfwItem.setTitle(R.string.action_mark_nsfw); + } + + MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_activity); + spoilerItem.setVisible(true); + if(mPost.isSpoiler()) { + spoilerItem.setTitle(R.string.action_unmark_spoiler); + } else { + spoilerItem.setTitle(R.string.action_mark_spoiler); + } } mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, @@ -459,7 +477,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void fetchPostFailed() { - showErrorMessage(R.string.refresh_post_failed); + showMessage(R.string.refresh_post_failed); isRefreshing = false; } }); @@ -474,7 +492,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mGlide.load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView); } - private void showErrorMessage(int resId) { + private void showMessage(int resId) { if(showToast) { Toast.makeText(ViewPostDetailActivity.this, resId, Toast.LENGTH_SHORT).show(); } else { @@ -482,6 +500,94 @@ public class ViewPostDetailActivity extends AppCompatActivity { } } + private void markNSFW() { + Map<String, String> params = new HashMap<>(); + params.put(RedditUtils.ID_KEY, mPost.getFullName()); + mOauthRetrofit.create(RedditAPI.class).markNSFW(RedditUtils.getOAuthHeader(mAccessToken), params) + .enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if(response.isSuccessful()) { + refresh(true); + showMessage(R.string.mark_nsfw_success); + } else { + showMessage(R.string.mark_nsfw_failed); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + showMessage(R.string.mark_nsfw_failed); + } + }); + } + + private void unmarkNSFW() { + Map<String, String> params = new HashMap<>(); + params.put(RedditUtils.ID_KEY, mPost.getFullName()); + mOauthRetrofit.create(RedditAPI.class).unmarkNSFW(RedditUtils.getOAuthHeader(mAccessToken), params) + .enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if(response.isSuccessful()) { + refresh(true); + showMessage(R.string.unmark_nsfw_success); + } else { + showMessage(R.string.unmark_nsfw_failed); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + showMessage(R.string.unmark_nsfw_failed); + } + }); + } + + private void markSpoiler() { + Map<String, String> params = new HashMap<>(); + params.put(RedditUtils.ID_KEY, mPost.getFullName()); + mOauthRetrofit.create(RedditAPI.class).markSpoiler(RedditUtils.getOAuthHeader(mAccessToken), params) + .enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if(response.isSuccessful()) { + refresh(true); + showMessage(R.string.mark_spoiler_success); + } else { + showMessage(R.string.mark_spoiler_failed); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + showMessage(R.string.mark_spoiler_failed); + } + }); + } + + private void unmarkSpoiler() { + Map<String, String> params = new HashMap<>(); + params.put(RedditUtils.ID_KEY, mPost.getFullName()); + mOauthRetrofit.create(RedditAPI.class).unmarkSpoiler(RedditUtils.getOAuthHeader(mAccessToken), params) + .enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if(response.isSuccessful()) { + refresh(true); + showMessage(R.string.unmark_spoiler_success); + } else { + showMessage(R.string.unmark_spoiler_failed); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + showMessage(R.string.unmark_spoiler_failed); + } + }); + } + void deleteComment(String fullName, int position) { new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.delete_this_comment) @@ -520,6 +626,22 @@ public class ViewPostDetailActivity extends AppCompatActivity { menu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true); } menu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true); + + MenuItem nsfwItem = menu.findItem(R.id.action_nsfw_view_post_detail_activity); + nsfwItem.setVisible(true); + if(mPost.isNSFW()) { + nsfwItem.setTitle(R.string.action_unmark_nsfw); + } else { + nsfwItem.setTitle(R.string.action_mark_nsfw); + } + + MenuItem spoilerItem = menu.findItem(R.id.action_spoiler_view_post_detail_activity); + spoilerItem.setVisible(true); + if(mPost.isSpoiler()) { + spoilerItem.setTitle(R.string.action_unmark_spoiler); + } else { + spoilerItem.setTitle(R.string.action_mark_spoiler); + } } return true; } @@ -565,12 +687,26 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void deleteFailed() { - showErrorMessage(R.string.delete_post_failed); + showMessage(R.string.delete_post_failed); } })) .setNegativeButton(R.string.cancel, null) .show(); return true; + case R.id.action_nsfw_view_post_detail_activity: + if(mPost.isNSFW()) { + unmarkNSFW(); + } else { + markNSFW(); + } + return true; + case R.id.action_spoiler_view_post_detail_activity: + if(mPost.isSpoiler()) { + unmarkSpoiler(); + } else { + markSpoiler(); + } + return true; case android.R.id.home: onBackPressed(); return true; diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index 1283aa5b..53613bc8 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -155,86 +155,6 @@ </androidx.constraintlayout.widget.ConstraintLayout> - <!--<RelativeLayout - android:id="@+id/relative_layout_item_post_comment" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginEnd="16dp"> - - <ImageView - android:id="@+id/plus_button_item_post_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentStart="true" - android:src="@drawable/ic_arrow_upward_black_20dp" - android:layout_centerVertical="true" - android:tint="@android:color/tab_indicator_text" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true"/> - - <TextView - android:id="@+id/score_text_view_item_post_comment" - android:layout_width="64dp" - android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:layout_toEndOf="@id/plus_button_item_post_comment" - android:gravity="center"/> - - <ImageView - android:id="@+id/minus_button_item_post_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:layout_toEndOf="@id/score_text_view_item_post_comment" - android:src="@drawable/ic_arrow_downward_black_20dp" - android:tint="@android:color/tab_indicator_text" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true"/> - - <ImageView - android:id="@+id/expand_button_item_post_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_toStartOf="@id/share_button_item_post_comment" - android:layout_centerVertical="true" - android:layout_marginEnd="16dp" - android:src="@drawable/ic_expand_less_black_20dp" - android:tint="@android:color/tab_indicator_text" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true" - android:visibility="gone"/> - - <ImageView - android:id="@+id/share_button_item_post_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_toStartOf="@id/reply_button_item_post_comment" - android:layout_centerVertical="true" - android:layout_marginEnd="16dp" - android:src="@drawable/ic_outline_share_20px" - android:tint="@android:color/tab_indicator_text" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true"/> - - <ImageView - android:id="@+id/reply_button_item_post_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:layout_alignParentEnd="true" - android:src="@drawable/ic_reply_black_20dp" - android:tint="@android:color/tab_indicator_text" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true"/> - - </RelativeLayout>--> - </LinearLayout> </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml index 76e2db37..3df40201 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -23,8 +23,20 @@ <item android:id="@+id/action_delete_view_post_detail_activity" - android:orderInCategory="3" + android:orderInCategory="4" android:title="@string/action_delete_post" app:showAsAction="never" android:visible="false" /> + + <item + android:id="@+id/action_nsfw_view_post_detail_activity" + android:orderInCategory="5" + app:showAsAction="never" + android:visible="false" /> + + <item + android:id="@+id/action_spoiler_view_post_detail_activity" + android:orderInCategory="6" + app:showAsAction="never" + android:visible="false" /> </menu>
\ 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 9b3dd695..77d23b4c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,8 @@ <string name="post_video_activity_label">Video Post</string> <string name="rules_activity_label">Rules</string> <string name="search_subreddits_activity_label">Subreddits</string> + <string name="edit_post_activity_label">Edit Post</string> + <string name="edit_comment_activity_label">Edit Comment</string> <string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string> @@ -26,6 +28,10 @@ <string name="action_sort">Sort</string> <string name="action_edit_post">Edit Post</string> <string name="action_delete_post">Delete Post</string> + <string name="action_mark_nsfw">Mark NSFW</string> + <string name="action_unmark_nsfw">Unmark NSFW</string> + <string name="action_mark_spoiler">Mark Spoiler</string> + <string name="action_unmark_spoiler">Unmark Spoiler</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> <string name="retrieve_token_error">Error Retrieving the token</string> @@ -187,8 +193,15 @@ <string name="edit">Edit</string> <string name="delete">Delete</string> <string name="cancel">Cancel</string> + <string name="edit_success">Edit successful</string> <string name="delete_post_success">Delete successfully</string> <string name="delete_post_failed">Delete failed</string> - - <string name="edit_success">Edit Successful</string> + <string name="mark_nsfw_success">Mark NSFW successful</string> + <string name="mark_nsfw_failed">Mark NSFW failed</string> + <string name="unmark_nsfw_success">Unmark NSFW successful</string> + <string name="unmark_nsfw_failed">Unmark NSFW failed</string> + <string name="mark_spoiler_success">Mark spoiler successful</string> + <string name="mark_spoiler_failed">Mark spoiler failed</string> + <string name="unmark_spoiler_success">Unmark spoiler successful</string> + <string name="unmark_spoiler_failed">Unmark spoiler failed</string> </resources> |