增加了显示当月总收入和总支出的功能,增加了选择收支类型的功能,删去了删除账目后恢复的功能。

1、数据库的升级

1、entity

添加了一个收支类型的字段:

package com.example.cashbook;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity
public class Notes {
@PrimaryKey(autoGenerate = true)
private int id;

@ColumnInfo(name = "money")
private int money;

@ColumnInfo(name = "money_data")
private String moneyData;

@ColumnInfo(name = "other_info")
private String otherInfo;

@ColumnInfo(name = "money_type")
private String moneyType;

public Notes() {
}

public Notes(int money, String moneyData, String otherInfo, String moneyType) {
this.money = money;
this.moneyData = moneyData;
this.otherInfo = otherInfo;
this.moneyType = moneyType;
}

public String getMoneyType() {
return moneyType;
}

public void setMoneyType(String moneyType) {
this.moneyType = moneyType;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getMoney() {
return money;
}

public void setMoney(int money) {
this.money = money;
}

public String getMoneyData() {
return moneyData;
}

public void setMoneyData(String moneyData) {
this.moneyData = moneyData;
}

public String getOtherInfo() {
return otherInfo;
}

public void setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo;
}
}

2、dao

增加了查询所有支出和收入的金额:

package com.example.cashbook;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface NotesDao {

@Insert
void insertNote(Notes... notes);

@Update
void updateNote(Notes... notes);

@Query("select * from notes")
LiveData<List<Notes>> getNotesList();

@Query("select * from notes where other_info like :pattern order by id desc")
LiveData<List<Notes>> getNotesByPattern(String pattern);

@Query("select money from notes where money_type = :pattern")
List<Integer> getMoneyListByPattern(String pattern);

@Delete
void deleteNote(Notes... notes);
}

3、database

为方便使用,使得数据库的操作可以在主线程中执行:

package com.example.cashbook;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

@Database(entities = {Notes.class},version = 2,exportSchema = false)
public abstract class NotesDatabase extends RoomDatabase {
private static NotesDatabase INSTANCE;

static synchronized NotesDatabase getDatabase(Context context){
if (INSTANCE == null){
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),NotesDatabase.class,"notes_database")
.addMigrations(VERSION_1_2)
.allowMainThreadQueries()
.build();
}
return INSTANCE;
}

public abstract NotesDao getNotesDao();

private static final Migration VERSION_1_2 = new Migration(1,2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE notes ADD COLUMN money_type varchar");
}
};
}

4、viewmodel

增加了获取总支出和总收入金额的方法:

package com.example.cashbook;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import java.util.List;

public class NotesViewModel extends AndroidViewModel {
private NotesRepository repository;

public NotesViewModel(@NonNull Application application) {
super(application);
repository = new NotesRepository(application);
}

public void updateNote(Notes... notes){
repository.updateNote(notes);
}

public void insertNote(Notes... notes){
repository.insertNote(notes);
}

public LiveData<List<Notes>> getAllList(){
return repository.getNotesList();
}

public LiveData<List<Notes>> getAllListByPattern(String pattern){
return repository.getNotesListByPattern(pattern);
}

public void deleteNote(Notes... notes){
repository.deleteNote(notes);
} //获得总收入
public int getMoneyIn(){
List<Integer> moenyIn = repository.getMoenyIn();
int sum = 0;
for (Integer integer : moenyIn) {
sum += integer.intValue();
}
return sum;
}

//获得总支出
public int getMoneyOut(){
List<Integer> moenyOut = repository.getMoenyOut();
int sum = 0;
for (Integer integer : moenyOut) {
sum += integer.intValue();
}
return sum;
}
}

2、布局的修改

在recyclerview上方添加了一个cardview,用来显示总支出和总收入。

记账本APP小升级的更多相关文章

  1. 安卓开发实战-记账本APP(六)

    记账本APP开发---终结篇 昨天的动态数字录屏奉上:在抖音上拍了一个(ps:欢迎点赞) https://v.douyin.com/poEjmG/ 今天将图表的内容进行了制作,我用的是MPChart的 ...

  2. 记账本APP(2)

    今天下载了Hbuiler,生成了一个记账本APP,目前里面只可以 输入今日消费 明天将会做出来记录以及计算总额于月消费.

  3. 简单记账本APP开发一

    在对Android的一些基础的知识有了一定了解,以及对于AndroidStudio的如何使用有了 一定的熟悉后,决定做一个简单的记账本APP 开发流程 1.记账本的页面 2.可以添加新的账目 (一)页 ...

  4. 家庭版记账本app开发完成

    经过这几天关于android的相关学习,对于家庭版记账本app以及开发结束. 实现的功能为:用户的注册.登录.添加支出账单.添加收入账单.显示所有的该用户的账单情况(收入和支出).生产图表(直观的显示 ...

  5. 进度1_家庭记账本App

    今天完成了昨天的初步构想,详细介绍见上一篇博客,具体项目结构和案例如下: MainActivity.java: package com.example.familybooks; import andr ...

  6. 安卓开发实战-记账本APP(四)

    今天实现的内容有:添加账本信息,个人头像的切换,密码的修改,退出登录. 添加账本信息有三个功能: ①记一笔支出项目 ②记一笔收入项目 ③清空所有项目 在此期间遇到的困难有:Activity与Fragm ...

  7. 记账本app(一)

    计划开发一款小程序应用,主要来记录自己的财务账目. 通过使用SpringBoot开发后端应用,提供接口,对应前端使用微信小程序来实现. 功能模块(用户信息,账本.账目列表,新增一笔账,修改一笔账,删除 ...

  8. 安卓开发实战-记账本APP(三)

    本次实现的是有关登录,注册和整体页面的改观,实现下方选项导致页面的切换效果. 利用到的技术有Sqlite数据库的增删改查,与fragment实现.由于暂时没有找到合适的图标,先借用微信的图标暂代一下. ...

  9. 家庭版记账本app开发进度相关界面的规划

    总的app界面包括四个页面,页面可以来回滑动.设计的时候就和微信的四个页面类似. 由于没有找到合适的图标进行替换,在此仍应用微信对应的四个图标. 总的四个页面是: 1.增加收入或者支出的小账单.当点击 ...

随机推荐

  1. 腾讯云--腾讯云sdk-实现脚本修改腾讯云负载均衡权重

    一.请确认你的当前python环境为python 2.x 获取 python 版本的方法 (linux shell) # python -v python 2.7.11 二.CLB SDK下载与配置 ...

  2. CC模型加载太慢?一招破解!

    伴随无人机性能的提升,单个项目涉及到的倾斜摄影数据范围不断扩大,模型的数据量越来越大,在同配置机器上的显示速度也相应的越来越慢,那么如何在不升级配置的情况下提升模型的加载速度呢? 01 百GB倾斜摄影 ...

  3. 不同角度看Handler——另类三问

    之前有一章节介绍了Handler的常见面试题,今天就来说说另类的,可能你没关注的其他问题,一起看看吧. 系统为什么提供Handler 这点大家应该都知道一些,就是为了切换线程,主要就是为了解决在子线程 ...

  4. ASP.NET Core管道详解[3]: Pipeline = IServer + IHttpApplication

    ASP.NET Core的请求处理管道由一个服务器和一组中间件构成,但对于面向传输层的服务器来说,它其实没有中间件的概念.当服务器接收到请求之后,会将该请求分发给一个处理器进行处理,对服务器而言,这个 ...

  5. vue中插值表达式中时间转换yyyy-MM-dd HH:mm:ss

    vue插值表达式中将时间转换两种方式:一.定义方法 <div id="app">当前实时时间:{{dateFormat(date)}}</div> //时间 ...

  6. Hadoop分布式平台搭建

    环境:CentOS 7.4 (1708  DVD) 工具:MobaXterm 一. 安装 1. 将hadoop安装包上传到/usr/local目录下,将其解压并重命名. 2. 配置hadoop的环境变 ...

  7. 全面解析RayFire的动态对象与静态对象

    我们在日常使用RayFire的过程中,接触得比较多的应该就是RayFire的对象设置了.RayFire的对象包含了动态对象.静态对象与休眠对象,其中动态对象.静态对象可以结合动力学.运动学概念设置动作 ...

  8. C语言讲义——结构化编程(分支、循环)

    顺序结构(从上到下) 分支结构(也叫选择结构) 循环结构 分支结构 if...else 最基本的分支结构是if(){}else{}. 为了代码的安全,同时也是出于代码规范的考虑,if()后面一定要加花 ...

  9. 深度阅读:大学生课外知识补充,这些课堂上不教的 C++ 的基本特性你都知道吗?

    来源:知乎 王师傅的专栏 C++ 作为一个历史久远,功能丰(yong)富(zhong)而且标准与时俱进的语言,理应什么都能做,什么都用得起来.不过日常使用中我们初学者真的好像只学到了其中的一部分,对于 ...

  10. 编程语言输出“ Hello World ”,你真的都会了吗?

    Hello World 中文意思是『你好,世界』.因为<The C Programming Language>中使用它做为第一个演示程序,非常著名,所以后来的程序员在学习编程或进行设备调试 ...