Skip to content

Commit

Permalink
step6
Browse files Browse the repository at this point in the history
  • Loading branch information
guohuan78 committed Dec 17, 2022
1 parent 974907c commit 93dcb7e
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 19 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,24 @@

![step5图1主界面右上角更多图标展示](img/step5_5.png)

### step6

1. 添加在固定时间指定备注的功能。目前为11点之前默认早饭,11\~16点午饭,16\~24点晚饭。
2. 添加恩格尔系数计算功能。根据定义,这里选取的生存性的食物只有三餐。很多有趣的提示语等待发现哦
3. 记录界面可以修改备注。在记录界面点击要修改的记录,直接输入新的备注内容即可。
4. 实现更改类别名称功能。输入待修改的名称,再输入新的名称。修改通过触发器实现级联更新,已经存在的记账条目中匹配的类别名称也会被修改。

| 主界面增加根据时间填备注 | 设置界面添加两个新功能 | 记录界面可修改备注 |
| :--------------------------------------------------: | :------------------------------------------------: | :--------------------------------------------: |
| ![step6图1主界面增加根据时间填备注](img/step6_1.png) | ![step6图2设置界面添加两个新功能](img/step6_2.png) | ![step6图3记录界面可修改备注](img/step6_3.png) |
| **恩格尔系数计算** | **更改类别名称** | **更改类别后首界面展示** |
| ![step6图4恩格尔系数计算](img/step6_4.png) | ![step6图5更改类别名称](img/step6_5.png) | ![step6图6更改后首界面展示](img/step6_6.png) |

### todo

1. 尝试写一下大作业的报告,遇到问题有需要补充的再继续开发
2. 添加在固定时间指定备注的功能 √
3. 添加恩格尔系数视图 √
4. 添加定时记账功能
5. 备份功能
6. 在记录界面添加点击弹出修改框可以修改备注的功能 √
明天ddl

1. 继续补充报告,遇到问题有需要补充的再继续开发
2. 制作演示视频
3. 添加周期性定时记账功能
4. 备份功能
Binary file added app/release/easy_bookkeeping_step6.apk
Binary file not shown.
46 changes: 43 additions & 3 deletions app/src/main/java/com/eb/easy_bookkeeping/SettingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.eb.easy_bookkeeping.db.DBManager;
import com.eb.easy_bookkeeping.frag_record.BaseRecordFragment;

public class SettingActivity extends AppCompatActivity {

Expand All @@ -27,11 +29,44 @@ public void onClick(View view) {
showDeleteDialog();
break;
case R.id.setting_tv_engel:
showEngelCoefficient();
showEngelCoefficientDialog();
break;
case R.id.setting_tv_change_typename:
changeTypenameDialog();
break;
}
}

private void changeTypenameDialog() {
final EditText inputServerSrc = new EditText(this);
final EditText inputServerDes = new EditText(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("修改类别名称")
.setMessage("被修改的类别名称为:")
.setView(inputServerSrc)
.setNegativeButton("取消",null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingActivity.this);
builder.setTitle("修改类别名称")
.setMessage("要修改为:")
.setView(inputServerDes)
.setNegativeButton("取消", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DBManager.updateTypenameFromTypetbByTypename(inputServerSrc.getText().toString(), inputServerDes.getText().toString());
Toast.makeText(SettingActivity.this,"修改成功!",Toast.LENGTH_SHORT).show();
}
});
builder.create().show();
}

});
builder.create().show();
}

private void showDeleteDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("删除提示")
Expand All @@ -47,9 +82,10 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();
}

private void showEngelCoefficient() {
private void showEngelCoefficientDialog() {
float engelCoefficient = DBManager.getEngelCoefficient();
String hint;
String str;
if (engelCoefficient < 0.3) {
hint = "最富裕!钱花不完可以多多打赏哦~";
} else if (engelCoefficient < 0.4) {
Expand All @@ -61,9 +97,13 @@ private void showEngelCoefficient() {
} else {
hint = "贫困,脱贫攻坚战漏网之鱼嘛呜呜呜";
}
str = String.format("%.3f", engelCoefficient) + "\n" + hint;
if(Float.isNaN(engelCoefficient)) {
str = "咦?找不到支出记录呢,快去记一笔叭!";
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("恩格尔系数为:")
.setMessage(String.format("%.3f", engelCoefficient) + "\n" + hint)
.setMessage(str)
.setNegativeButton("确定", null);
builder.create().show();
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/eb/easy_bookkeeping/db/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public static int deleteItemFromAccounttbById(int id){
int i = db.delete("accounttb", "id=?", new String[]{id + ""});
return i;
}
/*
* 根据传入的旧类别名,改变typetb表中匹配的typename为新类别名
* */
public static void updateTypenameFromTypetbByTypename(String oldTypename, String newTypename){
String sql = "update typetb set typename = \"" + newTypename + "\" where typename = \"" + oldTypename + "\"";
db.execSQL(sql);
}
/*
* 根据传入的id,改变accounttb表当中的一条数据的备注为传入值
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public void onCreate(SQLiteDatabase db) {
"time varchar(60),year integer,month integer,day integer,kind integer)";
db.execSQL(sql);
createFoodCostSumView(db);
createTriggerUpdateTypename(db);
}

private void createTriggerUpdateTypename(SQLiteDatabase db) {
String sql = "create trigger updateTypename after update on typetb begin update accounttb set typename = new.typename where typename = old.typename; end ;";
db.execSQL(sql);
}

private void createFoodCostSumView(SQLiteDatabase db) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
accountBean = new AccountBean(); //创建对象
}

@Override
public void onStart() {
super.onStart();
// 返回主界面时刷新数据
loadDataToGV();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.eb.easy_bookkeeping.frag_record;

import com.eb.easy_bookkeeping.R;
import com.eb.easy_bookkeeping.db.DBManager;
import com.eb.easy_bookkeeping.db.TypeBean;

Expand All @@ -18,10 +17,10 @@ public void loadDataToGV() {
List<TypeBean> inlist = DBManager.getTypeList(1);
typeList.addAll(inlist);
adapter.notifyDataSetChanged();
typeTv.setText("工资");
typeIv.setImageResource(R.mipmap.ic_salary);
accountBean.setTypename("工资");
accountBean.setImageId(R.mipmap.ic_salary);
typeTv.setText(inlist.get(0).getTypename());
typeIv.setImageResource(inlist.get(0).getImageId());
accountBean.setTypename(inlist.get(0).getTypename());
accountBean.setImageId(inlist.get(0).getImageId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public void loadDataToGV() {
List<TypeBean> outlist = DBManager.getTypeList(0);
typeList.addAll(outlist);
adapter.notifyDataSetChanged();
typeTv.setText("三餐");
typeIv.setImageResource(R.mipmap.ic_meal);
accountBean.setTypename("三餐");
accountBean.setImageId(R.mipmap.ic_meal);
typeTv.setText(outlist.get(0).getTypename());
typeIv.setImageResource(outlist.get(0).getImageId());
accountBean.setTypename(outlist.get(0).getTypename());
accountBean.setImageId(outlist.get(0).getImageId());
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
android:textSize="18sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_7D7D7D"/>
<TextView
android:id="@+id/setting_tv_clear"
android:layout_width="match_parent"
Expand All @@ -32,6 +36,10 @@
android:textStyle="bold"
android:padding="15dp"
android:background="@color/white"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_7D7D7D"/>
<TextView
android:id="@+id/setting_tv_engel"
android:layout_width="match_parent"
Expand All @@ -46,4 +54,18 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_7D7D7D"/>
<TextView
android:id="@+id/setting_tv_change_typename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/change_typename"
android:onClick="onClick"
android:textSize="16sp"
android:textStyle="bold"
android:padding="15dp"
android:background="@color/white"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_7D7D7D"/>
</LinearLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

<string name="history_info">本月账单记录</string>
<string name="clear_all">清空所有记录</string>
<string name="engel_coefficient">恩格尔系数视图</string>
<string name="engel_coefficient">恩格尔系数计算</string>
<string name="change_typename">更改类别名称</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="not_data">暂无数据</string>
Expand Down
Binary file added img/step6_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/step6_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/step6_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/step6_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/step6_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/step6_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 93dcb7e

Please sign in to comment.