Search in sources :

Example 26 with PageTitle

use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.

the class CompilationDetailFragment method onMainPageClick.

@OnClick(R.id.button_compilation_detail_main_page)
void onMainPageClick() {
    try {
        PageTitle title = new PageTitle(OfflineManager.instance().getMainPageTitle(compilation), WikipediaApp.getInstance().getWikiSite());
        HistoryEntry entry = new HistoryEntry(title, HistoryEntry.SOURCE_MAIN_PAGE);
        startActivity(PageActivity.newIntentForNewTab(getContext(), entry, entry.getTitle()));
    } catch (IOException e) {
        L.e(e);
        FeedbackUtil.showError(getActivity(), e);
    }
}
Also used : PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) IOException(java.io.IOException) OnClick(butterknife.OnClick)

Example 27 with PageTitle

use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.

the class EditPreviewFragment method displayPreview.

private void displayPreview(final String html) {
    if (!isWebViewSetup) {
        isWebViewSetup = true;
        L10nUtil.setupDirectionality(parentActivity.getPageTitle().getWikiSite().languageCode(), Locale.getDefault().getLanguage(), bridge);
        if (!WikipediaApp.getInstance().getCurrentTheme().isDefault()) {
            ThemeBridgeAdapter.setTheme(bridge);
        }
        bridge.addListener("linkClicked", new LinkHandler(getActivity()) {

            @Override
            public void onPageLinkClicked(@NonNull String href) {
            // TODO: also need to handle references, issues, disambig, ... in preview eventually
            }

            @Override
            public void onInternalLinkClicked(@NonNull final PageTitle title) {
                showLeavingEditDialogue(() -> startActivity(PageActivity.newIntentForNewTab(getContext(), new HistoryEntry(title, HistoryEntry.SOURCE_INTERNAL_LINK), title)));
            }

            @Override
            public void onExternalLinkClicked(@NonNull final Uri uri) {
                showLeavingEditDialogue(() -> handleExternalLink(getContext(), uri));
            }

            /**
             * Shows the user a dialogue asking them if they really meant to leave the edit
             * workflow, and warning them that their changes have not yet been saved.
             * @param runnable The runnable that is run if the user chooses to leave.
             */
            private void showLeavingEditDialogue(final Runnable runnable) {
                // Ask the user if they really meant to leave the edit workflow
                final AlertDialog leavingEditDialog = new AlertDialog.Builder(getActivity()).setMessage(R.string.dialog_message_leaving_edit).setPositiveButton(R.string.dialog_message_leaving_edit_leave, (dialog, which) -> {
                    // They meant to leave; close dialogue and run specified action
                    dialog.dismiss();
                    runnable.run();
                }).setNegativeButton(R.string.dialog_message_leaving_edit_stay, null).create();
                leavingEditDialog.show();
            }

            @Override
            public WikiSite getWikiSite() {
                return parentActivity.getPageTitle().getWikiSite();
            }
        });
        bridge.addListener("imageClicked", (messageType, messagePayload) -> {
        // TODO: do something when an image is clicked in Preview.
        });
        bridge.addListener("mediaClicked", (messageType, messagePayload) -> {
        // TODO: do something when a video is clicked in Preview.
        });
        bridge.addListener("referenceClicked", (messageType, messagePayload) -> {
        // TODO: do something when a reference is clicked in Preview.
        });
    }
    ViewAnimations.fadeIn(previewContainer, () -> parentActivity.supportInvalidateOptionsMenu());
    ViewAnimations.fadeOut(getActivity().findViewById(R.id.edit_section_container));
    JSONObject payload = new JSONObject();
    try {
        payload.put("html", html);
        payload.put("siteBaseUrl", parentActivity.getPageTitle().getWikiSite().url());
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    bridge.sendMessage("displayPreviewHTML", payload);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) ThemeBridgeAdapter(org.wikipedia.theme.ThemeBridgeAdapter) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull) PageActivity(org.wikipedia.page.PageActivity) UriUtil.handleExternalLink(org.wikipedia.util.UriUtil.handleExternalLink) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) ArrayList(java.util.ArrayList) L10nUtil(org.wikipedia.util.L10nUtil) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) AssetManager(android.content.res.AssetManager) Locale(java.util.Locale) WikipediaApp(org.wikipedia.WikipediaApp) View(android.view.View) DeviceUtil.hideSoftKeyboard(org.wikipedia.util.DeviceUtil.hideSoftKeyboard) LinkHandler(org.wikipedia.page.LinkHandler) EditSummaryTag(org.wikipedia.edit.summaries.EditSummaryTag) R(org.wikipedia.R) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) PageTitle(org.wikipedia.page.PageTitle) ProgressDialog(android.app.ProgressDialog) CommunicationBridge(org.wikipedia.bridge.CommunicationBridge) ViewAnimations(org.wikipedia.views.ViewAnimations) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) EditFunnel(org.wikipedia.analytics.EditFunnel) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) ConfigurationCompat(org.wikipedia.util.ConfigurationCompat) ScrollView(android.widget.ScrollView) Configuration(android.content.res.Configuration) L(org.wikipedia.util.log.L) EditSectionActivity(org.wikipedia.edit.EditSectionActivity) ObservableWebView(org.wikipedia.views.ObservableWebView) Call(retrofit2.Call) Resources(android.content.res.Resources) PageTitle(org.wikipedia.page.PageTitle) JSONException(org.json.JSONException) Uri(android.net.Uri) WikiSite(org.wikipedia.dataclient.WikiSite) JSONObject(org.json.JSONObject) HistoryEntry(org.wikipedia.history.HistoryEntry) LinkHandler(org.wikipedia.page.LinkHandler)

