<commit_before>package org.stepic.droid.features.achievements.ui.adapters.holders

import android.net.Uri
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import kotlinx.android.synthetic.main.view_achievement_tile.view.*
import org.stepic.droid.features.achievements.ui.custom.AchievementCircleProgressView
import org.stepic.droid.features.achievements.ui.custom.VectorRatingBar
import org.stepic.droid.features.achievements.util.AchievementResourceResolver
import org.stepic.droid.model.achievements.AchievementFlatItem
import org.stepic.droid.ui.adapters.viewhoders.GenericViewHolder
import org.stepic.droid.ui.util.changeVisibility
import org.stepic.droid.util.AppConstants
import org.stepic.droid.util.svg.GlideSvgRequestFactory

class AchievementTileViewHolder(
        root: View,
        private val achievementResourceResolver: AchievementResourceResolver
): GenericViewHolder<AchievementFlatItem>(root) {
    private val achievementLevels: VectorRatingBar = root.achievementLevels
    private val achievementLevelProgress: AchievementCircleProgressView = root.achievementLevelProgress
    private val achievementIcon: ImageView = root.achievementIcon

    private val svgRequestBuilder = GlideSvgRequestFactory
            .create(itemView.context, null)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)

    private fun setAchievementIcon(path: String) {
        if (path.endsWith(AppConstants.SVG_EXTENSION)) {
            svgRequestBuilder
                    .load(Uri.parse(path))
                    .into(achievementIcon)
        } else {
            Glide.with(itemView.context)
                    .load(path)
                    .asBitmap()
                    .into(achievementIcon)
        }
    }

    override fun onBind(item: AchievementFlatItem) {
        achievementLevels.progress = item.currentLevel
        achievementLevels.total = item.maxLevel

        achievementLevelProgress.progress = item.currentScore.toFloat() / item.targetScore

        setAchievementIcon(achievementResourceResolver.resolveAchievementIcon(item, achievementIcon))

        val alpha = if (item.isLocked) 0.4f else 1f
        achievementIcon.alpha = alpha
        achievementLevelProgress.alpha = alpha

        achievementLevels.changeVisibility(!item.isLocked)
    }
}<commit_msg>glide image wrapper for adapters<commit_after>package org.stepic.droid.features.achievements.ui.adapters.holders

import android.view.View
import kotlinx.android.synthetic.main.view_achievement_tile.view.*
import org.stepic.droid.features.achievements.ui.custom.AchievementCircleProgressView
import org.stepic.droid.features.achievements.ui.custom.VectorRatingBar
import org.stepic.droid.features.achievements.util.AchievementResourceResolver
import org.stepic.droid.model.achievements.AchievementFlatItem
import org.stepic.droid.ui.adapters.viewhoders.GenericViewHolder
import org.stepic.droid.ui.util.changeVisibility
import org.stepic.droid.ui.util.wrapWithGlide

class AchievementTileViewHolder(
        root: View,
        private val achievementResourceResolver: AchievementResourceResolver
): GenericViewHolder<AchievementFlatItem>(root) {
    private val achievementLevels: VectorRatingBar = root.achievementLevels
    private val achievementLevelProgress: AchievementCircleProgressView = root.achievementLevelProgress
    private val achievementIcon = root.achievementIcon.wrapWithGlide()

    override fun onBind(item: AchievementFlatItem) {
        achievementLevels.progress = item.currentLevel
        achievementLevels.total = item.maxLevel

        achievementLevelProgress.progress = item.currentScore.toFloat() / item.targetScore

        achievementIcon.setImagePath(achievementResourceResolver.resolveAchievementIcon(item, achievementIcon.imageView))

        val alpha = if (item.isLocked) 0.4f else 1f
        achievementIcon.imageView.alpha = alpha
        achievementLevelProgress.alpha = alpha

        achievementLevels.changeVisibility(!item.isLocked)
    }
}
{'fraction_non_alphanumeric': 0.07552721922511035, 'fraction_numerical': 0.0014713094654242277, 'mean_word_length': 4.150252525252525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6208313', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1161, 'n_words': 172}