<commit_before>/*
 * Copyright 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pyamsoft.homebutton.settings

import android.content.Context
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.preference.PreferenceViewHolder
import com.pyamsoft.homebutton.R
import com.pyamsoft.pydroid.ui.preference.PreferenceCompat
import com.pyamsoft.pydroid.util.doOnApplyWindowInsets

internal class PreferenceBottomSpace internal constructor(
    context: Context
) : PreferenceCompat(context) {

    init {
        layoutResource = R.layout.preference_spacer
    }

    override fun onBindViewHolder(holder: PreferenceViewHolder) {
        super.onBindViewHolder(holder)
        holder.itemView.doOnApplyWindowInsets { v, insets, _ ->
            v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
                height = insets.systemWindowInsetBottom
            }
        }
    }
}<commit_msg>Unregister inset watcher<commit_after>/*
 * Copyright 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pyamsoft.homebutton.settings

import android.content.Context
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.preference.PreferenceViewHolder
import com.pyamsoft.homebutton.R
import com.pyamsoft.pydroid.ui.preference.PreferenceCompat
import com.pyamsoft.pydroid.util.doOnApplyWindowInsets

internal class PreferenceBottomSpace internal constructor(
    context: Context,
) : PreferenceCompat(context), LifecycleOwner {

    private val registry by lazy(LazyThreadSafetyMode.NONE) { LifecycleRegistry(this) }

    init {
        layoutResource = R.layout.preference_spacer

        registry.currentState = Lifecycle.State.RESUMED
    }

    override fun getLifecycle(): Lifecycle {
        return registry
    }

    override fun onBindViewHolder(holder: PreferenceViewHolder) {
        super.onBindViewHolder(holder)
        holder.itemView.doOnApplyWindowInsets(this) { v, insets, _ ->
            v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
                height = insets.systemWindowInsetBottom
            }
        }
    }

    override fun onDetached() {
        super.onDetached()
        registry.currentState = Lifecycle.State.DESTROYED
    }
}
{'fraction_non_alphanumeric': 0.07311389455286921, 'fraction_numerical': 0.00466064666472473, 'mean_word_length': 3.7041095890410958, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7152882', 'n_tokens_mistral': 944, 'n_tokens_neox': 916, 'n_words': 269}