<commit_before>package com.neeplayer

import android.databinding.BaseObservable
import android.databinding.BindingAdapter
import android.databinding.ObservableField
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import org.jetbrains.anko.imageBitmap
import java.util.concurrent.TimeUnit
import kotlin.reflect.KProperty

@BindingAdapter("bind:imagePath")
fun loadImageFile(view: ImageView, path: String?) {
    //loadImage(view, "file://" + path)
    path ?: return

    val sampleSize = calculateSampleSize(path, view.width, view.height)
    val tag = path + "#" + sampleSize.toString()

    if (tag.equals(view.tag)) {
        return
    }

    view.tag = tag
    val options = BitmapFactory.Options()
    options.inSampleSize = sampleSize
    view.imageBitmap = BitmapFactory.decodeFile(path, options)
}

// http://developer.android.com/intl/ru/training/displaying-bitmaps/load-bitmap.html
fun calculateSampleSize(path: String, reqWidth: Int, reqHeight: Int): Int {
    val options = BitmapFactory.Options()
    options.inJustDecodeBounds = true
    BitmapFactory.decodeFile(path, options)

    val height = options.outHeight
    val width = options.outWidth
    var sampleSize = 1

    if (height > reqHeight || width > reqWidth) {

        val halfHeight = height / 2
        val halfWidth = width / 2

        while ((halfHeight / sampleSize) > reqHeight && (halfWidth / sampleSize) > reqWidth) {
            sampleSize *= 2
        }
    }

    return sampleSize<commit_msg>Switch to Glide for loading local images<commit_after>package com.neeplayer

import android.databinding.BaseObservable
import android.databinding.BindingAdapter
import android.databinding.ObservableField
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import org.jetbrains.anko.imageBitmap
import java.util.concurrent.TimeUnit
import kotlin.reflect.KProperty

@BindingAdapter("bind:imagePath")
fun loadImageFile(view: ImageView, path: String?) {
    loadImage(view, "file://" + path)
    return
//    path ?: return
//
//    val sampleSize = calculateSampleSize(path, view.width, view.height)
//    val tag = path + "#" + sampleSize.toString()
//
//    if (tag.equals(view.tag)) {
//        return
//    }
//
//    view.tag = tag
//    val options = BitmapFactory.Options()
//    options.inSampleSize = sampleSize
//    view.imageBitmap = BitmapFactory.decodeFile(path, options)
}

// http://developer.android.com/intl/ru/training/displaying-bitmaps/load-bitmap.html
fun calculateSampleSize(path: String, reqWidth: Int, reqHeight: Int): Int {
    val options = BitmapFactory.Options()
    options.inJustDecodeBounds = true
    BitmapFactory.decodeFile(path, options)

    val height = options.outHeight
    val width = options.outWidth
    var sampleSize = 1

    if (height > reqHeight || width > reqWidth) {

        val halfHeight = height / 2
        val halfWidth = width / 2

        while ((halfHeight / sampleSize) > reqHeight && (halfWidth / sampleSize) > reqWidth) {
            sampleSize *= 2
        }
    }

    return sampleSize
{'fraction_non_alphanumeric': 0.10616229408175717, 'fraction_numerical': 0.0024405125076266015, 'mean_word_length': 3.4917808219178084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7312649', 'n_tokens_mistral': 973, 'n_tokens_neox': 931, 'n_words': 218}