<commit_before>/*
 * Copyright 2019 <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.pydroid.ui.about.listitem

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CheckResult
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import com.pyamsoft.pydroid.arch.createComponent
import com.pyamsoft.pydroid.bootstrap.libraries.OssLibrary
import com.pyamsoft.pydroid.ui.Injector
import com.pyamsoft.pydroid.ui.PYDroidComponent
import com.pyamsoft.pydroid.ui.R
import com.pyamsoft.pydroid.ui.arch.factory

internal class AboutViewHolder private constructor(
    view: View,
    owner: LifecycleOwner,
    callback: (event: AboutItemControllerEvent) -> Unit
) : BaseViewHolder(view) {

    internal var titleView: AboutItemTitleView? = null
    internal var descriptionView: AboutItemDescriptionView? = null
    internal var actionView: AboutItemActionView? = null

    internal var factory: ViewModelProvider.Factory? = null
    private val viewModel by factory<AboutItemViewModel>(ViewModelStore()) { factory }

    init {
        val parent = view.findViewById<ViewGroup>(R.id.about_listitem_root)
        Injector.obtain<PYDroidComponent>(itemView.context.applicationContext)
            .plusAboutItem()
            .create(parent)
            .inject(this)

        createComponent(
            null, owner,
            viewModel,
            requireNotNull(titleView),
            requireNotNull(actionView),
            requireNotNull(descriptionView)
        ) { callback(it) }
    }

    override fun bind(model: OssLibrary) {
        viewModel.bind(model)
    }

    override fun unbind() {
        viewModel.unbind()
    }

    companion object {

        @CheckResult
        @JvmStatic
        fun create(
            inflater: LayoutInflater,
            container: ViewGroup,
            owner: LifecycleOwner,
            callback: (event: AboutItemControllerEvent) -> Unit
        ): AboutViewHolder {
            val view = inflater.inflate(R.layout.adapter_item_about_license, container, false)
            return AboutViewHolder(view, owner, callback)
        }
    }
}<commit_msg>Null on owner destroy<commit_after>/*
 * Copyright 2019 <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.pydroid.ui.about.listitem

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CheckResult
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import com.pyamsoft.pydroid.arch.createComponent
import com.pyamsoft.pydroid.arch.doOnDestroy
import com.pyamsoft.pydroid.bootstrap.libraries.OssLibrary
import com.pyamsoft.pydroid.ui.Injector
import com.pyamsoft.pydroid.ui.PYDroidComponent
import com.pyamsoft.pydroid.ui.R
import com.pyamsoft.pydroid.ui.arch.factory

internal class AboutViewHolder private constructor(
    view: View,
    owner: LifecycleOwner,
    callback: (event: AboutItemControllerEvent) -> Unit
) : BaseViewHolder(view) {

    internal var titleView: AboutItemTitleView? = null
    internal var descriptionView: AboutItemDescriptionView? = null
    internal var actionView: AboutItemActionView? = null

    internal var factory: ViewModelProvider.Factory? = null
    private val viewModel by factory<AboutItemViewModel>(ViewModelStore()) { factory }

    init {
        val parent = view.findViewById<ViewGroup>(R.id.about_listitem_root)
        Injector.obtain<PYDroidComponent>(itemView.context.applicationContext)
            .plusAboutItem()
            .create(parent)
            .inject(this)

        createComponent(
            null, owner,
            viewModel,
            requireNotNull(titleView),
            requireNotNull(actionView),
            requireNotNull(descriptionView)
        ) { callback(it) }

        owner.doOnDestroy {
            titleView = null
            descriptionView = null
            actionView = null
            factory = null
        }
    }

    override fun bind(model: OssLibrary) {
        viewModel.bind(model)
    }

    override fun unbind() {
        viewModel.unbind()
    }

    companion object {

        @CheckResult
        @JvmStatic
        fun create(
            inflater: LayoutInflater,
            container: ViewGroup,
            owner: LifecycleOwner,
            callback: (event: AboutItemControllerEvent) -> Unit
        ): AboutViewHolder {
            val view = inflater.inflate(R.layout.adapter_item_about_license, container, false)
            return AboutViewHolder(view, owner, callback)
        }
    }
}
{'fraction_non_alphanumeric': 0.07844155844155844, 'fraction_numerical': 0.0027705627705627706, 'mean_word_length': 3.0419874037788666, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7489814', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1533, 'n_words': 416}