Better menu pages handling
 New action - add (to be implemented)
This commit is contained in:
Przemek Grondek 2014-08-06 12:20:47 +02:00
parent 9ea0c789bb
commit 677df2941c
7 changed files with 30 additions and 11 deletions

View file

@ -54,7 +54,6 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
private CustomScrollView fakeScrollView;
private View dummyView;
private MenuInflater menuInflater;
private Menu menu;
@Override
@ -110,10 +109,12 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.entries_activity_actions, menu);
menuInflater = inflater; // I think we need it later
menu.findItem(R.id.action_previous).setVisible(false); // hide previous
if(pageCount<=1)
menu.findItem(R.id.action_next).setVisible(false); // hide next if we don't have any more pages
this.menu = menu;
// super.onCreateOptionsMenu(menu, inflater);
super.onCreateOptionsMenu(menu, inflater);
}
private void changeMenus(int page){
@ -137,22 +138,34 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
progressBar.setVisibility(isLoading ? View.VISIBLE : View.INVISIBLE);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(Static.isNetworkConnected(getActivity())) {
switch (item.getItemId()) {
case R.id.action_previous:
page--;
break;
case R.id.action_next:
page++;
break;
}
private void loadAnotherPage(){
changeMenus(page);
entriesTable.removeAllViews(); // clean table
setLoading(true);
Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page); // get new entries
}
private void addNewElement(){
//TODO Implement this method
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (Static.isNetworkConnected(getActivity())) {
switch (item.getItemId()) {
case R.id.action_previous:
page--;
loadAnotherPage();
break;
case R.id.action_next:
page++;
loadAnotherPage();
break;
case R.id.action_add:
addNewElement();
break;
}
} else {
Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity());
}
@ -225,7 +238,6 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
if( result%entriesLimit > 0)
pageCount++;
if(pageCount>1)
setHasOptionsMenu(true);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_add"
android:icon="@drawable/ic_action_add_circle"
android:title="@string/action_add"
android:showAsAction="ifRoom" />
<item
android:id="@+id/action_previous"
android:icon="@drawable/ic_action_arrow_back"

View file

@ -31,5 +31,6 @@
<string name="save_credentials">Save credentials</string>
<string name="connector_url">Connector URL</string>
<string name="no_connection">No Internet Connection</string>
<string name="action_add">Add new</string>
</resources>