From 5cfe8a601645383d0068f9acded1e99aa5f28459 Mon Sep 17 00:00:00 2001 From: andrewrasch Date: Tue, 21 Sep 2021 23:01:17 -0400 Subject: Added API call for generic wiki page. Updated old wiki-only call to cascade to new generic. --- .../infinityforreddit/activities/WikiActivity.java | 1 + .../java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index f4cc17fa..b6fc29af 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -71,6 +71,7 @@ import retrofit2.Retrofit; public class WikiActivity extends BaseActivity { public static final String EXTRA_SUBREDDIT_NAME = "ESN"; + public static final String WIKI_PATH = "WP"; private static final String WIKI_MARKDOWN_STATE = "WMS"; @BindView(R.id.coordinator_layout_comment_wiki_activity) 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 91b96c70..a7c67893 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java @@ -294,8 +294,12 @@ public interface RedditAPI { @GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1") Call getTrendingSearches(@HeaderMap Map headers); - @GET("/r/{subredditName}/wiki/index.json?raw_json=1") - Call getWiki(@Path("subredditName") String subredditName); + default Call getWiki(@Path("subredditName") String subredditName) { + return getWikiPage(subredditName, "index"); + }; + + @GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1") + Call getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage); @GET("{sortType}?raw_json=1") ListenableFuture> getBestPostsListenableFuture(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map headers); -- cgit v1.2.3 From 2d5829830e062d5cef8ca3ffa55e7dab607b84a7 Mon Sep 17 00:00:00 2001 From: andrewrasch Date: Tue, 21 Sep 2021 23:50:30 -0400 Subject: Fixed handling of wiki pages LinkResolverActivity now handles wiki pages other than index and their subpages. --- .../infinityforreddit/activities/LinkResolverActivity.java | 4 +++- .../ml/docilealligator/infinityforreddit/activities/WikiActivity.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index a6596edb..a4668cc5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -49,7 +49,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?"; private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?"; private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?"; - private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)/?\\w+"; + private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)?(?:/\\w+)+"; @Inject @Named("default") @@ -173,8 +173,10 @@ public class LinkResolverActivity extends AppCompatActivity { deepLinkError(uri); } } else if (path.matches(WIKI_PATTERN)) { + final String wikiPage = path.substring(path.lastIndexOf("/wiki/") + 6); Intent intent = new Intent(this, WikiActivity.class); intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1)); + intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage); startActivity(intent); } else if (path.matches(SUBREDDIT_PATTERN)) { Intent intent = new Intent(this, ViewSubredditDetailActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index b6fc29af..372d3c6f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -71,7 +71,7 @@ import retrofit2.Retrofit; public class WikiActivity extends BaseActivity { public static final String EXTRA_SUBREDDIT_NAME = "ESN"; - public static final String WIKI_PATH = "WP"; + public static final String EXTRA_WIKI_PATH = "EWP"; private static final String WIKI_MARKDOWN_STATE = "WMS"; @BindView(R.id.coordinator_layout_comment_wiki_activity) @@ -282,7 +282,7 @@ public class WikiActivity extends BaseActivity { Glide.with(this).clear(mFetchWikiInfoImageView); mFetchWikiInfoLinearLayout.setVisibility(View.GONE); - retrofit.create(RedditAPI.class).getWiki(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME)).enqueue(new Callback() { + retrofit.create(RedditAPI.class).getWikiPage(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME), getIntent().getStringExtra(EXTRA_WIKI_PATH)).enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { -- cgit v1.2.3 From 0ca6bc25af02b52ce7b89b1c895a3d00e307d821 Mon Sep 17 00:00:00 2001 From: andrewrasch Date: Wed, 22 Sep 2021 00:04:21 -0400 Subject: Added link to wiki in subreddit Subreddit details menu now has a link to its wiki. Subs without a wiki will show the "this subreddit has no wiki" page. --- .../infinityforreddit/activities/ViewSubredditDetailActivity.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 4096a96b..11d19e16 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1180,6 +1180,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show(); } return true; + } else if (itemId == R.id.action_go_to_wiki_activity ) { + Intent wikiIntent = new Intent(this, WikiActivity.class); + wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, subredditName); + wikiIntent.putExtra(WikiActivity.EXTRA_WIKI_PATH, "index"); + startActivity(wikiIntent); + return true; } return false; } -- cgit v1.2.3