Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/297101
Change subject: Remove Feed "MostReadClient" ...................................................................... Remove Feed "MostReadClient" Most read cards are available in the aggregated feed. Remove MostReadClient and use the aggregated results instead. Change-Id: I11dafa803500ff45c9dd38229e74efdf51fbbe72 --- M app/src/main/java/org/wikipedia/feed/FeedCoordinator.java M app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContent.java M app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.java D app/src/main/java/org/wikipedia/feed/mostread/MostReadClient.java D app/src/test/java/org/wikipedia/feed/mostread/MostReadClientTest.java 5 files changed, 14 insertions(+), 184 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/01/297101/1 diff --git a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java index 6690b0d..3fc11be 100644 --- a/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java +++ b/app/src/main/java/org/wikipedia/feed/FeedCoordinator.java @@ -7,7 +7,6 @@ import org.wikipedia.feed.becauseyouread.BecauseYouReadClient; import org.wikipedia.feed.continuereading.ContinueReadingClient; import org.wikipedia.feed.mainpage.MainPageClient; -import org.wikipedia.feed.mostread.MostReadClient; import org.wikipedia.feed.random.RandomClient; import org.wikipedia.feed.searchbar.SearchClient; @@ -28,7 +27,6 @@ addPendingClient(new BecauseYouReadClient()); addPendingClient(new ContinueReadingClient()); addPendingClient(new AggregatedFeedContentClient()); - addPendingClient(new MostReadClient()); addPendingClient(new RandomClient()); addPendingClient(new MainPageClient()); diff --git a/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContent.java b/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContent.java index 924838d..40790f5 100644 --- a/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContent.java +++ b/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContent.java @@ -2,7 +2,10 @@ import android.support.annotation.Nullable; +import com.google.gson.annotations.SerializedName; + import org.wikipedia.feed.model.CardPageItem; +import org.wikipedia.feed.mostread.MostReadArticles; import org.wikipedia.feed.news.NewsItem; import java.util.List; @@ -11,6 +14,7 @@ @SuppressWarnings("unused") @Nullable private CardPageItem tfa; @SuppressWarnings("unused") @Nullable private List<NewsItem> news; @SuppressWarnings("unused") @Nullable private CardPageItem random; + @SuppressWarnings("unused") @SerializedName("mostread") @Nullable private MostReadArticles mostRead; @Nullable public CardPageItem tfa() { @@ -21,4 +25,9 @@ public List<NewsItem> news() { return news; } -} + + @Nullable + public MostReadArticles mostRead() { + return mostRead; + } +} \ No newline at end of file diff --git a/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.java b/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.java index 007a5ac..321840c 100644 --- a/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.java +++ b/app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.java @@ -10,6 +10,7 @@ import org.wikipedia.feed.FeedClient; import org.wikipedia.feed.featured.FeaturedArticleCard; import org.wikipedia.feed.model.Card; +import org.wikipedia.feed.mostread.MostReadListCard; import org.wikipedia.feed.news.NewsListCard; import org.wikipedia.settings.Prefs; import org.wikipedia.util.DateUtil; @@ -88,6 +89,9 @@ if (content.news() != null) { cards.add(new NewsListCard(content.news(), DATE, site)); } + if (content.mostRead() != null) { + cards.add(new MostReadListCard(content.mostRead(), site)); + } cb.success(cards); } else { L.v(response.message()); diff --git a/app/src/main/java/org/wikipedia/feed/mostread/MostReadClient.java b/app/src/main/java/org/wikipedia/feed/mostread/MostReadClient.java deleted file mode 100644 index dcf05b1..0000000 --- a/app/src/main/java/org/wikipedia/feed/mostread/MostReadClient.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.wikipedia.feed.mostread; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; - -import org.apache.commons.lang3.StringUtils; -import org.wikipedia.Site; -import org.wikipedia.dataclient.retrofit.RbCachedService; -import org.wikipedia.feed.FeedClient; -import org.wikipedia.feed.model.Card; -import org.wikipedia.util.log.L; - -import java.io.IOException; -import java.util.Calendar; -import java.util.Collections; -import java.util.List; -import java.util.TimeZone; - -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.http.GET; -import retrofit2.http.Path; - -public class MostReadClient implements FeedClient { - @NonNull private final RbCachedService<Service> cachedService = new RbCachedService<>(Service.class); - @Nullable private Call<MostReadArticles> call; - - @Override public void request(@NonNull Context context, @NonNull Site site, int age, - @NonNull Callback cb) { - cancel(); - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - - time.add(Calendar.DAY_OF_MONTH, -(age + 1)); - - call = request(cachedService.service(site), site, time, cb); - } - - // Only handles last request made. - @Override public void cancel() { - if (call != null) { - call.cancel(); - call = null; - } - } - - @VisibleForTesting Call<MostReadArticles> request(@NonNull Service service, @NonNull Site site, - @NonNull Calendar date, - @NonNull Callback cb) { - int year = date.get(Calendar.YEAR); - String month = leftPad(date.get(Calendar.MONTH) + 1); - String day = leftPad(date.get(Calendar.DAY_OF_MONTH)); - @SuppressWarnings("checkstyle:hiddenfield") Call<MostReadArticles> call = service.get(year, month, day); - call.enqueue(new CallbackAdapter(cb, site)); - return call; - } - - @NonNull private String leftPad(int x) { - return StringUtils.leftPad(String.valueOf(x), 2, "0"); - } - - @VisibleForTesting interface Service { - @GET("page/most-read/{year}/{month}/{day}") - @NonNull Call<MostReadArticles> get(@Path("year") int year, - @Path("month") @NonNull String month, - @Path("day") @NonNull String day); - } - - private static class CallbackAdapter implements retrofit2.Callback<MostReadArticles> { - @NonNull private final Callback cb; - @NonNull private final Site site; - - CallbackAdapter(@NonNull Callback cb, @NonNull Site site) { - this.cb = cb; - this.site = site; - } - - @Override public void onResponse(Call<MostReadArticles> call, - Response<MostReadArticles> response) { - if (response.isSuccessful()) { - MostReadArticles result = response.body(); - List<? extends Card> cards = Collections.singletonList(new MostReadListCard(result, site)); - cb.success(cards); - } else { - L.v(response.message()); - cb.error(new IOException(response.message())); - } - } - - @Override public void onFailure(Call<MostReadArticles> call, Throwable t) { - L.v(t); - cb.error(t); - } - } -} diff --git a/app/src/test/java/org/wikipedia/feed/mostread/MostReadClientTest.java b/app/src/test/java/org/wikipedia/feed/mostread/MostReadClientTest.java deleted file mode 100644 index 9720751..0000000 --- a/app/src/test/java/org/wikipedia/feed/mostread/MostReadClientTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.wikipedia.feed.mostread; - -import android.support.annotation.NonNull; - -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.wikipedia.Site; -import org.wikipedia.feed.FeedClient.Callback; -import org.wikipedia.feed.model.Card; -import org.wikipedia.feed.mostread.MostReadClient.Service; -import org.wikipedia.test.MockWebServerTest; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.TimeZone; - -import okhttp3.mockwebserver.RecordedRequest; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -@SuppressWarnings("checkstyle:magicnumber") -public class MostReadClientTest extends MockWebServerTest { - @NonNull private final MostReadClient subject = new MostReadClient(); - @NonNull private final Site site = new Site("en.wikipedia.org"); - - @Test public void testRequestSuccess() throws Throwable { - enqueueFromFile("most_read.json"); - - Service service = service(Service.class); - Calendar date = calendar(2016, Calendar.JUNE, 1); - Callback cb = mock(Callback.class); - subject.request(service, site, date, cb); - - RecordedRequest req = server().takeRequest(); - assertRequestIssued(req, "2016/06/01"); - - assertCallbackSuccess(cb, date); - } - - @Test public void testRequestFailure() throws Throwable { - enqueue404(); - - Service service = service(Service.class); - Calendar date = calendar(2016, Calendar.JUNE, 1); - Callback cb = mock(Callback.class); - subject.request(service, site, date, cb); - - RecordedRequest req = server().takeRequest(); - assertRequestIssued(req, "2016/06/01"); - - verify(cb, never()).success(anyListOf(Card.class)); - } - - private void assertRequestIssued(@NonNull RecordedRequest req, @NonNull String date) { - assertThat(req.getPath(), endsWith(date)); - } - - private void assertCallbackSuccess(@NonNull Callback cb, @NonNull Calendar date) { - @SuppressWarnings({"unchecked", "rawtypes"}) - ArgumentCaptor<List<MostReadListCard>> captor = ArgumentCaptor.forClass((Class) List.class); - verify(cb).success(captor.capture()); - - List<MostReadListCard> rsp = captor.getValue(); - assertThat(rsp, notNullValue()); - assertThat(rsp.size(), greaterThan(0)); - assertThat(rsp.get(0).date(), is(date.getTime())); - } - - @NonNull private Calendar calendar(int year, int month, int day) throws Throwable { - TimeZone utc = TimeZone.getTimeZone("UTC"); - Calendar calendar = new GregorianCalendar(utc); - calendar.clear(); - calendar.set(year, month, day); - return calendar; - } -} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/297101 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I11dafa803500ff45c9dd38229e74efdf51fbbe72 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits