diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java index 005821c..e6d6bc5 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java @@ -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); } + 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())) { + 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; } - changeMenus(page); - entriesTable.removeAllViews(); // clean table - - setLoading(true); - Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page); // get new entries } else { Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity()); } @@ -225,8 +238,7 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector. if( result%entriesLimit > 0) pageCount++; - if(pageCount>1) - setHasOptionsMenu(true); + setHasOptionsMenu(true); } private void syncWidths(){ // TODO: Merge with adding columns maybe? Loops -= 3 should be quicker diff --git a/app/src/main/res/drawable-hdpi/ic_action_add_circle.png b/app/src/main/res/drawable-hdpi/ic_action_add_circle.png new file mode 100644 index 0000000..5f68a01 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_add_circle.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_add_circle.png b/app/src/main/res/drawable-mdpi/ic_action_add_circle.png new file mode 100644 index 0000000..649d671 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_add_circle.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_add_circle.png b/app/src/main/res/drawable-xhdpi/ic_action_add_circle.png new file mode 100644 index 0000000..adbda7f Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_add_circle.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_add_circle.png b/app/src/main/res/drawable-xxhdpi/ic_action_add_circle.png new file mode 100644 index 0000000..73e6e67 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_add_circle.png differ diff --git a/app/src/main/res/menu/entries_activity_actions.xml b/app/src/main/res/menu/entries_activity_actions.xml index 43bef46..d4eca48 100644 --- a/app/src/main/res/menu/entries_activity_actions.xml +++ b/app/src/main/res/menu/entries_activity_actions.xml @@ -1,6 +1,12 @@ + + Save credentials Connector URL No Internet Connection + Add new