Example 28 with PageTitle

use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.

the class FeaturedArticleCardView method footer.

private void footer(@NonNull FeaturedArticleCard card) {
    PageTitle title = new PageTitle(card.articleTitle(), card.wikiSite());
    CallbackTask.execute(() -> ReadingListDbHelper.instance().findPageInAnyList(title), new CallbackTask.DefaultCallback<ReadingListPage>() {

        @Override
        public void success(ReadingListPage page) {
            boolean pageInList = page != null;
            int actionIcon = pageInList ? R.drawable.ic_bookmark_white_24dp : R.drawable.ic_bookmark_border_black_24dp;
            int actionText = pageInList ? R.string.view_featured_article_footer_saved_button_label : R.string.view_featured_article_footer_save_button_label;
            footerView.actionIcon(actionIcon).actionText(actionText).onActionListener(pageInList ? new CardBookmarkMenuListener() : new CardAddToListListener()).onShareListener(new CardShareListener());
            footerView.actionIconColor(ResourceUtil.getThemedAttributeId(getContext(), pageInList ? R.attr.colorAccent : R.attr.secondary_text_color));
            footerView.actionTextColor(ResourceUtil.getThemedAttributeId(getContext(), pageInList ? R.attr.colorAccent : R.attr.secondary_text_color));
        }
    });
}
Also used : CallbackTask(org.wikipedia.concurrency.CallbackTask) PageTitle(org.wikipedia.page.PageTitle) ReadingListPage(org.wikipedia.readinglist.database.ReadingListPage)

Example 29 with PageTitle

use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.

the class MainPageClient method getMainPageTitle.

@NonNull
public static PageTitle getMainPageTitle() {
    WikipediaApp app = WikipediaApp.getInstance();
    PageTitle title = new PageTitle(SiteInfoClient.getMainPageForLang(app.getAppOrSystemLanguageCode()), app.getWikiSite());
    if (OfflineManager.hasCompilation() && !DeviceUtil.isOnline()) {
        try {
            title = new PageTitle(OfflineManager.instance().getMainPageTitle(), app.getWikiSite());
        } catch (IOException e) {
            L.e(e);
        }
    }
    return title;
}
Also used : WikipediaApp(org.wikipedia.WikipediaApp) PageTitle(org.wikipedia.page.PageTitle) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Example 30 with PageTitle

use of org.wikipedia.page.PageTitle in project apps-android-wikipedia by wikimedia.

the class OnThisDayPagesViewHolder method onBaseViewClicked.

@OnClick(R.id.parent)
void onBaseViewClicked() {
    Context context = WikipediaApp.getInstance().getApplicationContext();
    PageTitle pageTitle = new PageTitle(selectedPage.getTitle(), wiki);
    HistoryEntry entry = new HistoryEntry(pageTitle, isSingleCard ? HistoryEntry.SOURCE_ON_THIS_DAY_CARD : HistoryEntry.SOURCE_ON_THIS_DAY_ACTIVITY);
    Intent intent = new Intent(ACTION_LOAD_IN_NEW_TAB).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setClass(context, PageActivity.class).putExtra(EXTRA_HISTORYENTRY, entry).putExtra(EXTRA_PAGETITLE, pageTitle);
    context.startActivity(intent);
}
Also used : Context(android.content.Context) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) Intent(android.content.Intent) OnClick(butterknife.OnClick)

Aggregations

PageTitle (org.wikipedia.page.PageTitle)60 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)15 WikiSite (org.wikipedia.dataclient.WikiSite)11 HistoryEntry (org.wikipedia.history.HistoryEntry)11 NonNull (android.support.annotation.NonNull)6 OnClick (butterknife.OnClick)5 ReadingListPage (org.wikipedia.readinglist.database.ReadingListPage)5 IOException (java.io.IOException)4 Date (java.util.Date)4 WikipediaApp (org.wikipedia.WikipediaApp)3 PageBackStackItem (org.wikipedia.page.PageBackStackItem)3 Tab (org.wikipedia.page.tabs.Tab)3 ProgressDialog (android.app.ProgressDialog)2 Intent (android.content.Intent)2 AssetManager (android.content.res.AssetManager)2 Configuration (android.content.res.Configuration)2 Resources (android.content.res.Resources)2 Bundle (android.os.Bundle)2 DisplayMetrics (android.util.DisplayMetrics)2