Skip to content

Commit

Permalink
Move save button to action bar
Browse files Browse the repository at this point in the history
  • Loading branch information
brarcher committed Apr 5, 2017
1 parent 3177da9 commit 54064e6
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 161 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ App icons from [The Noun Project](https://thenounproject.com) and
[Dima Lagunov](https://thenounproject.com/lagunov.dmitriy/)
- [Ticket Bill](https://thenounproject.com/term/ticket-bill/634398/)
by [naim](https://thenounproject.com/naim.solis/)
- [Save](https://thenounproject.com/term/save/716011) by [Bernar Novalyi](https://thenounproject.com/bernar.novalyi)
39 changes: 11 additions & 28 deletions app/src/main/java/protect/budgetwatch/BudgetViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ public void onResume()
{
_budgetNameEdit.setVisibility(View.GONE);
_valueEdit.setVisibility(View.GONE);

Button saveButton = (Button) findViewById(R.id.saveButton);
Button cancelButton = (Button) findViewById(R.id.cancelButton);
saveButton.setVisibility(Button.GONE);
cancelButton.setVisibility(Button.GONE);

setTitle(R.string.viewBudgetTitle);
}
}
Expand All @@ -98,26 +92,6 @@ public void onResume()
_budgetNameView.setVisibility(View.GONE);
_valueView.setVisibility(View.GONE);
}

Button saveButton = (Button)findViewById(R.id.saveButton);
saveButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
doSave();
}
});

Button cancelButton = (Button)findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
}
});
}

private void doSave()
Expand Down Expand Up @@ -172,11 +146,14 @@ public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.view_menu, menu);
}

if(editBudget)
else if(editBudget)
{
getMenuInflater().inflate(R.menu.edit_menu, menu);
}
else
{
getMenuInflater().inflate(R.menu.add_menu, menu);
}

return super.onCreateOptionsMenu(menu);
}
Expand Down Expand Up @@ -234,6 +211,12 @@ public void onClick(DialogInterface dialog, int which)
return true;
}

if(id == R.id.action_save)
{
doSave();
return true;
}

if(id == android.R.id.home)
{
finish();
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/protect/budgetwatch/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ private void displayAboutDialog()
"Piggy Bank by Icons8", "https://thenounproject.com/term/piggy-bank/61478/",
"Purse by Dima Lagunov", "https://thenounproject.com/term/purse/26896/",
"Ticket Bill by naim", "https://thenounproject.com/term/ticket-bill/634398/",
"Purchase Order by Icons8", "https://icons8.com/web-app/for/all/purchase-order"
"Purchase Order by Icons8", "https://icons8.com/web-app/for/all/purchase-order",
"Save by Bernar Novalyi", "https://thenounproject.com/term/save/716011"
);

StringBuilder libs = new StringBuilder().append("<ul>");
Expand Down
35 changes: 7 additions & 28 deletions app/src/main/java/protect/budgetwatch/TransactionViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public class TransactionViewActivity extends AppCompatActivity
private TextView _noteView;
private TextView _budgetView;
private TextView _dateView;
private Button _cancelButton;
private Button _saveButton;
private Button _captureButton;
private Button _viewButton;
private Button _updateButton;
Expand Down Expand Up @@ -112,8 +110,6 @@ protected void onCreate(Bundle savedInstanceState)
_noteView = (TextView) findViewById(R.id.noteView);
_budgetView = (TextView) findViewById(R.id.budgetView);
_dateView = (TextView) findViewById(R.id.dateView);
_cancelButton = (Button)findViewById(R.id.cancelButton);
_saveButton = (Button)findViewById(R.id.saveButton);
_captureButton = (Button)findViewById(R.id.captureButton);
_viewButton = (Button)findViewById(R.id.viewButton);
_updateButton = (Button)findViewById(R.id.updateButton);
Expand Down Expand Up @@ -237,9 +233,6 @@ public void onFocusChange(View v, boolean hasFocus)
_noteEdit.setVisibility(View.GONE);
_dateEdit.setVisibility(View.GONE);

_cancelButton.setVisibility(Button.GONE);
_saveButton.setVisibility(Button.GONE);

// The no receipt layout need never be displayed
// when only viewing a transaction, as one should
// not be able to capture a receipt
Expand Down Expand Up @@ -352,24 +345,6 @@ public void onClick(View v)
startActivity(i);
}
});

_saveButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
doSave();
}
});

_cancelButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
}
});
}

private void doSave()
Expand Down Expand Up @@ -518,11 +493,14 @@ public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.view_menu, menu);
}

if(editBudget)
else if(editBudget)
{
getMenuInflater().inflate(R.menu.edit_menu, menu);
}
else
{
getMenuInflater().inflate(R.menu.add_menu, menu);
}

return super.onCreateOptionsMenu(menu);
}
Expand Down Expand Up @@ -584,7 +562,8 @@ public void onClick(DialogInterface dialog, int which)

if(id == R.id.action_save)
{

doSave();
return true;
}

if(id == android.R.id.home)
Expand Down
Binary file added app/src/main/res/drawable-hdpi/save_24dp.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 app/src/main/res/drawable-mdpi/save_24dp.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 app/src/main/res/drawable-xhdpi/save_24dp.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 app/src/main/res/drawable-xxhdpi/save_24dp.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 app/src/main/res/drawable-xxxhdpi/save_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 0 additions & 22 deletions app/src/main/res/layout/budget_view_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,6 @@
android:layout_height="10dip"/>
</TableRow>
</TableLayout>

