<commit_before>@file:Suppress("unused", "UNUSED_PARAMETER")

package com.u1f4f1.betterbottomsheet.bottomsheet

import android.content.Context
import android.support.v4.view.ViewCompat
import android.support.v4.widget.NestedScrollView
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.util.SparseArray
import android.view.View
import android.view.ViewTreeObserver
import com.u1f4f1.betterbottomsheet.coordinatorlayoutbehaviors.AnchorPointBottomSheetBehavior
import inkapplicaitons.android.logger.ConsoleLogger
import inkapplicaitons.android.logger.Logger
import java.util.*

abstract class BottomSheet : NestedScrollView {
    var recyclerView: RecyclerView? = null
    private var bottomSheetBehavior: AnchorPointBottomSheetBehavior<*>? = null

    private val postOnStableStateRunnables = SparseArray<MutableList<Runnable>>()

    private var activatedListener: OnSheetActivatedListener? = null
    private var bottomSheetAdapter: BottomSheetAdapter? = null

    open var isActive: Boolean = false
        set(isActive) {
            field = isActive
            activatedListener?.isActivated(isActive)
        }

    internal var logger: Logger = ConsoleLogger("ANDROIDISBAD")

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    interface OnSheetActivatedListener {
        fun isActivated(isActive: Boolean)
    }

    fun setActivatedListener(activatedListener: OnSheetActivatedListener) {
        this.activatedListener = activatedListener
    }

    open fun removeAdapter() {
        this.recyclerView?.adapter = null
    }

    open fun setupRecyclerview(adapter: BottomSheetAdapter) {
        if (recyclerView == null) {
            throw RuntimeException("You must provide the BottomSheet with a RecyclerView before attaching an Adapter")
        }

        bottomSheetAdapter = adapter
        bottomSheetBehavior = AnchorPointBottomSheetBehavior.from(this)

        recyclerView?.let {
            it.layoutManager = LinearLayoutManager(context)
            it.adapter = bottomSheetAdapter
            it.isNestedScrollingEnabled = false

            it.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
                // this has to be so gross so we can remove this listener
                override fun onGlobalLayout() {
                    bottomSheetBehavior!!.state = BottomSheetState.STATE_COLLAPSED
                    it.viewTreeObserver.removeOnGlobalLayoutListener(this)<commit_msg>Exposed methods to interact with the BottomSheet's child behavior<commit_after>@file:Suppress("unused", "UNUSED_PARAMETER")

package com.u1f4f1.betterbottomsheet.bottomsheet

import android.content.Context
import android.support.design.widget.BottomSheetBehavior
import android.support.v4.view.ViewCompat
import android.support.v4.widget.NestedScrollView
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.util.SparseArray
import android.view.View
import android.view.ViewTreeObserver
import com.u1f4f1.betterbottomsheet.coordinatorlayoutbehaviors.AnchorPointBottomSheetBehavior
import inkapplicaitons.android.logger.ConsoleLogger
import inkapplicaitons.android.logger.Logger
import java.util.*

abstract class BottomSheet : NestedScrollView {
    var recyclerView: RecyclerView? = null
    private var bottomSheetBehavior: AnchorPointBottomSheetBehavior<*>? = null

    private val postOnStableStateRunnables = SparseArray<MutableList<Runnable>>()

    private var activatedListener: OnSheetActivatedListener? = null
    private var bottomSheetAdapter: BottomSheetAdapter? = null

    open var isActive: Boolean = false
        set(isActive) {
            field = isActive
            activatedListener?.isActivated(isActive)
        }

    internal var logger: Logger = ConsoleLogger("ANDROIDISBAD")

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    interface OnSheetActivatedListener {
        fun isActivated(isActive: Boolean)
    }

    fun setActivatedListener(activatedListener: OnSheetActivatedListener) {
        this.activatedListener = activatedListener
    }

    open fun removeAdapter() {
        this.recyclerView?.adapter = null
    }

    open fun setState(state: BottomSheetState) {
        this.bottomSheetBehavior?.state = state
    }

    open fun addBottomSheetStateCallback(callback: AnchorPointBottomSheetBehavior.BottomSheetStateCallback) {
        this.bottomSheetBehavior?.addBottomSheetStateCallback(callback)
    }

    open fun addBottomSheetSlideCallback(callback: AnchorPointBottomSheetBehavior.BottomSheetSlideCallback) {
        this.bottomSheetBehavior?.addBottomSheetSlideCallback(callback)
    }

    open fun setupRecyclerview(adapter: BottomSheetAdapter) {
        if (recyclerView == null) {
            throw RuntimeException("You must provide the BottomSheet with a RecyclerView before attaching an Adapter")
        }

        bottomSheetAdapter = adapter
        bottomSheetBehavior = AnchorPointBottomSheetBehavior.from(this)

        recyclerView?.let {
            it.layoutManager = LinearLayoutManager(context)
            it.adapter = bottomSheetAdapter
            it.isNestedScrollingEnabled = false

            it.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
                // this has to be so gross so we can remove this listener
                override fun onGlobalLayout() {
                    bottomSheetBehavior!!.state = BottomSheetState.STATE_COLLAPSED
                    it.viewTreeObserver.removeOnGlobalLayoutListener(this)
{'fraction_non_alphanumeric': 0.07059596125430964, 'fraction_numerical': 0.003283533081595797, 'mean_word_length': 3.9248181083265967, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1222841', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1554, 'n_words': 335}