Search in sources :

Example 36 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikiSiteTypeAdapterTest method testReadLegacyUri.

@Test
public void testReadLegacyUri() {
    String json = "{\"domain\": \"test.wikipedia.org\", \"languageCode\": \"test\"}";
    WikiSite expected = WikiSite.forLanguageCode("test");
    assertThat(unmarshal(WikiSite.class, json), is(expected));
}
Also used : WikiSite(org.wikipedia.dataclient.WikiSite) Test(org.junit.Test)

Example 37 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class HistoryEntryDatabaseTable method fromCursor.

@Override
public HistoryEntry fromCursor(Cursor cursor) {
    WikiSite wiki = new WikiSite(Col.SITE.val(cursor), Col.LANG.val(cursor));
    PageTitle title = new PageTitle(Col.NAMESPACE.val(cursor), Col.TITLE.val(cursor), wiki);
    Date timestamp = Col.TIMESTAMP.val(cursor);
    int source = Col.SOURCE.val(cursor);
    return new HistoryEntry(title, timestamp, source);
}
Also used : PageTitle(org.wikipedia.page.PageTitle) WikiSite(org.wikipedia.dataclient.WikiSite) Date(java.util.Date)

Example 38 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class NewsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_news, container, false);
    unbinder = ButterKnife.bind(this, view);
    gradientView.setBackground(GradientUtil.getPowerGradient(R.color.black54, Gravity.TOP));
    getAppCompatActivity().setSupportActionBar(toolbar);
    getAppCompatActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getAppCompatActivity().getSupportActionBar().setTitle("");
    NewsItem item = GsonUnmarshaller.unmarshal(NewsItem.class, requireActivity().getIntent().getStringExtra(EXTRA_NEWS_ITEM));
    WikiSite wiki = GsonUnmarshaller.unmarshal(WikiSite.class, requireActivity().getIntent().getStringExtra(EXTRA_WIKI));
    Uri imageUri = item.featureImage();
    if (imageUri == null) {
        appBarLayout.setExpanded(false, false);
    }
    DeviceUtil.updateStatusBarTheme(requireActivity(), toolbar, true);
    appBarLayout.addOnOffsetChangedListener((layout, offset) -> DeviceUtil.updateStatusBarTheme(requireActivity(), toolbar, (layout.getTotalScrollRange() + offset) > layout.getTotalScrollRange() / 2));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        toolBarLayout.setStatusBarScrimColor(ResourceUtil.getThemedColor(requireContext(), R.attr.main_status_bar_color));
    }
    image.loadImage(imageUri);
    text.setText(stripHtml(item.story()));
    initRecycler();
    links.setAdapter(new RecyclerAdapter(item.linkCards(wiki), new Callback()));
    return view;
}
Also used : DefaultRecyclerAdapter(org.wikipedia.views.DefaultRecyclerAdapter) BindView(butterknife.BindView) View(android.view.View) FaceAndColorDetectImageView(org.wikipedia.views.FaceAndColorDetectImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ListCardItemView(org.wikipedia.feed.view.ListCardItemView) WikiSite(org.wikipedia.dataclient.WikiSite) Uri(android.net.Uri) Nullable(android.support.annotation.Nullable)

Example 39 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class BecauseYouReadClient method request.

@Override
public void request(@NonNull Context context, @NonNull final WikiSite wiki, int age, @NonNull final FeedClient.Callback cb) {
    cancel();
    disposables.add(Observable.fromCallable(new MainPageReadMoreTopicTask(age)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(entry -> getCardForHistoryEntry(entry, cb), throwable -> cb.success(Collections.emptyList())));
}
Also used : Context(android.content.Context) FeedClient(org.wikipedia.feed.dataclient.FeedClient) ServiceFactory(org.wikipedia.dataclient.ServiceFactory) MainPageReadMoreTopicTask(org.wikipedia.page.bottomcontent.MainPageReadMoreTopicTask) NonNull(android.support.annotation.NonNull) RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) ArrayList(java.util.ArrayList) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Constants(org.wikipedia.Constants) FeedCoordinator(org.wikipedia.feed.FeedCoordinator) Collections(java.util.Collections) MainPageReadMoreTopicTask(org.wikipedia.page.bottomcontent.MainPageReadMoreTopicTask)

Example 40 with WikiSite

use of org.wikipedia.dataclient.WikiSite in project apps-android-wikipedia by wikimedia.

the class WikipediaApp method getWikiSite.

/**
 * Default wiki for the app
 * You should use PageTitle.getWikiSite() to get the article wiki
 */
@NonNull
public synchronized WikiSite getWikiSite() {
    // TODO: why don't we ensure that the app language hasn't changed here instead of the client?
    if (wiki == null) {
        String lang = Prefs.getMediaWikiBaseUriSupportsLangCode() ? getAppOrSystemLanguageCode() : "";
        WikiSite newWiki = WikiSite.forLanguageCode(lang);
        // Kick off a task to retrieve the site info for the current wiki
        SiteInfoClient.updateFor(newWiki);
        wiki = newWiki;
        return newWiki;
    }
    return wiki;
}
Also used : StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) WikiSite(org.wikipedia.dataclient.WikiSite) NonNull(android.support.annotation.NonNull)

Aggregations

WikiSite (org.wikipedia.dataclient.WikiSite)46 Test (org.junit.Test)23 PageTitle (org.wikipedia.page.PageTitle)13 ArrayList (java.util.ArrayList)7 HistoryEntry (org.wikipedia.history.HistoryEntry)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 NonNull (android.support.annotation.NonNull)4 View (android.view.View)4 Date (java.util.Date)4 Uri (android.net.Uri)3 HashMap (java.util.HashMap)3 PageProperties (org.wikipedia.page.PageProperties)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 RecyclerView (android.support.v7.widget.RecyclerView)2 BindView (butterknife.BindView)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 Schedulers (io.reactivex.schedulers.Schedulers)2 JSONException (org.json.JSONException)2