aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/build.gradle4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/user/BlockUser.java40
-rw-r--r--app/src/main/res/menu/view_user_detail_activity.xml5
-rw-r--r--app/src/main/res/values/strings.xml5
6 files changed, 82 insertions, 2 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 94cf7c9f..6644ba75 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdk 21
targetSdk 33
- versionCode 110
- versionName "5.4.0-beta2"
+ versionCode 111
+ versionName "5.4.0-beta3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
index b1119059..2daef67b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
@@ -111,6 +111,7 @@ import ml.docilealligator.infinityforreddit.post.PostPagingSource;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
+import ml.docilealligator.infinityforreddit.user.BlockUser;
import ml.docilealligator.infinityforreddit.user.FetchUserData;
import ml.docilealligator.infinityforreddit.user.UserDao;
import ml.docilealligator.infinityforreddit.user.UserData;
@@ -1119,6 +1120,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (username.equals(mAccountName)) {
menu.findItem(R.id.action_send_private_message_view_user_detail_activity).setVisible(false);
menu.findItem(R.id.action_report_view_user_detail_activity).setVisible(false);
+ menu.findItem(R.id.action_block_user_view_user_detail_activity).setVisible(false);
} else {
menu.findItem(R.id.action_edit_profile_view_user_detail_activity).setVisible(false);
}
@@ -1187,6 +1189,30 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
reportIntent.setData(Uri.parse("https://www.reddithelp.com/en/categories/rules-reporting/account-and-community-restrictions/what-should-i-do-if-i-see-something-i"));
startActivity(reportIntent);
return true;
+ } else if (itemId == R.id.action_block_user_view_user_detail_activity) {
+ if (mAccessToken == null) {
+ Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.block_user)
+ .setMessage(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> BlockUser.blockUser(mOauthRetrofit, mAccessToken, username, new BlockUser.BlockUserListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewUserDetailActivity.this, R.string.block_user_success, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewUserDetailActivity.this, R.string.block_user_failed, Toast.LENGTH_SHORT).show();
+ }
+ }))
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
} else if (itemId == R.id.action_edit_profile_view_user_detail_activity) {
startActivity(new Intent(this, EditProfileActivity.class));
return true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index 07119b1f..41d44d38 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -215,6 +215,10 @@ public interface RedditAPI {
@POST("/api/compose")
Call<String> composePrivateMessage(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
+ @FormUrlEncoded
+ @POST("api/block_user")
+ Call<String> blockUser(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
+
@GET("r/{subredditName}/api/user_flair_v2.json?raw_json=1")
Call<String> getUserFlairs(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/BlockUser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/BlockUser.java
new file mode 100644
index 00000000..c7a7207e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/BlockUser.java
@@ -0,0 +1,40 @@
+package ml.docilealligator.infinityforreddit.user;
+
+import androidx.annotation.NonNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class BlockUser {
+ public interface BlockUserListener {
+ void success();
+ void failed();
+ }
+
+ public static void blockUser(Retrofit oauthRetrofit, String accessToken, String username, BlockUserListener blockUserListener) {
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.NAME_KEY, username);
+ oauthRetrofit.create(RedditAPI.class).blockUser(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ blockUserListener.success();
+ } else {
+ blockUserListener.failed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ blockUserListener.failed();
+ }
+ });
+ }
+}
diff --git a/app/src/main/res/menu/view_user_detail_activity.xml b/app/src/main/res/menu/view_user_detail_activity.xml
index 41e3527a..ec9128e4 100644
--- a/app/src/main/res/menu/view_user_detail_activity.xml
+++ b/app/src/main/res/menu/view_user_detail_activity.xml
@@ -56,6 +56,11 @@
android:title="@string/action_report" />
<item
+ android:id="@+id/action_block_user_view_user_detail_activity"
+ android:orderInCategory="10"
+ android:title="@string/action_block_user" />
+
+ <item
android:id="@+id/action_edit_profile_view_user_detail_activity"
android:orderInCategory="11"
android:title="@string/action_edit_profile" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d4986fc8..2b77b298 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -79,6 +79,7 @@
<string name="action_crosspost">Crosspost</string>
<string name="action_set_wallpaper">Set as Wallpaper</string>
<string name="action_send_private_message">Send Private Message</string>
+ <string name="action_block_user">Block User</string>
<string name="action_select_user_flair">Select User Flair</string>
<string name="action_give_award">Give Award</string>
<string name="action_save_to_database">Save to Database</string>
@@ -1053,6 +1054,10 @@
<string name="login_activity_2fa_prompt">If you have 2-factor authentication enabled, kindly type your password like the following: &lt;password&gt;:&lt;2FA code&gt;.\nExample: yourpass:123456</string>
+ <string name="block_user">Block User</string>
+ <string name="block_user_success">Blocked</string>
+ <string name="block_user_failed">Failed to block user</string>
+
<string name="select_user_flair_success">User flair selected</string>
<string name="select_this_user_flair">Select this user flair?</string>
<string name="clear_user_flair">Clear Flair</string>