xushanning / easyload Goto Github PK
View Code? Open in Web Editor NEWA library about android loading status
A library about android loading status
package com.cultraview.commonlibrary.base
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.cultraview.commonlibrary.utils.L
import com.xu.easyload.EasyLoad
import com.xu.easyload.service.ILoadService
abstract class BaseFragmentKt<T:ViewBinding> (val layoutId :Int) : Fragment() {
var isFragmentVisibleToUser :Boolean = false
var isViewCreate : Boolean =false
/**
* 设置是否可加载数据 只作用于FragmentPagerAdapter
*/
var canLoadData =true
private var mViewBinding : T? =null
public var loadService : ILoadService? =null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
L.d(this,"onCreateView")
mViewBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layoutId,null,false)
//注入加载状态页
loadService = EasyLoad.initLocal()
.inject(mViewBinding!!.root){
setOnReloadListener { iLoadService, clickState, view ->
//加了这行模板空方法会崩溃,不知道为什么
// reLoaded()
}
}
L.d("BaseFragmentKt","setOnReloadListener")
return loadService?.getParentView()
}
//前一个fragment对用户来说是隐藏还是显示,
// 这个方法仅仅工作在FragmentPagerAdapter中,
// 不能被使用在一个普通的activity
//可以重写 onHiddenChanged() 方法来得知当前 fragment 的状态。
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
isFragmentVisibleToUser =isVisibleToUser
if(canLoadData()){
lazyData()
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
initData()
setListener();
}
override fun onDestroyView() {
super.onDestroyView()
L.e(this,"onDestroyView")
mViewBinding =null //销毁页面时置空,防止内存泄露
}
override fun getContext():Context{
return requireActivity();
}
/**
* 懒加载数据方法 只作用于FragmentPagerAdapter
*/
abstract fun lazyData()
abstract fun initData()
abstract fun setListener()
/**
* 重新加载触发
*/
abstract fun reLoaded()
/**
* 是否可加载数据 只作用于FragmentPagerAdapter
* @return
*/
open fun canLoadData(): Boolean {
return isViewCreate && isFragmentVisibleToUser && canLoadData
}
open fun getBinding(): T {
return mViewBinding!!
}
fun getCurFragment():Fragment{
return this;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.