package app.murinelauncher.settings

import androidx.preference.Preference
import app.murinelauncher.graphics.IconShapeDrawables
import app.murinelauncher.settings.common.AbstractSettingsFragment
import app.murinelauncher.widget.radio.RadioGroupPreference
import com.android.launcher3.BuildConfig
import com.android.launcher3.R
import com.android.launcher3.graphics.ThemeManager
import com.android.launcher3.shapes.ShapesProvider
import com.android.launcher3.util.DisplayController

public final class SettingsIconsFragment: AbstractSettingsFragment() {

    companion object {
        const val NOTIFICATION_DOTS_PREFERENCE_KEY: String = "pref_icon_badging"
        const val ICON_SIZE_KEY: String = "pref_icon_bitmap_size"
        const val ICON_LABEL_SIZE_KEY: String = "pref_icon_label_size"
        const val ICON_SHAPE_KEY: String = "pref_icon_shape"
    }

    override fun getPreferenceScreenResId() = R.xml.murine_prefs_icons

    override fun getPreferenceTitle(): Int? = R.string.pref_category_icons_title

    override fun initPreference(preference: Preference, info: DisplayController.Info): Boolean {
        when (preference.key) {
            NOTIFICATION_DOTS_PREFERENCE_KEY -> return BuildConfig.NOTIFICATION_DOTS_ENABLED
            ICON_SHAPE_KEY -> {
                preference as RadioGroupPreference
                preference.asEnum(ShapesProvider.IconShape::class.java).apply {
                    setDefaultValue(ThemeManager.PREF_ICON_SHAPE.defaultValue)
                    setTextProvider { ctx, shape -> ctx.getString(shape.title) }
                    setIconProvider { ctx, shape -> IconShapeDrawables.getShapePreviewDrawable(ctx, shape) }
                }
                return true
            }
            else -> return true
        }
    }
}