Entries limit from preferences
This commit is contained in:
parent
56cd6f109b
commit
5a7aa1797c
2 changed files with 38 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nerull7.mysqlbrowser;
|
package info.nerull7.mysqlbrowser;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -24,6 +25,7 @@ public class EntriesFragment extends Fragment {
|
||||||
TableLayout entriesTable;
|
TableLayout entriesTable;
|
||||||
ScrollView entriesScrollView;
|
ScrollView entriesScrollView;
|
||||||
FrameLayout headerFrame;
|
FrameLayout headerFrame;
|
||||||
|
private int entriesLimit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -34,6 +36,7 @@ public class EntriesFragment extends Fragment {
|
||||||
entriesTable = (TableLayout) rootView.findViewById(R.id.entriesTable);
|
entriesTable = (TableLayout) rootView.findViewById(R.id.entriesTable);
|
||||||
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);
|
||||||
setupTable();
|
setupTable();
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
@ -75,11 +78,11 @@ public class EntriesFragment extends Fragment {
|
||||||
headerFrame.addView(fakeHeaderView);
|
headerFrame.addView(fakeHeaderView);
|
||||||
|
|
||||||
// Now we get Rows
|
// Now we get Rows
|
||||||
List<List<String>> rows = Static.databaseConnector.getRows(tableName, 50); //TODO some normal number definition in header
|
List<List<String>> rows = Static.databaseConnector.getRows(tableName, entriesLimit);
|
||||||
for(int i=0;i<rows.size();i++){ // The same arbitrary number FIXME
|
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());
|
||||||
for(int j=0;j<elements.size();j++) { // elements.size is the same as in header so maybe some one number ?
|
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 textView = new TextView(getActivity());
|
||||||
textView.setText(elements.get(j));
|
textView.setText(elements.get(j));
|
||||||
textView.setLayoutParams(layoutParams);
|
textView.setLayoutParams(layoutParams);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package info.nerull7.mysqlbrowser;
|
package info.nerull7.mysqlbrowser;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
|
@ -8,14 +11,22 @@ import android.preference.PreferenceScreen;
|
||||||
/**
|
/**
|
||||||
* Created by nerull7 on 18.07.14.
|
* Created by nerull7 on 18.07.14.
|
||||||
*/
|
*/
|
||||||
public class SettingsFragment extends PreferenceFragment{
|
public class SettingsFragment extends PreferenceFragment implements NumberPickerDialog.OnNumberSetListener {
|
||||||
public final static String ENTRIES_PAGE_LIMIT = "entries_limit";
|
public static final String PREFERENCE_FILE = "preferences";
|
||||||
|
public static final String ENTRIES_PAGE_LIMIT = "entries_limit";
|
||||||
|
|
||||||
Preference mEntriesLimit;
|
public static final int ENTRIES_PAGE_LIMIT_DEF = 20;
|
||||||
|
public static final int ENTRIES_MIN_PAGE = 20;
|
||||||
|
public static final int ENTRIES_MAX_PAGE = 100;
|
||||||
|
|
||||||
|
private Activity parent;
|
||||||
|
private SharedPreferences preferences;
|
||||||
|
private Preference mEntriesLimit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState){
|
public void onCreate(Bundle savedInstanceState){
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
preferences = getActivity().getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||||
loadPrefs();
|
loadPrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,14 +34,31 @@ public class SettingsFragment extends PreferenceFragment{
|
||||||
addPreferencesFromResource(R.xml.settings);
|
addPreferencesFromResource(R.xml.settings);
|
||||||
|
|
||||||
mEntriesLimit = findPreference(ENTRIES_PAGE_LIMIT);
|
mEntriesLimit = findPreference(ENTRIES_PAGE_LIMIT);
|
||||||
|
setEntriesPageLimitSummary();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getEntriesPageLimit(){
|
||||||
|
return preferences.getInt(ENTRIES_PAGE_LIMIT, ENTRIES_PAGE_LIMIT_DEF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEntriesPageLimitSummary(){
|
||||||
|
mEntriesLimit.setSummary(getString(R.string.entries_summary, getEntriesPageLimit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||||
if(preference == mEntriesLimit){
|
if(preference == mEntriesLimit){
|
||||||
new NumberPickerDialog
|
new NumberPickerDialog(getActivity(), this, getEntriesPageLimit(), ENTRIES_MIN_PAGE, ENTRIES_MAX_PAGE, R.string.entries_limit).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNumberSet(int number) {
|
||||||
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
editor.putInt(ENTRIES_PAGE_LIMIT, number);
|
||||||
|
editor.apply();
|
||||||
|
setEntriesPageLimitSummary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue