Skip to content

Ability to Remove Subreddit from Multireddit #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ private void makeCacheRequest(
DownloadStrategyIfNotCached.INSTANCE,
Constants.FileType.IMAGE,
CacheRequest.DownloadQueueType.IMMEDIATE,
CacheRequest.RequestMethod.GET,
this,
new CacheRequestCallbacks() {

Expand Down Expand Up @@ -979,6 +980,7 @@ public void onDataStreamAvailable(
DownloadStrategyIfNotCached.INSTANCE,
Constants.FileType.IMAGE,
CacheRequest.DownloadQueueType.IMMEDIATE,
CacheRequest.RequestMethod.GET,
this,
new CacheRequestCallbacks() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ private void uploadImage() {
DownloadStrategyAlways.INSTANCE,
Constants.FileType.NOCACHE,
CacheRequest.DownloadQueueType.IMGUR_API,
CacheRequest.RequestMethod.POST,
new HTTPRequestBody.Multipart()
.addPart(new Part.FormDataBinary("image", mImageData)),
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ private void makeFirstRequest(final Context context) {
DownloadStrategyAlways.INSTANCE,
Constants.FileType.INBOX_LIST,
CacheRequest.DownloadQueueType.REDDIT_API,
CacheRequest.RequestMethod.GET,
false,
context,
new CacheRequestCallbacks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.quantumbadger.redreader.fragments.MainMenuFragment;
import org.quantumbadger.redreader.receivers.announcements.Announcement;
import org.quantumbadger.redreader.receivers.announcements.AnnouncementDownloader;
import org.quantumbadger.redreader.reddit.api.RedditAPIMultiredditAction;
import org.quantumbadger.redreader.reddit.api.RedditSubredditSubscriptionManager;
import org.quantumbadger.redreader.reddit.api.SubredditSubscriptionState;
import org.quantumbadger.redreader.reddit.things.SubredditCanonicalId;
Expand Down Expand Up @@ -951,13 +952,18 @@ private GroupedRecyclerViewItemListItemView makeMultiredditItem(
final View.OnClickListener clickListener = view -> mListener.onSelected(
(PostListingURL)MultiredditPostListURL.getMultireddit(name));

final View.OnLongClickListener longClickListener = view -> {
RedditAPIMultiredditAction.showActionMenu(mActivity, name);
return true;
};

return new GroupedRecyclerViewItemListItemView(
null,
name,
ScreenreaderPronunciation.getPronunciation(mContext, name),
hideDivider,
clickListener,
null,
longClickListener,
Optional.empty(),
Optional.empty(),
Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public CacheDownload(
initiator.context,
new HTTPBackend.RequestDetails(
mInitiator.url,
mInitiator.requestMethod,
mInitiator.requestBody.asNullable()));
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/quantumbadger/redreader/cache/CacheRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public enum RequestFailureType {
CACHE_DIR_DOES_NOT_EXIST
}

public enum RequestMethod {
GET,
POST,
DELETE
}

public final UriString url;
public final RedditAccount user;
public final UUID requestSession;
Expand All @@ -75,6 +81,7 @@ public enum RequestFailureType {
public final int fileType;

public final DownloadQueueType queueType;
public final RequestMethod requestMethod;
@NonNull public final Optional<HTTPRequestBody> requestBody;

public final boolean cache;
Expand Down Expand Up @@ -114,6 +121,7 @@ public CacheRequest(
@NonNull final DownloadStrategy downloadStrategy,
final int fileType,
final DownloadQueueType queueType,
final RequestMethod requestMethod,
final boolean cache,
@NonNull final Context context,
@NonNull final CacheRequestCallbacks callbacks) {
Expand All @@ -126,6 +134,7 @@ public CacheRequest(
downloadStrategy,
fileType,
queueType,
requestMethod,
null,
cache,
context,
Expand All @@ -140,6 +149,7 @@ public CacheRequest(
@NonNull final DownloadStrategy downloadStrategy,
final int fileType,
final DownloadQueueType queueType,
final RequestMethod requestMethod,
@NonNull final Context context,
@NonNull final CacheRequestCallbacks callbacks) {

Expand All @@ -151,6 +161,7 @@ public CacheRequest(
downloadStrategy,
fileType,
queueType,
requestMethod,
true,
context,
callbacks);
Expand All @@ -164,6 +175,7 @@ public CacheRequest(
@NonNull final DownloadStrategy downloadStrategy,
final int fileType,
final DownloadQueueType queueType,
final RequestMethod requestMethod,
@Nullable final HTTPRequestBody requestBody,
@NonNull final Context context,
@NonNull final CacheRequestCallbacks callbacks) {
Expand All @@ -176,6 +188,7 @@ public CacheRequest(
downloadStrategy,
fileType,
queueType,
requestMethod,
requestBody,
false,
context,
Expand All @@ -191,6 +204,7 @@ private CacheRequest(
@NonNull final DownloadStrategy downloadStrategy,
final int fileType,
final DownloadQueueType queueType,
final RequestMethod requestMethod,
@Nullable final HTTPRequestBody requestBody,
final boolean cache,
@NonNull final Context context,
Expand All @@ -216,6 +230,7 @@ private CacheRequest(
this.downloadStrategy = downloadStrategy;
this.fileType = fileType;
this.queueType = queueType;
this.requestMethod = requestMethod;
this.requestBody = Optional.ofNullable(requestBody);
this.cache = (requestBody == null) && cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static final class Reddit {
public static final String PATH_MULTIREDDITS_MINE = "/api/multi/mine.json";
public static final String PATH_COMMENTS = "/comments/";
public static final String PATH_ME = "/api/v1/me";
public static final String PATH_MULTIREDDIT = "/api/multi";

public static String getScheme() {
return SCHEME_HTTPS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ private static void internalDownloadImageToSaveAudio(
DownloadStrategyIfNotCached.INSTANCE,
Constants.FileType.IMAGE,
CacheRequest.DownloadQueueType.IMMEDIATE,
CacheRequest.RequestMethod.GET,
activity,
new CacheRequestCallbacks() {

Expand Down Expand Up @@ -604,6 +605,7 @@ public void onSuccess(final ImageInfo info) {
DownloadStrategyIfNotCached.INSTANCE,
Constants.FileType.IMAGE,
CacheRequest.DownloadQueueType.IMMEDIATE,
CacheRequest.RequestMethod.GET,
activity,
new CacheRequestCallbacks() {
@Override
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/quantumbadger/redreader/common/General.kt
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,15 @@ object General {
if(status == 404) {
title = R.string.error_404_title
message = R.string.error_404_message
} else {
} else if (status == 403) {
title = R.string.error_403_title
message = R.string.error_403_message
} else if (status == 401) {
title = R.string.error_401_title
message = R.string.error_401_message
} else {
title = R.string.error_400_title
message = R.string.error_400_message
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/quantumbadger/redreader/common/PrefsUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.quantumbadger.redreader.reddit.PostSort;
import org.quantumbadger.redreader.reddit.UserCommentSort;
import org.quantumbadger.redreader.reddit.api.RedditAPICommentAction;
import org.quantumbadger.redreader.reddit.api.RedditAPIMultiredditAction;
import org.quantumbadger.redreader.reddit.api.RedditPostActions;
import org.quantumbadger.redreader.reddit.things.InvalidSubredditNameException;
import org.quantumbadger.redreader.reddit.things.SubredditCanonicalId;
Expand Down Expand Up @@ -1789,6 +1790,24 @@ public static String pref_reddit_client_id_override() {
return valueTrimmed;
}

public static EnumSet<RedditAPIMultiredditAction.MultiredditAction>
pref_menus_multireddit_context_items() {
final Set<String> strings = getStringSet(
R.string.pref_menus_multireddits_context_items_key,
R.array.pref_menus_multireddits_context_items_return);

final EnumSet<RedditAPIMultiredditAction.MultiredditAction> result
= EnumSet.noneOf(
RedditAPIMultiredditAction.MultiredditAction.class);

for(final String s : strings) {
result.add(RedditAPIMultiredditAction.MultiredditAction.valueOf(
StringUtils.asciiUppercase(s)));
}

return result;
}

private static final String REDDIT_USER_AGREEMENT_PREF = "accepted_reddit_user_agreement";
private static final int REDDIT_USER_AGREEMENT_DECLINED = -1;
private static final int REDDIT_USER_AGREEMENT_APRIL_2023 = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ private fun <T> fetchFile(
downloadStrategy,
fileType,
queueType,
CacheRequest.RequestMethod.GET,
cache,
context,
object : CacheRequestCallbacks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.quantumbadger.redreader.reddit.PostSort;
import org.quantumbadger.redreader.reddit.RedditPostListItem;
import org.quantumbadger.redreader.reddit.RedditSubredditManager;
import org.quantumbadger.redreader.reddit.api.RedditAPIMultiredditAction;
import org.quantumbadger.redreader.reddit.api.RedditSubredditSubscriptionManager;
import org.quantumbadger.redreader.reddit.kthings.JsonUtils;
import org.quantumbadger.redreader.reddit.kthings.MaybeParseError;
Expand Down Expand Up @@ -275,11 +276,18 @@ public void onScrolled(
break;

case RedditURLParser.USER_POST_LISTING_URL:
case RedditURLParser.MULTIREDDIT_POST_LISTING_URL:
setHeader(
mPostListingURL.humanReadableName(getActivity(), true),
mPostListingURL.humanReadableUrl(),
null);
CacheManager.getInstance(context).makeRequest(mRequest);
break;

case RedditURLParser.MULTIREDDIT_POST_LISTING_URL:
setMultiredditHeader(
mPostListingURL.humanReadableName(getActivity(), true),
mPostListingURL.humanReadableUrl(),
null);
mPostListingURL.asMultiredditPostListURL().name);
CacheManager.getInstance(context).makeRequest(mRequest);
break;

Expand Down Expand Up @@ -464,6 +472,28 @@ private void onSubredditReceived() {

}

private void setMultiredditHeader(
@NonNull final String title,
@NonNull final String subtitle,
@NonNull final String multiredditName) {

final PostListingHeader postListingHeader = new PostListingHeader(
getActivity(),
title,
subtitle,
mPostListingURL,
null);

setHeader(postListingHeader);

postListingHeader.setOnLongClickListener(view -> {
RedditAPIMultiredditAction.showActionMenu(
getActivity(),
multiredditName);
return true;
});
}

private void setHeader(
@NonNull final String title,
@NonNull final String subtitle,
Expand Down Expand Up @@ -665,6 +695,7 @@ private CacheRequest createPostListingRequest(
downloadStrategy,
Constants.FileType.POST_LIST,
CacheRequest.DownloadQueueType.REDDIT_API,
CacheRequest.RequestMethod.GET,
activity,
new CacheRequestCallbacks() {
@Override
Expand Down Expand Up @@ -1018,6 +1049,7 @@ private void precacheComments(
TimestampBound.notOlderThan(TimeDuration.minutes(15))),
Constants.FileType.COMMENT_LIST,
CacheRequest.DownloadQueueType.REDDIT_API,
CacheRequest.RequestMethod.GET,
// Don't parse the JSON
activity,
new CacheRequestCallbacks() {
Expand Down Expand Up @@ -1133,6 +1165,7 @@ private void precacheImage(
DownloadStrategyIfNotCached.INSTANCE,
Constants.FileType.IMAGE,
CacheRequest.DownloadQueueType.IMAGE_PRECACHE,
CacheRequest.RequestMethod.GET,
activity,
new CacheRequestCallbacks() {
@Override
Expand Down
Loading