Skip to content

Commit

Permalink
fixed shared preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Jul 5, 2012
1 parent 57e58df commit 7d10ba9
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 90 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MensaTheme">
android:theme="@style/MensaTheme" android:debuggable="false">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
4 changes: 2 additions & 2 deletions res/layout/checkboxpref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:layout_weight="1"
android:background="@drawable/box_stretch">
<CheckBox
android:id="@+android:id/checkbox"
android:id="@+id/checkbox"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignParentRight="true"
Expand All @@ -19,7 +19,7 @@
android:button="@drawable/prefcheckbox"/>

<TextView
android:id="@+android:id/title"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
Expand Down
4 changes: 2 additions & 2 deletions res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
android:layout_height="fill_parent"
android:baselineAligned="true"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingBottom="6dp"
android:paddingLeft="26dp"
android:paddingRight="26dp"
android:paddingTop="4dp" >
android:paddingTop="6dp" >

<TextView
android:id="@+id/itemViewBig"
Expand Down
7 changes: 3 additions & 4 deletions res/layout/listviewpref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
android:background="@drawable/box_stretch">

<TextView
android:id="@+android:id/title"
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+android:id/summary"
android:id="@+id/summaryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+android:id/title"
android:layout_marginLeft="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/listSummary"/>
android:textColor="@color/listSummary" android:layout_toRightOf="@id/titleText"/>
<ImageView
android:id="@+id/listviewprefImage"
android:layout_width="wrap_content"
Expand Down
34 changes: 20 additions & 14 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/net.pherth.mensa"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Expand All @@ -13,17 +12,24 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/tab_bar" />

<android.support.v4.view.ViewPager
android:id="@+id/mainpager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:background="@drawable/background"
android:paddingTop="10dp" >

</android.support.v4.view.ViewPager>

