<commit_before>/*
 * Copyright 2019 <NAME>. Use of this source code is governed by the Apache 2.0 license.
 */

package com.example.splitties.extensions

import android.app.Activity
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.appcompat.app.AppCompatDelegate.getDefaultNightMode
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
import splitties.exceptions.illegalArg

fun Activity.toggleNightMode() {
    val newNightMode = when (val currentNightMode = getDefaultNightMode()) {
        MODE_NIGHT_YES -> MODE_NIGHT_NO
        MODE_NIGHT_NO, MODE_NIGHT_AUTO, MODE_NIGHT_FOLLOW_SYSTEM -> MODE_NIGHT_YES
        else -> illegalArg(currentNightMode)
    }
    setDefaultNightMode(newNightMode)
    recreate()
}<commit_msg>Minor toggleNightMode improvement<commit_after>/*
 * Copyright 2019 <NAME>. Use of this source code is governed by the Apache 2.0 license.
 */

@file:Suppress("NOTHING_TO_INLINE")

package com.example.splitties.extensions

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.appcompat.app.AppCompatDelegate.getDefaultNightMode
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
import timber.log.Timber

inline fun AppCompatActivity.toggleNightMode() {
    delegate.toggleNightMode()
}

fun AppCompatDelegate.toggleNightMode() {
    val newNightMode = when (val currentNightMode = getDefaultNightMode()) {
        MODE_NIGHT_YES -> MODE_NIGHT_NO
        MODE_NIGHT_NO, MODE_NIGHT_AUTO, MODE_NIGHT_FOLLOW_SYSTEM -> MODE_NIGHT_YES
        else -> MODE_NIGHT_YES.also { Timber.w("Unexpected night mode: $currentNightMode") }
    }
    setDefaultNightMode(newNightMode)
    applyDayNight()
}
{'fraction_non_alphanumeric': 0.07650273224043716, 'fraction_numerical': 0.00546448087431694, 'mean_word_length': 5.7392638036809815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7324951', 'n_tokens_mistral': 707, 'n_tokens_neox': 677, 'n_words': 117}