| | |
| | | |
| | | import android.app.Activity |
| | | import android.content.Context |
| | | import android.graphics.drawable.Drawable |
| | | import android.os.Build |
| | | import android.os.Bundle |
| | | import android.support.v4.app.Fragment |
| | | import android.support.v7.widget.Toolbar |
| | | import android.view.LayoutInflater |
| | | import android.view.View |
| | | import android.view.ViewGroup |
| | | import android.view.inputmethod.InputMethodManager |
| | | import android.widget.TextView |
| | | import cn.flightfeather.thirdapp.R |
| | | import kotlinx.android.synthetic.main.tool_bar_layout.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | |
| | | /** |
| | |
| | | * 2019.7.29 |
| | | * 基类fragment |
| | | */ |
| | | abstract class BaseFragment : Fragment() { |
| | | abstract class BaseFragment : Fragment(), ToolbarSetInterface { |
| | | |
| | | var mContext: Context? = null |
| | | |
| | | var mRootView: ViewGroup? = null |
| | | |
| | | private lateinit var contentView: View |
| | | |
| | | override fun getToolBar(): Toolbar = contentView.findViewById(R.id.tool_bar) |
| | | |
| | | override fun toolbarEnabled(): Boolean =false |
| | | |
| | | override fun getHeadIcon(): View = contentView.findViewById(R.id.img_back) |
| | | |
| | | override fun onHeadIconClick() { activity?.onBackPressed() } |
| | | |
| | | override fun getMyTitleTextView(): TextView? = contentView.findViewById(R.id.tv_main_title) |
| | | |
| | | override fun getTitleEnabled(): Boolean = true |
| | | |
| | | override fun getTitleText(): String? = "" |
| | | |
| | | override fun getMenus(): List<View>? = listOf(contentView.findViewById(R.id.img_menu_1), contentView.findViewById(R.id.img_menu_2), contentView.findViewById(R.id.img_menu_3)) |
| | | |
| | | override fun getMenuVisibility(): List<Int?> = listOf(View.VISIBLE, View.VISIBLE, View.VISIBLE) |
| | | |
| | | override fun getMenuRes(): List<Drawable?> = listOf(null) |
| | | |
| | | override fun getMenuClickListener(): List<View.OnClickListener?> = listOf(null) |
| | | |
| | | override fun onCreateView( |
| | | inflater: LayoutInflater, container: ViewGroup?, |
| | | savedInstanceState: Bundle? |
| | | inflater: LayoutInflater, container: ViewGroup?, |
| | | savedInstanceState: Bundle? |
| | | ): View? { |
| | | mRootView = container |
| | | val view = inflater.inflate(getLayoutId(), container, false) |
| | | contentView = inflater.inflate(getLayoutId(), container, false) |
| | | onCreateView() |
| | | return view |
| | | initToolbar() |
| | | return contentView |
| | | } |
| | | |
| | | override fun onAttach(context: Context?) { |
| | |
| | | } |
| | | } |
| | | |
| | | open fun onBackPressed(onActivityBack: () -> Unit) { |
| | | onActivityBack() |
| | | } |
| | | |
| | | open fun onCreateView() = Unit |
| | | |
| | | abstract fun getLayoutId(): Int |
| | | |
| | | /** |
| | | * 拓展fragment中隐藏软键盘的方法 |
| | | */ |
| | | fun Fragment.hideKeyboard() { |
| | | this.activity?.window?.peekDecorView()?.let { |
| | | val inputManager = |
| | | this.activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
| | | inputManager.hideSoftInputFromWindow(it.windowToken, 0) |
| | | } |
| | | } |
| | | |
| | | } |