Skip to content

Commit

Permalink
更新第三方库,新增扩展方法
Browse files Browse the repository at this point in the history
  • Loading branch information
br3ant committed Sep 9, 2021
1 parent 6d12435 commit 47c2ded
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions utils/src/main/java/com/br3ant/base/BaseFragment.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.br3ant.base

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.IdRes
import com.weikaiyun.fragmentation.SupportFragment

abstract class BaseFragment(val layout: Int = 0) : SupportFragment() {
private lateinit var mRootView: View
protected lateinit var mContext: Context
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (!this::mRootView.isInitialized) {
val id = if (layout == 0) getLayoutId() else layout
if (id == 0) throw IllegalAccessException("layoutId 不能为空")

mRootView = inflater.inflate(id, container, false)
mContext = mRootView.context
}
return mRootView
/**
* layout必须传,使用viewBing也要传
*/
abstract class BaseFragment(private val layout: Int = 0) : SupportFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val id = if (layout == 0) getLayoutId() else layout
return inflater.inflate(id, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -33,10 +27,9 @@ abstract class BaseFragment(val layout: Int = 0) : SupportFragment() {
observeData()
}

fun <T : View> findViewById(@IdRes id: Int): T {
return mRootView.findViewById(id)
}
fun <T : View> findViewById(@IdRes viewId: Int): T? = view?.findViewById(viewId)

@Deprecated("使用构造函数传递或者使用viewBing", ReplaceWith("viewBing"))
protected open fun getLayoutId(): Int = 0
protected open fun observeData() {}
protected abstract fun initView()
Expand Down

0 comments on commit 47c2ded

Please sign in to comment.