<commit_before>package de.synyx.calenope.organizer.ui

import android.app.Fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.GridView
import android.widget.TextView
import de.synyx.calenope.organizer.R

/**
 * @author clausen - <EMAIL>
 */

class Overview : Fragment () {

    private val grid : GridView by lazy { view.findViewById (R.id.overview_grid) as GridView }

    override fun onActivityCreated (savedInstanceState : Bundle?) {
        super.onActivityCreated    (savedInstanceState)

        val   activity = activity

        when (activity) {
            is Interaction ->
                grid.setOnItemClickListener { parent, view, position, id ->
                    val        adapter = grid.adapter as OverviewAdapter
                    val item = adapter.getItem (position)

                    activity.onOverviewClick (item.first)
                }
        }

        grid.adapter = OverviewAdapter () { activity.layoutInflater }
    }

    override fun onCreateView (inflater : LayoutInflater?, container : ViewGroup?, savedInstanceState : Bundle?) : View {
        return inflater?.inflate (R.layout.overview, container, false)!!
    }

    interface Interaction {

        fun onOverviewClick (name : String) : Unit

    }

}

private class OverviewAdapter (private val inflater : () -> LayoutInflater) : BaseAdapter () {

    private val items = listOf (
        "Nullpointer",
        "MemoryLeak"
    )

    override fun getView (position : Int, previous : View?, parent : ViewGroup?) : View {
        val holder : ViewCache?

        when (previous) {
            null -> {
                    holder = ViewCache (parent)
                    holder.view.tag = holder
            }
            else -> holder = previous.tag as ViewCache
        }

        holder.apply {
            room.text = getItem (position)
        }

        return holder.view
    }

    override fun getItem   (position : Int) : String = items[position]

    override fun getItemId (position : Int) : Long = position.toLong ()

    override fun getCount  () : Int = items.size

    private inner class ViewCache (parent: ViewGroup?) {

        val view   : View     by lazy { inflater ().inflate (R.layout.overview_tile, parent, false) }
        val room   : TextView by lazy { view.findViewById   (R.id.overview_tile_room)   as TextView }

    }

}<commit_msg>adds an update mechanism to provide elements to the overview<commit_after>package de.synyx.calenope.organizer.ui

import android.app.Fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.GridView
import android.widget.TextView
import de.synyx.calenope.organizer.R

/**
 * @author clausen - <EMAIL>
 */

class Overview : Fragment () {

    private val grid : GridView by lazy { view.findViewById (R.id.overview_grid) as GridView }

    override fun onActivityCreated (savedInstanceState : Bundle?) {
        super.onActivityCreated    (savedInstanceState)

        val   activity = activity

        when (activity) {
            is Interaction ->
                grid.setOnItemClickListener { parent, view, position, id ->
                    val        adapter = grid.adapter as OverviewAdapter
                    val item = adapter.getItem (position)

                    activity.onOverviewClick (item)
                }
        }

        update (
            listOf (
                "Nullpointer",
                "MemoryLeak"
            )
        )
    }

    override fun onCreateView (inflater : LayoutInflater?, container : ViewGroup?, savedInstanceState : Bundle?) : View {
        return inflater?.inflate (R.layout.overview, container, false)!!
    }

    fun update (events : Collection<String>) {
        grid.adapter = OverviewAdapter (events) { activity.layoutInflater }
    }

    interface Interaction {

        fun onOverviewClick (name : String) : Unit

    }

}

private class OverviewAdapter (
    private val items    : Collection<String> = emptyList(),
    private val inflater : () -> LayoutInflater
) : BaseAdapter () {

    override fun getView (position : Int, previous : View?, parent : ViewGroup?) : View {
        val holder : ViewCache?

        when (previous) {
            null -> {
                    holder = ViewCache (parent)
                    holder.view.tag = holder
            }
            else -> holder = previous.tag as ViewCache
        }

        holder.apply {
            room.text = getItem (position)
        }

        return holder.view
    }

    override fun getItem   (position : Int) : String = items.elementAt (position)

    override fun getItemId (position : Int) : Long = position.toLong ()

    override fun getCount  () : Int = items.size

    private inner class ViewCache (parent: ViewGroup?) {

        val view   : View     by lazy { inflater ().inflate (R.layout.overview_tile, parent, false) }
        val room   : TextView by lazy { view.findViewById   (R.id.overview_tile_room)   as TextView }

    }

}
{'fraction_non_alphanumeric': 0.08979042491828494, 'fraction_numerical': 0.0, 'mean_word_length': 2.1777642028100184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '4557970', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1314, 'n_words': 380}