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;
}
Aggregations