前言
代码实现部分较为冗长,代码部分后面我会给出GitHub仓库地址。插件统计出来的代码量有点夸张,实际上没这么多,关键地方使用了第三方来解决问题。所以详细开发过程我就不讲述了,GitHub的代码仓库里有注释!
一、开发环境
- 开发环境:Android studio 3.5
- 版本控制:GitHub
- 运行平台:Android5.1以上
二、模式和第三方库
1、软件模式——MVVM
2、用到的第三方库
Gson gson:2.8.4
日历 material-calendarview:1.4.3
选择器 Android-PickerView:4.1.9
图表 MPAndroidChart:v3.0.3
SwipeRecyclerView recyclerview:x:1.3.2
网格布局分页 PageGridView:1.2.1
3、Google官方库
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
def room_version = '2.2.1'
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
def lifecycle_version = "2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
三、开发总结
该软件的构建遵循一定的技术规范、代码风格。虽然这仅是一个类似于简单的记账APP,首先该软件采用的是MVVM的软件模式,为MVC的进化版本。MVVM 就是将其中的View 的状态和行为抽象化,让我们将视图UI和业务逻辑分开。当然这些事 ViewModel 已经帮我们做了,它可以取出Model的数据同时帮忙处理View 中由于需要展示内容而涉及的业务逻辑。
该模式需要ViewModel来配合使用,数据库使用ROOM来封装,大大简化了SQL语句的编写,对数据库的操作是极其耗时的。我们定义了Dao接口和单实例抽象类,之后实现时采用了异步线程。将数据库获取的数据使用LIveData封装,使Activity和Fragment作为观察者能够动态感知数据库的数据变化,并通知更新界面。在标签界面采用了DataBinding,降低布局和逻辑的耦合性,使代码逻辑更加清晰。
在主页的导航上,我使用了谷歌原生BottomNavigationView进行底部的导航。同一个Activity上管理着多个fragment。Fragment之间传递对象数据时用gson先将其序列化,之后再反序列化。在列表显示里使用了RecycleView。图表显示采用了强大的第三封装好的绘图库,当然还有其他的布局可以通过查阅其文档来结合自身需求进行个性化。
软件中的标签图像来自阿里巴巴矢量图库,免费开源。其他的系统图标为Android官方提供的开源矢量图。
查阅了大量的Google Android的官方开发文档,虽然这仅是一个简单的APP,但其设计原则以及各类依赖项均是较是较新的
Github仓库地址 代码可下载编译直接运行
本系列教程到此完结,软件界面见《从零开始的记账本开发》第0篇 背景介绍及软件界面