<commit_before>package org.wikipedia.views

import android.content.Context
import android.net.Uri
import android.util.AttributeSet
import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.view_message_card.view.*
import org.wikipedia.Constants
import org.wikipedia.R
import org.wikipedia.analytics.LoginFunnel.SOURCE_SUGGESTED_EDITS
import org.wikipedia.login.LoginActivity
import org.wikipedia.util.StringUtil
import org.wikipedia.util.UriUtil

internal class MessageCardView constructor(context: Context, attrs: AttributeSet? = null) : WikiCardView(context, attrs) {

    init {
        View.inflate(context, R.layout.view_message_card, this)
    }

    fun setMessageTitle(title: String) {
        messageTitleView.text = title
    }

    fun setMessageText(text: String) {
        messageTextView.text = text
    }

    fun setImageResource(@DrawableRes imageResource: Int, visible: Boolean) {
        if (visible) {
            imageView.visibility = View.VISIBLE
            imageView.setImageResource(imageResource)
        } else {
            imageView.visibility = View.GONE
        }
    }

    fun setPositiveButton(@StringRes stringRes: Int, listener: OnClickListener, applyListenerToContainer: Boolean) {
        positiveButton.text = context.getString(stringRes)
        positiveButton.setOnClickListener(listener)
        if (applyListenerToContainer) {
            containerClickArea.setOnClickListener(listener)
        }
    }

    fun setNegativeButton(@StringRes stringRes: Int, listener: OnClickListener, applyListenerToContainer: Boolean) {
        negativeButton.text = context.getString(stringRes)
        negativeButton.setOnClickListener(listener)
        negativeButton.visibility = View.VISIBLE
        if (applyListenerToContainer) {
            containerClickArea.setOnClickListener(listener)
        }
    }

    fun setPaused(message: String) {
        setDefaultState()
        messageTitleView.text = context.getString(R.string.suggested_edits_paused_title)
        messageTextView.text = StringUtil.fromHtml(message)
        imageView.setImageResource(R.drawable.ic_suggested_edits_paused)
    }

    fun setDisabled(message: String) {
        setDefaultState()
        messageTitleView.text = context.getString(R.string.suggested_edits_disabled_title)
        messageTextView.text = StringUtil.fromHtml(message)
        imageView.setImageResource(R.drawable.ic_suggested_edits_disabled)
    }

