Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit b35dc70

Browse files
author
Evgenii Kanivets
committed
#140[30m]. Add alert on account deletion. Mark archived account grey on Accounts screen.
1 parent 8c3a19a commit b35dc70

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/account/EditAccountActivity.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.blogspot.e_kanivets.moneytracker.activity.account;
22

3+
import android.app.AlertDialog;
4+
import android.content.DialogInterface;
35
import android.view.Menu;
46
import android.view.MenuItem;
57
import android.view.View;
@@ -89,7 +91,7 @@ void done() {
8991

9092
private void archive() {
9193
if (account.equals(accountController.readDefaultAccount())) {
92-
showToast("You can't archive a default account.");
94+
showToast(R.string.cant_archive_default_account);
9395
} else {
9496
accountController.archive(account);
9597
setResult(RESULT_OK);
@@ -104,9 +106,19 @@ private void restore() {
104106
}
105107

106108
private void delete() {
107-
accountController.delete(account);
108-
setResult(RESULT_OK);
109-
finish();
109+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
110+
builder.setTitle(R.string.delete_account_title);
111+
builder.setMessage(R.string.delete_account_message);
112+
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
113+
@Override
114+
public void onClick(DialogInterface dialog, int which) {
115+
accountController.delete(account);
116+
setResult(RESULT_OK);
117+
finish();
118+
}
119+
});
120+
builder.setNegativeButton(android.R.string.cancel, null);
121+
builder.show();
110122
}
111123

112124
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/adapter/AccountAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class AccountAdapter extends BaseAdapter {
3737
private int whiteGreen;
3838
private int red;
3939
private int green;
40+
private int grey;
4041

4142
@SuppressWarnings("deprecation")
4243
public AccountAdapter(Context context, List<Account> accounts) {
@@ -49,6 +50,7 @@ public AccountAdapter(Context context, List<Account> accounts) {
4950
whiteGreen = context.getResources().getColor(R.color.white_green);
5051
red = context.getResources().getColor(R.color.red);
5152
green = context.getResources().getColor(R.color.green);
53+
grey = context.getResources().getColor(R.color.grey_inactive);
5254
}
5355

5456
@Override
@@ -82,7 +84,11 @@ public View getView(final int position, View convertView, ViewGroup parent) {
8284

8385
Account account = accounts.get(position);
8486

85-
convertView.setBackgroundColor(account.getFullSum() >= 0.0 ? whiteGreen : whiteRed);
87+
if (account.isArchived()) {
88+
convertView.setBackgroundColor(grey);
89+
} else {
90+
convertView.setBackgroundColor(account.getFullSum() >= 0.0 ? whiteGreen : whiteRed);
91+
}
8692

8793
viewHolder.tvCurSum.setTextColor(account.getFullSum() >= 0.0 ? green : red);
8894
viewHolder.tvCurrency.setTextColor(account.getFullSum() >= 0.0 ? green : red);

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="white">#ffffff</color>
4+
<color name="grey_inactive">#E0E0E0</color>
45

56
<color name="white_green">#f1f8e9</color>
67
<color name="green_light">#8bc34a</color>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,7 @@
129129
<string name="goal">Goal</string>
130130
<string name="restore">Restore</string>
131131
<string name="archive">Archive</string>
132+
<string name="cant_archive_default_account">You can\'t archive a default account.</string>
133+
<string name="delete_account_title">Delete account</string>
134+
<string name="delete_account_message">Are you sure about deleting this account? It can\'t be restored after.</string>
132135
</resources>

0 commit comments

Comments
 (0)