<commit_before>package ru.fantlab.android.ui.modules.award.overview

import android.content.Context
import android.os.Bundle
import android.support.annotation.StringRes
import android.view.View
import android.widget.ImageView
import butterknife.BindView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import ru.fantlab.android.R
import ru.fantlab.android.data.dao.model.Award
import ru.fantlab.android.helper.BundleConstant
import ru.fantlab.android.helper.Bundler
import ru.fantlab.android.helper.InputHelper
import ru.fantlab.android.provider.markdown.MarkDownProvider
import ru.fantlab.android.provider.scheme.LinkParserHelper
import ru.fantlab.android.ui.base.BaseFragment
import ru.fantlab.android.ui.modules.award.AwardPagerMvp
import ru.fantlab.android.ui.widgets.FontTextView
import ru.fantlab.android.ui.widgets.ForegroundImageView

class AwardOverviewFragment : BaseFragment<AwardOverviewMvp.View, AwardOverviewPresenter>(),
		AwardOverviewMvp.View {

	@BindView(R.id.progress) lateinit var progress: View
    @BindView(R.id.coverLayout) lateinit var coverLayout: ForegroundImageView
    @BindView(R.id.langIcon) lateinit var langLayout: ImageView
    @BindView(R.id.title) lateinit var title: FontTextView
    @BindView(R.id.title2) lateinit var title2: FontTextView
    @BindView(R.id.description) lateinit var description: FontTextView
    @BindView(R.id.comment) lateinit var comment: FontTextView
    @BindView(R.id.notes) lateinit var notes: FontTextView
    @BindView(R.id.country) lateinit var country: FontTextView
    @BindView(R.id.date) lateinit var date: FontTextView
    @BindView(R.id.homepage) lateinit var homepage: FontTextView

	private var award: Award? = null
	private var pagerCallback: AwardPagerMvp.View? = null

	override fun fragmentLayout() = R.layout.award_overview_layout

	override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
		if (savedInstanceState == null) {
			presenter.onFragmentCreated(arguments)
		} else {
			award = savedInstanceState.getParcelable("award")
			if (award != null) {
				onInitViews(award!!)
			} else {
				presenter.onFragmentCreated(arguments)
			}
		}
	}

	override fun providePresenter() = AwardOverviewPresenter()

	override fun onInitViews(award: Award) {
		hideProgress()
		if (award.isOpened == 0) {
			showErrorMessage(getString(R.string.award_not_opened))
			activity?.finish()
			return
		}
		pagerCallback?.onSetTitle(if (!InputHelper.isEmpty(award.rusname)) award.rusname else award.name)

		Glide.with(context)
				.load("https://${LinkParserHelper.HOST_DATA}/images/awards/${award.awardId}")
				.diskCacheStrategy(DiskCacheStrategy.ALL)
				.dontAnimate()
				.into(coverLayout)

		if (award.rusname.isBlank()) {
			title.text = award.name
			title2.visibility = View.GONE
		} else {
			title.text = award.rusname
			if (award.name.isBlank()) {
				title2.visibility = View.GONE
			} else title2.text = award.name
		}

				MarkDownProvider.setMdText(description, award.description
				.replace("[*]", "<li>")
				.replace("\\u003d".toRegex(), "=")<commit_msg>оригинальное название премии в заголовке<commit_after>package ru.fantlab.android.ui.modules.award.overview

import android.content.Context
import android.os.Bundle
import android.support.annotation.StringRes
import android.view.View
import android.widget.ImageView
import butterknife.BindView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import ru.fantlab.android.R
import ru.fantlab.android.data.dao.model.Award
import ru.fantlab.android.helper.BundleConstant
import ru.fantlab.android.helper.Bundler
import ru.fantlab.android.helper.InputHelper
import ru.fantlab.android.provider.markdown.MarkDownProvider
import ru.fantlab.android.provider.scheme.LinkParserHelper
import ru.fantlab.android.ui.base.BaseFragment
import ru.fantlab.android.ui.modules.award.AwardPagerMvp
import ru.fantlab.android.ui.widgets.FontTextView
import ru.fantlab.android.ui.widgets.ForegroundImageView

class AwardOverviewFragment : BaseFragment<AwardOverviewMvp.View, AwardOverviewPresenter>(),
		AwardOverviewMvp.View {

	@BindView(R.id.progress) lateinit var progress: View
    @BindView(R.id.coverLayout) lateinit var coverLayout: ForegroundImageView
    @BindView(R.id.langIcon) lateinit var langLayout: ImageView
    @BindView(R.id.title) lateinit var title: FontTextView
    @BindView(R.id.title2) lateinit var title2: FontTextView
    @BindView(R.id.description) lateinit var description: FontTextView
    @BindView(R.id.comment) lateinit var comment: FontTextView
    @BindView(R.id.notes) lateinit var notes: FontTextView
    @BindView(R.id.country) lateinit var country: FontTextView
    @BindView(R.id.date) lateinit var date: FontTextView
    @BindView(R.id.homepage) lateinit var homepage: FontTextView

	private var award: Award? = null
	private var pagerCallback: AwardPagerMvp.View? = null

	override fun fragmentLayout() = R.layout.award_overview_layout

	override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
		if (savedInstanceState == null) {
			presenter.onFragmentCreated(arguments)
		} else {
			award = savedInstanceState.getParcelable("award")
			if (award != null) {
				onInitViews(award!!)
			} else {
				presenter.onFragmentCreated(arguments)
			}
		}
	}

	override fun providePresenter() = AwardOverviewPresenter()

	override fun onInitViews(award: Award) {
		hideProgress()
		if (award.isOpened == 0) {
			showErrorMessage(getString(R.string.award_not_opened))
			activity?.finish()
			return
		}

		val awardLabel = if (!award.rusname.isEmpty()) {
			if (!award.name.isEmpty()) {
				String.format("%s / %s", award.rusname, award.name)
			} else {
				award.rusname
			}
		} else {
			award.name
		}

		pagerCallback?.onSetTitle(awardLabel)

		Glide.with(context)
				.load("https://${LinkParserHelper.HOST_DATA}/images/awards/${award.awardId}")
				.diskCacheStrategy(DiskCacheStrategy.ALL)
				.dontAnimate()
				.into(coverLayout)

		if (award.rusname.isBlank()) {
			title.text = award.name
			title2.visibility = View.GONE
		} else {
			title.text = award.rusname
			if (award.name.isBlank()) {
				title2.visibility = View.GONE
			} else title2.text = award.name
		}

				MarkDownProvider.setMdText(description, award.description
				.replace("[*]", "<li>")
				.replace("\\u003d".toRegex(), "=")
{'fraction_non_alphanumeric': 0.11288805268109126, 'fraction_numerical': 0.0028222013170272815, 'mean_word_length': 4.7416741674167415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3877370', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2042, 'n_words': 372}