<commit_before>/*
 * Copyright (c) 2019 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package jp.toastkid.yobidashi.media.image.setting

import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.lib.view.RightSwipeActionAttachment
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.FragmentSettingImageExcludingBinding
import jp.toastkid.yobidashi.media.image.list.ImageViewerFragmentViewModel

/**
 * @author toastkidjp
 */
class ExcludingSettingFragment : BottomSheetDialogFragment() {

    private lateinit var binding: FragmentSettingImageExcludingBinding

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View {
        binding = DataBindingUtil.inflate(
                inflater,
                R.layout.fragment_setting_image_excluding,
                container,
                false
        )
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val preferenceApplier = PreferenceApplier(view.context)
        val excludedItems = preferenceApplier.excludedItems()
        if (excludedItems.isEmpty()) {
            dismiss()
            return
        }

        binding.excludingItems.layoutManager = LinearLayoutManager(activity)

        val viewModel = ViewModelProvider(this)
                .get(ExcludingSettingFragmentViewModel::class.java)

        viewModel.dismiss.observe(this, Observer {
            dismiss()
        })

        val adapter = Adapter(preferenceApplier, viewModel)
        binding.excludingItems.adapter = adapter
        RightSwipeActionAttachment().invoke(binding.excludingItems) {
            adapter.removeAt(it)
        }
        adapter.addAll(excludedItems)
        adapter.notifyDataSetChanged()
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        val targetFragment = targetFragment ?: return
        ViewModelProvider(targetFragment).get(ImageViewerFragmentViewModel::class.java)
                .refresh()
    }
}<commit_msg>refactor #506 Remove redundant SAM-constructor.<commit_after>/*
 * Copyright (c) 2019 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package jp.toastkid.yobidashi.media.image.setting

import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.lib.view.RightSwipeActionAttachment
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.FragmentSettingImageExcludingBinding
import jp.toastkid.yobidashi.media.image.list.ImageViewerFragmentViewModel

/**
 * @author toastkidjp
 */
class ExcludingSettingFragment : BottomSheetDialogFragment() {

    private lateinit var binding: FragmentSettingImageExcludingBinding

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View {
        binding = DataBindingUtil.inflate(
                inflater,
                R.layout.fragment_setting_image_excluding,
                container,
                false
        )
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val preferenceApplier = PreferenceApplier(view.context)
        val excludedItems = preferenceApplier.excludedItems()
        if (excludedItems.isEmpty()) {
            dismiss()
            return
        }

        binding.excludingItems.layoutManager = LinearLayoutManager(activity)

        val viewModel = ViewModelProvider(this)
                .get(ExcludingSettingFragmentViewModel::class.java)

        viewModel.dismiss.observe(this, {
            dismiss()
        })

        val adapter = Adapter(preferenceApplier, viewModel)
        binding.excludingItems.adapter = adapter
        RightSwipeActionAttachment().invoke(binding.excludingItems) {
            adapter.removeAt(it)
        }
        adapter.addAll(excludedItems)
        adapter.notifyDataSetChanged()
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        val targetFragment = targetFragment ?: return
        ViewModelProvider(targetFragment).get(ImageViewerFragmentViewModel::class.java)
                .refresh()
    }
}
{'fraction_non_alphanumeric': 0.075, 'fraction_numerical': 0.003368794326241135, 'mean_word_length': 3.197172619047619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3114196', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1435, 'n_words': 293}