<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.settings.fragment

import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.appwidget.search.Updater
import jp.toastkid.yobidashi.databinding.FragmentSettingOtherBinding
import jp.toastkid.yobidashi.libs.HtmlCompat
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.intent.SettingsIntentFactory
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import jp.toastkid.yobidashi.main.StartUp

/**
 * @author toastkidjp
 */
class OtherSettingFragment : Fragment(), TitleIdSupplier {

    /**
     * View Data Binding object.
     */
    private lateinit var binding: FragmentSettingOtherBinding

    /**
     * Preferences wrapper.
     */
    private lateinit var preferenceApplier: PreferenceApplier

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_setting_other, container, false)
        val activityContext = context
                ?: return super.onCreateView(inflater, container, savedInstanceState)
        preferenceApplier = PreferenceApplier(activityContext)
        binding.fragment = this

        binding.startUpItems.startUpSelector.setOnCheckedChangeListener { _, checkedId ->
            preferenceApplier.startUp = StartUp.findById(checkedId)
        }

        return binding.root
    }

    override fun onResume() {
        super.onResume()
        binding.startUpItems.startUpSelector.let {
            it.check(preferenceApplier.startUp.radioButtonId)
            it.jumpDrawablesToCurrentState()
        }
        binding.wifiOnlyCheck.let {
            it.isChecked = preferenceApplier.wifiOnly
            it.jumpDrawablesToCurrentState()
        }
    }

    /**
     * Switch Wi-Fi only mode.
     *
     * @param v
     */
    fun switchWifiOnly(v: View) {
        val newState = !preferenceApplier.wifiOnly
        preferenceApplier.wifiOnly = newState
        binding.wifiOnlyCheck.isChecked = newState
    }


    /**
     * Clear all settings.
     *
     * @param v
     */
    fun clearSettings(v: View) {
        val fragmentActivity = activity ?: return
        AlertDialog.Builder(fragmentActivity)
                .setTitle(R.string.title_clear_settings)
                .setMessage(HtmlCompat.fromHtml(getString(R.string.confirm_clear_all_settings)))
                .setCancelable(true)
                .setNegativeButton(R.string.cancel) { d, _ -> d.cancel() }
                .setPositiveButton(R.string.ok) { d, _ ->
                    preferenceApplier.clear()
                    //TODO colorFilter.stop()
                    //TODO setCurrentValues()
                    Updater.update(fragmentActivity)
                    Toaster.snackShort(binding.root, R.string.done_clear, preferenceApplier.colorPair())
                }
                .show()
    }

    /**
     * Call device settings.
     *
     * @param v
     */
    fun deviceSetting(v: View) {
        startActivity(SettingsIntentFactory.makeLaunch())
    }

    /**
     * Call Wi-Fi settings.
     *
     * @param v
     */
    fun wifi(v: View) {
        startActivity(SettingsIntentFactory.wifi())
    }<commit_msg>refactor #307 Replace snackbar's parameter in OtherSettingFragment.<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.settings.fragment

import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.appwidget.search.Updater
import jp.toastkid.yobidashi.databinding.FragmentSettingOtherBinding
import jp.toastkid.yobidashi.libs.HtmlCompat
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.intent.SettingsIntentFactory
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import jp.toastkid.yobidashi.main.StartUp

/**
 * @author toastkidjp
 */
class OtherSettingFragment : Fragment(), TitleIdSupplier {

    /**
     * View Data Binding object.
     */
    private lateinit var binding: FragmentSettingOtherBinding

    /**
     * Preferences wrapper.
     */
    private lateinit var preferenceApplier: PreferenceApplier

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_setting_other, container, false)
        val activityContext = context
                ?: return super.onCreateView(inflater, container, savedInstanceState)
        preferenceApplier = PreferenceApplier(activityContext)
        binding.fragment = this

        binding.startUpItems.startUpSelector.setOnCheckedChangeListener { _, checkedId ->
            preferenceApplier.startUp = StartUp.findById(checkedId)
        }

        return binding.root
    }

    override fun onResume() {
        super.onResume()
        binding.startUpItems.startUpSelector.let {
            it.check(preferenceApplier.startUp.radioButtonId)
            it.jumpDrawablesToCurrentState()
        }
        binding.wifiOnlyCheck.let {
            it.isChecked = preferenceApplier.wifiOnly
            it.jumpDrawablesToCurrentState()
        }
    }

    /**
     * Switch Wi-Fi only mode.
     *
     * @param v
     */
    fun switchWifiOnly(v: View) {
        val newState = !preferenceApplier.wifiOnly
        preferenceApplier.wifiOnly = newState
        binding.wifiOnlyCheck.isChecked = newState
    }


    /**
     * Clear all settings.
     *
     * @param v
     */
    fun clearSettings(v: View) {
        val fragmentActivity = activity ?: return
        AlertDialog.Builder(fragmentActivity)
                .setTitle(R.string.title_clear_settings)
                .setMessage(HtmlCompat.fromHtml(getString(R.string.confirm_clear_all_settings)))
                .setCancelable(true)
                .setNegativeButton(R.string.cancel) { d, _ -> d.cancel() }
                .setPositiveButton(R.string.ok) { d, _ ->
                    preferenceApplier.clear()
                    //TODO colorFilter.stop()
                    //TODO setCurrentValues()
                    Updater.update(fragmentActivity)
                    Toaster.snackShort(v, R.string.done_clear, preferenceApplier.colorPair())
                }
                .show()
    }

    /**
     * Call device settings.
     *
     * @param v
     */
    fun deviceSetting(v: View) {
        startActivity(SettingsIntentFactory.makeLaunch())
    }

    /**
     * Call Wi-Fi settings.
     *
     * @param v
     */
    fun wifi(v: View) {
        startActivity(SettingsIntentFactory.wifi())
    }
{'fraction_non_alphanumeric': 0.08982725527831094, 'fraction_numerical': 0.002943058221369162, 'mean_word_length': 2.484618814088275, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3231843', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2175, 'n_words': 410}