Skip to content
Browse files

Now with database support

  • Loading branch information...
1 parent ac1b1e4 commit af28cfbf0022485f79f640ef183ffc6ab303888e @vIiRuS committed Mar 23, 2012
View
3 AndroidManifest.xml
@@ -12,11 +12,10 @@
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar">
+ android:theme="@style/MensaTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
- android:theme="@style/MensaTheme"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
View
BIN res/drawable-hdpi/schatten.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-ldpi/schatten.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/schatten.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 res/layout/list_item.xml
@@ -22,7 +22,7 @@
android:paddingBottom="4dp"
android:paddingLeft="28dp"
android:paddingRight="28dp"
- android:paddingTop="4dp">
+ android:paddingTop="4dp" >
<TextView
android:id="@+id/itemViewBig"
View
4 res/values/strings.xml
@@ -116,4 +116,8 @@
</string-array>
<string name="city">City</string>
<string name="connError">Something went wrong. Please try later.</string>
+ <string name="about">About</string>
+ <string name="general">General</string>
+ <string name="misc">Misc.</string>
+ <string name="help">Help</string>
</resources>
View
8 res/values/themes.xml
@@ -2,6 +2,7 @@
<resources>
<style name="MensaTheme" parent="@style/Theme.Sherlock">
<item name="vpiTitlePageIndicatorStyle">@style/CustomTitlePageIndicator</item>
+ <item name="android:typeface">serif</item>
</style>
<style name="CustomTitlePageIndicator">
@@ -11,4 +12,11 @@
<item name="selectedBold">false</item>
<item name="footerPadding">19dp</item>
</style>
+
+
+ <style name="PreferencesTheme" parent="@style/Theme.Sherlock">
+ <item name="android:windowBackground">@drawable/background_settings</item>
+ <item name="android:textColor">@color/fontcolor</item>
+ <item name="android:typeface">serif</item>
+ </style>
</resources>
View
9 res/xml/mainpreferences.xml
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
- <CheckBoxPreference android:title="@string/updateAutomatic" android:key="automaticUpdate" android:layout="@layout/checkboxpref"/><ListPreference android:key="cityPreference" android:entries="@array/cityList" android:title="@string/city" android:entryValues="@array/cityListValues"/><ListPreference android:key="mensaPreference" android:title="@string/mensa" android:summary="@string/chosenMensa"/>
- <ListPreference android:key="priceCategory" android:title="@string/price" android:entryValues="@array/priceClassesValue" android:entries="@array/priceClasses"/>
+ <PreferenceCategory android:title="@string/general"><CheckBoxPreference android:title="@string/updateAutomatic" android:key="automaticUpdate" android:layout="@layout/checkboxpref" android:defaultValue="true" /><ListPreference android:key="cityPreference" android:entries="@array/cityList" android:title="@string/city" android:entryValues="@array/cityListValues" android:defaultValue="beList" /><ListPreference android:key="mensaPreference" android:title="@string/mensa" android:summary="@string/chosenMensa" android:defaultValue="fu1" /><ListPreference android:key="priceCategory" android:title="@string/price" android:entryValues="@array/priceClassesValue" android:entries="@array/priceClasses" android:defaultValue="2" /></PreferenceCategory>
+
<PreferenceCategory android:title="@string/contentBadges">
<CheckBoxPreference android:title="@string/vegetarian" android:key="vegetarianCheckbox" android:layout="@layout/checkboxpref"/>
<CheckBoxPreference android:title="@string/vegan" android:key="veganCheckbox" android:layout="@layout/checkboxpref"/>
<CheckBoxPreference android:title="@string/bio" android:key="bioCheckbox" android:layout="@layout/checkboxpref"/>
<CheckBoxPreference android:title="@string/fish" android:key="mscCheckbox" android:layout="@layout/checkboxpref"/>
</PreferenceCategory>
+ <PreferenceCategory android:title="@string/misc"><Preference android:title="@string/help" /><Preference android:title="@string/about" android:selectable="true" />
+
+</PreferenceCategory>
+
+
</PreferenceScreen>
View
47 src/net/pherth/mensa/Data.java
@@ -39,36 +39,48 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.util.Log;
import android.util.Pair;
public class Data {
public static final String TAG = Data.class.getSimpleName();
List<Day> res;
private Context context;
SharedPreferences sharedPrefs;
+ Dataprovider dataprov;
public Data(Context cxt) {
+ dataprov = new Dataprovider(cxt);
this.context = cxt;
}
- public void getAllData() {
+ public void getAllData(boolean fromDatabase) {
res = new ArrayList<Day>();
-
- sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.context);
- String city = sharedPrefs.getString("cityPreference", "beList");
- String mensa = sharedPrefs.getString("mensaPreference", "fu1");
- String url = getURL(city, mensa);
- RSSHandler rh = new RSSHandler();
- String htmlString= rh.getHTML(url);
- if (htmlString != null) {
- parseHTML(htmlString, city);
+ if(fromDatabase) {
+ Log.i("Data", "Load from database");
+ loadDataFromDatabase();
} else {
+ Log.i("Data", "Load new data");
+ sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.context);
+ String city = sharedPrefs.getString("cityPreference", "beList");
+ String mensa = sharedPrefs.getString("mensaPreference", "fu1");
+ String url = getURL(city, mensa);
+ RSSHandler rh = new RSSHandler();
+ String htmlString= rh.getHTML(url);
+ if (htmlString != null) {
+ parseHTML(htmlString, city);
+ } else {
+ }
+ dataprov.open();
+ dataprov.newData(res);
+ dataprov.close();
}
- //TODO save data in database
}
public void loadDataFromDatabase() {
- //TODO function that loads the data from database
+ dataprov.open();
+ res = dataprov.getData();
+ dataprov.close();
}
public int getDayCount() {
@@ -79,13 +91,13 @@ public int getDayCount() {
}
private void parseHTML(String html, String id) {
- if (id == "beList") {
+ if (id.equals("beList")) {
parseHTMLBerlin(html);
}
}
private void parseHTMLBerlin(String htmlString) {
- System.out.println("parsing HTML");
+ Log.i("HTML", "beginning to parse");
Document doc = Jsoup.parse(htmlString);
Elements headers = doc.getElementsByClass("mensa_week_head_col");
for (int x=0; x < headers.size(); x++){
@@ -172,15 +184,16 @@ private void parseHTMLBerlin(String htmlString) {
List<Pair<Integer, List<Meal>>> currentMeals = new ArrayList<Pair<Integer, List<Meal>>>();
Day currentDay = res.get(position);
currentMeals = currentDay.getMeals();
- System.out.println(currentMeals);
+ Log.i("Current Meals", currentMeals.toString());
return currentMeals;
}
private String getURL(String city, String mensa) {
- String url = null;
- if (city == "beList") {
+ String url = "";
+ if (city.equals("beList")) {
url = "http://www.studentenwerk-berlin.de/speiseplan/rss/" + mensa + "/woche/lang/1";
}
+ Log.i("url", city + ", " + mensa + ", " + url);
return url;
}
}
View
36 src/net/pherth/mensa/Database.java
@@ -2,36 +2,52 @@
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
public class Database extends SQLiteOpenHelper {
- private static final int DATABASE_VERSION = 2;
+ private static final int DATABASE_VERSION = 3;
private static final String DAY_TABLE_NAME = "day";
- private static final String DICTIONARY_TABLE_CREATE =
- "CREATE TABLE " + DAY_TABLE_NAME + " ( id INTEGER, date TEXT);";
+ private static final String DAY_TABLE_CREATE =
+ "CREATE TABLE " + DAY_TABLE_NAME + " ( _id integer primary key autoincrement, date TEXT);";
private static final String meal_TABLE_NAME = "meal";
private static final String meal_TABLE_CREATE =
- "CREATE TABLE " + meal_TABLE_NAME + " ( dayID INTEGER, id INTEGER, name TEXT, vegan BOOLEAN, " +
+ "CREATE TABLE " + meal_TABLE_NAME + " ( _id integer primary key autoincrement, dayID INTEGER, groupID INTEGER, name TEXT, price1 FLOAT, price2 FLOAT, price3 FLOAT, vegan BOOLEAN, " +
"vegetarian BOOLEAN, msc BOOLEAN, bio BOOLEAN);";
private static final String addition_TABLE_NAME = "additions";
private static final String addition_TABLE_CREATE =
"CREATE TABLE " + addition_TABLE_NAME + " ( mealID INTEGER, name TEXT);";
+ private static String DB_PATH = "/data/data/net.pherth.mensa/databases/";
+ private static String DB_NAME = "omnomagon.db";
+
Database(Context context) {
- super(context, "omnomagon", null, DATABASE_VERSION);
+ super(context,DB_NAME, null, DATABASE_VERSION);
+ Log.i("Database", "Database initialized");
}
@Override
public void onCreate(SQLiteDatabase db) {
- db.execSQL(DICTIONARY_TABLE_CREATE);
+ Log.i("Database", "create database");
+ db.execSQL(DAY_TABLE_CREATE);
db.execSQL(meal_TABLE_CREATE);
db.execSQL(addition_TABLE_CREATE);
}
-
+
@Override
- public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
- //super.onUpgrade(arg0, arg1, arg2);
-
+ public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
+ db.execSQL("DROP TRIGGER IF EXISTS fk_empdept_deptid");
+ db.execSQL("DROP TABLE IF EXISTS "+ DAY_TABLE_NAME);
+ db.execSQL("DROP TABLE IF EXISTS "+ meal_TABLE_NAME);
+ db.execSQL("DROP TABLE IF EXISTS "+ addition_TABLE_NAME);
+ onCreate(db);
+ }
+
+ public void clearDatabase(SQLiteDatabase db) {
+ db.execSQL("DELETE FROM '" + DAY_TABLE_NAME + "';");
+ db.execSQL("DELETE FROM '" + meal_TABLE_NAME + "';");
+ db.execSQL("DELETE FROM '" + addition_TABLE_NAME + "';");
}
}
View
125 src/net/pherth/mensa/Dataprovider.java
@@ -0,0 +1,125 @@
+package net.pherth.mensa;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+import android.util.Pair;
+
+public class Dataprovider {
+
+ // Database fields
+ private SQLiteDatabase database;
+ private Database dbHelper;
+
+ public Dataprovider(Context context) {
+ Log.i("Dataprovider", "initializing Dataprovider");
+ dbHelper = new Database(context);
+ }
+
+ public void open() throws SQLException {
+ database = dbHelper.getWritableDatabase();
+ }
+
+ public void close() {
+ dbHelper.close();
+ }
+
+ public Boolean newData(List<Day> data) {
+ dbHelper.clearDatabase(database);
+ for (int d = 0; d < data.size(); d++) {
+ Day day = data.get(d);
+ List<Pair<String, String>> daydata = new ArrayList<Pair<String, String>>();
+ daydata.add(new Pair<String, String>("date", day.date.toString()));
+ long dayId = insert("day", daydata);
+ List<Pair<Integer, List<Meal>>> meals = day.getMeals();
+ for (int m = 0; m < meals.size(); m++) {
+ List<Meal> meallist = meals.get(m).second;
+ Integer groupID = meals.get(m).first;
+ for(int n = 0; n < meallist.size(); n++) {
+ Meal meal = meallist.get(n);
+ ContentValues mealValues = new ContentValues();
+ mealValues.put("dayID", dayId);
+ mealValues.put("groupID", groupID);
+ mealValues.put("name", meal.getName());
+ mealValues.put("vegan", meal.getVegan());
+ mealValues.put("vegetarian", meal.getVegetarian());
+ mealValues.put("msc", meal.getMsc());
+ mealValues.put("bio", meal.getBio());
+ Float[] prices = meal.getPrices();
+ mealValues.put("price1", prices[0]);
+ mealValues.put("price2", prices[1]);
+ mealValues.put("price3", prices[2]);
+ long mealID = database.insert("meal", null, mealValues);
+
+ List<String> additions = meal.getAdditions();
+ for(int addition = 0; addition < additions.size(); addition++) {
+ ContentValues additiondata = new ContentValues();
+ additiondata.put("mealid", mealID);
+ additiondata.put("name", additions.get(addition));
+ database.insert("additions", null, additiondata);
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ public long insert(String table, List<Pair<String, String>> data) {
+ ContentValues values = new ContentValues();
+ for (int i = 0; i < data.size(); i++) {
+ Pair<String, String> line = data.get(i);
+ values.put(line.first, line.second);
+ }
+ Log.i("Database insert", database.toString());
+ return database.insert(table, null, values);
+ }
+
+ public List<Day> getData() {
+ List<Day> data = new ArrayList<Day>();
+ String[] daycolumns = {"date", "_id"};
+ String[] mealcolumns = {"_id", "name", "dayID", "groupID", "price1", "price2", "price3", "vegan", "vegetarian", "msc", "bio"};
+ String[] additioncolumns = {"name"};
+ Cursor cursor = database.query("day", daycolumns, null, null, null, null, null);
+ cursor.moveToFirst();
+ while (!cursor.isAfterLast()) {
+ data.add(new Day(cursor.getString(0), cursor.getString(1)));
+ cursor.moveToNext();
+ }
+ cursor.close();
+
+ for (int day = 0; day < data.size(); day++) {
+ String[] dayarg = {data.get(day).id};
+ cursor = database.query("meal", mealcolumns, "dayID = ?", dayarg, null, null, null);
+ cursor.moveToFirst();
+ while (!cursor.isAfterLast()) {
+ Meal meal = new Meal(cursor.getString(1));
+ Float[] prices = {cursor.getFloat(4), cursor.getFloat(5),cursor.getFloat(6)};
+ meal.setPrices(prices);
+ meal.setBio((cursor.getInt(10) == 1));
+ meal.setMsc((cursor.getInt(9) == 1));
+ meal.setVegetarian((cursor.getInt(8) == 1));
+ meal.setVegan((cursor.getInt(7) == 1));
+ String[] mealarg = {cursor.getString(0)};
+ Cursor acursor = database.query("additions", additioncolumns, "mealID = ?", mealarg, null, null, null);
+ acursor.moveToFirst();
+ while (!acursor.isAfterLast()) {
+ meal.addAddition(acursor.getString(0));
+ acursor.moveToNext();
+ }
+ acursor.close();
+ data.get(day).addMeal(cursor.getInt(3), meal);
+ cursor.moveToNext();
+ }
+ cursor.close();
+
+ }
+
+ return data;
+ }
+}
View
44 src/net/pherth/mensa/Day.java
@@ -25,20 +25,44 @@
package net.pherth.mensa;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import android.util.Log;
import android.util.Pair;
public class Day {
List<Pair<Integer, List<Meal>>> allMeals = new ArrayList<Pair<Integer, List<Meal>>>();
- Date date;
+ public Date date;
+ public String id;
public Day(Date currentDay) {
date = currentDay;
}
+ public Day(String currentDayString) {
+ try {
+ SimpleDateFormat sdfToDate = new SimpleDateFormat("dd.MM.yyyy");
+ date = sdfToDate.parse(currentDayString);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Day(String currentDayString, String dayid) {
+ try {
+ SimpleDateFormat sdfToDate = new SimpleDateFormat("dd.MM.yyyy");
+ date = sdfToDate.parse(currentDayString);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ id = dayid;
+ }
+
public List<Pair<Integer, List<Meal>>> getMeals() {
return allMeals;
}
@@ -55,7 +79,23 @@ public void addMealGroup(Pair<Integer, List<Meal>> meals) {
allMeals.add(meals);
}
- public void addMeal(String groupname, Meal meal) {
+ public void addMeal(Integer groupID, Meal meal) {
+ boolean found = false;
+ for(int group = 0; group < allMeals.size(); group++) {
+ if (allMeals.get(group).first.equals(groupID)) {
+ allMeals.get(group).second.add(meal);
+ found = true;
+ }
+ }
+ if (!found) {
+ List<Meal> meallist = new ArrayList<Meal>();
+ meallist.add(meal);
+ allMeals.add(new Pair<Integer, List<Meal>>(groupID, meallist));
+ }
+ }
+
+ public void setMeals(List<Pair<Integer, List<Meal>>> meals) {
+ allMeals = meals;
}
}
View
39 src/net/pherth/mensa/MainActivity.java
@@ -43,6 +43,7 @@
import android.preference.PreferenceManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
+import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -63,7 +64,7 @@
private static int NUM_VIEWS = 5;
private Context cxt;
private ProgressDialog m_ProgressDialog = null;
- private Runnable viewOrders;
+ private Runnable loadNew;
private String[] items;
AmazingListView lsComposer;
private MainPagerAdapter adapter;
@@ -89,7 +90,7 @@ public void onCreate(Bundle savedInstanceState) {
items = getResources().getStringArray(R.array.weekDays);
Calendar calendar = Calendar.getInstance();
- System.out.println(calendar);
+ Log.i("Calendar", calendar.toString());
calendar.setFirstDayOfWeek(0);
int day = calendar.get(Calendar.DAY_OF_WEEK) - 2;
@@ -111,20 +112,31 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
indicator.bringToFront();
pager.setAdapter( adapter );
indicator.setViewPager( pager );
- System.out.println(day);
+ Log.i("Day", String.valueOf(day));
if (day < 5) {
pager.setCurrentItem(day);
}
-
+ loadNew = new Runnable(){
+ @Override
+ public void run() {
+ getPlan(false);
+ }
+ };
//TODO only update if hasn't updated today. Otherwise load data from database
if (sharedPrefs.getBoolean("automaticUpdate", true)) {
- viewOrders = new Runnable(){
+ Thread thread = new Thread(null, loadNew, "MagentoBackground");
+ thread.start();
+ m_ProgressDialog = ProgressDialog.show(MainActivity.this,
+ getString( R.string.pleaseWait), getString(R.string.retrvData), true);
+ } else {
+ Runnable loadDatabase = new Runnable(){
@Override
public void run() {
- getPlan();
+ getPlan(true);
+
}
};
- Thread thread = new Thread(null, viewOrders, "MagentoBackground");
+ Thread thread = new Thread(null, loadDatabase, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(MainActivity.this,
getString( R.string.pleaseWait), getString(R.string.retrvData), true);
@@ -177,7 +189,7 @@ public void onItemClick(AdapterView<?> arg0, View res,
} else {
listView.setVisibility(View.GONE);
}
- System.out.println(listView.getCount());
+ Log.i("Listview", String.valueOf(listView.getCount()));
}
});
@@ -242,17 +254,17 @@ public String getTitle( int position )
}
}
- private void getPlan(){
+ private void getPlan(boolean fromDatabase){
if (isNetworkAvailable()) {
data = new Data(cxt);
- data.getAllData();
+ data.getAllData(fromDatabase);
for(int i=0; i<data.getDayCount(); i++){
MealAdapter mealAdapter = mAdapterList.get(i);
mealAdapter.setData(data.getCurrentDay(i));
mAdapterList.set(i, mealAdapter);
}
}
- runOnUiThread(returnRes);
+ runOnUiThread(returnRes);
}
private Runnable returnRes = new Runnable() {
@@ -276,16 +288,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- System.out.println(item);
- System.out.println(item.getItemId());
+ Log.i("Item", item.toString());
switch (item.getItemId()) {
case R.id.menu_settings:
Intent settingsActivity = new Intent(getBaseContext(),
MainPreference.class);
startActivityForResult(settingsActivity, 0);
break;
case R.id.menu_refresh:
- Thread thread = new Thread(null, viewOrders, "MagentoBackground");
+ Thread thread = new Thread(null, loadNew, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(MainActivity.this,
getString( R.string.pleaseWait), getString(R.string.retrvData), true);
View
80 src/net/pherth/mensa/MainPreference.java
@@ -25,18 +25,17 @@
package net.pherth.mensa;
-import android.content.res.Resources;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-public class MainPreference extends SherlockPreferenceActivity {
+public class MainPreference extends SherlockPreferenceActivity implements OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -48,39 +47,24 @@ protected void onCreate(Bundle savedInstanceState) {
CharSequence entry;
ListPreference cityPref = (ListPreference) findPreference("cityPreference");
- cityPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(
- Preference arg0, Object arg1) {
- int index = ((ListPreference) arg0).findIndexOfValue(arg1.toString());
- CharSequence summary = ((ListPreference) arg0).getEntries()[index];
- arg0.setSummary(summary);
- ListPreference mensaPref = (ListPreference) findPreference("mensaPreference");
- mensaPref.setValueIndex(0);
- CharSequence entry = mensaPref.getEntry();
- mensaPref.setSummary(entry);
-
- return true;
- }
- });
-
entry = cityPref.getEntry();
cityPref.setSummary(entry);
+
ListPreference mensaPref = (ListPreference) findPreference("mensaPreference");
- String currMensa = mensaPref.getValue();
- mensaPref.setEntries(getResources().getIdentifier(cityPref.getValue(), "array", "net.pherth.mensa"));
- mensaPref.setEntryValues(getResources().getIdentifier(cityPref.getValue()+"Values", "array", "net.pherth.mensa"));
- mensaPref.setOnPreferenceChangeListener(setListListener());
- if (mensaPref.findIndexOfValue(currMensa) != -1) {
- mensaPref.setKey(currMensa);
-
+ if (cityPref.getValue() != null) {
+ System.out.println("cityPref " + cityPref.getValue());
+ System.out.println("mensaPref " + mensaPref);
+ mensaPref.setEntries(getResources().getIdentifier(cityPref.getValue(), "array", "net.pherth.mensa"));
+ mensaPref.setEntryValues(getResources().getIdentifier(cityPref.getValue()+"Values", "array", "net.pherth.mensa"));
} else {
- mensaPref.setValueIndex(0);
+ mensaPref.setEntries(R.array.beList);
+ mensaPref.setEntryValues(R.array.beListValues);
}
entry = mensaPref.getEntry();
mensaPref.setSummary(entry);
+
ListPreference pricePref = (ListPreference) findPreference("priceCategory");
pricePref.setOnPreferenceChangeListener(setListListener());
entry = pricePref.getEntry();
@@ -105,28 +89,22 @@ public boolean onPreferenceChange(
return listener;
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- //MenuInflater inflater = getSupportMenuInflater();
- //inflater.inflate(R.menu.preferencemenu, menu);
- return true;
- }
-
-
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- /* switch (item.getItemId()) {
- case R.id.menu_save:
- if (getParent() == null) {
- setResult(Activity.RESULT_OK);
- } else {
- getParent().setResult(Activity.RESULT_OK);
- }
- finish();
- break;
-
- }*/
- return true;
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (key.equals("cityPreference")) {
+ ListPreference mensaPref = (ListPreference) findPreference("mensaPreference");
+ ListPreference cityPref = (ListPreference) findPreference("cityPreference");
+ if (cityPref.getValue() != null) {
+ System.out.println("cityPref " + cityPref.getValue());
+ System.out.println("mensaPref " + mensaPref);
+ mensaPref.setEntries(getResources().getIdentifier(cityPref.getValue(), "array", "net.pherth.mensa"));
+ mensaPref.setEntryValues(getResources().getIdentifier(cityPref.getValue()+"Values", "array", "net.pherth.mensa"));
+ } else {
+ mensaPref.setEntries(R.array.beList);
+ mensaPref.setEntryValues(R.array.beListValues);
+ }
+ mensaPref.setValueIndex(0);
+ CharSequence entry = mensaPref.getEntry();
+ mensaPref.setSummary(entry);
+ }
}
}
View
3 src/net/pherth/mensa/Meal.java
@@ -32,6 +32,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.util.Log;
public class Meal {
@@ -115,7 +116,7 @@ public void addAddition(String addition) {
}
public List<String> getAdditions() {
- System.out.println(this.additions);
+ Log.i("Additions", this.additions.toString());
return this.additions;
}
View
7 src/net/pherth/mensa/MealAdapter.java
@@ -28,16 +28,14 @@
import java.util.ArrayList;
import java.util.List;
-import net.pherth.mensa.R;
-
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@@ -101,9 +99,10 @@ protected void bindSectionHeader(View view, int position, boolean displaySection
ImageView lSectionTitle = (ImageView) view.findViewById(R.id.header);
int section = getSections()[getSectionForPosition(position)];
lSectionTitle.setImageResource(section);
- //view.findViewById(R.id.listTextContainer).setBackgroundResource(R.drawable.schatten);
+ view.findViewById(R.id.listTextContainer).setBackgroundResource(R.drawable.schatten);
} else {
view.findViewById(R.id.header).setVisibility(View.GONE);
+ view.findViewById(R.id.listTextContainer).setBackgroundResource(android.R.color.transparent);
}
}

0 comments on commit af28cfb

Please sign in to comment.
Something went wrong with that request. Please try again.