# Widgets **Repository Path**: bookbuf/Widgets ## Basic Information - **Project Name**: Widgets - **Description**: 项目中常用的控件集合 - **Primary Language**: Android - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 2 - **Created**: 2016-09-10 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README > 文档更新时间:2016-10-08 18:25 # 项目介绍 收集项目中使用到的通用的视觉控件。 # app 用于调试控件效果,目前仅调试`module = loadinglayout` # loadinglayout ## 在由外部的数据加载框架控制数据加载,UI仅根据状态判断。 如结合`EventBus`+`JobQueue`或其他数据加载模块,使用`Loader`的方式会破坏大量原先的接入方式。 参考如下方式接入: 1. 使用时由调用方统一适配`LoaderResult`对象,如: ``` public static LoaderResult cast (Result result) { LoaderResult loaderResult = new LoaderResult<> (); loaderResult.setSuccess (result.isSuccess ()); loaderResult.setMsgError (result.getMsgContent ()); loaderResult.setData (result.getModel ()); return loaderResult; } ``` ## 内置数据加载框架,请参考`GenericAsyncLoader`。如果是v4包下,请使用`GenericAsyncV4Loader`、`WebViewV4Loader`. * 基于视图的数据加载生命周期: ``` // LoaderState.java * init (初始化) * loading (加载中) * empty (加载成功,数据为空) * content (加载成功,数据不为空) * error (加载失败、或其他失败原因) ``` * 封装结果的数据类`LoaderResult` ``` // LoaderResult.java * (Boolean) isSuccess = null 表示请求未处理完成,加载中。 * (Boolean) isSuccess = false 表示请求处理失败。 * (Boolean) isSuccess = true 表示请求处理成功。 * () data = null 表示数据为空 * () data = object 表示数据非空 * (IStatePolicy) policy = IStatePolicy.generic 表示使用通用策略 ``` ** Note!!! 需要确保`isSuccess` 与 `data` 都被正确初始化。** * `Adapter` & `LoaderDataSetObserver` 解耦**数据、视图** * 继承`Loader`封装数据加载流程 ``` * GenericAsyncLoader 异步加载数据 * WebViewLoader 同步加载WebView!!!WebView结合WebViewClient判定加载成功或失败。 ``` * `LoaderLayout`封装视图的变化 ``` * !!! mPreInitContent = true , 表示同时加载LoadingView(Visible) & ContentView(Invisible) ```