Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed semi-persistence in activity

  • Loading branch information...
commit cb67d236faacaa0e4c82a5460b0d845a2228e821 1 parent 1842ba8
Erik Ramfelt redsolo authored
1  android/res/values/strings.xml
View
@@ -14,4 +14,5 @@
<string name="menu_scan_qr_code">Scan QR</string>
+ <string name="list_retrieving_registations">Retrieving participants</string>
</resources>
74 android/src/com/squeed/attendit/android/AttendItActivity.java
View
@@ -5,16 +5,15 @@
import java.util.List;
import android.app.ListActivity;
+import android.app.ProgressDialog;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
@@ -26,11 +25,16 @@
public class AttendItActivity extends ListActivity {
+ private static final String BUNDLE_REGISTRATIONS_JSON = "BUNDLE_REGISTRATIONS";
+ private static final String EVENT_ID = "EVENT_ID";
+
public static final String URL = "http://localhost:8080/server/rest/";
public static final String REGISTRATION_REST_URL = URL + "registration";
private static final String SCAN_QR_CODE = "Scan QR";
- private ArrayList<RegistrationDTO> attendants = new ArrayList<RegistrationDTO>();
+ private static final Type jsonRegistrationsType = new TypeToken<List<RegistrationDTO>>(){}.getType();
+
+ private long eventId;
private PersonAdapter listAdapter;
private EditText filterText;
@@ -50,26 +54,29 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.person_list);
- RestClient client = new RestClient(REGISTRATION_REST_URL + String.format("/event/%d/attendants", 5));
- try {
- client.Execute(RestClient.RequestMethod.GET);
- Type jsonType = new TypeToken<List<RegistrationDTO>>(){}.getType();
- attendants = new Gson().fromJson(client.getResponse(), jsonType);
- // setTitle("Attend It - " +
- // attendants.get(0).getEvent().getTitle());
- } catch (Exception e) {
- Toast.makeText(this.getBaseContext(), "An error occured during retrieval: " + e.getMessage(),
- Toast.LENGTH_SHORT).show();
+ eventId = 5;
+ if (getIntent().getExtras() != null) {
+ eventId = getIntent().getExtras().getLong(EVENT_ID, eventId);
}
+
filterText = (EditText) findViewById(R.building_list.search_box);
filterText.addTextChangedListener(filterTextWatcher);
// ListView lView = (ListView) getListView();
// registerForContextMenu(lView);
+ ArrayList<RegistrationDTO> attendants = ((ArrayList<RegistrationDTO>) getLastNonConfigurationInstance());
+ if (attendants == null) {
+ if (savedInstanceState != null) {
+ attendants = new Gson().fromJson(savedInstanceState.getString(BUNDLE_REGISTRATIONS_JSON), jsonRegistrationsType);
+ } else {
+ new DownloadRegistrationsTask().execute(REGISTRATION_REST_URL + String.format("/event/%d/attendants", eventId));
+ attendants = new ArrayList<RegistrationDTO>();
+ }
+ }
listAdapter = new PersonAdapter(this, R.layout.person_list_item, attendants);
setListAdapter(listAdapter);
-
+
/*
* viewOrders = new Runnable() {
*
@@ -78,11 +85,21 @@ public void onCreate(Bundle savedInstanceState) {
* m_ProgressDialog = ProgressDialog.show(SoftwarePassionView.this,
* "Please wait...", "Retrieving data ...", true);
*/
-
}
@Override
+ public Object onRetainNonConfigurationInstance() {
+ return listAdapter.getAttendants();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString(BUNDLE_REGISTRATIONS_JSON, new Gson().toJson(listAdapter.getAttendants(), jsonRegistrationsType));
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.list_menu, menu);
@@ -186,4 +203,29 @@ public void afterTextChanged(Editable arg0) {
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
};
+
+ private class DownloadRegistrationsTask extends AsyncTask<String, Void, List<RegistrationDTO>> {
+ private ProgressDialog dialog;
+
+ @Override
+ protected void onPreExecute() {
+ dialog = ProgressDialog.show(AttendItActivity.this, null, getResources().getString(R.string.list_retrieving_registations), true);
+ super.onPreExecute();
+ }
+
+ protected List<RegistrationDTO> doInBackground(String... urls) {
+ RestClient client = new RestClient(urls[0]);
+ try {
+ client.Execute(RestClient.RequestMethod.GET);
+ return new Gson().fromJson(client.getResponse(), jsonRegistrationsType);
+ } catch (Exception e) {
+ return new ArrayList<RegistrationDTO>();
+ }
+ }
+
+ protected void onPostExecute(List<RegistrationDTO> result) {
+ listAdapter.add(result);
+ dialog.dismiss();
+ }
+ }
}
13 android/src/com/squeed/attendit/android/PersonAdapter.java
View
@@ -47,6 +47,19 @@ public PersonAdapter(Context context, int textViewResourceId, ArrayList<Registra
setShowAll(false);
}
+ public ArrayList<RegistrationDTO> getAttendants() {
+ return attendants;
+ }
+
+ public void add(List<RegistrationDTO> registrations) {
+ setNotifyOnChange(false);
+ for (RegistrationDTO registration : registrations) {
+ super.add(registration);
+ attendants.add(registration);
+ }
+ notifyDataSetChanged();
+ }
+
private List<RegistrationDTO> getFilteredResults(CharSequence constraint) {
List<RegistrationDTO> list = new ArrayList<RegistrationDTO>();
for (RegistrationDTO attendant : attendants) {
Please sign in to comment.
Something went wrong with that request. Please try again.