Archived
Created Utils class to contain small, general utility functions that don't fit anywhere else.
This commit is contained in:
1 parent
00bea7f3ef
commit
d0ae3bc2b5
5 files changed
+46
-36
No files matched your search
@@ -25,26 +25,4 @@ public class DataHandler {
|
||||
public Event[] populateList() {
|
||||
return events.toArray(new Event[events.size()]);
|
||||
}
|
||||
|
||||
public static String toMonth(String m) {
|
||||
int monthInt = Integer.parseInt(m);
|
||||
String monthString;
|
||||
|
||||
switch (monthInt) {
|
||||
case 1: monthString = "Jan"; break;
|
||||
case 2: monthString = "Feb"; break;
|
||||
case 3: monthString = "Mar"; break;
|
||||
case 4: monthString = "Apr"; break;
|
||||
case 5: monthString = "Mai"; break;
|
||||
case 6: monthString = "Jun"; break;
|
||||
case 7: monthString = "Jul"; break;
|
||||
case 8: monthString = "Aug"; break;
|
||||
case 9: monthString = "Sep"; break;
|
||||
case 10: monthString = "Okt"; break;
|
||||
case 11: monthString = "Nov"; break;
|
||||
case 12: monthString = "Des"; break;
|
||||
default: monthString = "NA"; break;
|
||||
}
|
||||
return monthString;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,13 @@ public class Event {
|
||||
public String location;
|
||||
public String category;
|
||||
|
||||
public Event(int id, String title, String description, String date, String location, String category) {
|
||||
public Event(
|
||||
int id,
|
||||
String title,
|
||||
String description,
|
||||
String date,
|
||||
String location,
|
||||
String category) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
@@ -26,6 +32,6 @@ public class Event {
|
||||
|
||||
String month = date.substring(5, 7);
|
||||
String day = date.substring(8, 10);
|
||||
return day + ". " + DataHandler.toMonth(month);
|
||||
return day + ". " + Utils.intToMonthStr(Integer.parseInt(month));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
public class Utils {
|
||||
public static String intToMonthStr(int monthInt) {
|
||||
String monthString;
|
||||
|
||||
switch (monthInt) {
|
||||
case 1: monthString = "Jan"; break;
|
||||
case 2: monthString = "Feb"; break;
|
||||
case 3: monthString = "Mar"; break;
|
||||
case 4: monthString = "Apr"; break;
|
||||
case 5: monthString = "Mai"; break;
|
||||
case 6: monthString = "Jun"; break;
|
||||
case 7: monthString = "Jul"; break;
|
||||
case 8: monthString = "Aug"; break;
|
||||
case 9: monthString = "Sep"; break;
|
||||
case 10: monthString = "Okt"; break;
|
||||
case 11: monthString = "Nov"; break;
|
||||
case 12: monthString = "Des"; break;
|
||||
default: monthString = "NA"; break;
|
||||
}
|
||||
return monthString;
|
||||
}
|
||||
|
||||
/* Check for Internet connection. */
|
||||
public static boolean checkConnection(Context context) {
|
||||
ConnectivityManager conMan
|
||||
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
|
||||
return netInfo != null;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -50,12 +47,4 @@ public class DnsActivity extends Activity {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for Internet connection. */
|
||||
static boolean checkConnection(Context context) {
|
||||
ConnectivityManager conMan
|
||||
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
|
||||
return netInfo != null;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.studentersamfundet.app.DataHandler;
|
||||
import com.studentersamfundet.app.Event;
|
||||
import com.studentersamfundet.app.FeedFetcher;
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.Utils;
|
||||
import com.studentersamfundet.app.XmlParser;
|
||||
|
||||
public class ProgramList extends ListActivity {
|
||||
@@ -36,7 +37,7 @@ public class ProgramList extends ListActivity {
|
||||
// Do we have intarwebs?
|
||||
// YAY = Fetch the feed.
|
||||
// NAY = Inform about no connection.
|
||||
if (DnsActivity.checkConnection(this)) {
|
||||
if (Utils.checkConnection(this)) {
|
||||
NodeList itemNodes = feed.fetch(feedURL, this, true);
|
||||
dh = parser.parse(itemNodes);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user