<RelativeLayout
android:id="@+id/loadScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/loadText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/loadText"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/mainpager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/background"
android:paddingTop="20dp" />
</RelativeLayout>
6 changes: 4 additions & 2 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@
<string name="retrvData">Speiseplan wird abgerufen…</string>
<string name="bio">Bio</string>
<string name="fish">MSC zertifizierter Fisch</string>
<string name="connError">Es gab einen Verbinungsfehler. Bitte versuche es später wieder.</string>
<string name="connError">Es gab einen Verbindungsfehler. Bitte versuche es später wieder.</string>
<string name="about">Über</string>
<string name="general">Generell</string>
<string name="misc">Misc.</string>
<string name="help">Hilfe</string>
<string name="graphics">Grrafiken:</string>
<string name="graphics">Grafiken:</string>
<string name="code">Code:</string>
<string name="version">Version:</string>
<string name="github">Github:</string>
<string name="contact">Kontakt:</string>
<string name="website">Webseite:</string>
<string name="loadText">ucanhaz Update?</string>
<string name="noData">Keine Daten verfügbar.</string>
</resources>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@
<string name="github">Github:</string>
<string name="contact">Contact:</string>
<string name="website">Website:</string>
<string name="loadText">ucanhaz Update?</string>
<string name="noData">No data available.</string>
</resources>
10 changes: 5 additions & 5 deletions src/net/pherth/omnomagon/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public Data(Context cxt) {
public void getAllData(boolean fromDatabase) {
res = new ArrayList<Day>();
if(fromDatabase) {
Log.i("Data", "Load from database");
if(false) Log.i("Data", "Load from database");
loadDataFromDatabase();
} else {
Log.i("Data", "Load new data");
if(false) Log.i("Data", "Load new data");
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.context);
String city = sharedPrefs.getString("cityPreference", "beList");
String mensa = sharedPrefs.getString("mensaPreference", "fu1");
Expand Down Expand Up @@ -111,7 +111,7 @@ private void parseHTML(String html, String id) {
}

private void parseHTMLBerlin(String htmlString) {
Log.i("HTML", "beginning to parse");
if(false) 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++){
Expand Down Expand Up @@ -198,7 +198,7 @@ public List<Pair<Pair<Integer, String>, List<Meal>>> getCurrentDay(int position)
List<Pair<Pair<Integer, String>, List<Meal>>> currentMeals = new ArrayList<Pair<Pair<Integer, String>, List<Meal>>>();
Day currentDay = res.get(position);
currentMeals = currentDay.getMeals();
Log.i("Current Meals", currentMeals.toString());
if(false) Log.i("Current Meals", currentMeals.toString());
return currentMeals;
}

Expand All @@ -207,7 +207,7 @@ private String getURL(String city, String mensa) {
if (city.equals("beList")) {
url = "http://www.studentenwerk-berlin.de/speiseplan/rss/" + mensa + "/woche/lang/1";
}
Log.i("url", city + ", " + mensa + ", " + url);
if(false) Log.i("url", city + ", " + mensa + ", " + url);
return url;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/pherth/omnomagon/Dataprovider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Dataprovider {
private Database dbHelper;

public Dataprovider(Context context) {
Log.i("Dataprovider", "initializing Dataprovider");
if(false) Log.i("Dataprovider", "initializing Dataprovider");
dbHelper = new Database(context);
}

Expand Down
70 changes: 38 additions & 32 deletions src/net/pherth/omnomagon/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator;
Expand All @@ -70,7 +67,10 @@ public class MainActivity extends SherlockActivity {
private Runnable loadNew;
private String[] items;
private ArrayList<MealAdapter> mAdapterList = new ArrayList<MealAdapter>();
//private ViewSwitcher mSwitcher;
com.actionbarsherlock.app.ActionBar actionBar;
OnSharedPreferenceChangeListener prefListener;
SharedPreferences sharedPrefs;

/** Called when the activity is first created. */
@Override
Expand All @@ -79,41 +79,44 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
cxt = this;

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(cxt);
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(cxt);

actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar));
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setTitle(getCurrentMensa(sharedPrefs.getString("mensaPreference", "Mensa")));
actionBar.setSubtitle("07.05.2012");
//actionBar.setSubtitle("07.05.2012");

items = getResources().getStringArray(R.array.weekDays);

Calendar calendar = Calendar.getInstance();
Log.i("Calendar", calendar.toString());
if(false) Log.i("Calendar", calendar.toString());
calendar.setFirstDayOfWeek(0);
int day = calendar.get(Calendar.DAY_OF_WEEK) - 2;

OnSharedPreferenceChangeListener prefsListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
actionBar.setTitle(getCurrentMensa(prefs.getString("mensaPreference", "Mensa")));
for(int i=0; i<5; i++){
mAdapterList.get(i).notifyDataSetChanged();
}
}
};
sharedPrefs.registerOnSharedPreferenceChangeListener(prefsListener);
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {

actionBar.setTitle(getCurrentMensa(prefs.getString("mensaPreference", "Mensa")));
for(int i=0; i<5; i++){
mAdapterList.get(i).notifyDataSetChanged();
}
}
};
sharedPrefs.registerOnSharedPreferenceChangeListener(prefListener);
for(int x=0; x<5; x++) {
mAdapterList.add(new MealAdapter(cxt));
}
MainPagerAdapter adapter = new MainPagerAdapter(this);
//mSwitcher = (ViewSwitcher)findViewById(R.id.mainSwitcher);
ViewPager pager = (ViewPager)findViewById( R.id.mainpager );
TitlePageIndicator indicator = (TitlePageIndicator)findViewById( R.id.indicator );
indicator.bringToFront();
pager.setAdapter(adapter);
indicator.setViewPager( pager );
Log.i("Day", String.valueOf(day));
if(false) Log.i("Day", String.valueOf(day));
if (day < 5) {
pager.setCurrentItem(day);
}
Expand Down Expand Up @@ -161,10 +164,12 @@ public int getCount() {
@Override
public Object instantiateItem(View collection, int position) {
AmazingListView v = new AmazingListView( context );
ImageView iv = new ImageView( context );
((ViewPager) collection).addView(v, 0);
v.addFooterView(iv);
iv.setImageResource(R.drawable.footer);
/*if (!mAdapterList.get(position).isEmpty()) {
ImageView iv = new ImageView( context );
v.addFooterView(iv);
iv.setImageResource(R.drawable.footer);
}*/
v.setAdapter(mAdapterList.get(position));
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
v.setDivider(getResources().getDrawable(android.R.color.transparent));
Expand Down Expand Up @@ -201,11 +206,7 @@ public void destroyItem(View collection, int position, Object view) {

@Override
public boolean isViewFromObject(View view, Object object) {
return view==((ListView)object);
}

@Override
public void finishUpdate(View arg0) {
return view==(object);
}


Expand All @@ -217,9 +218,6 @@ public Parcelable saveState() {
return null;
}

@Override
public void startUpdate(View arg0) {}

@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
Expand Down Expand Up @@ -253,6 +251,7 @@ public void run() {
for(int i=0; i<5; i++){
mAdapterList.get(i).notifyDataSetChanged();
}
//mSwitcher.showNext();
}
};

Expand All @@ -266,7 +265,7 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i("Item", item.toString());
if(false) Log.i("Item", item.toString());
switch (item.getItemId()) {
case R.id.menu_settings:
Intent settingsActivity = new Intent(getBaseContext(),
Expand Down Expand Up @@ -300,9 +299,10 @@ public void onPause() {
if(m_ProgressDialog != null) {
m_ProgressDialog.dismiss();
}
super.onPause();
//sharedPrefs.unregisterOnSharedPreferenceChangeListener(prefListener);
super.onPause();
}

private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down Expand Up @@ -342,9 +342,15 @@ public void onConfigurationChanged(Configuration newConfig) {
public Boolean updateToday(Long timestamp) {
Long currTimestamp = System.currentTimeMillis();
Float diff = (currTimestamp.floatValue() - timestamp) / 86400000;
Log.i("MainActivity", diff.toString());
if(false) Log.i("MainActivity", diff.toString());
return (diff < 1);

}

@Override
protected void onResume() {
super.onResume();
sharedPrefs.registerOnSharedPreferenceChangeListener(prefListener);
}
}

Loading

0 comments on commit 7d10ba9

Please sign in to comment.