|
25 | 25 | import androidx.annotation.Nullable; |
26 | 26 | import androidx.appcompat.app.AppCompatActivity; |
27 | 27 |
|
| 28 | +import org.json.JSONObject; |
28 | 29 | import org.quantumbadger.redreader.account.RedditAccount; |
29 | 30 | import org.quantumbadger.redreader.activities.BugReportActivity; |
30 | 31 | import org.quantumbadger.redreader.cache.CacheManager; |
|
65 | 66 | import java.util.ArrayList; |
66 | 67 | import java.util.Collection; |
67 | 68 | import java.util.Collections; |
| 69 | +import java.util.HashMap; |
68 | 70 | import java.util.LinkedList; |
69 | 71 | import java.util.List; |
70 | 72 | import java.util.Map; |
@@ -959,6 +961,35 @@ public void onFailure(@NonNull final RRError error) { |
959 | 961 | )); |
960 | 962 | } |
961 | 963 |
|
| 964 | + public static void addSubredditToMultireddit( |
| 965 | + final CacheManager cm, |
| 966 | + final APIResponseHandler.ActionResponseHandler handler, |
| 967 | + final RedditAccount user, |
| 968 | + final String multiredditName, |
| 969 | + final String subredditName, |
| 970 | + final Context context) { |
| 971 | + |
| 972 | + final Uri.Builder builder = Constants.Reddit.getUriBuilder( |
| 973 | + Constants.Reddit.PATH_MULTIREDDIT) |
| 974 | + .appendPath("user") |
| 975 | + .appendPath(user.username) |
| 976 | + .appendPath("m") |
| 977 | + .appendPath(multiredditName) |
| 978 | + .appendPath("r") |
| 979 | + .appendPath(subredditName); |
| 980 | + |
| 981 | + final Map<String, String> jsonData = new HashMap<>(); |
| 982 | + jsonData.put("name", subredditName); |
| 983 | + |
| 984 | + cm.makeRequest(createPutRequest( |
| 985 | + UriString.from(builder.build()), |
| 986 | + user, |
| 987 | + new ArrayList<>(Collections.singleton( |
| 988 | + new PostField("model", new JSONObject(jsonData).toString()))), |
| 989 | + context, |
| 990 | + new GenericResponseHandler(handler))); |
| 991 | + } |
| 992 | + |
962 | 993 | @Nullable |
963 | 994 | private static APIResponseHandler.APIFailureType findFailureType(final JsonValue response) { |
964 | 995 |
|
|
0 commit comments