<commit_before>package com.battlelancer.seriesguide.ui.shows

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialogFragment
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.SgApp
import com.battlelancer.seriesguide.provider.SgRoomDatabase
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.coroutines.CoroutineContext

/**
 * Confirms before making all hidden shows visible again.
 */
class MakeAllVisibleDialogFragment : AppCompatDialogFragment(), CoroutineScope {

    private lateinit var job: Job
    override val coroutineContext: CoroutineContext
        get() = job + Dispatchers.Main

    private lateinit var dialog: AlertDialog

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        dialog = MaterialAlertDialogBuilder(requireContext())
            .setMessage(getString(R.string.description_make_all_visible_format, "?"))
            .setPositiveButton(R.string.action_shows_make_all_visible) { _, _ ->
                SgApp.getServicesComponent(requireContext()).showTools().storeAllHiddenVisible()
                dismiss()
            }
            .setNegativeButton(android.R.string.cancel) { _, _ -> dismiss() }
            .create()
        return dialog
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        job = Job()
        launch {
            updateHiddenShowCountAsync()
        }
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    private suspend fun updateHiddenShowCountAsync() {
        val count = withContext(Dispatchers.IO) {
            SgRoomDatabase.getInstance(requireContext()).showHelper().countHiddenShows()
        }
        withContext(Dispatchers.Main) {
            dialog.setMessage(getString(R.string.description_make_all_visible_format, count))
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        job.cancel()
    }

}<commit_msg>MakeAllVisibleDialogFragment: drop custom Job in favor of Lifecycle CoroutineScope.<commit_after>package com.battlelancer.seriesguide.ui.shows

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.lifecycle.lifecycleScope
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.SgApp
import com.battlelancer.seriesguide.provider.SgRoomDatabase
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * Confirms before making all hidden shows visible again.
 */
class MakeAllVisibleDialogFragment : AppCompatDialogFragment() {

    private lateinit var dialog: AlertDialog

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        dialog = MaterialAlertDialogBuilder(requireContext())
            .setMessage(getString(R.string.description_make_all_visible_format, "?"))
            .setPositiveButton(R.string.action_shows_make_all_visible) { _, _ ->
                SgApp.getServicesComponent(requireContext()).showTools().storeAllHiddenVisible()
                dismiss()
            }
            .setNegativeButton(android.R.string.cancel) { _, _ -> dismiss() }
            .create()
        return dialog
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        lifecycleScope.launch {
            updateHiddenShowCountAsync()
        }
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    private suspend fun updateHiddenShowCountAsync() {
        val count = withContext(Dispatchers.IO) {
            SgRoomDatabase.getInstance(requireContext()).showHelper().countHiddenShows()
        }
        withContext(Dispatchers.Main) {
            dialog.setMessage(getString(R.string.description_make_all_visible_format, count))
        }
    }

}
{'fraction_non_alphanumeric': 0.0839929639401935, 'fraction_numerical': 0.0, 'mean_word_length': 3.4906219151036524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6082304', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1212, 'n_words': 214}