    fun setIPBlocked() {
        setDefaultState()
        imageView.visibility = GONE
        messageTitleView.text = context.getString(R.string.suggested_edits_ip_blocked_title)
        messageTextView.text = context.getString(R.string.suggested_edits_ip_blocked_message)
        positiveButton.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.create_account_ip_block_help_url))) }
        setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.create_account_ip_block_help_url))) }
    }

    fun setRequiredLogin(fragment: Fragment) {
        imageView.visibility = View.VISIBLE
        messageTitleView.text = context.getString(R.string.suggested_edits_encourage_account_creation_title)
        messageTextView.text = context.getString(R.string.suggested_edits_encourage_account_creation_message)
        imageView.setImageResource(R.drawable.ic_require_login_header)
        positiveButton.text = context.getString(R.string.suggested_edits_encourage_account_creation_login_button)
        positiveButton.setOnClickListener { fragment.startActivityForResult(LoginActivity.newIntent(context, SOURCE_SUGGESTED_EDITS), Constants.ACTIVITY_REQUEST_LOGIN) }
        containerClickArea.setOnClickListener { fragment.startActivityForResult(LoginActivity.newIntent(context, SOURCE_SUGGESTED_EDITS), Constants.ACTIVITY_REQUEST_LOGIN) }
    }

    private fun setDefaultState() {
        imageView.visibility = View.VISIBLE
        positiveButton.text = context.getString(R.string.suggested_edits_learn_more)
        positiveButton.setIconResource(R.drawable.ic_open_in_new_black_24px)
        positiveButton.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.android_app_edit_help_url))) }
        containerClickArea.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.android_app_edit_help_url))) }
    }
}<commit_msg>Use view binding on MessageCardView (#2043)<commit_after>package org.wikipedia.views

import android.content.Context
import android.net.Uri
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import org.wikipedia.Constants
import org.wikipedia.R
import org.wikipedia.analytics.LoginFunnel.SOURCE_SUGGESTED_EDITS
import org.wikipedia.databinding.ViewMessageCardBinding
import org.wikipedia.login.LoginActivity
import org.wikipedia.util.StringUtil
import org.wikipedia.util.UriUtil

internal class MessageCardView constructor(context: Context, attrs: AttributeSet? = null) : WikiCardView(context, attrs) {

    val binding = ViewMessageCardBinding.inflate(LayoutInflater.from(context), this, true)

    fun setMessageTitle(title: String) {
        binding.messageTitleView.text = title
    }

    fun setMessageText(text: String) {
        binding.messageTextView.text = text
    }

    fun setImageResource(@DrawableRes imageResource: Int, visible: Boolean) {
        if (visible) {
            binding.imageView.visibility = View.VISIBLE
            binding.imageView.setImageResource(imageResource)
        } else {
            binding.imageView.visibility = View.GONE
        }
    }

    fun setPositiveButton(@StringRes stringRes: Int, listener: OnClickListener, applyListenerToContainer: Boolean) {
        binding.positiveButton.text = context.getString(stringRes)
        binding.positiveButton.setOnClickListener(listener)
        if (applyListenerToContainer) {
            binding.containerClickArea.setOnClickListener(listener)
        }
    }

    fun setNegativeButton(@StringRes stringRes: Int, listener: OnClickListener, applyListenerToContainer: Boolean) {
        binding.negativeButton.text = context.getString(stringRes)
        binding.negativeButton.setOnClickListener(listener)
        binding.negativeButton.visibility = View.VISIBLE
        if (applyListenerToContainer) {
            binding.containerClickArea.setOnClickListener(listener)
        }
    }

    fun setPaused(message: String) {
        setDefaultState()
        binding.messageTitleView.text = context.getString(R.string.suggested_edits_paused_title)
        binding.messageTextView.text = StringUtil.fromHtml(message)
        binding.imageView.setImageResource(R.drawable.ic_suggested_edits_paused)
    }

    fun setDisabled(message: String) {
        setDefaultState()
        binding.messageTitleView.text = context.getString(R.string.suggested_edits_disabled_title)
        binding.messageTextView.text = StringUtil.fromHtml(message)
        binding.imageView.setImageResource(R.drawable.ic_suggested_edits_disabled)
    }

    fun setIPBlocked() {
        setDefaultState()
        binding.imageView.visibility = GONE
        binding.messageTitleView.text = context.getString(R.string.suggested_edits_ip_blocked_title)
        binding.messageTextView.text = context.getString(R.string.suggested_edits_ip_blocked_message)
        binding.positiveButton.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.create_account_ip_block_help_url))) }
        setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.create_account_ip_block_help_url))) }
    }

    fun setRequiredLogin(fragment: Fragment) {
        binding.imageView.visibility = View.VISIBLE
        binding.messageTitleView.text = context.getString(R.string.suggested_edits_encourage_account_creation_title)
        binding.messageTextView.text = context.getString(R.string.suggested_edits_encourage_account_creation_message)
        binding.imageView.setImageResource(R.drawable.ic_require_login_header)
        binding.positiveButton.text = context.getString(R.string.suggested_edits_encourage_account_creation_login_button)
        binding.positiveButton.setOnClickListener { fragment.startActivityForResult(LoginActivity.newIntent(context, SOURCE_SUGGESTED_EDITS), Constants.ACTIVITY_REQUEST_LOGIN) }
        binding.containerClickArea.setOnClickListener { fragment.startActivityForResult(LoginActivity.newIntent(context, SOURCE_SUGGESTED_EDITS), Constants.ACTIVITY_REQUEST_LOGIN) }
    }

    private fun setDefaultState() {
        binding.imageView.visibility = View.VISIBLE
        binding.positiveButton.text = context.getString(R.string.suggested_edits_learn_more)
        binding.positiveButton.setIconResource(R.drawable.ic_open_in_new_black_24px)
        binding.positiveButton.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.android_app_edit_help_url))) }
        binding.containerClickArea.setOnClickListener { UriUtil.visitInExternalBrowser(context, Uri.parse(context.getString(R.string.android_app_edit_help_url))) }
    }
}
{'fraction_non_alphanumeric': 0.08040254237288136, 'fraction_numerical': 0.000847457627118644, 'mean_word_length': 4.382554161915621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3398546', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2551, 'n_words': 338}