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

Commit 01f476b

Browse files
author
Evgenii Kanivets
committed
#46[30m]. Hide goal and color fields. Implement account title edit.
1 parent 8e093bb commit 01f476b

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private boolean addAccount() {
100100
double goal = 0;
101101
int color = 0;
102102

103-
Account account = new Account(title, initSum, currency, goal, false, color);
103+
Account account = new Account(-1, title, initSum, currency, goal, false, color);
104104
return accountController.create(account) != null;
105105
} else {
106106
return false;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.AlertDialog;
44
import android.content.DialogInterface;
5+
import android.support.design.widget.TextInputLayout;
56
import android.view.Menu;
67
import android.view.MenuItem;
78
import android.view.View;
@@ -26,6 +27,8 @@ public class EditAccountActivity extends BaseBackActivity {
2627

2728
private Account account;
2829

30+
@BindView(R.id.til_title)
31+
TextInputLayout tilTitle;
2932
@BindView(R.id.et_title)
3033
EditText etTitle;
3134
@BindView(R.id.et_goal)
@@ -86,7 +89,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
8689

8790
@OnClick(R.id.fabDone)
8891
void done() {
92+
String title = etTitle.getText().toString().trim();
8993

94+
if (title.isEmpty()) {
95+
tilTitle.setError(getString(R.string.field_cant_be_empty));
96+
} else {
97+
Account newAccount = new Account(account.getId(), title, account.getCurSum(),
98+
account.getCurrency(), account.getGoal(), account.isArchived(), account.getColor());
99+
boolean updated = accountController.update(newAccount) != null;
100+
if (updated) {
101+
setResult(RESULT_OK);
102+
finish();
103+
}
104+
}
90105
}
91106

92107
private void archive() {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/entity/data/Account.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public Account(long id, String title, long curSum, String currency, long decimal
3232
this.color = color;
3333
}
3434

35-
public Account(String title, double curSum, String currency, double goal,
35+
public Account(long id, String title, double curSum, String currency, double goal,
3636
boolean archived, int color) {
37-
this.id = -1;
37+
this.id = id;
3838
this.title = title;
3939
this.currency = currency;
4040
this.curSum = getLong(curSum);

app/src/main/res/layout/activity_edit_account.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@
3939
android:layout_width="match_parent"
4040
android:layout_height="wrap_content"
4141
android:hint="@string/title"
42-
android:inputType="numberDecimal"
42+
android:inputType="text"
4343
android:maxLines="1"
4444
android:singleLine="true" />
4545
</android.support.design.widget.TextInputLayout>
4646

4747
<android.support.design.widget.TextInputLayout
4848
android:id="@+id/til_goal"
4949
android:layout_width="match_parent"
50-
android:layout_height="wrap_content">
50+
android:layout_height="wrap_content"
51+
android:visibility="invisible">
5152

5253
<EditText
5354
android:id="@+id/et_goal"
@@ -62,7 +63,8 @@
6263
<LinearLayout
6364
android:layout_width="match_parent"
6465
android:layout_height="wrap_content"
65-
android:orientation="vertical">
66+
android:orientation="vertical"
67+
android:visibility="invisible">
6668

6769
<TextView
6870
android:layout_width="wrap_content"
@@ -89,12 +91,12 @@
8991
</LinearLayout>
9092

9193
<android.support.design.widget.FloatingActionButton
94+
android:id="@+id/fabDone"
9295
android:layout_width="wrap_content"
9396
android:layout_height="wrap_content"
9497
android:layout_gravity="bottom|end"
9598
android:layout_margin="16dp"
9699
android:src="@drawable/ic_done"
97-
app:layout_anchorGravity="bottom|end"
98-
android:id="@+id/fabDone"/>
100+
app:layout_anchorGravity="bottom|end" />
99101

100102
</android.support.design.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)