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.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();
|
||||||
|
if(databases!= null) {
|
||||||
|
listAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, databases);
|
||||||
databasesListView.setAdapter(listAdapter);
|
databasesListView.setAdapter(listAdapter);
|
||||||
databasesListView.setOnItemClickListener(this);
|
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
|
||||||
|
|
|
@ -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,6 +82,7 @@ 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);
|
||||||
|
if(rows!=null) {
|
||||||
for (int i = 0; i < rows.size(); i++) {
|
for (int i = 0; i < rows.size(); i++) {
|
||||||
List<String> elements = rows.get(i);
|
List<String> elements = rows.get(i);
|
||||||
TableRow newRow = new TableRow(getActivity());
|
TableRow newRow = new TableRow(getActivity());
|
||||||
|
@ -90,7 +94,16 @@ public class EntriesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
entriesTable.addView(newRow);
|
entriesTable.addView(newRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
entriesTable.addView(headerRow);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, tables);
|
||||||
tablesList.setAdapter(listAdapter);
|
tablesList.setAdapter(listAdapter);
|
||||||
tablesList.setOnItemClickListener(this);
|
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
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue