<commit_before>package org.wikipedia.bridge

import android.content.Context
import org.wikipedia.BuildConfig
import org.wikipedia.R
import org.wikipedia.WikipediaApp
import org.wikipedia.dataclient.RestService
import org.wikipedia.page.Namespace
import org.wikipedia.page.PageViewModel
import org.wikipedia.settings.Prefs
import org.wikipedia.util.L10nUtil
import org.wikipedia.util.L10nUtil.formatDateRelative

object JavaScriptActionHandler {
    @JvmStatic
    fun setHandler(): String {
        return "pcs.c1.InteractionHandling.setInteractionHandler((interaction) => { marshaller.onReceiveMessage(JSON.stringify(interaction))})"
    }

    @JvmStatic
    fun setTopMargin(top: Int): String {
        return String.format("pcs.c1.Page.setMargins({ top:'%dpx', right:'%dpx', bottom:'%dpx', left:'%dpx' })", top + 16, 16, 48, 16)
    }

    @JvmStatic
    fun setScrollTop(top: Int): String {
        return String.format("pcs.c1.Page.setScrollTop(%d)", top)
    }

    @JvmStatic
    fun getTextSelection(): String {
        return "pcs.c1.InteractionHandling.getSelectionInfo()"
    }

    @JvmStatic
    fun getOffsets(): String {
        return "pcs.c1.Sections.getOffsets(document.body);"
    }

    @JvmStatic
    fun setUp(topMargin: Int): String {
        val app: WikipediaApp = WikipediaApp.getInstance()
        return String.format("pcs.c1.Page.setup({" +
                "platform: pcs.c1.Platforms.ANDROID," +
                "clientVersion: '%s'," +
                "theme: pcs.c1.Themes.%s," +
                "dimImages: %b," +
                "margins: { top: '%dpx', right: '%dpx', bottom: '%dpx', left: '%dpx' }," +
                "areTablesInitiallyExpanded: %b," +
                "textSizeAdjustmentPercentage: '100%%'," +
                "loadImages: %b" +
                "})", BuildConfig.VERSION_NAME, app.currentTheme.funnelName.toUpperCase(),
                (app.currentTheme.isDark && Prefs.shouldDimDarkModeImages()),
                topMargin + 16, 16, 48, 16,
                !Prefs.isCollapseTablesEnabled(), Prefs.isImageDownloadEnabled())
    }

    @JvmStatic
    fun setUpEditButtons(isEditable: Boolean, isProtected: Boolean): String {
        return String.format("pcs.c1.Page.setEditButtons(%b, %b)", isEditable, isProtected)
    }

    @JvmStatic
    fun setFooter(context: Context, model: PageViewModel): String {
        if (model.page == null) {
            return ""
        }

        val languageCount = L10nUtil.getUpdatedLanguageCountIfNeeded(model.page!!.title.wikiSite.languageCode(),
                model.page!!.pageProperties.languageCount)
        val showLanguagesLink = languageCount > 0
        val showEditHistoryLink = !(model.page!!.isMainPage || model.page!!.isFilePage)
        val lastModifiedDate = formatDateRelative(model.page!!.pageProperties.lastModified)
        val showTalkLink = !(model.page!!.title.namespace() === Namespace.TALK)
        val showMapLink = model.page!!.pageProperties.geo != null

        // TODO: page-library also supports showing disambiguation ("similar pages") links and
        // "page issues". We should be mindful that they exist, even if we don't want them for now.

        return "pcs.c1.Footer.add({" +
                "platform: pcs.c1.Platforms.ANDROID," +
                "clientVersion: '" + BuildConfig.VERSION_NAME + "'," +
                "title: '${model.page?.displayTitle}'," +
                "menuItems: [" +
                (if (showLanguagesLink) "pcs.c1.Footer.MenuItemType.languages, " else "") +
                (if (showEditHistoryLink) "pcs.c1.Footer.MenuItemType.lastEdited, " else "") +
                (if (showTalkLink) "pcs.c1.Footer.MenuItemType.talkPage, " else "") +
                (if (showMapLink) "pcs.c1.Footer.MenuItemType.coordinate, " else "") +
                "pcs.c1.Footer.MenuItemType.referenceList " +
                "], l10n: {" +
                "        'readMoreHeading': '${context.getString(R.string.read_more_section)}'," +
                "        'menuDisambiguationTitle': '${context.getString(R.string.page_similar_titles)}'," +
                "        'menuLanguagesTitle': '${context.getString(R.string.language_count_link_text, languageCount)}'," +
                "        'menuHeading': '${context.getString(R.string.about_article_section)}'," +
                "        'menuLastEditedSubtitle': '${context.getString(R.string.edit_history_link_text)}'," +
                "        'menuLastEditedTitle': '${context.getString(R.string.last_updated_text, lastModifiedDate)}'," +
                "        'licenseString': '${context.getString(R.string.content_license_html)}'," +
                "        'menuTalkPageTitle': '${context.getString(R.string.talk_page_link_text)}'," +
                "        'viewInBrowserString': '${context.getString(R.string.page_view_in_browser)}'," +
                "        'licenseSubstitutionString': 'CC BY-SA 3.0'," +
                "        'menuCoordinateTitle': '${context.getString(R.string.map_view_link_text)}'," +
                "        'menuReferenceListTitle': '${context.getString(R.string.reference_list_title)}'" +
                "     }," +
                "readMore: { " +
                "    itemCount: 3," +
                "    baseURL: '${model.title?.wikiSite?.url() + RestService.REST_API_PREFIX}'" +
                "}" +
                "})"
    }
}
<commit_msg>Correct value to set collapse table<commit_after>package org.wikipedia.bridge

