添加了界面及逻辑
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
package com.sw.platecabinet.fragment
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.view.CustomDialog
|
||||
|
||||
abstract class BaseFragment<VB : ViewBinding>(
|
||||
private val bindingInflater: (inflater: LayoutInflater, parent: ViewGroup?, attachToParent: Boolean) -> VB
|
||||
) : Fragment() {
|
||||
private var _binding: VB? = null
|
||||
protected val binding get() = _binding!!
|
||||
private var mDialogWaiting: CustomDialog? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -22,16 +26,37 @@ abstract class BaseFragment<VB : ViewBinding>(
|
||||
): View? {
|
||||
_binding = bindingInflater(inflater, container, false)
|
||||
initialize()
|
||||
registerDataChange()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册数据变化监听
|
||||
*/
|
||||
open fun registerDataChange() {}
|
||||
|
||||
abstract fun initialize()
|
||||
|
||||
class ViewModelFactory<T : ViewModel>(private val creator: () -> T) :
|
||||
ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return creator() as T
|
||||
}
|
||||
/**
|
||||
* 显示等待提示框
|
||||
*/
|
||||
fun showWaitingDialog(tip: String?): Dialog? {
|
||||
hideWaitingDialog()
|
||||
val view = View.inflate(requireContext(), R.layout.dialog_waiting, null)
|
||||
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text = tip
|
||||
mDialogWaiting = CustomDialog(requireContext(), view, R.style.MyDialog)
|
||||
mDialogWaiting!!.show()
|
||||
mDialogWaiting!!.setCancelable(true)
|
||||
return mDialogWaiting
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 隐藏等待提示框
|
||||
*/
|
||||
fun hideWaitingDialog() {
|
||||
mDialogWaiting?.dismiss()
|
||||
mDialogWaiting = null
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user