<commit_before>/*
 * Copyright (c) 2017. <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 splitties.preferences

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.os.Build.VERSION.SDK_INT
import splitties.init.appCtx
import splitties.init.directBootCtx
import kotlin.reflect.KProperty

@SuppressLint("CommitPrefEdits")
@Suppress("NOTHING_TO_INLINE")
abstract class Preferences(
    name: String,
    availableAtDirectBoot: Boolean = false,
    mode: Int = Context.MODE_PRIVATE
) {

    protected val prefs: SharedPreferences

    init {
        val storageCtx: Context = if (availableAtDirectBoot && SDK_INT > 24) {
            // Moving the sharedPreferences from is done by the system only if you had it outside
            // the direct boot available storage or if the device was running Android M or older,
            // and just got updated. These two cases are extremely rare, and it's unlikely that your
            // sharedPreferences are big enough to significantly harm the user experience because of
            // the operation happening on UI thread for the single time (per preference file) this
            // move operations will take place.
            // noinspection NewApi
            directBootCtx.moveSharedPreferencesFrom(appCtx, name)
            directBootCtx
        } else appCtx
        prefs = storageCtx.getSharedPreferences(name, mode)
    }

    protected var editor: SharedPreferences.Editor by ResettableLazy { prefs.edit() }
        private set

    operator fun contains(o: Any) = prefs === o

    protected fun boolPref(
        defaultValue: Boolean = false
    ) = BoolPref(key = PROP_NAME, defaultValue = defaultValue)

    protected fun intPref(defaultValue: Int) = IntPref(key = PROP_NAME, defaultValue = defaultValue)
    protected fun floatPref(
        defaultValue: Float
    ) = FloatPref(key = PROP_NAME, defaultValue = defaultValue)
<commit_msg>Remove unneeded noInspection comment<commit_after>/*
 * Copyright (c) 2017. <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 splitties.preferences

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.os.Build.VERSION.SDK_INT
import splitties.init.appCtx
import splitties.init.directBootCtx
import kotlin.reflect.KProperty

@SuppressLint("CommitPrefEdits")
@Suppress("NOTHING_TO_INLINE")
abstract class Preferences(
    name: String,
    availableAtDirectBoot: Boolean = false,
    mode: Int = Context.MODE_PRIVATE
) {

    protected val prefs: SharedPreferences

    init {
        val storageCtx: Context = if (availableAtDirectBoot && SDK_INT > 24) {
            // Moving the sharedPreferences from is done by the system only if you had it outside
            // the direct boot available storage or if the device was running Android M or older,
            // and just got updated. These two cases are extremely rare, and it's unlikely that your
            // sharedPreferences are big enough to significantly harm the user experience because of
            // the operation happening on UI thread for the single time (per preference file) this
            // move operations will take place.
            directBootCtx.moveSharedPreferencesFrom(appCtx, name)
            directBootCtx
        } else appCtx
        prefs = storageCtx.getSharedPreferences(name, mode)
    }

    protected var editor: SharedPreferences.Editor by ResettableLazy { prefs.edit() }
        private set

    operator fun contains(o: Any) = prefs === o

    protected fun boolPref(
        defaultValue: Boolean = false
    ) = BoolPref(key = PROP_NAME, defaultValue = defaultValue)

    protected fun intPref(defaultValue: Int) = IntPref(key = PROP_NAME, defaultValue = defaultValue)
    protected fun floatPref(
        defaultValue: Float
    ) = FloatPref(key = PROP_NAME, defaultValue = defaultValue)

{'fraction_non_alphanumeric': 0.06821829855537721, 'fraction_numerical': 0.0040128410914927765, 'mean_word_length': 3.3085566119273984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3833750', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1263, 'n_words': 505}