Empty handling

Implement handling:
- No entries in table
- No tables in database
- No databases available
This commit is contained in:
Przemek Grondek 2014-07-21 14:40:46 +02:00
parent d2ef2a958c
commit c9d7d32223
4 changed files with 70 additions and 20 deletions

View file

@ -2,6 +2,7 @@ package info.nerull7.mysqlbrowser;
import android.app.Fragment; import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -10,6 +11,10 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.List;
/** /**
* Created by nerull7 on 14.07.14. * Created by nerull7 on 14.07.14.
@ -17,21 +22,33 @@ import android.widget.ListView;
public class DatabaseFragment extends Fragment implements AdapterView.OnItemClickListener { public class DatabaseFragment extends Fragment implements AdapterView.OnItemClickListener {
private ListView databasesListView; private ListView databasesListView;
private ListAdapter listAdapter; private ListAdapter listAdapter;
private RelativeLayout rootView;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//Inflate the layout for this fragment //Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_database, container, false); View rootView = inflater.inflate(R.layout.fragment_database, container, false);
databasesListView = (ListView) rootView.findViewById(R.id.databaseList); databasesListView = (ListView) rootView.findViewById(R.id.databaseList);
this.rootView = (RelativeLayout) rootView;
setupListViewDatabase(); setupListViewDatabase();
return rootView; return rootView;
} }
private void setupListViewDatabase(){ // TODO: Handle no databases available problem private void setupListViewDatabase(){
listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getDatabases()); List<String> databases = Static.databaseConnector.getDatabases();
databasesListView.setAdapter(listAdapter); if(databases!= null) {
databasesListView.setOnItemClickListener(this); listAdapter = new ArrayAdapter<String>(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 @Override

View file

@ -9,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TableLayout; import android.widget.TableLayout;
import android.widget.TableRow; import android.widget.TableRow;
@ -26,6 +27,7 @@ public class EntriesFragment extends Fragment {
private ScrollView entriesScrollView; private ScrollView entriesScrollView;
private FrameLayout headerFrame; private FrameLayout headerFrame;
private int entriesLimit; private int entriesLimit;
private RelativeLayout rootView;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -37,11 +39,12 @@ public class EntriesFragment extends Fragment {
entriesScrollView = (ScrollView) rootView.findViewById(R.id.entriesScrollView); entriesScrollView = (ScrollView) rootView.findViewById(R.id.entriesScrollView);
headerFrame = (FrameLayout) rootView.findViewById(R.id.headerFrame); 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); entriesLimit = getActivity().getSharedPreferences(SettingsFragment.PREFERENCE_FILE, Context.MODE_PRIVATE).getInt(SettingsFragment.ENTRIES_PAGE_LIMIT, SettingsFragment.ENTRIES_PAGE_LIMIT_DEF);
this.rootView = (RelativeLayout) rootView;
setupTable(); setupTable();
return rootView; return rootView;
} }
private void setupTable(){ // TODO Empty table handling private void setupTable(){
List<String> fieldList = Static.databaseConnector.getFields(tableName); List<String> fieldList = Static.databaseConnector.getFields(tableName);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); 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 // Now we get Rows
List<List<String>> rows = Static.databaseConnector.getRows(tableName, entriesLimit); List<List<String>> rows = Static.databaseConnector.getRows(tableName, entriesLimit);
for(int i=0;i<rows.size();i++){ if(rows!=null) {
List<String> elements = rows.get(i); for (int i = 0; i < rows.size(); i++) {
TableRow newRow = new TableRow(getActivity()); List<String> elements = rows.get(i);
for(int j=0;j<elements.size();j++) { // elements.size can be the same as in header so maybe some one number or not TableRow newRow = new TableRow(getActivity());
TextView textView = new TextView(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.setText(elements.get(j)); TextView textView = new TextView(getActivity());
textView.setLayoutParams(layoutParams); textView.setText(elements.get(j));
newRow.addView(textView); 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);
} }
} }

View file

@ -2,14 +2,20 @@ package info.nerull7.mysqlbrowser;
import android.app.Fragment; import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.List;
/** /**
* Created by nerull7 on 14.07.14. * Created by nerull7 on 14.07.14.
@ -18,6 +24,7 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
private String databaseName; private String databaseName;
private ListView tablesList; private ListView tablesList;
private ListAdapter listAdapter; private ListAdapter listAdapter;
private RelativeLayout rootView;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 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); View rootView = inflater.inflate(R.layout.fragment_table, container, false);
databaseName = getArguments().getString("DatabaseName"); databaseName = getArguments().getString("DatabaseName");
tablesList = (ListView) rootView.findViewById(R.id.tableList); tablesList = (ListView) rootView.findViewById(R.id.tableList);
this.rootView = (RelativeLayout) rootView;
setupList(); setupList();
return rootView; return rootView;
} }
private void setupList(){ private void setupList(){
listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getTables()); List<String> tables = Static.databaseConnector.getTables();
// TODO No tables handling if(tables != null) {
tablesList.setAdapter(listAdapter); listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, tables);
tablesList.setOnItemClickListener(this); 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 @Override

View file

@ -22,5 +22,8 @@
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="set">Set</string> <string name="set">Set</string>
<string name="pref_entries_per_page">Set number of entries per page</string> <string name="pref_entries_per_page">Set number of entries per page</string>
<string name="error_no_tables">No tables in this database</string>
<string name="error_no_entries">No entries in this table</string>
<string name="error_no_databases">No available databases</string>
</resources> </resources>