<commit_before>package com.alexstyl.specialdates.upcoming.widget.list

import android.content.res.Resources
import android.support.annotation.Px
import android.widget.RemoteViews
import com.alexstyl.specialdates.R
import com.alexstyl.specialdates.upcoming.UpcomingContactEventViewModel


internal class ContactEventBinder(private val remoteViews: RemoteViews,
                                  private val resources: Resources,
                                  private val avatarFactory: CircularAvatarFactory)
    : UpcomingEventViewBinder<UpcomingContactEventViewModel> {

    override fun bind(viewModel: UpcomingContactEventViewModel) {
        remoteViews.setTextViewText(R.id.row_upcoming_event_contact_name, viewModel.contactName)
        remoteViews.setTextViewText(R.id.row_upcoming_event_contact_event, viewModel.eventLabel)
        @Px val targetSize = resources.getDimensionPixelSize(R.dimen.widget_upcoming_avatar_size)
        val avatar = avatarFactory.circularAvatarFor(viewModel.contact, targetSize)
        if (avatar.isPresent) {
            remoteViews.setImageViewBitmap(R.id.row_upcoming_event_contact_image, avatar.get())
        }
    }

    override fun getViews(): RemoteViews = remoteViews
}<commit_msg>Create a circle avatar if a contact has none<commit_after>package com.alexstyl.specialdates.upcoming.widget.list

import android.content.res.Resources
import android.graphics.Bitmap
import android.support.annotation.Px
import android.widget.RemoteViews
import com.alexstyl.specialdates.R
import com.alexstyl.specialdates.contact.Contact
import com.alexstyl.specialdates.upcoming.UpcomingContactEventViewModel


internal class ContactEventBinder(private val remoteViews: RemoteViews,
                                  private val resources: Resources,
                                  private val avatarFactory: CircularAvatarFactory)
    : UpcomingEventViewBinder<UpcomingContactEventViewModel> {

    override fun bind(viewModel: UpcomingContactEventViewModel) {
        remoteViews.setTextViewText(R.id.row_upcoming_event_contact_name, viewModel.contactName)
        remoteViews.setTextViewText(R.id.row_upcoming_event_contact_event, viewModel.eventLabel)
        remoteViews.setTextColor(R.id.row_upcoming_event_contact_event, viewModel.eventColor)

        val avatar = createAvatarFor(viewModel.contact)
        remoteViews.setImageViewBitmap(R.id.row_upcoming_event_contact_image, avatar)
    }

    private fun createAvatarFor(contact: Contact): Bitmap {
        @Px val targetSize = resources.getDimensionPixelSize(R.dimen.widget_upcoming_avatar_size)
        val avatar = avatarFactory.circularAvatarFor(contact, targetSize)
        return if (avatar.isPresent) {
            avatar.get()
        } else {
            val textSize = resources.getDimensionPixelSize(R.dimen.widget_upcoming_avatar_text_size)
            avatarFactory.createLetterAvatarFor(contact.displayName, targetSize, textSize)
        }
    }

    override fun getViews(): RemoteViews = remoteViews
}
{'fraction_non_alphanumeric': 0.06839309428950863, 'fraction_numerical': 0.0, 'mean_word_length': 3.899186991869919, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5532906', 'n_tokens_mistral': 848, 'n_tokens_neox': 807, 'n_words': 135}