<commit_before>package io.github.droidkaigi.confsched2017.view.helper;

import com.squareup.picasso.Picasso;

import net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout;

import org.lucasr.twowayview.widget.SpannableGridLayoutManager;

import android.content.Context;
import android.content.res.ColorStateList;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.model.Topic;
import io.github.droidkaigi.confsched2017.view.customview.InfoRowView;
import io.github.droidkaigi.confsched2017.view.customview.SettingSwitchRowView;
import io.github.droidkaigi.confsched2017.view.customview.transformation.CropCircleTransformation;

public class DataBindingHelper {

    //--------------------------------------------------------------
    // Common
    //--------------------------------------------------------------
    @BindingAdapter("photoImageUrl")
    public static void setPhotoImageUrl(ImageView imageView, @Nullable String imageUrl) {
        setImageUrl(imageView, imageUrl, R.color.grey200);
    }

    private static void setImageUrl(ImageView imageView, @Nullable String imageUrl,
            @DrawableRes int placeholderResId) {
        if (TextUtils.isEmpty(imageUrl)) {
            imageView.setImageDrawable(
                    ContextCompat.getDrawable(imageView.getContext(), placeholderResId));
        } else {
            Picasso.with(imageView.getContext())
                    .load(imageUrl)
                    .placeholder(placeholderResId)
                    .error(placeholderResId)
                    .into(imageView);
        }
    }

    @BindingAdapter({"speakerImageUrl", "speakerImageSize"})
    public static void setSpeakerImageUrlWithSize(ImageView imageView, @Nullable String imageUrl, float sizeInDimen) {
        setImageUrlWithSize(imageView, imageUrl, sizeInDimen, R.drawable.ic_speaker_placeholder);
    }

    private static void setImageUrlWithSize(ImageView imageView, @Nullable String imageUrl, float sizeInDimen,
            int placeholderResId) {
        if (TextUtils.isEmpty(imageUrl)) {
            imageView.setImageDrawable(ContextCompat.getDrawable(imageView.getContext(), placeholderResId));
        } else {
            final int size = Math.round(sizeInDimen);
            imageView.setBackground(ContextCompat.getDrawable(imageView.getContext(), R.drawable.circle_border_grey200));
            Picasso.with(imageView.getContext())
                    .load(imageUrl)
                    .resize(size, size)
                    .centerInside()
                    .placeholder(placeholderResId)
                    .error(placeholderResId)
                    .transform(new CropCircleTransformation())
                    .into(imageView);
        }
    }

    @BindingAdapter("textLinkify")
    public static void setTextLinkify(TextView textView, boolean isLinkify) {
        if (isLinkify) {
            Linkify.addLinks(textView, Linkify.ALL);
        }
    }

    @BindingAdapter("webViewUrl")
    public static void loadUrl(WebView webView, String url) {
        if (TextUtils.isEmpty(url)) {
            return;
        }
        webView.loadUrl(url);
    }

    @BindingAdapter("webViewClient")
    public static void setWebViewClient(WebView webView, WebViewClient client) {
        webView.setWebViewClient(client);
    }

    //--------------------------------------------------------------
    // Settings
    //--------------------------------------------------------------
    @BindingAdapter("settingEnabled")
    public static void setSettingEnabled(SettingSwitchRowView view, boolean enabled) {<commit_msg>Fix #383<commit_after>package io.github.droidkaigi.confsched2017.view.helper;

import com.squareup.picasso.Picasso;

import net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout;

import org.lucasr.twowayview.widget.SpannableGridLayoutManager;

import android.content.Context;
import android.content.res.ColorStateList;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.model.Topic;
import io.github.droidkaigi.confsched2017.view.customview.InfoRowView;
import io.github.droidkaigi.confsched2017.view.customview.SettingSwitchRowView;
import io.github.droidkaigi.confsched2017.view.customview.transformation.CropCircleTransformation;

public class DataBindingHelper {

    //--------------------------------------------------------------
    // Common
    //--------------------------------------------------------------
    @BindingAdapter("photoImageUrl")
    public static void setPhotoImageUrl(ImageView imageView, @Nullable String imageUrl) {
        setImageUrl(imageView, imageUrl, R.color.grey200);
    }

    private static void setImageUrl(ImageView imageView, @Nullable String imageUrl,
            @DrawableRes int placeholderResId) {
        if (TextUtils.isEmpty(imageUrl)) {
            imageView.setImageDrawable(
                    ContextCompat.getDrawable(imageView.getContext(), placeholderResId));
        } else {
            Picasso.with(imageView.getContext())
                    .load(imageUrl)
                    .placeholder(placeholderResId)
                    .error(placeholderResId)
                    .into(imageView);
        }
    }

    @BindingAdapter({"speakerImageUrl", "speakerImageSize"})
    public static void setSpeakerImageUrlWithSize(ImageView imageView, @Nullable String imageUrl, float sizeInDimen) {
        setImageUrlWithSize(imageView, imageUrl, sizeInDimen, R.drawable.ic_speaker_placeholder);
    }

    private static void setImageUrlWithSize(ImageView imageView, @Nullable String imageUrl, float sizeInDimen,
            int placeholderResId) {
        if (TextUtils.isEmpty(imageUrl)) {
            imageView.setImageDrawable(ContextCompat.getDrawable(imageView.getContext(), placeholderResId));
        } else {
            final int size = Math.round(sizeInDimen);
            imageView.setBackground(ContextCompat.getDrawable(imageView.getContext(), R.drawable.circle_border_grey200));
            Picasso.with(imageView.getContext())
                    .load(convertToFullImageUrl(imageUrl))
                    .resize(size, size)
                    .centerInside()
                    .placeholder(placeholderResId)
                    .error(placeholderResId)
                    .transform(new CropCircleTransformation())
                    .into(imageView);
        }
    }

    private static String convertToFullImageUrl(String imageUrl) {
        if (imageUrl.startsWith("/")) {
            return "https://droidkaigi.github.io/2017" + imageUrl;
        }

        return imageUrl;
    }

    @BindingAdapter("textLinkify")
    public static void setTextLinkify(TextView textView, boolean isLinkify) {
        if (isLinkify) {
            Linkify.addLinks(textView, Linkify.ALL);
        }
    }

    @BindingAdapter("webViewUrl")
    public static void loadUrl(WebView webView, String url) {
        if (TextUtils.isEmpty(url)) {
            return;
        }
        webView.loadUrl(url);
    }

    @BindingAdapter("webViewClient")
    public static void setWebViewClient(WebView webView, WebViewClient client) {
        webView.setWebViewClient(client);
    }

    //--------------------------------------------------------------
    // Settings
    //--------------------------------------------------------------
    @BindingAdapter("settingEnabled")
    public static void setSettingEnabled(SettingSwitchRowView view, boolean enabled) {
{'fraction_non_alphanumeric': 0.14316604074200523, 'fraction_numerical': 0.008080118356663252, 'mean_word_length': 2.5521422797089732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '5741740', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2256, 'n_words': 379}