Search in sources :

Example 1 with FeedConfigureFunnel

use of org.wikipedia.analytics.FeedConfigureFunnel in project apps-android-wikipedia by wikimedia.

the class ConfigureFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_feed_configure, container, false);
    unbinder = ButterKnife.bind(this, view);
    setupRecyclerView();
    funnel = new FeedConfigureFunnel(WikipediaApp.getInstance(), WikipediaApp.getInstance().getWikiSite(), requireActivity().getIntent().getIntExtra(ConfigureActivity.INVOKE_SOURCE_EXTRA, -1));
    new FeedAvailabilityClient().request(new FeedAvailabilityClient.Callback() {

        @Override
        public void success(@NonNull Call<FeedAvailabilityClient.FeedAvailability> call, @NonNull FeedAvailabilityClient.FeedAvailability result) {
            if (!isAdded()) {
                return;
            }
            // apply the new availability rules to our content types
            FeedContentType.NEWS.getLangCodesSupported().clear();
            if (isLimitedToDomains(result.news())) {
                addDomainNamesAsLangCodes(FeedContentType.NEWS.getLangCodesSupported(), result.news());
            }
            FeedContentType.ON_THIS_DAY.getLangCodesSupported().clear();
            if (isLimitedToDomains(result.onThisDay())) {
                addDomainNamesAsLangCodes(FeedContentType.ON_THIS_DAY.getLangCodesSupported(), result.onThisDay());
            }
            FeedContentType.TRENDING_ARTICLES.getLangCodesSupported().clear();
            if (isLimitedToDomains(result.mostRead())) {
                addDomainNamesAsLangCodes(FeedContentType.TRENDING_ARTICLES.getLangCodesSupported(), result.mostRead());
            }
            FeedContentType.FEATURED_ARTICLE.getLangCodesSupported().clear();
            if (isLimitedToDomains(result.featuredArticle())) {
                addDomainNamesAsLangCodes(FeedContentType.FEATURED_ARTICLE.getLangCodesSupported(), result.featuredArticle());
            }
            FeedContentType.FEATURED_IMAGE.getLangCodesSupported().clear();
            if (isLimitedToDomains(result.featuredPicture())) {
                addDomainNamesAsLangCodes(FeedContentType.FEATURED_IMAGE.getLangCodesSupported(), result.featuredPicture());
            }
            FeedContentType.saveState();
            prepareContentTypeList();
        }

        @Override
        public void failure(@NonNull Call<FeedAvailabilityClient.FeedAvailability> call, @NonNull Throwable caught) {
            if (!isAdded()) {
                return;
            }
            prepareContentTypeList();
        }

        private boolean isLimitedToDomains(@NonNull List<String> domainNames) {
            return !domainNames.isEmpty() && !domainNames.get(0).contains("*");
        }

        private void addDomainNamesAsLangCodes(@NonNull List<String> outList, @NonNull List<String> domainNames) {
            for (String domainName : domainNames) {
                outList.add(new WikiSite(domainName).languageCode());
            }
        }
    });
    return view;
}
Also used : BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FeedConfigureFunnel(org.wikipedia.analytics.FeedConfigureFunnel) WikiSite(org.wikipedia.dataclient.WikiSite)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 FeedConfigureFunnel (org.wikipedia.analytics.FeedConfigureFunnel)1 WikiSite (org.wikipedia.dataclient.WikiSite)1