<LinearLayout
android:orientation="horizontal"
android:padding="5.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:background="@color/inputContrastBackground">
<Button
android:id="@+id/cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:layout_weight="1.0" />
<Button
android:id="@+id/saveButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/save"
android:layout_weight="1.0" />
</LinearLayout>

</LinearLayout>
</ScrollView>

Expand Down
24 changes: 0 additions & 24 deletions app/src/main/res/layout/transaction_view_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,30 +438,6 @@
</TableRow>

</TableLayout>

<!-- Save/Cancel buttons -->

<LinearLayout
android:orientation="horizontal"
android:padding="5.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:background="@color/inputContrastBackground">
<Button
android:id="@+id/cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:layout_weight="1.0" />
<Button
android:id="@+id/saveButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/save"
android:layout_weight="1.0" />
</LinearLayout>

</LinearLayout>
</ScrollView>

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/menu/add_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_save"
android:icon="@drawable/save_24dp"
android:title="@string/save"
app:showAsAction="always"/>
</menu>
8 changes: 7 additions & 1 deletion app/src/main/res/menu/edit_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_save"
android:icon="@drawable/save_24dp"
android:title="@string/save"
app:showAsAction="always"/>

<item
android:id="@+id/action_delete"
android:icon="@drawable/ic_delete_white_24dp"
android:title="@string/delete"
app:showAsAction="always"/>
app:showAsAction="never"/>
</menu>
39 changes: 13 additions & 26 deletions app/src/test/java/protect/budgetwatch/BudgetViewActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ private void checkAllFields(final Activity activity, ViewMode mode,
checkFieldProperties(activity, R.id.budgetNameView, viewVisibility, mode == ViewMode.VIEW_CARD ? budget : "");
checkFieldProperties(activity, R.id.valueEdit, editVisibility, mode == ViewMode.VIEW_CARD ? "" : value);
checkFieldProperties(activity, R.id.valueView, viewVisibility, mode == ViewMode.VIEW_CARD ? value : "");
checkFieldProperties(activity, R.id.saveButton, editVisibility, null);
checkFieldProperties(activity, R.id.cancelButton, editVisibility, null);
}

private void checkFieldProperties(final Activity activity, final int id, final int visibility,
Expand Down Expand Up @@ -146,8 +144,6 @@ public void startAsAddCannotCreateBudget()
DBHelper db = new DBHelper(activity);
assertEquals(0, db.getBudgetCount());

final Button saveButton = (Button) activity.findViewById(R.id.saveButton);

for(String[] test : Arrays.asList(
new String[]{"", ""},
new String[]{"", "100"},
Expand All @@ -165,27 +161,13 @@ public void startAsAddCannotCreateBudget()
valueField.setText(value);

// Perform the actual test, no transaction should be created
saveButton.performClick();
shadowOf(activity).clickMenuItem(R.id.action_save);
assertEquals(0, db.getBudgetCount());
}

db.close();
}

@Test
public void startAsAddCancel()
{
ActivityController activityController = setupActivity(null, 0, false, false);

Activity activity = (Activity)activityController.get();

final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);

assertEquals(false, activity.isFinishing());
cancelButton.performClick();
assertEquals(true, activity.isFinishing());
}

/**
* Save a budget and check that the database contains the
* expected value
Expand All @@ -208,13 +190,11 @@ private void saveBudgetWithArguments(final Activity activity,
final EditText budgetField = (EditText) activity.findViewById(R.id.budgetNameEdit);
final EditText valueField = (EditText) activity.findViewById(R.id.valueEdit);

final Button saveButton = (Button) activity.findViewById(R.id.saveButton);

budgetField.setText(budgetName);
valueField.setText(Integer.toString(value));

assertEquals(false, activity.isFinishing());
saveButton.performClick();
shadowOf(activity).clickMenuItem(R.id.action_save);
assertEquals(true, activity.isFinishing());

assertEquals(1, db.getBudgetCount());
Expand Down Expand Up @@ -270,16 +250,19 @@ public void startAsViewCheckDisplay() throws IOException
}

@Test
public void startAsAddNoButtonsInActionBar() throws Exception
public void startAsAddCheckActionBar() throws Exception
{
ActivityController activityController = setupActivity(null, 0, false, false);
Activity activity = (Activity)activityController.get();

final Menu menu = shadowOf(activity).getOptionsMenu();
assertTrue(menu != null);

// There should be no buttons
assertEquals(menu.size(), 0);
assertEquals(menu.size(), 1);

MenuItem item = menu.findItem(R.id.action_save);
assertNotNull(item);
assertEquals("Save", item.getTitle().toString());
}

@Test
Expand All @@ -291,11 +274,15 @@ public void startAsUpdateCheckActionBar() throws Exception
final Menu menu = shadowOf(activity).getOptionsMenu();
assertTrue(menu != null);

assertEquals(menu.size(), 1);
assertEquals(menu.size(), 2);

MenuItem item = menu.findItem(R.id.action_delete);
assertNotNull(item);
assertEquals("Delete", item.getTitle().toString());

item = menu.findItem(R.id.action_save);
assertNotNull(item);
assertEquals("Save", item.getTitle().toString());
}

@Test
Expand Down
Loading

0 comments on commit 54064e6

Please sign in to comment.