Giter Club home page Giter Club logo

easyload's People

Contributors

xushanning avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

longtianme

easyload's Issues

崩溃

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;
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.