From c9d7d322238eaa5b2e3cfd7b33f4f2e0e5d81123 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 21 Jul 2014 14:40:46 +0200 Subject: [PATCH] Empty handling Implement handling: - No entries in table - No tables in database - No databases available --- .../mysqlbrowser/DatabaseFragment.java | 25 +++++++++++-- .../nerull7/mysqlbrowser/EntriesFragment.java | 37 +++++++++++++------ .../nerull7/mysqlbrowser/TableFragment.java | 25 +++++++++++-- app/src/main/res/values/strings.xml | 3 ++ 4 files changed, 70 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java index 9a73878..95619ef 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java @@ -2,6 +2,7 @@ package info.nerull7.mysqlbrowser; import android.app.Fragment; import android.content.Intent; +import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -10,6 +11,10 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import java.util.List; /** * Created by nerull7 on 14.07.14. @@ -17,21 +22,33 @@ import android.widget.ListView; public class DatabaseFragment extends Fragment implements AdapterView.OnItemClickListener { private ListView databasesListView; private ListAdapter listAdapter; + private RelativeLayout rootView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ //Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_database, container, false); databasesListView = (ListView) rootView.findViewById(R.id.databaseList); + this.rootView = (RelativeLayout) rootView; setupListViewDatabase(); return rootView; } - private void setupListViewDatabase(){ // TODO: Handle no databases available problem - listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getDatabases()); - databasesListView.setAdapter(listAdapter); - databasesListView.setOnItemClickListener(this); + private void setupListViewDatabase(){ + List databases = Static.databaseConnector.getDatabases(); + 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); + } } @Override diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java index 177f83a..f2517ff 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java @@ -9,6 +9,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TableLayout; import android.widget.TableRow; @@ -26,6 +27,7 @@ public class EntriesFragment extends Fragment { private ScrollView entriesScrollView; private FrameLayout headerFrame; private int entriesLimit; + private RelativeLayout rootView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -37,11 +39,12 @@ public class EntriesFragment extends Fragment { entriesScrollView = (ScrollView) rootView.findViewById(R.id.entriesScrollView); headerFrame = (FrameLayout) rootView.findViewById(R.id.headerFrame); entriesLimit = getActivity().getSharedPreferences(SettingsFragment.PREFERENCE_FILE, Context.MODE_PRIVATE).getInt(SettingsFragment.ENTRIES_PAGE_LIMIT, SettingsFragment.ENTRIES_PAGE_LIMIT_DEF); + this.rootView = (RelativeLayout) rootView; setupTable(); return rootView; } - private void setupTable(){ // TODO Empty table handling + private void setupTable(){ List fieldList = Static.databaseConnector.getFields(tableName); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); @@ -79,18 +82,28 @@ public class EntriesFragment extends Fragment { // Now we get Rows List> rows = Static.databaseConnector.getRows(tableName, entriesLimit); - for(int i=0;i elements = rows.get(i); - TableRow newRow = new TableRow(getActivity()); - for(int j=0;j 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); + newRow.addView(textView); + } + entriesTable.addView(newRow); } - entriesTable.addView(newRow); + entriesTable.addView(headerRow); + } else { + TextView errorMessage = new TextView(getActivity()); + errorMessage.setText(R.string.error_no_entries); + errorMessage.setTypeface(null, Typeface.ITALIC); + errorMessage.setClickable(false); + entriesScrollView.removeView(entriesTable); + rootView.addView(errorMessage); + headerFrame.addView(headerRow); + headerRow.setVisibility(View.VISIBLE); } - - entriesTable.addView(headerRow); } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java index ab0d6dd..969392a 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java @@ -2,14 +2,20 @@ package info.nerull7.mysqlbrowser; import android.app.Fragment; import android.content.Intent; +import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import java.util.List; /** * Created by nerull7 on 14.07.14. @@ -18,6 +24,7 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi private String databaseName; private ListView tablesList; private ListAdapter listAdapter; + private RelativeLayout rootView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -25,15 +32,25 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi View rootView = inflater.inflate(R.layout.fragment_table, container, false); databaseName = getArguments().getString("DatabaseName"); tablesList = (ListView) rootView.findViewById(R.id.tableList); + this.rootView = (RelativeLayout) rootView; setupList(); return rootView; } private void setupList(){ - listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getTables()); - // TODO No tables handling - tablesList.setAdapter(listAdapter); - tablesList.setOnItemClickListener(this); + List tables = Static.databaseConnector.getTables(); + 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); + } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d51ab90..d9e5ce6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,5 +22,8 @@ Cancel Set Set number of entries per page + No tables in this database + No entries in this table + No available databases