Archived
Not sure what I did here. I've done it like a month ago and I just don't remember, but I don't want to lose the code in case it does something important or fancy.
This commit is contained in:
1 parent
e13c92ecf7
commit
855ae6c055
2 files changed
+11
-10
No files matched your search
@@ -22,11 +22,12 @@ import android.content.Context;
|
||||
|
||||
public class FeedFetcher implements Serializable {
|
||||
private static final long serialVersionUID = 3408406671996232103L;
|
||||
private static final String LOCAL_FILENAME = "dns_events";
|
||||
private final String localFilename;
|
||||
private String url;
|
||||
|
||||
public FeedFetcher(String url) {
|
||||
public FeedFetcher(String url, String localFilename) {
|
||||
this.url = url;
|
||||
this.localFilename = localFilename;
|
||||
}
|
||||
|
||||
private InputStream openHttpConnection() throws IOException {
|
||||
@@ -86,7 +87,7 @@ public class FeedFetcher implements Serializable {
|
||||
return itemNodes;
|
||||
}
|
||||
|
||||
public static NodeList loadLocalData(Context c) throws IOException {
|
||||
public NodeList loadLocalData(Context c) throws IOException {
|
||||
NodeList nodes;
|
||||
|
||||
InputStream is = loadFile(c);
|
||||
@@ -120,11 +121,11 @@ public class FeedFetcher implements Serializable {
|
||||
return doc.getElementsByTagName("item");
|
||||
}
|
||||
|
||||
private static boolean doesFileNeedUpdate(Context c) throws IOException {
|
||||
private boolean doesFileNeedUpdate(Context c) throws IOException {
|
||||
/** Maximum amount of time before the file needs updating, in ms: */
|
||||
final long maxInterval = 1000 * 60 * 60; // one hour
|
||||
|
||||
File file = c.getFileStreamPath(LOCAL_FILENAME);
|
||||
File file = c.getFileStreamPath(localFilename);
|
||||
if (! file.exists()) return true;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -133,10 +134,10 @@ public class FeedFetcher implements Serializable {
|
||||
return now - lastMod > maxInterval;
|
||||
}
|
||||
|
||||
private static void saveFile(InputStream in, Context c) throws IOException, FileNotFoundException {
|
||||
private void saveFile(InputStream in, Context c) throws IOException, FileNotFoundException {
|
||||
final int BUFFER_SIZE = 128;
|
||||
|
||||
OutputStream os = c.openFileOutput(LOCAL_FILENAME, Context.MODE_PRIVATE);
|
||||
OutputStream os = c.openFileOutput(localFilename, Context.MODE_PRIVATE);
|
||||
byte[] inputBuffer = new byte[BUFFER_SIZE];
|
||||
|
||||
int bytes = 0;
|
||||
@@ -147,7 +148,7 @@ public class FeedFetcher implements Serializable {
|
||||
os.close();
|
||||
}
|
||||
|
||||
private static InputStream loadFile(Context c) throws FileNotFoundException {
|
||||
return c.openFileInput(LOCAL_FILENAME);
|
||||
private InputStream loadFile(Context c) throws FileNotFoundException {
|
||||
return c.openFileInput(localFilename);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class DnsActivity extends BaseDnsActivity {
|
||||
setContentView(R.layout.main);
|
||||
|
||||
/* Initialize necessary variables: */
|
||||
feedFetcher = new FeedFetcher(feedURL);
|
||||
feedFetcher = new FeedFetcher(feedURL, "local_events");
|
||||
|
||||
/* Set opening hours: */
|
||||
TextView tvNeuf = (TextView)findViewById(R.id.main_menu_hours_neuf);
|
||||
|
||||
Reference in new issue
Block a user