package cn.flightfeather.thirdapp.module.base
|
|
|
import android.app.Activity
|
import android.content.Context
|
import android.os.Build
|
import android.os.Bundle
|
import android.support.v4.app.Fragment
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.view.ViewGroup
|
import org.greenrobot.eventbus.EventBus
|
|
/**
|
* @author riku
|
* 2019.7.29
|
* 基类fragment
|
*/
|
abstract class BaseFragment : Fragment() {
|
|
var mContext: Context? = null
|
|
var mRootView: ViewGroup? = null
|
|
override fun onCreateView(
|
inflater: LayoutInflater, container: ViewGroup?,
|
savedInstanceState: Bundle?
|
): View? {
|
mRootView = container
|
val view = inflater.inflate(getLayoutId(), container, false)
|
onCreateView()
|
return view
|
}
|
|
override fun onAttach(context: Context?) {
|
super.onAttach(context)
|
mContext = context
|
}
|
|
override fun onAttach(activity: Activity?) {
|
super.onAttach(activity)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
mContext = context
|
}
|
}
|
|
override fun onDestroyView() {
|
super.onDestroyView()
|
if (EventBus.getDefault().isRegistered(this)) {
|
EventBus.getDefault().unregister(this)
|
}
|
}
|
|
open fun onCreateView() = Unit
|
|
abstract fun getLayoutId(): Int
|
|
}
|