Create an alternate dialog if user isn't on a Google Maps enabled device

pull/14/head
Tim Su 13 years ago
parent 410ebab943
commit 572296e023

@ -631,10 +631,8 @@
android:windowSoftInputMode="stateHidden" android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait"></activity> android:screenOrientation="portrait"></activity>
<!-- Uses Library --> <!-- Uses Library -->
<uses-library android:name="com.google.android.maps" android:required="false" />
<uses-library android:name="com.google.android.maps" />
</application> </application>

@ -77,8 +77,8 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
public interface TaskRabbitSetListener { public interface TaskRabbitSetListener {
public void readFromModel(JSONObject json, String key, int mode); public void readFromModel(JSONObject json, String key, int mode);
public void saveToJSON(JSONObject json, String key) throws JSONException; public void saveToDatabase(JSONObject json, String key) throws JSONException;
public void writeToJSON(JSONObject json, String key) throws JSONException; public void postToTaskRabbit(JSONObject json, String key) throws JSONException;
} }
public interface ActivityResultSetListener { public interface ActivityResultSetListener {
@ -430,7 +430,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
return; return;
} }
if(taskRabbitTask.getTaskID() > 0) { if(taskRabbitTask.getTaskID() != TaskRabbitTaskContainer.NO_ID) {
taskButton.setText("Already Posted!"); taskButton.setText("Already Posted!");
taskButton.setEnabled(false); taskButton.setEnabled(false);
} }
@ -472,7 +472,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
for (int i = 0; i < controls.size(); i++) { for (int i = 0; i < controls.size(); i++) {
if (presetValues[i] == -1) continue; if (presetValues[i] == -1) continue;
TaskRabbitSetListener set = controls.get(i); TaskRabbitSetListener set = controls.get(i);
set.writeToJSON(parameters, keys[i]); set.postToTaskRabbit(parameters, keys[i]);
} }
if (parameters.optJSONArray("other_locations_attributes") == null) { if (parameters.optJSONArray("other_locations_attributes") == null) {
parameters.put(getString(R.string.tr_attr_city_id), Preferences.getInt("task_rabbit_city_id", 1)); parameters.put(getString(R.string.tr_attr_city_id), Preferences.getInt("task_rabbit_city_id", 1));
@ -498,7 +498,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
String[] keys = getResources().getStringArray(R.array.tr_default_set_key); String[] keys = getResources().getStringArray(R.array.tr_default_set_key);
for (int i = 0; i < controls.size(); i++) { for (int i = 0; i < controls.size(); i++) {
TaskRabbitSetListener set = controls.get(i); TaskRabbitSetListener set = controls.get(i);
set.saveToJSON(parameters, keys[i]); set.saveToDatabase(parameters, keys[i]);
} }
parameters.put(getString(R.string.tr_set_key_type), currentSelectedItem); parameters.put(getString(R.string.tr_set_key_type), currentSelectedItem);
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString()); parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
@ -636,7 +636,8 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
private void loadLocation() { private void loadLocation() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if ( !locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) || !locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) { if ( !locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) &&
!locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
buildAlertMessageNoGps(); buildAlertMessageNoGps();
} }

@ -291,7 +291,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
Log.d("TRControlSet", "Location changed and found"); Log.d("TRControlSet", "Location changed and found");
currentLocation = location; currentLocation = location;
isEnabledForTRLocation = supportsCurrentLocation(); isEnabledForTRLocation = supportsCurrentLocation();
@ -320,7 +319,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
@Override @Override
public boolean didPostToTaskRabbit() { public boolean didPostToTaskRabbit() {
if (taskRabbitTask == null) return false; if (taskRabbitTask == null) return false;
return taskRabbitTask.getTaskID() > 0; return taskRabbitTask.getTaskID() != TaskRabbitTaskContainer.NO_ID;
} }

@ -85,13 +85,13 @@ public class TaskRabbitDeadlineControlSet extends PopupControlSet implements Tas
@Override @Override
public void saveToJSON(JSONObject json, String key) throws JSONException { public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, dateAndTimePicker.constructDueDate()); json.put(key, dateAndTimePicker.constructDueDate());
} }
@Override @Override
public void writeToJSON(JSONObject json, String key) throws JSONException { public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
long dueDate = dateAndTimePicker.constructDueDate(); long dueDate = dateAndTimePicker.constructDueDate();
json.put(key, dueDate); json.put(key, dueDate);
} }

