Empty handling
Implement handling: - No entries in table - No tables in database - No databases available
This commit is contained in:
parent
d2ef2a958c
commit
c9d7d32223
4 changed files with 70 additions and 20 deletions
|
@ -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<String>(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getDatabases());
|
||||
databasesListView.setAdapter(listAdapter);
|
||||
databasesListView.setOnItemClickListener(this);
|
||||
private void setupListViewDatabase(){
|
||||
List<String> databases = Static.databaseConnector.getDatabases();
|
||||
if(databases!= null) {
|
||||
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
|
||||
|
|
|
@ -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<String> 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<List<String>> rows = Static.databaseConnector.getRows(tableName, entriesLimit);
|
||||
for(int i=0;i<rows.size();i++){
|
||||
List<String> 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);
|
||||
if(rows!=null) {
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String>(getActivity(),android.R.layout.simple_list_item_1, Static.databaseConnector.getTables());
|
||||
// TODO No tables handling
|
||||
tablesList.setAdapter(listAdapter);
|
||||
tablesList.setOnItemClickListener(this);
|
||||
List<String> tables = Static.databaseConnector.getTables();
|
||||
if(tables != null) {
|
||||
listAdapter = new ArrayAdapter<String>(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
|
||||
|
|
|
@ -22,5 +22,8 @@
|
|||
<string name="cancel">Cancel</string>
|
||||
<string name="set">Set</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>
|
||||
|
|
Loading…
Reference in a new issue