Permalink
Browse files

Beerlist and brewerylist do not reload if the list is called quickly …

…again, like the timeline
  • Loading branch information...
1 parent 32ed2b4 commit a98d332e2621e215d0ca20864a6332b492d90c2f Jonas Furrer committed May 28, 2012
@@ -38,6 +38,9 @@
private BeerListAdapter adapter;
private ProgressDialog progressDialog;
private HttpHelper httpHelper;
+
+ private static final long UPDATE_THRESHOLD = 30000;
+ private long updateTimestamp = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -55,7 +58,10 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
- new GetBeerData().execute();
+ if (System.currentTimeMillis() - this.updateTimestamp > UPDATE_THRESHOLD) {
+ new GetBeerData().execute();
+ this.updateTimestamp = System.currentTimeMillis();
+ }
}
@Override
@@ -1,5 +1,13 @@
package ch.hsr.bieridee.android.activities;
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.json.JSONArray;
+import org.json.JSONException;
+
import android.app.ExpandableListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -14,20 +22,15 @@
import ch.hsr.bieridee.android.http.HttpHelper;
import ch.hsr.bieridee.android.utils.ErrorHelper;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.json.JSONArray;
-import org.json.JSONException;
-
-import java.io.IOException;
-
/**
* Activity that shows a list of all beertype in our database.
*/
public class BeertypeListActivity extends ExpandableListActivity {
private static final String LOG_TAG = BeertypeListActivity.class.getName();
+ private static final long UPDATE_THRESHOLD = 30000;
+ private long updateTimestamp = 0;
+
private BeertypeListAdapter adapter;
private MultithreadProgressDialog progressDialog;
private HttpHelper httpHelper;
@@ -47,7 +50,10 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
- new GetBeertypeData().execute();
+ if (System.currentTimeMillis() - this.updateTimestamp > UPDATE_THRESHOLD) {
+ new GetBeertypeData().execute();
+ this.updateTimestamp = System.currentTimeMillis();
+ }
}
@Override
@@ -1,5 +1,13 @@
package ch.hsr.bieridee.android.activities;
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.json.JSONArray;
+import org.json.JSONException;
+
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
@@ -18,20 +26,15 @@
import ch.hsr.bieridee.android.http.HttpHelper;
import ch.hsr.bieridee.android.utils.ErrorHelper;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.json.JSONArray;
-import org.json.JSONException;
-
-import java.io.IOException;
-
/**
* Activity that shows a list of all breweries in our database.
*/
public final class BreweryListActivity extends ListActivity {
private static final String LOG_TAG = BreweryListActivity.class.getName();
+ private static final long UPDATE_THRESHOLD = 30000;
+ private long updateTimestamp = 0;
+
private BreweryListAdapter adapter;
private ProgressDialog progressDialog;
private HttpHelper httpHelper;
@@ -51,7 +54,10 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
- new GetBreweryData().execute();
+ if (System.currentTimeMillis() - this.updateTimestamp > UPDATE_THRESHOLD) {
+ new GetBreweryData().execute();
+ this.updateTimestamp = System.currentTimeMillis();
+ }
}
@Override
@@ -47,7 +47,7 @@
private TextView noActions;
private Button gotoBeerlistButton;
- private static final long THRESHOLD = 30000;
+ private static final long UPDATE_THRESHOLD = 30000;
private long updateTimestamp = 0;
private static final int SIMILARITY_TIMEDIFF = 15;
@@ -88,7 +88,7 @@ public void onClick(View v) {
@Override
public void onStart() {
super.onStart();
- if (System.currentTimeMillis() - this.updateTimestamp > THRESHOLD) {
+ if (System.currentTimeMillis() - this.updateTimestamp > UPDATE_THRESHOLD) {
new GetActionData().execute();
this.updateTimestamp = System.currentTimeMillis();
}

0 comments on commit a98d332

Please sign in to comment.