@ -1,5 +1,6 @@
package com.todoroo.astrid.taskrabbit; package com.todoroo.astrid.taskrabbit;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -8,6 +9,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.location.Address; import android.location.Address;
import android.location.Geocoder; import android.location.Geocoder;
@ -16,9 +18,13 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet; import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.ActivityResultSetListener; import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.ActivityResultSetListener;
@ -30,8 +36,9 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
private final TextView displayText; private final TextView displayText;
private final TextView displayEdit; private final TextView displayEdit;
private final Activity activity; private final Activity activity;
public Location location;
private String locationName; private String locationName;
public Location location;
public JSONObject manualEntry = null;
public int REQUEST_CODE_TASK_RABBIT_LOCATION = 6; public int REQUEST_CODE_TASK_RABBIT_LOCATION = 6;
@ -50,14 +57,48 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent mapIntent = new Intent(activity, TaskRabbitMapActivity.class); try {
activity.startActivityForResult(mapIntent, REQUEST_CODE_TASK_RABBIT_LOCATION); Class.forName("com.google.android.maps.MapView");
Intent mapIntent = new Intent(activity, TaskRabbitMapActivity.class);
activity.startActivityForResult(mapIntent, REQUEST_CODE_TASK_RABBIT_LOCATION);
} catch (Exception e) {
manualLocationEntry();
}
} }
}); });
} }
protected void manualLocationEntry() {
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
final String[] fields = new String[] { "Address", "City", "State", "Zip" };
final HashMap<String, EditText> views = new HashMap<String, EditText>();
for(String field : fields) {
EditText et = new EditText(activity);
et.setHint(field);
et.setLayoutParams(lp);
views.put(field, et);
layout.addView(et);
}
DialogUtilities.viewDialog(activity, "Enter Location", layout, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
displayEdit.setText(views.get("Address").getText());
manualEntry = new JSONObject();
for(String field : fields)
try {
manualEntry.put(field.toLowerCase(), views.get(field).getText());
} catch (JSONException e) {
// fail
}
}
}, null);
}
private void parseTaskLocation(JSONObject json) { private void parseTaskLocation(JSONObject json) {
if (json == null) return; if (json == null) return;
@ -85,6 +126,7 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
location.setLatitude(locationToDouble(lat)); location.setLatitude(locationToDouble(lat));
location.setLongitude(locationToDouble(lng)); location.setLongitude(locationToDouble(lng));
displayEdit.setText(getLocationText()); displayEdit.setText(getLocationText());
manualEntry = null;
getAddressFromLocation(location); getAddressFromLocation(location);
@ -136,12 +178,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
} }
@Override @Override
public void saveToJSON(JSONObject json, String key) throws JSONException { public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, getTaskLocation()); json.put(key, getTaskLocation());
} }
@Override @Override
public void writeToJSON(JSONObject json, String key) throws JSONException { public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
JSONArray locations = json.optJSONArray("other_locations_attributes"); JSONArray locations = json.optJSONArray("other_locations_attributes");
if (locations == null) { if (locations == null) {
locations = new JSONArray(); locations = new JSONArray();
@ -152,6 +194,8 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
} }
private JSONObject getTaskLocation() { private JSONObject getTaskLocation() {
if(manualEntry != null)
return manualEntry;
try { try {
JSONObject locationObject = new JSONObject(); JSONObject locationObject = new JSONObject();

@ -57,7 +57,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
List<Overlay> mapOverlays = mapView.getOverlays(); List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon_locale); Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this); currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this);
GeoPoint point = null; GeoPoint point = null;
@ -65,7 +65,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
if(lastKnownLocation != null) { if(lastKnownLocation != null) {
point = new GeoPoint((int)(lastKnownLocation.getLatitude()*1E6),(int)(lastKnownLocation.getLongitude()*1E6)); point = new GeoPoint((int)(lastKnownLocation.getLatitude()*1E6),(int)(lastKnownLocation.getLongitude()*1E6));
OverlayItem overlayitem = new OverlayItem(point, "Set this location", "Send this location to Task Rabbit!"); OverlayItem overlayitem = createOverlayItem(point);
currentOverlayItem.addOverlay(overlayitem); currentOverlayItem.addOverlay(overlayitem);
mapOverlays.add(currentOverlayItem); mapOverlays.add(currentOverlayItem);
@ -86,11 +86,8 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
ImageButton searchButton=(ImageButton)findViewById(R.id.search_button); ImageButton searchButton=(ImageButton)findViewById(R.id.search_button);
searchButton.setImageResource(android.R.drawable.ic_menu_search); searchButton.setImageResource(android.R.drawable.ic_menu_search);
searchButton.setOnClickListener(new View.OnClickListener() { searchButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// TODO Auto-generated method stub
searchLocation(); searchLocation();
} }
}); });
@ -112,12 +109,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
builder.setMessage("GPS needs to be enabled in order to add location based tasks. Do you want to enable it?") builder.setMessage("GPS needs to be enabled in order to add location based tasks. Do you want to enable it?")
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
} }
}) })
.setNegativeButton("No", new DialogInterface.OnClickListener() { .setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) { public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel(); dialog.cancel();
} }
}); });
@ -150,59 +147,64 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
private void searchLocation() { private void searchLocation() {
Thread thread = new Thread(){ Thread thread = new Thread() {
@Override @Override
public void run (){ public void run() {
List<Address> addresses = null; List<Address> addresses = null;
try { try {
Geocoder geoCoder = new Geocoder(TaskRabbitMapActivity.this, Locale.getDefault()); Geocoder geoCoder = new Geocoder(
addresses = geoCoder.getFromLocationName(searchText.getText().toString(),5); TaskRabbitMapActivity.this, Locale.getDefault());
} catch (IOException e) { addresses = geoCoder.getFromLocationName(
// TODO Auto-generated catch block searchText.getText().toString(), 5);
e.printStackTrace(); } catch (IOException e) {
} e.printStackTrace();
}
if(addresses != null && addresses.size() > 0) if (addresses != null && addresses.size() > 0) {
{ updateAddress(addresses.get(0));
updateAddress(addresses.get(0)); GeoPoint q = new GeoPoint(
GeoPoint q = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6), (int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6)); (int) (addresses.get(0).getLongitude() * 1E6));
Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable(R.drawable.icon_locale); Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable(
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, TaskRabbitMapActivity.this); R.drawable.icon_locale);
mapController.animateTo(q); currentOverlayItem = new TaskRabbitMapOverlayItem(drawable,
mapController.setZoom(12); TaskRabbitMapActivity.this);
mapController.animateTo(q);
mapController.setZoom(12);
OverlayItem overlayitem = new OverlayItem(q, "Set this location", "For the rabbits!"); OverlayItem overlayitem = createOverlayItem(q);
currentOverlayItem.addOverlay(overlayitem); currentOverlayItem.addOverlay(overlayitem);
List<Overlay> mapOverlays = mapView.getOverlays(); List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.clear(); mapOverlays.clear();
mapOverlays.add(currentOverlayItem); mapOverlays.add(currentOverlayItem);
Message successMessage = new Message(); Message successMessage = new Message();
successMessage.what = 1; successMessage.what = 1;
handler.sendMessage(successMessage); handler.sendMessage(successMessage);
// searchText.setText(""); } else {
}
else
{
Message failureMessage = new Message(); Message failureMessage = new Message();
failureMessage.what = -1; failureMessage.what = -1;
handler.sendMessage(failureMessage); handler.sendMessage(failureMessage);
} }
} }
};
thread.start(); };
} thread.start();
}
protected OverlayItem createOverlayItem(GeoPoint q) {
OverlayItem overlayitem = new OverlayItem(q, "Set this location",
"Use this location for TaskRabbit");
return overlayitem;
}
private void getAddressFromLocation(Location location){ private void getAddressFromLocation(Location location){
try { try {
@ -220,7 +222,6 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
} }
private void updateAddress(Address address){ private void updateAddress(Address address){
if(address.getLocality() != null && address.getPostalCode() != null){ if(address.getLocality() != null && address.getPostalCode() != null){
// locationAddress = (address.getLocality() + ", " + address.getPostalCode());
locationAddress = ""; locationAddress = "";
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){ for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
locationAddress += address.getAddressLine(i) + ", "; locationAddress += address.getAddressLine(i) + ", ";
@ -241,13 +242,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable); TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable);
GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6)); GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Set this location", "For the rabbits!"); OverlayItem overlayitem = createOverlayItem(point);
myItemizedOverlay.addOverlay(overlayitem); myItemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(myItemizedOverlay); mapOverlays.add(myItemizedOverlay);
} }
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) { if (location != null) {
double lat = location.getLatitude(); double lat = location.getLatitude();
double lng = location.getLongitude(); double lng = location.getLongitude();
@ -260,17 +260,17 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
} }
@Override @Override
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub //
} }
@Override @Override
public void onProviderEnabled(String provider) { public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub //
} }
@Override @Override
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub //
} }

@ -6,36 +6,26 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Point;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem; import com.google.android.maps.OverlayItem;
import com.timsu.astrid.R;
public class TaskRabbitMapOverlayItem extends ItemizedOverlay { public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Drawable defaultMarker;
private TaskRabbitMapActivity mActivity; private TaskRabbitMapActivity mActivity;
private OverlayItem inDrag; private ImageView dragImage = null;
private int xDragImageOffset=0; private OverlayItem selectedItem = null;
private int yDragImageOffset=0;
private final int xDragTouchOffset=0;
private final int yDragTouchOffset=0;
private ImageView dragImage=null;
private OverlayItem selectedItem=null;
private final int didTap = -1;
private final Point tapPoint = null;
public TaskRabbitMapOverlayItem(Drawable defaultMarker) { public TaskRabbitMapOverlayItem(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker)); super(boundCenterBottom(defaultMarker));
} }
public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) { public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) {
super(boundCenterBottom(defaultMarker)); super(boundCenterBottom(defaultMarker));
this.defaultMarker = defaultMarker;
mActivity = activity; mActivity = activity;
getDragImage(); getDragImage();
@ -46,13 +36,9 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay {
dragImage= new ImageView(mActivity); dragImage= new ImageView(mActivity);
dragImage.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.icon_locale)); dragImage.setImageDrawable(mActivity.getResources().getDrawable(
//dragImage.setImageDrawable(R.drawable.gl_alarm); android.R.drawable.star_big_on));
dragImage.setLayoutParams(new RelativeLayout.LayoutParams(50, 50)); dragImage.setLayoutParams(new RelativeLayout.LayoutParams(50, 50));
xDragImageOffset=dragImage.getDrawable().getIntrinsicWidth()/2;
yDragImageOffset=dragImage.getDrawable().getIntrinsicHeight();
} }
return dragImage; return dragImage;
} }
@ -83,8 +69,8 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay {
dialog.setIcon( dialog.setIcon(
android.R.drawable.ic_dialog_alert).setPositiveButton( android.R.drawable.ic_dialog_alert).setPositiveButton(
android.R.string.ok, new DialogInterface.OnClickListener() { android.R.string.ok, new DialogInterface.OnClickListener() {
@SuppressWarnings("nls")
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("lat",selectedItem.getPoint().getLatitudeE6()); data.putExtra("lat",selectedItem.getPoint().getLatitudeE6());
data.putExtra("lng",selectedItem.getPoint().getLongitudeE6()); data.putExtra("lng",selectedItem.getPoint().getLongitudeE6());

@ -78,12 +78,12 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
} }
@Override @Override
public void saveToJSON(JSONObject json, String key) throws JSONException { public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, editText.getText().toString()); json.put(key, editText.getText().toString());
} }
@Override @Override
public void writeToJSON(JSONObject json, String key) throws JSONException { public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
String nameKey = activity.getString(R.string.tr_set_key_description); String nameKey = activity.getString(R.string.tr_set_key_description);
if (key.equals(activity.getString(R.string.tr_set_key_name)) && json.has(nameKey)) { if (key.equals(activity.getString(R.string.tr_set_key_name)) && json.has(nameKey)) {
json.put(nameKey, json.optString(nameKey, "") + "\nRestaurant Name: " + editText.getText().toString()); json.put(nameKey, json.optString(nameKey, "") + "\nRestaurant Name: " + editText.getText().toString());

@ -160,7 +160,7 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
} }
} }
@Override @Override
public void saveToJSON(JSONObject json, String key) throws JSONException { public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, spinner.getSelectedItemPosition()); json.put(key, spinner.getSelectedItemPosition());
} }
@ -174,7 +174,7 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
} }
@Override @Override
public void writeToJSON(JSONObject json, String key) throws JSONException { public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
if(spinner.getSelectedItem() != null){ if(spinner.getSelectedItem() != null){
String spinnerString = spinner.getSelectedItem().toString(); String spinnerString = spinner.getSelectedItem().toString();

@ -20,6 +20,8 @@ import com.todoroo.astrid.sync.SyncContainer;
*/ */
public class TaskRabbitTaskContainer extends SyncContainer { public class TaskRabbitTaskContainer extends SyncContainer {
public static final int NO_ID = 0;
public Metadata trTask; public Metadata trTask;
public TaskRabbitTaskContainer(Task task, Metadata trTask) { public TaskRabbitTaskContainer(Task task, Metadata trTask) {
@ -42,18 +44,16 @@ public class TaskRabbitTaskContainer extends SyncContainer {
return getJSONData(TaskRabbitMetadata.DATA_REMOTE); return getJSONData(TaskRabbitMetadata.DATA_REMOTE);
} }
public int getTaskID() { public long getTaskID() {
if(TextUtils.isEmpty(trTask.getValue(TaskRabbitMetadata.ID)))
return NO_ID;
try { try {
int taskID = Integer.parseInt(trTask.getValue(TaskRabbitMetadata.ID)); return Long.parseLong(trTask.getValue(TaskRabbitMetadata.ID));
if(taskID > 0) } catch (Exception e) {
return taskID; return NO_ID;
} }
catch (Exception e) {
e.printStackTrace();
}
return 0;
} }
private JSONObject getJSONData(StringProperty key) { private JSONObject getJSONData(StringProperty key) {
if(trTask.containsNonNullValue(key)) { if(trTask.containsNonNullValue(key)) {
String jsonString = trTask.getValue(key); String jsonString = trTask.getValue(key);

Loading…
Cancel
Save