This repository was archived by the owner on Jun 27, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed
src/main/java/com/blogspot/e_kanivets/moneytracker/activity/account Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -64,4 +64,4 @@ dependencies {
6464 androidTestCompile ' com.crittercism.dexmaker:dexmaker:1.4'
6565 androidTestCompile ' com.crittercism.dexmaker:dexmaker-dx:1.4'
6666 androidTestCompile ' com.crittercism.dexmaker:dexmaker-mockito:1.4'
67- }
67+ }
Original file line number Diff line number Diff line change @@ -65,23 +65,31 @@ public boolean onCreateOptionsMenu(Menu menu) {
6565 public boolean onOptionsItemSelected (MenuItem item ) {
6666 switch (item .getItemId ()) {
6767 case R .id .action_done :
68- addAccount ();
69-
70- setResult ( RESULT_OK );
71- finish ( );
68+ if ( addAccount ()) {
69+ setResult ( RESULT_OK );
70+ finish ( );
71+ } else showToast ( R . string . wrong_number_text );
7272 return true ;
7373
7474 default :
7575 return super .onOptionsItemSelected (item );
7676 }
7777 }
7878
79- private void addAccount () {
79+ private boolean addAccount () {
8080 String title = etTitle .getText ().toString ().trim ();
81- double initSum = Double .parseDouble (etInitSum .getText ().toString ().trim ());
81+
82+ double initSum ;
83+ try {
84+ initSum = Double .parseDouble (etInitSum .getText ().toString ().trim ());
85+ } catch (NumberFormatException e ) {
86+ e .printStackTrace ();
87+ return false ;
88+ }
89+
8290 String currency = (String ) spinner .getSelectedItem ();
8391
8492 Account account = new Account (title , initSum , currency );
85- accountController .create (account );
93+ return accountController .create (account ) != null ;
8694 }
87- }
95+ }
You can’t perform that action at this time.
0 commit comments