import android.content.Context
import org.wikipedia.BuildConfig
import org.wikipedia.R
import org.wikipedia.WikipediaApp
import org.wikipedia.dataclient.RestService
import org.wikipedia.page.Namespace
import org.wikipedia.page.PageViewModel
import org.wikipedia.settings.Prefs
import org.wikipedia.util.L10nUtil
import org.wikipedia.util.L10nUtil.formatDateRelative

object JavaScriptActionHandler {
    @JvmStatic
    fun setHandler(): String {
        return "pcs.c1.InteractionHandling.setInteractionHandler((interaction) => { marshaller.onReceiveMessage(JSON.stringify(interaction))})"
    }

    @JvmStatic
    fun setTopMargin(top: Int): String {
        return String.format("pcs.c1.Page.setMargins({ top:'%dpx', right:'%dpx', bottom:'%dpx', left:'%dpx' })", top + 16, 16, 48, 16)
    }

    @JvmStatic
    fun setScrollTop(top: Int): String {
        return String.format("pcs.c1.Page.setScrollTop(%d)", top)
    }

    @JvmStatic
    fun getTextSelection(): String {
        return "pcs.c1.InteractionHandling.getSelectionInfo()"
    }

    @JvmStatic
    fun getOffsets(): String {
        return "pcs.c1.Sections.getOffsets(document.body);"
    }

    @JvmStatic
    fun setUp(topMargin: Int): String {
        val app: WikipediaApp = WikipediaApp.getInstance()
        return String.format("pcs.c1.Page.setup({" +
                "platform: pcs.c1.Platforms.ANDROID," +
                "clientVersion: '%s'," +
                "theme: pcs.c1.Themes.%s," +
                "dimImages: %b," +
                "margins: { top: '%dpx', right: '%dpx', bottom: '%dpx', left: '%dpx' }," +
                "areTablesInitiallyExpanded: %b," +
                "textSizeAdjustmentPercentage: '100%%'," +
                "loadImages: %b" +
                "})", BuildConfig.VERSION_NAME, app.currentTheme.funnelName.toUpperCase(),
                (app.currentTheme.isDark && Prefs.shouldDimDarkModeImages()),
                topMargin + 16, 16, 48, 16,
                Prefs.isCollapseTablesEnabled(), Prefs.isImageDownloadEnabled())
    }

    @JvmStatic
    fun setUpEditButtons(isEditable: Boolean, isProtected: Boolean): String {
        return String.format("pcs.c1.Page.setEditButtons(%b, %b)", isEditable, isProtected)
    }

    @JvmStatic
    fun setFooter(context: Context, model: PageViewModel): String {
        if (model.page == null) {
            return ""
        }

        val languageCount = L10nUtil.getUpdatedLanguageCountIfNeeded(model.page!!.title.wikiSite.languageCode(),
                model.page!!.pageProperties.languageCount)
        val showLanguagesLink = languageCount > 0
        val showEditHistoryLink = !(model.page!!.isMainPage || model.page!!.isFilePage)
        val lastModifiedDate = formatDateRelative(model.page!!.pageProperties.lastModified)
        val showTalkLink = !(model.page!!.title.namespace() === Namespace.TALK)
        val showMapLink = model.page!!.pageProperties.geo != null

        // TODO: page-library also supports showing disambiguation ("similar pages") links and
        // "page issues". We should be mindful that they exist, even if we don't want them for now.

        return "pcs.c1.Footer.add({" +
                "platform: pcs.c1.Platforms.ANDROID," +
                "clientVersion: '" + BuildConfig.VERSION_NAME + "'," +
                "title: '${model.page?.displayTitle}'," +
                "menuItems: [" +
                (if (showLanguagesLink) "pcs.c1.Footer.MenuItemType.languages, " else "") +
                (if (showEditHistoryLink) "pcs.c1.Footer.MenuItemType.lastEdited, " else "") +
                (if (showTalkLink) "pcs.c1.Footer.MenuItemType.talkPage, " else "") +
                (if (showMapLink) "pcs.c1.Footer.MenuItemType.coordinate, " else "") +
                "pcs.c1.Footer.MenuItemType.referenceList " +
                "], l10n: {" +
                "        'readMoreHeading': '${context.getString(R.string.read_more_section)}'," +
                "        'menuDisambiguationTitle': '${context.getString(R.string.page_similar_titles)}'," +
                "        'menuLanguagesTitle': '${context.getString(R.string.language_count_link_text, languageCount)}'," +
                "        'menuHeading': '${context.getString(R.string.about_article_section)}'," +
                "        'menuLastEditedSubtitle': '${context.getString(R.string.edit_history_link_text)}'," +
                "        'menuLastEditedTitle': '${context.getString(R.string.last_updated_text, lastModifiedDate)}'," +
                "        'licenseString': '${context.getString(R.string.content_license_html)}'," +
                "        'menuTalkPageTitle': '${context.getString(R.string.talk_page_link_text)}'," +
                "        'viewInBrowserString': '${context.getString(R.string.page_view_in_browser)}'," +
                "        'licenseSubstitutionString': 'CC BY-SA 3.0'," +
                "        'menuCoordinateTitle': '${context.getString(R.string.map_view_link_text)}'," +
                "        'menuReferenceListTitle': '${context.getString(R.string.reference_list_title)}'" +
                "     }," +
                "readMore: { " +
                "    itemCount: 3," +
                "    baseURL: '${model.title?.wikiSite?.url() + RestService.REST_API_PREFIX}'" +
                "}" +
                "})"
    }
}

{'fraction_non_alphanumeric': 0.14111449958414193, 'fraction_numerical': 0.008686812679049995, 'mean_word_length': 2.4685897435897437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1792120', 'n_tokens_mistral': 3393, 'n_tokens_neox': 3202, 'n_words': 497}