diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java index d1648d0..428cc0d 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java @@ -30,6 +30,8 @@ public class DatabaseFragment extends Fragment implements AdapterView.OnItemClic private RelativeLayout rootView; private ProgressBar progressBar; + private String chosenDatabase; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ //Inflate the layout for this fragment @@ -38,35 +40,48 @@ public class DatabaseFragment extends Fragment implements AdapterView.OnItemClic this.rootView = (RelativeLayout) rootView; progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar); - Static.asyncDatabaseConnector.setListReturnListener(this); - Static.asyncDatabaseConnector.getDatabases(); +// Static.asyncDatabaseConnector.setListReturnListener(this); +// Static.asyncDatabaseConnector.getDatabases(); + + listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, Static.databases); + databasesListView.setAdapter(listAdapter); + databasesListView.setOnItemClickListener(this); + progressBar.setVisibility(View.INVISIBLE); + return rootView; } @Override public void onItemClick(AdapterView adapterView, View view, int position, long id) { - String chosenDatabase = (String) listAdapter.getItem(position); + chosenDatabase = (String) listAdapter.getItem(position); listAdapter.getItem(position); - Intent intent = new Intent(getActivity(), TableActivity.class); - intent.putExtra(Static.DATABASE_NAME_ARG,chosenDatabase); + + progressBar.setVisibility(View.VISIBLE); Static.asyncDatabaseConnector.setDatabaseInUse(chosenDatabase); - startActivity(intent); + Static.asyncDatabaseConnector.setListReturnListener(this); + Static.asyncDatabaseConnector.getTables(); } @Override - public void onListReturn(List databases) { - if(databases!= null) { - listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, databases); - databasesListView.setAdapter(listAdapter); - databasesListView.setOnItemClickListener(this); - } else { - TextView errorMessage = new TextView(getActivity()); - errorMessage.setText(R.string.error_no_databases); - errorMessage.setTypeface(null, Typeface.ITALIC); - errorMessage.setClickable(false); - rootView.addView(errorMessage); - rootView.removeView(databasesListView); + public void onListReturn(List tables) { +// if(databases!= null) { +// listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, databases); +// databasesListView.setAdapter(listAdapter); +// databasesListView.setOnItemClickListener(this); +// } else { +// TextView errorMessage = new TextView(getActivity()); +// errorMessage.setText(R.string.error_no_databases); +// errorMessage.setTypeface(null, Typeface.ITALIC); +// errorMessage.setClickable(false); +// rootView.addView(errorMessage); +// rootView.removeView(databasesListView); +// } +// progressBar.setVisibility(View.INVISIBLE); + if(tables!=null) { + Static.tables = tables; } - progressBar.setVisibility(View.INVISIBLE); + Intent intent = new Intent(getActivity(), TableActivity.class); + intent.putExtra(Static.DATABASE_NAME_ARG, chosenDatabase); + startActivity(intent); } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java index 6d10075..ddc5daa 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java @@ -62,11 +62,62 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector. initArguments(); initViewItems(rootView); - Static.asyncDatabaseConnector.setIntegerReturnListener(this); - Static.asyncDatabaseConnector.setListReturnListener(this); - Static.asyncDatabaseConnector.setMatrixReturnListener(this); - Static.asyncDatabaseConnector.getFields(tableName); - Static.asyncDatabaseConnector.getEntriesCount(tableName); +// Static.asyncDatabaseConnector.setIntegerReturnListener(this); +// Static.asyncDatabaseConnector.setListReturnListener(this); +// Static.asyncDatabaseConnector.setMatrixReturnListener(this); +// Static.asyncDatabaseConnector.getFields(tableName); +// Static.asyncDatabaseConnector.getEntriesCount(tableName); + + pageCount = Static.pageCount/entriesLimit; + if( Static.pageCount%entriesLimit > 0) + pageCount++; + + if(pageCount>1) + setHasOptionsMenu(true); + + // First we need header + headerRow = new TableRow(getActivity()); + headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); + for(int i =0;i elements = Static.entries.get(i); + TableRow newRow = new TableRow(getActivity()); + for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not + TextView textView = new TextView(getActivity()); + textView.setText(elements.get(j)); + textView.setLayoutParams(layoutParams); + textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM); + textView.setBackgroundResource(R.drawable.background_element); + newRow.addView(textView); + } + entriesTable.addView(newRow); + + syncWidths(); + fakeScroll(); + } + } else { + TextView errorMessage = new TextView(getActivity()); + errorMessage.setText(R.string.error_no_entries); + errorMessage.setTypeface(null, Typeface.ITALIC); + errorMessage.setClickable(false); + entriesScrollView.removeView(entriesTable); + headerFrame.setVisibility(View.VISIBLE); + entriesScrollView.addView(errorMessage); + } + + setLoading(false); return rootView; } @@ -153,54 +204,54 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector. @Override public void onMatrixReturn(List> rows) { - // Now we get Rows - if(rows!=null) { - for (int i = 0; i < rows.size(); i++) { - List elements = rows.get(i); - TableRow newRow = new TableRow(getActivity()); - for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not - TextView textView = new TextView(getActivity()); - textView.setText(elements.get(j)); - textView.setLayoutParams(layoutParams); - textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM); - textView.setBackgroundResource(R.drawable.background_element); - newRow.addView(textView); - } - entriesTable.addView(newRow); - - syncWidths(); - fakeScroll(); - } - } else { - TextView errorMessage = new TextView(getActivity()); - errorMessage.setText(R.string.error_no_entries); - errorMessage.setTypeface(null, Typeface.ITALIC); - errorMessage.setClickable(false); - entriesScrollView.removeView(entriesTable); - headerFrame.setVisibility(View.VISIBLE); - entriesScrollView.addView(errorMessage); - } - - setLoading(false); +// // Now we get Rows +// if(rows!=null) { +// for (int i = 0; i < rows.size(); i++) { +// List elements = rows.get(i); +// TableRow newRow = new TableRow(getActivity()); +// for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not +// TextView textView = new TextView(getActivity()); +// textView.setText(elements.get(j)); +// textView.setLayoutParams(layoutParams); +// textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM); +// textView.setBackgroundResource(R.drawable.background_element); +// newRow.addView(textView); +// } +// entriesTable.addView(newRow); +// +// syncWidths(); +// fakeScroll(); +// } +// } else { +// TextView errorMessage = new TextView(getActivity()); +// errorMessage.setText(R.string.error_no_entries); +// errorMessage.setTypeface(null, Typeface.ITALIC); +// errorMessage.setClickable(false); +// entriesScrollView.removeView(entriesTable); +// headerFrame.setVisibility(View.VISIBLE); +// entriesScrollView.addView(errorMessage); +// } +// +// setLoading(false); } @Override public void onListReturn(List fieldList) { - // First we need header - headerRow = new TableRow(getActivity()); - headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); - for(int i =0;i databases) { + if(databases!= null) { + Static.databases = databases; + + Intent intent = new Intent(getActivity(), DatabaseActivity.class); + startActivity(intent); + } +// listAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, databases); +// databasesListView.setAdapter(listAdapter); +// databasesListView.setOnItemClickListener(this); +// } else { +// TextView errorMessage = new TextView(getActivity()); +// errorMessage.setText(R.string.error_no_databases); +// errorMessage.setTypeface(null, Typeface.ITALIC); +// errorMessage.setClickable(false); +// rootView.addView(errorMessage); +// rootView.removeView(databasesListView); +// } + } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/Static.java b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java index 055f1f7..d271055 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/Static.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java @@ -3,6 +3,8 @@ package info.nerull7.mysqlbrowser; import android.content.Context; import android.content.Intent; +import java.util.List; + import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector; /** @@ -13,6 +15,11 @@ public class Static { public static final String TABLE_NAME_ARG = "TableName"; public static AsyncDatabaseConnector asyncDatabaseConnector = null; + static List tables; + static List databases; + static List header; + static List> entries; + static int pageCount; public static void startSettings(Context context){ Intent intent = new Intent(context, SettingsActivity.class); diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java index 812f260..62af04b 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java @@ -4,6 +4,7 @@ import android.app.Fragment; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,13 +24,16 @@ import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector; /** * Created by nerull7 on 14.07.14. */ -public class TableFragment extends Fragment implements AdapterView.OnItemClickListener, AsyncDatabaseConnector.ListReturnListener{ +public class TableFragment extends Fragment implements AdapterView.OnItemClickListener, AsyncDatabaseConnector.ListReturnListener, AsyncDatabaseConnector.IntegerReturnListener, AsyncDatabaseConnector.MatrixReturnListener { private String databaseName; private ListView tablesList; private ListAdapter listAdapter; private RelativeLayout rootView; private ProgressBar progressBar; + private int listenerCalled; + private String chosenTable; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -38,25 +42,12 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi tablesList = (ListView) rootView.findViewById(R.id.tableList); this.rootView = (RelativeLayout) rootView; progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar); - Static.asyncDatabaseConnector.setListReturnListener(this); - Static.asyncDatabaseConnector.getTables(); - return rootView; - } + listenerCalled = 0; +// Static.asyncDatabaseConnector.setListReturnListener(this); +// Static.asyncDatabaseConnector.getTables(); - @Override - public void onItemClick(AdapterView adapterView, View view, int position, long id) { - String chosenTable = (String) listAdapter.getItem(position); - listAdapter.getItem(position); - Intent intent = new Intent(getActivity(), EntriesActivity.class); - intent.putExtra(Static.DATABASE_NAME_ARG,databaseName); - intent.putExtra(Static.TABLE_NAME_ARG,chosenTable); - startActivity(intent); - } - - @Override - public void onListReturn(List tables) { - if(tables != null) { - listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, tables); + if(Static.tables != null) { + listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, Static.tables); tablesList.setAdapter(listAdapter); tablesList.setOnItemClickListener(this); } else { @@ -64,9 +55,73 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi errorMessage.setText(R.string.error_no_tables); errorMessage.setTypeface(null, Typeface.ITALIC); errorMessage.setClickable(false); - rootView.addView(errorMessage); - rootView.removeView(tablesList); + this.rootView.addView(errorMessage); + this.rootView.removeView(tablesList); } progressBar.setVisibility(View.INVISIBLE); + + return rootView; + } + + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long id) { + chosenTable = (String) listAdapter.getItem(position); + listAdapter.getItem(position); + + progressBar.setVisibility(View.VISIBLE); + Static.asyncDatabaseConnector.setIntegerReturnListener(this); + Static.asyncDatabaseConnector.setListReturnListener(this); + Static.asyncDatabaseConnector.setMatrixReturnListener(this); + + int entriesLimit = PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt(SettingsFragment.ENTRIES_PAGE_LIMIT, SettingsFragment.ENTRIES_PAGE_LIMIT_DEF); + + Static.asyncDatabaseConnector.getRows(chosenTable, entriesLimit, 1); + Static.asyncDatabaseConnector.getFields(chosenTable); + Static.asyncDatabaseConnector.getEntriesCount(chosenTable); + } + + @Override + public void onListReturn(List header) { +// if(tables != null) { +// listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, tables); +// tablesList.setAdapter(listAdapter); +// tablesList.setOnItemClickListener(this); +// } else { +// TextView errorMessage = new TextView(getActivity()); +// errorMessage.setText(R.string.error_no_tables); +// errorMessage.setTypeface(null, Typeface.ITALIC); +// errorMessage.setClickable(false); +// rootView.addView(errorMessage); +// rootView.removeView(tablesList); +// } +// progressBar.setVisibility(View.INVISIBLE); + Static.header = header; + listenerCalled++; + if(listenerCalled==3) + startEntriesActivity(); + } + + @Override + public void onIntegerReturn(int result) { + Static.pageCount = result; + listenerCalled++; + if(listenerCalled==3) + startEntriesActivity(); + } + + @Override + public void onMatrixReturn(List> data) { + Static.entries = data; + listenerCalled++; + if(listenerCalled==3) + startEntriesActivity(); + } + + + private void startEntriesActivity() { + Intent intent = new Intent(getActivity(), EntriesActivity.class); + intent.putExtra(Static.DATABASE_NAME_ARG,databaseName); + intent.putExtra(Static.TABLE_NAME_ARG,chosenTable); + startActivity(intent); } }