aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-13 07:29:27 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-13 07:29:27 +0000
commit6872faa93dabeb37d5899dea7126c85976383388 (patch)
tree087558a33359f7efc873ae7408621d5f251f8cae /app/src/main/java
parent81e0897a1f91a546452a07fb3f3e880e374db368 (diff)
downloadinfinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar.gz
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar.bz2
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar.lz
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar.xz
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.tar.zst
infinity-for-reddit-6872faa93dabeb37d5899dea7126c85976383388.zip
Set NSFW and spoiler are now available.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java142
4 files changed, 170 insertions, 3 deletions
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;