diff --git a/.classpath b/.classpath index 609aa00..b665303 100644 --- a/.classpath +++ b/.classpath @@ -2,6 +2,6 @@ - + diff --git a/src/com/studentersamfundet/app/FeedFetcher.java b/src/com/studentersamfundet/app/FeedFetcher.java index 24fc453..a9805b1 100644 --- a/src/com/studentersamfundet/app/FeedFetcher.java +++ b/src/com/studentersamfundet/app/FeedFetcher.java @@ -21,7 +21,6 @@ import org.xml.sax.SAXException; import android.content.Context; public class FeedFetcher { - String curLastBuild = ""; private InputStream OpenHttpConnection(String URL) throws IOException { InputStream in = null; diff --git a/src/com/studentersamfundet/app/ui/DnsActivity.java b/src/com/studentersamfundet/app/ui/DnsActivity.java index d72be56..2d0f7c9 100644 --- a/src/com/studentersamfundet/app/ui/DnsActivity.java +++ b/src/com/studentersamfundet/app/ui/DnsActivity.java @@ -1,30 +1,17 @@ package com.studentersamfundet.app.ui; -import org.w3c.dom.NodeList; - -import com.studentersamfundet.app.DataHandler; -import com.studentersamfundet.app.FeedFetcher; -import com.studentersamfundet.app.R; -import com.studentersamfundet.app.XmlParser; - import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.view.View; import android.widget.ImageView; -import android.widget.Toast; + +import com.studentersamfundet.app.R; public class DnsActivity extends Activity { - public static final String PREFS_NAME = "DnsPrefs"; - public static final String feedURL = "http://folk.uio.no/larsjeng/test.xml"; - public static final String localURL = "/data/com.studentersamfundet.app/files/dns_events"; - public static FeedFetcher feed = new FeedFetcher(); - public static XmlParser parser = new XmlParser(); - public DataHandler dh; Context context = null; /** Called when the activity is first created. */ @@ -36,35 +23,6 @@ public class DnsActivity extends Activity { View tmp = this.findViewById(R.id.join_us_textview); tmp.setVisibility(View.INVISIBLE); - - context = getApplicationContext(); - SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - boolean firstStart = prefs.getBoolean("firstStart", false); - - // Is it the first time the app is started? - if (!firstStart) { - // Do we have intarwebs? - // YAY = Fetch the feed. - // NAY = Inform about no connection. - if (checkConnection()) { - NodeList itemNodes = feed.fetch(feedURL, this, true); - dh = parser.parse(itemNodes); - } else { - Toast toast = Toast.makeText(context, R.string.error_noconnection_firstart, Toast.LENGTH_LONG); - toast.show(); - } - } else { - if (checkConnection()) { - NodeList itemNodes = feed.fetch(feedURL, this, true); - dh = parser.parse(itemNodes); - } else { - NodeList itemNodes = feed.fetch(localURL, this, false); - dh = parser.parse(itemNodes); - - Toast toast = Toast.makeText(context, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG); - toast.show(); - } - } } public void clickHandler(View v) { @@ -99,9 +57,9 @@ public class DnsActivity extends Activity { } /* Check for Internet connection. */ - boolean checkConnection() { + static boolean checkConnection(Context context) { ConnectivityManager conMan - = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = conMan.getActiveNetworkInfo(); return netInfo != null; } diff --git a/src/com/studentersamfundet/app/ui/ProgramList.java b/src/com/studentersamfundet/app/ui/ProgramList.java index 8480823..3caeb68 100644 --- a/src/com/studentersamfundet/app/ui/ProgramList.java +++ b/src/com/studentersamfundet/app/ui/ProgramList.java @@ -1,6 +1,11 @@ package com.studentersamfundet.app.ui; +import org.w3c.dom.NodeList; + +import com.studentersamfundet.app.DataHandler; +import com.studentersamfundet.app.FeedFetcher; import com.studentersamfundet.app.R; +import com.studentersamfundet.app.XmlParser; import android.app.ListActivity; import android.os.Bundle; @@ -8,8 +13,15 @@ import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.Toast; public class ProgramList extends ListActivity { + public static final String feedURL = "http://folk.uio.no/larsjeng/test.xml"; + public static final String localURL = "/data/com.studentersamfundet.app/files/dns_events"; + public static FeedFetcher feed = new FeedFetcher(); + public static XmlParser parser = new XmlParser(); + public DataHandler dh; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -18,6 +30,20 @@ public class ProgramList extends ListActivity { // View v = this.findViewById(R.id.program_button); // v.setClickable(false); + // Do we have intarwebs? + // YAY = Fetch the feed. + // NAY = Inform about no connection. + if (DnsActivity.checkConnection(this)) { + NodeList itemNodes = feed.fetch(feedURL, this, true); + dh = parser.parse(itemNodes); + } else { + NodeList itemNodes = feed.fetch(localURL, this, false); + dh = parser.parse(itemNodes); + + Toast toast = Toast.makeText(this, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG); + toast.show(); + } + View header = getLayoutInflater().inflate(R.layout.header, null); View footer = getLayoutInflater().inflate(R.layout.footer, null);