• Stars
    star
    229
  • Rank 174,666 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📬 The LifecycleModel class is designed to store and manage UI-related data in a lifecycle conscious way, the LifecycleModel class allows data to survive configuration changes such as screen rotations, it also handles the communication of the Activity / Fragment with the rest of the application, base on https://developer.android.google.cn/topic/libraries/architecture/viewmodel.html

LifecycleModel

Jcenter Build Status Android Arsenal API License Author QQ-Group

The LifecycleModel class is designed to store and manage UI-related data in a lifecycle conscious way, the LifecycleModel class allows data to survive configuration changes such as screen rotations, it also handles the communication of the Activity / Fragment with the rest of the application, base on ViewModel

Introduction

LifecycleModel 基于 Google 在 2017 年 I/O 大会上发布的 Android 架构组件中的 ViewModel, 可以帮助 ActivityFragment 储存和管理一些与 UI 相关以及他们必需的数据, 避免数据在屏幕旋转或配置更改时发生的数据丢失, 还可以帮助开发者轻易实现 FragmentFragment 之间, ActivityFragment 之间的通讯以及共享数据, 因为我看到 Google 让 MVVM 框架中的 ViewModel 具有了这些功能, 所以我也想让 MVP 框架中的 Presenter, 乃至其他更多的模块都具有这些功能, 所以 LifecycleModel 诞生了

框架的分析和思路

Lifecycle

lifecycle

Download

 implementation 'me.jessyan:lifecyclemodel:1.0.1'

Usage

Step 1

 public class UserLifecycleModel implements LifecycleModel {
         private int id;
 
         public UserLifecycleModel(int id) {
             this.id = id;
         }
         
         void doAction() {
         
         }
 
         @Override
         public void onCleared() {
             //release resources
         }
     }

Step 2

 //Put data
 LifecycleModelProviders.of(activity/fragment).put(UserLifecycleModel.class.getName(), new UserLifecycleModel(1));  

 //Get data
 LifecycleModelProviders.of(activity/fragment).get(UserLifecycleModel.class.getName());  
 
 //Remove data
 LifecycleModelProviders.of(activity/fragment).remove(UserLifecycleModel.class.getName());

Communication of the Activity / Fragment

 public class UserLifecycleModel implements LifecycleModel {
     private Subject<String, String> mSubject = PublishSubject.create();

     public void doAction(String s) {
         mSubject.onNext(s);
     }

     public void addAction(Action1<String> action) {
         mSubject.subscribe(action);
     }
 }
 
 public class AFragment extends Fragment {
     @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
         lifecycleModel.addAction(new Action1<String>() {
             @Override
             public void call(String s) {
                 // Update the UI.
             }
         });
     }
 }
 
 public class BFragment extends Fragment {
     @Override
     public void onStart() {
         super.onStart();
         UserLifecycleModel lifecycleModel = LifecycleModelProviders.of(getActivity()).get(UserLifecycleModel.class.getName());
         lifecycleModel.doAction("JessYan");
     }
 }

About Me

License

 Copyright 2017, jessyan

   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.

More Repositories

1

AndroidAutoSize

🔥 A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).
Java
13,018
star
2

MVPArms

⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Java
10,269
star
3

ProgressManager

⏳ Listen the progress of downloading and uploading in Okhttp, compatible Retrofit and Glide (一行代码即可监听 App 中所有网络链接的上传以及下载进度, 包括 Glide 的图片加载进度).
Java
2,612
star
4

RetrofitUrlManager

🔮 Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
Java
2,114
star
5

ArmsComponent

📦 A complete android componentization solution, powered by MVPArms (MVPArms 官方快速组件化方案).
Java
1,691
star
6

MVPArt

🎨 A new Android MVP architecture (此框架旨在解决传统 MVP 类和接口太多, 并且 Presenter 和 View 通过接口通信过于繁琐, 重用 Presenter 代价太大等问题).
Java
782
star
7

InsGallery

📸 Instagram-like image picker for Android (一款 UI 炫酷高仿 Instagram 的图片、视频选择器)
Java
636
star
8

ArmsComponent-Template

🛠️ 一键搭建 ArmsComponent 快速组件化方案的整体组件架构, 让新手也可以一秒开始组件化项目, 开发神器, 让您一秒起飞, 体验纯傻瓜式的组件化开发, 避免组件化从入门到放弃!
FreeMarker
345
star
9

MVPArms-Module-Template

🛠 一键搭建 MVPArms 的官方架构, 让新手一秒即可开启 MVPArms 的世界, 免于项目繁琐配置的烦恼
FreeMarker
244
star
10

CameraFilters

📷 摄像头实时滤镜处理库,自带10多种滤镜,支持滤镜扩展,并且兼容七牛云直播滤镜处理
Java
187
star
11

RxErrorHandler

🗑 Error Handle Of Rxjava
Java
164
star
12

MobileSafe

🛡 下载过三万并且非常适合初学者学习的一个项目(没错就是黑马手机卫士)
Java
159
star
13

WideEyes

👁️ 源于{开眼视频},架构使用Mvp+Dagger2+Retrofit+Rxjava的一款内外兼得的学习项目
Java
70
star
14

AudioManagerSDK

智播项目(应用场景)专门用于处理录音逻辑的SDK
Java
56
star
15

RaiseManagerSDK

智播项目,教育类应用场景之举手发言
12
star
16

JessYanCoding

3
star