Coder Social home page Coder Social logo

timelock's Introduction

TimeLock

控制 android app 的使用时段, MVVM DataBinding

具体功能

请看早期版本Lock

结构

长期驻后台的监控进程 + 显示界面的主进程

  1. common 通用
  2. monitor 后台监控
  3. main 界面

MVVM实践

  • main
    • entity 所有封装数据的实体
    • event +RxBus 传递消息
    • model 从后台获取数据
    • modules 根据界面功能划分模块(View+ViewModel)
      • lock 列出所有的app,lock,增删lock
      • usage 展示app的使用时间统计
      • setting
      • about

基于DataBinding解耦/模板化View+ViewModel

栗子:branch:messUsage --> cleanUsage --> (cleanerUsage)
  1. View : Activity,Fragment

    ViewModel : ActivityModel,FragmentModel

  2. View 只关注UI变换,不持有数据引用

    • onCreate 创建ViewModel,传递原始数据

    • onCreateView/inflate 获取Databinding,绑定ViewModel+XML

    • onDestroy 销毁ViewModel

    • View分层

      • ? 共用一个顶层ViewModel
      • activity/fragment
      • adapter/customView
      • 父View创建子View,传递顶层View、ViewModel,提供UI交互方法
      • 父View监听子View的整体性事件
      • 子View调用顶层View的方法完成内部事件监听
  3. ViewModel 只关注data的获取、变换、分发,持有数据引用

    • getXxx
    • setXxx
    • destroy 由View调用,销毁所有引用
  4. 所有要显示的数据由ViewModel提供

    • View.onCreateView binding.setValue(BR.xxxModel,xxxModel);
    • XML "@{xxxModel.getXxx()}"
    • xml只绑定xxxModel???还是绑定所有需要的entity???
  5. 监听器绑定

    • 修改数据

      • XML xxxModel.getEntity.setter
      • XML xxxModel.set/saveXxx()
      • View xxxModel.setXxx()
    • 视图变换

      • 简单效果翻转变换 XML
      • 界面跳转/打开/关闭 View
      • 界面跳转+数据保存 View+xxxModel.setXxx()
  6. adapter

    • 视为子View

    • 传递view.xxxModel 父View

    • inflate时获取DataBinding,getItemView时绑定数据

    • 多层View嵌套,顶层View提供方法,子View内部调用并绑定监听器

    • 父View实例化子View,

  7. View与ViewModel线程切换

    • ViewModel只处理数据,同步获取数据,不关心线程问题
    • View认为调用的ViewModel方法可能耗时长,可通过Rx切换线程异步调用

timelock's People

Contributors

ruiaa avatar

Stargazers

chonamdoo avatar

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.