package com.photo.keyboard.themes.manager

import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.view.inputmethod.InputMethodInfo
import android.view.inputmethod.InputMethodManager
import com.photo.keyboard.themes.App

object EnableActive {

    val inputMan =
        App.instance.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

    fun onsetInput(): Boolean {
        App.instance.run {
            Settings.Secure.getString(contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD)
                ?.let { id ->
                    return id.startsWith(packageName)
                } ?: return false

        }
    }
    fun toEnable(): Boolean {
        for (info: InputMethodInfo in inputMan.enabledInputMethodList) {
            if (info.id.startsWith(App.instance.packageName)) {
                return true
            }
        }

        return false
    }

    fun toSet(context: Context) {
        Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).apply {
            context.startActivity(this)
        }
    }

    fun onSetEnab() {
        inputMan.showInputMethodPicker()
    }

}