package com.yidian.common.extensions

import android.app.Activity
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.yidian.common.R
import com.yidian.xpage.XPageManager

fun Activity.hideKeyBoard(): Boolean {
  val mInputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
  return if (currentFocus != null) {
    mInputMethodManager.hideSoftInputFromWindow(currentFocus!!.windowToken, 0)
  } else {
    false
  }
}

fun AppCompatActivity.initTitleBar(toolbar: Toolbar, textView: TextView, title: String) {
  toolbar.title = ""
  setSupportActionBar(toolbar)
  supportActionBar?.let {
    it.setDisplayHomeAsUpEnabled(true)
    it.setDisplayShowHomeEnabled(true)
  }
  toolbar.setNavigationIcon(R.drawable.icon_back)
  toolbar.setNavigationOnClickListener {
    onBackPressed()
    // 在XPage服务中pop
    XPageManager.pop(null)
  }
  // 设置title
  textView.text = title
}

