Repository: DylanCaiCoding/LoadingStateView Branch: master Commit: a91fa3f3142b Files: 152 Total size: 264.8 KB Directory structure: gitextract_ifim0oyk/ ├── .gitignore ├── LICENSE ├── README.md ├── README_ZH.md ├── build.gradle ├── docs/ │ ├── .nojekyll │ ├── README.md │ ├── _sidebar.md │ ├── index.html │ └── zh/ │ ├── basic-usage.md │ ├── delegate.md │ ├── migration-guide.md │ ├── q&a.md │ └── viewbinding.md ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── loadingstateview/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── dylanc/ │ │ └── loadingstateview/ │ │ └── LoadingStateView.kt │ └── res/ │ └── values/ │ └── strings.xml ├── loadingstateview-ktx/ │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── com/ │ └── dylanc/ │ └── loadingstateview/ │ ├── BaseToolbarViewDelegate.kt │ ├── Decorative.kt │ ├── LoadingState.kt │ ├── LoadingStateDelegate.kt │ └── ToolbarConfig.kt ├── sample-java/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ ├── release/ │ │ ├── app-release.apk │ │ └── output.json │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── dylanc/ │ │ └── loadingstateview/ │ │ └── sample/ │ │ └── java/ │ │ └── ExampleInstrumentedTest.kt │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── dylanc/ │ │ │ └── loadingstateview/ │ │ │ └── sample/ │ │ │ └── java/ │ │ │ ├── App.java │ │ │ ├── animation/ │ │ │ │ └── FadeAnimatable.java │ │ │ ├── base/ │ │ │ │ └── BaseActivity.java │ │ │ ├── delegate/ │ │ │ │ ├── BottomEditorDecorViewDelegate.java │ │ │ │ ├── CoolLoadingViewDelegate.java │ │ │ │ ├── CustomHeaderViewDelegate.java │ │ │ │ ├── EmptyViewDelegate.java │ │ │ │ ├── ErrorViewDelegate.java │ │ │ │ ├── LoadingViewDelegate.java │ │ │ │ ├── NavIconType.java │ │ │ │ ├── NothingViewDelegate.java │ │ │ │ ├── PlaceholderViewDelegate.java │ │ │ │ ├── ScrollingDecorViewDelegate.java │ │ │ │ ├── SearchHeaderViewDelegate.java │ │ │ │ ├── TimeoutViewDelegate.java │ │ │ │ └── ToolbarViewDelegate.java │ │ │ ├── ui/ │ │ │ │ ├── ActErrorActivity.java │ │ │ │ ├── BottomEditorActivity.java │ │ │ │ ├── CustomHeaderActivity.java │ │ │ │ ├── FragmentEmptyActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MultipleHeaderActivity.java │ │ │ │ ├── RecyclerViewActivity.java │ │ │ │ ├── ScrollingToolbarActivity.java │ │ │ │ ├── ViewPagerActivity.java │ │ │ │ ├── ViewPlaceholderActivity.java │ │ │ │ └── fragment/ │ │ │ │ ├── EmptyFragment.java │ │ │ │ ├── SimpleFragment.java │ │ │ │ └── TimeoutFragment.java │ │ │ ├── utils/ │ │ │ │ ├── DensityUtils.java │ │ │ │ ├── HttpUtils.java │ │ │ │ ├── KeyboardUtils.java │ │ │ │ └── ToolbarUtils.java │ │ │ └── widget/ │ │ │ ├── LoadingDrawable.java │ │ │ ├── LoadingRenderer.java │ │ │ ├── LoadingRendererFactory.java │ │ │ ├── LoadingView.java │ │ │ └── renderer/ │ │ │ └── ElectricFanLoadingRenderer.java │ │ └── res/ │ │ ├── drawable/ │ │ │ ├── bg_reload_btn.xml │ │ │ ├── bg_search.xml │ │ │ ├── ic_baseline_favorite_24.xml │ │ │ ├── ic_baseline_message_24.xml │ │ │ ├── ic_baseline_photo_camera_24.xml │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ ├── activity_fragment.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_recycler_view.xml │ │ │ ├── activity_scrolling.xml │ │ │ ├── activity_tab_layout.xml │ │ │ ├── activity_view.xml │ │ │ ├── activity_view_pager.xml │ │ │ ├── layout_bottom_editor.xml │ │ │ ├── layout_content.xml │ │ │ ├── layout_cool_loading.xml │ │ │ ├── layout_custom_header.xml │ │ │ ├── layout_empty.xml │ │ │ ├── layout_error.xml │ │ │ ├── layout_loading.xml │ │ │ ├── layout_placeholder.xml │ │ │ ├── layout_scrolling_toolbar.xml │ │ │ ├── layout_search_header.xml │ │ │ ├── layout_timeout.xml │ │ │ ├── layout_toolbar.xml │ │ │ └── recycler_item_image.xml │ │ ├── menu/ │ │ │ └── menu_about.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── values/ │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test/ │ └── java/ │ └── com/ │ └── dylanc/ │ └── loadingstateview/ │ └── sample/ │ └── java/ │ └── ExampleUnitTest.kt ├── sample-kotlin/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── dylanc/ │ │ └── loadingstateview/ │ │ └── sample/ │ │ └── kotlin/ │ │ └── ExampleInstrumentedTest.kt │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── dylanc/ │ │ │ └── loadingstateview/ │ │ │ └── sample/ │ │ │ └── kotlin/ │ │ │ ├── App.kt │ │ │ ├── base/ │ │ │ │ ├── BaseActivity.kt │ │ │ │ ├── BaseBindingActivity.kt │ │ │ │ ├── BaseBindingFragment.kt │ │ │ │ └── BaseFragment.kt │ │ │ ├── delegate/ │ │ │ │ ├── EmptyViewDelegate.kt │ │ │ │ ├── ErrorViewDelegate.kt │ │ │ │ ├── FadeAnimatable.kt │ │ │ │ ├── LoadingViewDelegate.kt │ │ │ │ ├── ScrollingDecorViewDelegate.kt │ │ │ │ └── ToolbarViewDelegate.kt │ │ │ └── ui/ │ │ │ └── MainActivity.kt │ │ └── res/ │ │ ├── drawable/ │ │ │ ├── bg_reload_btn.xml │ │ │ ├── ic_add.xml │ │ │ ├── ic_arrow_back_ios.xml │ │ │ ├── ic_launcher_background.xml │ │ │ └── ic_refresh.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ ├── activity_main.xml │ │ │ ├── layout_empty.xml │ │ │ ├── layout_error.xml │ │ │ ├── layout_loading.xml │ │ │ ├── layout_scrolling_toolbar.xml │ │ │ └── layout_toolbar.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ └── values-night/ │ │ └── themes.xml │ └── test/ │ └── java/ │ └── com/ │ └── dylanc/ │ └── loadingstateview/ │ └── sample/ │ └── kotlin/ │ └── ExampleUnitTest.kt └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.iml .gradle .idea /local.properties /.idea/caches /.idea/libraries /.idea/modules.xml /.idea/workspace.xml /.idea/navEditor.xml /.idea/assetWizardSettings.xml .DS_Store /build /captures .externalNativeBuild ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # LoadingStateView English | [中文](README_ZH.md) [](https://www.jitpack.io/#DylanCaiCoding/LoadingLoadingStateView) [](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/LICENSE) `LoadingStateView` is a highly expandable Android library for showing loading status view on the low-coupling way, the core function is implemented with a [Kotlin file](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/loadingstateview/src/main/java/com/dylanc/loadingstateview/LoadingStateView.kt) of over 200 lines. it not only shows different view like loading, content, error, empty and customized view when loading network data, but also manages title bar. **Major update: With the Kotlin feature, you can quickly add all functionality to the base class without affecting existing code. The overall usage is further simplified with removing the `ViewHolder`. It is recommended to upgrade!** ## Feature - No need to add view code to the layout. - Quickly add all functionality to the base class without affecting existing code. (Kotlin) - Support for use for Activity, Fragment, RecyclerView, View. - Support for show custom views. - Support for managing the title bar and add multiple headers. - Support for set reload event. - Support for update views anytime. - Support for use with most third-party libraries. ## Demo Click or scan QR code to download [](https://www.pgyer.com/loadinghelper) | [Activity(error)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ActErrorActivity.java) | [View(placeholder)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPlaceholderActivity.java) | [ViewPager(timeout)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPagerActivity.java) | [RecyclerView(cool loading)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/RecyclerViewActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | | [SpecialHeader(custom)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/CustomHeaderActivity.java) | [MultipleHeader(search)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/MultipleHeaderActivity.java) | [SpecialDecorView(scrolling)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ScrollingToolbarActivity.java) | [BottomDecorView(editor)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/BottomEditorActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | ## Usage :pencil: **[>> Usage documentation <<](https://dylancaicoding.github.io/LoadingStateView)** ## Gradle Add it in your root `build.gradle` at the end of repositories: ```groovy allprojects { repositories { // ... maven { url 'https://www.jitpack.io' } } } ``` Add dependencies in your module `build.gradle` : ```groovy dependencies { // java implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview:5.0.0' // kotlin implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview-ktx:5.0.0' } ``` ## Change log [Releases](https://github.com/DylanCaiCoding/LoadingStateView/releases) ## Author's other libraries | Library | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | | [Longan](https://github.com/DylanCaiCoding/Longan) | Probably the best Kotlin utils library for Android. | | [ViewBindingKTX](https://github.com/DylanCaiCoding/ViewBindingKTX) | The most comprehensive utils of ViewBinding. | | [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | Use MMKV with property delegates. | | [MultiBaseUrls](https://github.com/DylanCaiCoding/MultiBaseUrls) | Use annotation to allow Retrofit to support multiple baseUrl and dynamically change baseUrl | | [Tracker](https://github.com/DylanCaiCoding/Tracker) | A lightweight tracking framework based on the tracking idea of Buzzvideo.| ## Thanks - [luckbilly/Gloading](https://github.com/luckybilly/Gloading) Optimize my library standing on the shoulders of giants. - [drakeet/MultiType](https://github.com/drakeet/MultiType) Referenced the usage of multiple adapters. - [dinuscxj/LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable) The cool loading effect in the demo. ## License ``` Copyright (C) 2019. Dylan Cai Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ================================================ FILE: README_ZH.md ================================================ # LoadingStateView [English](README.md) | 中文 [](https://www.jitpack.io/#DylanCaiCoding/LoadingLoadingStateView) [](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/LICENSE) `LoadingStateView` 是一个深度解耦缺省页和标题栏的工具,核心功能的实现代码只有一个 200 多行的 [Kotlin 文件](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/loadingstateview/src/main/java/com/dylanc/loadingstateview/LoadingStateView.kt)。不仅能在请求网络数据时显示加载中、加载成功、加载失败、无数据的视图或自定义视图,还可以对标题栏进行解耦。 **重大更新:结合 Kotlin 语法特性能快速将所有功能集成到基类,不会影响已有代码。移除了 `ViewHolder`,整体用法得到进一步简化,建议升级!** - 无需在布局添加视图代码 - 支持快速集成到基类,并且不影响有代码(仅 Kotlin) - 支持 Activity、Fragment、列表或指定的 View - 支持显示自定义视图 - 支持添加多个头部控件 - 支持设置重新请求数据的事件 - 支持动态更新视图样式 - 可结合绝大部分第三方控件使用 ## 示例 点击或者扫描二维码下载 [](https://www.pgyer.com/loadinghelper) 动态添加加载状态的布局: | [Activity(error)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ActErrorActivity.java) | [View(placeholder)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPlaceholderActivity.java) | [ViewPager(timeout)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPagerActivity.java) | [RecyclerView(cool loading)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/RecyclerViewActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | 动态添加标题栏或装饰容器: | [SpecialHeader(custom)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/CustomHeaderActivity.java) | [MultipleHeader(search)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/MultipleHeaderActivity.java) | [SpecialDecorView(scrolling)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ScrollingToolbarActivity.java) | [BottomDecorView(editor)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/BottomEditorActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | ## 用法 :pencil: **[>> 使用文档 <<](https://dylancaicoding.github.io/LoadingStateView)** ## Gradle 在根目录的 `build.gradle` 添加: ```groovy allprojects { repositories { // ... maven { url 'https://www.jitpack.io' } } } ``` 在模块的 `build.gradle` 添加依赖: ```groovy dependencies { // java implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview:5.0.0' // kotlin implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview-ktx:5.0.0' } ``` ## 更新日志 [Releases](https://github.com/DylanCaiCoding/LoadingStateView/releases) ## 作者其它的库 | 库 | 简介 | | ------------------------------------------------------------ | ---------------------------------------------- | | [Longan](https://github.com/DylanCaiCoding/Longan) | 可能是最好用的 Kotlin 工具库 | | [ViewBindingKTX](https://github.com/DylanCaiCoding/ViewBindingKTX) | 最全面的 ViewBinding 工具 | | [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | 最灵活易用的 MMKV 工具 | | [MultiBaseUrls](https://github.com/DylanCaiCoding/MultiBaseUrls) | 用注解让 Retrofit 同时支持多个 baseUrl 以及动态改变 baseUrl | | [Tracker](https://github.com/DylanCaiCoding/Tracker) | 基于西瓜视频的责任链埋点思路实现的轻量级埋点框架 | ## 感谢 - [luckbilly/Gloading](https://github.com/luckybilly/Gloading) 站在了巨人肩膀上优化了本库,非常感谢! - [drakeet/MultiType](https://github.com/drakeet/MultiType) 参考了注册配置多适配器的思想和用法 - [dinuscxj/LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable) 示例中的自定义加载动画 ## License ``` Copyright (C) 2019. Dylan Cai Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ================================================ FILE: build.gradle ================================================ buildscript { ext.buildConfig = [ 'versionCode' : 1, 'versionName' : "1.0.0", 'compileSdkVersion': 30, 'minSdkVersion' : 14, 'targetSdkVersion' : 30 ] ext { appCompatVersion = '1.3.1' constraintLayoutVersion = '2.1.1' coreVersion = '1.7.0-alpha01' espressoVersion = '3.4.0' glideVersion = '4.12.0' kotlinVersion = "1.5.31" lifecycleVersion = '2.4.0-alpha03' junitExtVersion = '1.1.3' junitVersion = '4.13.2' materialVersion = '1.4.0' viewBindingKTXVersion = '2.1.0' } repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } allprojects { repositories { google() jcenter() maven { url 'https://www.jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir } ================================================ FILE: docs/.nojekyll ================================================ ================================================ FILE: docs/README.md ================================================ # LoadingStateView [](https://www.jitpack.io/#DylanCaiCoding/LoadingLoadingStateView) [](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/LICENSE) [](https://github.com/DylanCaiCoding/LoadingStateView) `LoadingStateView` 是一个深度解耦缺省页和标题栏的工具,核心功能的实现代码只有一个 200 行左右(不算注释)的 [Kotlin 文件](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/loadingstateview/src/main/java/com/dylanc/loadingstateview/LoadingStateView.kt)。不仅能在请求网络数据时显示加载中、加载成功、加载失败、无数据的视图或自定义视图,还可以对标题栏进行解耦。 **重大更新:结合 Kotlin 语法特性能快速将所有功能集成到基类,不会影响已有代码。移除了 `ViewHolder`,整体用法得到进一步简化,建议升级!** - 无需在布局添加视图代码 - 支持快速集成到基类,并且不影响有代码(仅 Kotlin) - 支持 Activity、Fragment、列表或指定的 View - 支持显示自定义视图 - 支持添加多个头部控件 - 支持设置重新请求数据的事件 - 支持动态更新视图样式 - 可结合绝大部分第三方控件使用 ## 示例 点击或者扫描二维码下载 [](https://www.pgyer.com/loadinghelper) 动态添加加载状态的布局: | [Activity(error)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ActErrorActivity.java) | [View(placeholder)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPlaceholderActivity.java) | [ViewPager(timeout)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ViewPagerActivity.java) | [RecyclerView(cool loading)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/RecyclerViewActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | 动态添加标题栏或装饰容器: | [SpecialHeader(custom)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/CustomHeaderActivity.java) | [MultipleHeader(search)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/MultipleHeaderActivity.java) | [SpecialDecorView(scrolling)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ScrollingToolbarActivity.java) | [BottomDecorView(editor)](https://github.com/DylanCaiCoding/LoadingStateView/blob/master/sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/BottomEditorActivity.java) | | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | |  |  |  |  | ## Gradle 在根目录的 `build.gradle` 添加: ```groovy allprojects { repositories { // ... maven { url 'https://www.jitpack.io' } } } ``` 在模块的 `build.gradle` 添加依赖: ```groovy dependencies { // java implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview:5.0.0' // kotlin implementation 'com.github.DylanCaiCoding.LoadingStateView:loadingstateview-ktx:5.0.0' } ``` ## 更新日志 [Releases](https://github.com/DylanCaiCoding/LoadingStateView/releases) ## 作者其它的库 | 库 | 简介 | | ------------------------------------------------------------ | ---------------------------------------------- | | [Longan](https://github.com/DylanCaiCoding/Longan) | 可能是最好用的 Kotlin 工具库 | | [ViewBindingKTX](https://github.com/DylanCaiCoding/ViewBindingKTX) | 最全面的 ViewBinding 工具 | | [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | 用属性委托的方式使用 MMKV | | [Tracker](https://github.com/DylanCaiCoding/Tracker) | 基于西瓜视频的责任链埋点思路实现的轻量级埋点框架 | ## 感谢 - [luckbilly/Gloading](https://github.com/luckybilly/Gloading) 站在了巨人肩膀上优化了本库,非常感谢! - [drakeet/MultiType](https://github.com/drakeet/MultiType) 参考了注册配置多适配器的思想和用法 - [dinuscxj/LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable) 示例中的自定义加载动画 ## License ``` Copyright (C) 2019. Dylan Cai Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ================================================ FILE: docs/_sidebar.md ================================================ * [介绍](/) * [基础用法](/zh/basic-usage) * [Kotlin 委托用法](/zh/delegate) * [结合 ViewBinding 使用](/zh/viewbinding) * [老版本迁移指南](/zh/migration-guide) * [Q&A](/zh/q&a) ================================================ FILE: docs/index.html ================================================
* 使用该基类时注意以下事项:
* 1. 显示对应视图之前需要注册适配器,可以设置全局适配器,某个页面想修改样式时再注册个新的适配器。
* 2. 设置标题栏的方法应该根据项目需要进行编写,下面提供了参考示例。
*
* @author Dylan Cai
*/
@SuppressWarnings("unused")
public class BaseActivity extends AppCompatActivity implements OnReloadListener {
private LoadingStateView loadingStateView;
@Override
public void setContentView(int layoutResID) {
this.setContentView(layoutResID, 0);
}
public void setContentView(int layoutResID, @IdRes int contentViewId) {
super.setContentView(layoutResID);
if (contentViewId == 0) {
loadingStateView = new LoadingStateView(this, this);
} else {
loadingStateView = new LoadingStateView(findViewById(contentViewId));
}
}
/**
* 添加标题栏的示例方法,请根据自己的需求进行修改
*/
public void setToolbar(String title) {
setToolbar(title, NavIconType.BACK, 0);
}
public void setToolbar(String title, NavIconType type) {
setToolbar(title, type, 0);
}
public void setToolbar(String title, NavIconType type, int menuId) {
loadingStateView.setHeaders(new ToolbarViewDelegate(title, type, menuId, this::onOptionsItemSelected));
}
public void showLoadingView() {
loadingStateView.showLoadingView();
}
public void showContentView() {
loadingStateView.showContentView();
}
public void showErrorView() {
loadingStateView.showErrorView();
}
public void showEmptyView() {
loadingStateView.showEmptyView();
}
public void showCustomView(Object viewType) {
loadingStateView.showView(viewType);
}
@Override
public void onReload() {
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/BottomEditorDecorViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.NonNull;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.utils.KeyboardUtils;
import org.jetbrains.annotations.NotNull;
/**
* @author Dylan Cai
*/
public class BottomEditorDecorViewDelegate extends LoadingStateView.DecorViewDelegate {
private final OnSendListener onSendListener;
public BottomEditorDecorViewDelegate(OnSendListener onSendListener) {
this.onSendListener = onSendListener;
}
@NotNull
@Override
@SuppressLint("InflateParams")
public View onCreateDecorView(@NonNull Context context, @NotNull LayoutInflater inflater) {
View view = inflater.inflate(R.layout.layout_bottom_editor, null);
EditText edtContent = view.findViewById(R.id.edt_content);
view.findViewById(R.id.btn_send).setOnClickListener(v -> {
if (onSendListener != null) {
onSendListener.onSend(edtContent.getText().toString());
edtContent.setText("");
KeyboardUtils.hideKeyboard(edtContent);
}
});
return view;
}
@NotNull
@Override
public ViewGroup getContentParent(@NotNull View decorView) {
return decorView.findViewById(R.id.content_parent);
}
public interface OnSendListener {
void onSend(String content);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/CoolLoadingViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class CoolLoadingViewDelegate extends LoadingStateView.ViewDelegate {
public CoolLoadingViewDelegate() {
super(ViewType.LOADING);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return inflater.inflate(R.layout.layout_cool_loading, parent, false);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/CustomHeaderViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import android.app.Activity;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class CustomHeaderViewDelegate extends LoadingStateView.ViewDelegate {
private final View.OnClickListener onMessageClickListener;
private final int firstDrawableId;
private final View.OnClickListener onFirstBtnClickListener;
private final int secondDrawableId;
private final View.OnClickListener onSecondBtnClickListener;
public CustomHeaderViewDelegate(View.OnClickListener onMessageClickListener, int firstDrawableId,
View.OnClickListener onFirstBtnClickListener, int secondDrawableId,
View.OnClickListener onSecondBtnClickListener) {
super(ViewType.TITLE);
this.onMessageClickListener = onMessageClickListener;
this.firstDrawableId = firstDrawableId;
this.onFirstBtnClickListener = onFirstBtnClickListener;
this.secondDrawableId = secondDrawableId;
this.onSecondBtnClickListener = onSecondBtnClickListener;
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_custom_header, parent, false);
ImageView btnFirst = view.findViewById(R.id.btn_first);
ImageView btnSecond = view.findViewById(R.id.btn_second);
View btnMessage = view.findViewById(R.id.btn_message);
Activity activity = (Activity) view.getContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
btnMessage.setOnClickListener(onMessageClickListener);
btnFirst.setImageDrawable(ContextCompat.getDrawable(activity, firstDrawableId));
btnFirst.setOnClickListener(onFirstBtnClickListener);
btnSecond.setImageDrawable(ContextCompat.getDrawable(activity, secondDrawableId));
btnSecond.setOnClickListener(onSecondBtnClickListener);
return view;
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/EmptyViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class EmptyViewDelegate extends LoadingStateView.ViewDelegate {
public EmptyViewDelegate() {
super(ViewType.EMPTY);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return inflater.inflate(R.layout.layout_empty, parent, false);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/ErrorViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class ErrorViewDelegate extends LoadingStateView.ViewDelegate {
public ErrorViewDelegate() {
super(ViewType.ERROR);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_error, parent, false);
view.findViewById(R.id.btn_reload).setOnClickListener(v -> {
if (getOnReloadListener() != null) {
getOnReloadListener().onReload();
}
});
return view;
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/LoadingViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class LoadingViewDelegate extends LoadingStateView.ViewDelegate {
public int height = ViewGroup.LayoutParams.MATCH_PARENT;
public LoadingViewDelegate() {
super(ViewType.LOADING);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_loading, parent, false);
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.height = height;
view.setLayoutParams(layoutParams);
return view;
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/NavIconType.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
/**
* @author Dylan Cai
*/
public enum NavIconType {
BACK, NONE
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/NothingViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
/**
* @author Dylan Cai
*/
public class NothingViewDelegate extends LoadingStateView.ViewDelegate {
public NothingViewDelegate() {
super(ViewType.EMPTY);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return new View(parent.getContext());
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/PlaceholderViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class PlaceholderViewDelegate extends LoadingStateView.ViewDelegate {
public PlaceholderViewDelegate() {
super(ViewType.LOADING);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
return inflater.inflate(R.layout.layout_placeholder, parent, false);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/ScrollingDecorViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.sample.java.R;
import org.jetbrains.annotations.NotNull;
/**
* @author Dylan Cai
*/
public class ScrollingDecorViewDelegate extends LoadingStateView.DecorViewDelegate {
private final String title;
public ScrollingDecorViewDelegate(String title) {
this.title = title;
}
@NotNull
@Override
@SuppressLint("InflateParams")
public View onCreateDecorView(@NonNull Context context, @NotNull LayoutInflater inflater) {
View view = inflater.inflate(R.layout.layout_scrolling_toolbar, null);
Activity activity = (Activity) inflater.getContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
Toolbar toolbar = view.findViewById(R.id.toolbar);
toolbar.setTitle(title);
toolbar.setNavigationOnClickListener(v -> activity.finish());
return view;
}
@NotNull
@Override
public ViewGroup getContentParent(@NotNull View decorView) {
return decorView.findViewById(R.id.content_parent);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/SearchHeaderViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import androidx.annotation.NonNull;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.utils.KeyboardUtils;
/**
* @author Dylan Cai
*/
public class SearchHeaderViewDelegate extends LoadingStateView.ViewDelegate{
public static final String VIEW_TYPE_SEARCH = "search";
private final OnSearchListener onSearchListener;
public SearchHeaderViewDelegate(OnSearchListener onSearchListener) {
super(VIEW_TYPE_SEARCH);
this.onSearchListener = onSearchListener;
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_search_header, parent, false);
EditText edtSearch = view.findViewById(R.id.edt_search);
edtSearch.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
KeyboardUtils.hideKeyboard(edtSearch);
if (onSearchListener != null) {
onSearchListener.onSearch(edtSearch.getText().toString());
}
return true;
}
return false;
});
return view;
}
public interface OnSearchListener {
void onSearch(String keyword);
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/TimeoutViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.sample.java.R;
/**
* @author Dylan Cai
*/
public class TimeoutViewDelegate extends LoadingStateView.ViewDelegate {
public static final String VIEW_TYPE_TIMEOUT = "timeout";
public TimeoutViewDelegate() {
super(VIEW_TYPE_TIMEOUT);
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_timeout, parent, false);
view.setOnClickListener(v -> {
if (getOnReloadListener() != null) {
getOnReloadListener().onReload();
}
});
return view;
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/delegate/ToolbarViewDelegate.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.delegate;
import android.app.Activity;
import android.os.Build;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
import org.jetbrains.annotations.NotNull;
import kotlin.jvm.functions.Function1;
/**
* @author Dylan Cai
*/
public class ToolbarViewDelegate extends LoadingStateView.ViewDelegate {
private final String title;
private final NavIconType type;
private final int menuId;
private final Function1 super MenuItem, Boolean> onMenuItemClick;
public ToolbarViewDelegate(String title, NavIconType type) {
this(title, type, 0, null);
}
public ToolbarViewDelegate(String title, NavIconType type, int menuId, Function1 super MenuItem, Boolean> onMenuItemClick) {
super(ViewType.TITLE);
this.title = title;
this.type = type;
this.menuId = menuId;
this.onMenuItemClick = onMenuItemClick;
}
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
View view = inflater.inflate(R.layout.layout_toolbar, parent, false);
Activity activity = (Activity) view.getContext();
Toolbar toolbar = view.findViewById(R.id.toolbar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
if (!TextUtils.isEmpty(title)) {
toolbar.setTitle(title);
}
if (type == NavIconType.BACK) {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black);
toolbar.setNavigationOnClickListener(v -> activity.finish());
} else {
toolbar.setNavigationIcon(null);
}
if (menuId > 0 && onMenuItemClick != null) {
toolbar.inflateMenu(menuId);
toolbar.setOnMenuItemClickListener(onMenuItemClick::invoke);
}
return view;
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/ActErrorActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.OnReloadListener;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.utils.HttpUtils;
import com.dylanc.loadingstateview.sample.java.utils.ToolbarUtils;
/**
* @author Dylan Cai
*/
public class ActErrorActivity extends AppCompatActivity implements OnReloadListener {
private LoadingStateView loadingStateView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_content);
loadingStateView = ToolbarUtils.setToolbar(this, "Activity(error)", NavIconType.BACK);
loadingStateView.setOnReloadListener(this);
loadData();
}
private void loadData() {
loadingStateView.showLoadingView();
HttpUtils.requestFailure(new HttpUtils.Callback() {
@Override
public void onSuccess() {
loadingStateView.showContentView();
}
@Override
public void onFailure() {
loadingStateView.showErrorView();
}
});
}
@Override
public void onReload() {
loadingStateView.showLoadingView();
HttpUtils.requestSuccess(new HttpUtils.Callback() {
@Override
public void onSuccess() {
loadingStateView.showContentView();
}
@Override
public void onFailure() {
loadingStateView.showErrorView();
}
});
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/BottomEditorActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.BottomEditorDecorViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.NothingViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.utils.HttpUtils;
import com.dylanc.loadingstateview.sample.java.utils.ToolbarUtils;
/**
* @author Dylan Cai
*/
public class BottomEditorActivity extends AppCompatActivity implements BottomEditorDecorViewDelegate.OnSendListener {
private LoadingStateView loadingStateView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_content);
loadingStateView = ToolbarUtils.setToolbar(this, "BottomDecorView(editor)", NavIconType.BACK);
loadingStateView.addChildDecorView(new BottomEditorDecorViewDelegate(this));
loadingStateView.register(new NothingViewDelegate());
loadingStateView.showEmptyView();
}
@Override
public void onSend(String content) {
loadingStateView.showLoadingView();
HttpUtils.requestSuccess(new HttpUtils.Callback() {
@Override
public void onSuccess() {
loadingStateView.showContentView();
}
@Override
public void onFailure() {
loadingStateView.showErrorView();
}
});
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/CustomHeaderActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.ui.fragment.SimpleFragment;
import com.dylanc.loadingstateview.sample.java.utils.ToolbarUtils;
import com.google.android.material.tabs.TabLayout;
/**
* @author Dylan Cai
*/
public class CustomHeaderActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager);
ToolbarUtils.setCustomToolbar(this, this::onMessageClick,
R.drawable.ic_baseline_photo_camera_24, this::onFirstBtnClick,
R.drawable.ic_baseline_favorite_24, this::onSecondBtnClick);
// This TabLayout is in the custom toolbar.
TabLayout tabLayout = findViewById(R.id.tab_layout);
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(new TabPagerAdapter(getSupportFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
}
private void onMessageClick(View view) {
Toast.makeText(this, "message", Toast.LENGTH_SHORT).show();
}
private void onFirstBtnClick(View view) {
Toast.makeText(this, "camera", Toast.LENGTH_SHORT).show();
}
private void onSecondBtnClick(View view) {
Toast.makeText(this, "favorite", Toast.LENGTH_SHORT).show();
}
public static class TabPagerAdapter extends FragmentPagerAdapter {
public TabPagerAdapter(FragmentManager fm) {
super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
@NonNull
@Override
public Fragment getItem(int i) {
return new SimpleFragment();
}
@Override
public int getCount() {
return 2;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return "tab " + position;
}
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/FragmentEmptyActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.ui.fragment.EmptyFragment;
import com.dylanc.loadingstateview.sample.java.utils.ToolbarUtils;
/**
* @author Dylan Cai
*/
public class FragmentEmptyActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
ToolbarUtils.setToolbar(this,"Fragment(empty)", NavIconType.BACK);
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.content_view, new EmptyFragment());
transaction.commit();
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/MainActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.base.BaseActivity;
/**
* @author Dylan Cai
*/
public class MainActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setToolbar(getString(R.string.app_name), NavIconType.NONE, R.menu.menu_about);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.about) {
Uri uri = Uri.parse("https://github.com/DylanCaiCoding/LoadingHelper");
Intent intent = new Intent("android.intent.action.VIEW", uri);
startActivity(intent);
}
return true;
}
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_activity_error:
startActivity(new Intent(this, ActErrorActivity.class));
break;
case R.id.btn_fragment_empty:
startActivity(new Intent(this, FragmentEmptyActivity.class));
break;
case R.id.btn_view_placeholder:
startActivity(new Intent(this, ViewPlaceholderActivity.class));
break;
case R.id.btn_viewpager_timeout:
startActivity(new Intent(this, ViewPagerActivity.class));
break;
case R.id.btn_recyclerview_loading:
startActivity(new Intent(this, RecyclerViewActivity.class));
break;
case R.id.btn_custom_header:
startActivity(new Intent(this, CustomHeaderActivity.class));
break;
case R.id.btn_search_header:
startActivity(new Intent(this, MultipleHeaderActivity.class));
break;
case R.id.btn_scrolling:
startActivity(new Intent(this, ScrollingToolbarActivity.class));
break;
case R.id.btn_bottom_editor:
startActivity(new Intent(this, BottomEditorActivity.class));
break;
}
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/MultipleHeaderActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.NothingViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.SearchHeaderViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.ToolbarViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.utils.HttpUtils;
/**
* @author Dylan Cai
*/
public class MultipleHeaderActivity extends AppCompatActivity implements SearchHeaderViewDelegate.OnSearchListener {
private LoadingStateView loadingStateView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_content);
loadingStateView = new LoadingStateView(this);
loadingStateView.register(new NothingViewDelegate());
loadingStateView.setHeaders(
new ToolbarViewDelegate("MultipleHeader(search)", NavIconType.BACK),
new SearchHeaderViewDelegate(this)
);
loadingStateView.showEmptyView();
}
@Override
public void onSearch(String keyword) {
Toast.makeText(this, "search: " + keyword, Toast.LENGTH_SHORT).show();
loadingStateView.showLoadingView();
HttpUtils.requestSuccess(new HttpUtils.Callback() {
@Override
public void onSuccess() {
loadingStateView.showContentView();
}
@Override
public void onFailure() {
loadingStateView.showErrorView();
}
});
}
}
================================================
FILE: sample-java/src/main/java/com/dylanc/loadingstateview/sample/java/ui/RecyclerViewActivity.java
================================================
/*
* Copyright (c) 2019. Dylan Cai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dylanc.loadingstateview.sample.java.ui;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.dylanc.loadingstateview.LoadingStateView;
import com.dylanc.loadingstateview.ViewType;
import com.dylanc.loadingstateview.sample.java.R;
import com.dylanc.loadingstateview.sample.java.delegate.CoolLoadingViewDelegate;
import com.dylanc.loadingstateview.sample.java.delegate.NavIconType;
import com.dylanc.loadingstateview.sample.java.utils.HttpUtils;
import com.dylanc.loadingstateview.sample.java.utils.ToolbarUtils;
/**
* @author Dylan Cai
*/
public class RecyclerViewActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view);
ToolbarUtils.setToolbar(this,"RecyclerView(cool loading)", NavIconType.BACK);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(new ImageAdapter());
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
}
public static class ImageAdapter extends RecyclerView.Adapter