package com.ridi.books.helper.view

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

private val Context.inputMethodManager: InputMethodManager
    get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

@JvmOverloads
fun View.showSoftKeyboard(flags: Int = InputMethodManager.SHOW_IMPLICIT) =
    context.inputMethodManager.showSoftInput(this, flags)

@JvmOverloads
fun View.hideSoftKeyboard(flags: Int = 0) = context.inputMethodManager.hideSoftInputFromWindow(windowToken, flags)

@JvmOverloads
fun Context.toggleSoftKeyboard(showFlags: Int = 0, hideFlags: Int = 0) {
    inputMethodManager.toggleSoftInput(showFlags, hideFlags)
}

@JvmOverloads
fun View.focusAndShowSoftKeyboard(
    flags: Int = InputMethodManager.SHOW_IMPLICIT,
    repeatIntervalInMs: Long = 100,
    condition: () -> Boolean = { true }
) {
    if (condition().not()) {
        return
    }

    requestFocus()
    if (showSoftKeyboard(flags).not()) {
        postDelayed({ focusAndShowSoftKeyboard(flags, repeatIntervalInMs, condition) }, repeatIntervalInMs)
    }
}

package com.ridi.books.helper.view

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

private val Context.inputMethodManager: InputMethodManager
    get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

@JvmOverloads
fun View.showSoftKeyboard(flags: Int = InputMethodManager.SHOW_IMPLICIT) =
    context.inputMethodManager.showSoftInput(this, flags)

@JvmOverloads
fun View.hideSoftKeyboard(flags: Int = 0) = context.inputMethodManager.hideSoftInputFromWindow(windowToken, flags)

@JvmOverloads
fun Context.toggleSoftKeyboard(showFlags: Int = 0, hideFlags: Int = 0) {
    inputMethodManager.toggleSoftInput(showFlags, hideFlags)
}

Revert "뷰에 포커스를 주고 동시에 키보드를 띄우는 확장 매서드 추가"
Revert "뷰에 포커스를 주고 동시에 키보드를 띄우는 확장 매서드 추가"

This reverts commit 4b14402b2c40c17a1af636310079e712fc346b6a.

ridibooks/rbhelper-android,ridibooks/rbhelper-android