diff options
20 files changed, 305 insertions, 218 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index 1ea0d28..004ecc0 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -111,8 +111,7 @@ android:windowSoftInputMode="stateHidden" > </activity> <activity - android:name=".EditWaypointActivity" - android:configChanges="keyboardHidden|orientation" + android:name=".EditWaypointActivity_" android:label="@string/waypoint_edit_title" android:windowSoftInputMode="stateHidden" > </activity> diff --git a/main/res/layout/editwaypoint_activity.xml b/main/res/layout/editwaypoint_activity.xml index 657e9f4..cd0b46c 100644 --- a/main/res/layout/editwaypoint_activity.xml +++ b/main/res/layout/editwaypoint_activity.xml @@ -21,12 +21,14 @@ <Button android:id="@+id/buttonLatitude" style="@style/button_full" - android:hint="@string/latitude" /> + android:hint="@string/latitude" + android:freezesText="true" /> <Button android:id="@+id/buttonLongitude" style="@style/button_full" - android:hint="@string/longitude" /> + android:hint="@string/longitude" + android:freezesText="true" /> <EditText android:id="@+id/bearing" @@ -62,7 +64,8 @@ <Spinner android:id="@+id/type" android:layout_width="fill_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content" + android:visibility="gone" /> <EditText android:id="@+id/note" diff --git a/main/res/layout/main_activity.xml b/main/res/layout/main_activity.xml index 40e3d6a..11827a4 100644 --- a/main/res/layout/main_activity.xml +++ b/main/res/layout/main_activity.xml @@ -176,9 +176,16 @@ android:orientation="vertical" > <TextView - android:id="@+id/user_info" + android:id="@+id/user_info_gc" style="@style/location_current" - android:text="@string/init_login_popup_working" /> + android:text="@string/init_login_popup_working" + android:visibility="gone" /> + + <TextView + android:id="@+id/user_info_ocde" + style="@style/location_current" + android:text="@string/init_login_popup_working" + android:visibility="gone" /> <TextView android:id="@+id/nav_location" diff --git a/main/res/menu/map_activity.xml b/main/res/menu/map_activity.xml index d76f5ca..df8fe09 100644 --- a/main/res/menu/map_activity.xml +++ b/main/res/menu/map_activity.xml @@ -55,22 +55,18 @@ android:checkableBehavior="single" > <item android:id="@+id/menu_strategy_fastest" - android:checkable="true" android:title="@string/map_strategy_fastest"> </item> <item android:id="@+id/menu_strategy_fast" - android:checkable="true" android:title="@string/map_strategy_fast"> </item> <item android:id="@+id/menu_strategy_auto" - android:checkable="true" android:title="@string/map_strategy_auto"> </item> <item android:id="@+id/menu_strategy_detailed" - android:checkable="true" android:title="@string/map_strategy_detailed"> </item> </group> diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 32aabd8..b4c7b33 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1873,8 +1873,10 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc @Override public void onFinishEditNoteDialog(final String note) { cache.setPersonalNote(note); + cache.parseWaypointsFromNote(); setPersonalNote(); cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); + CacheDetailActivity.this.notifyDataSetChanged(); } }; final FragmentManager fm = getSupportFragmentManager(); diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index f97e9b5..ab35641 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -1,7 +1,5 @@ package cgeo.geocaching; -import butterknife.InjectView; - import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; @@ -17,11 +15,15 @@ import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.GeoDirHandler; import cgeo.geocaching.utils.Log; +import com.googlecode.androidannotations.annotations.EActivity; +import com.googlecode.androidannotations.annotations.Extra; +import com.googlecode.androidannotations.annotations.InstanceState; +import com.googlecode.androidannotations.annotations.ViewById; + import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; import android.content.Context; -import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -29,90 +31,88 @@ import android.os.Message; import android.text.Html; import android.view.View; import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import java.util.List; +@EActivity public class EditWaypointActivity extends AbstractActivity { - @InjectView(R.id.buttonLatitude) protected Button buttonLat; - @InjectView(R.id.buttonLongitude) protected Button buttonLon; - @InjectView(R.id.add_waypoint) protected Button addWaypoint; - @InjectView(R.id.note) protected EditText note; - @InjectView(R.id.wpt_visited_checkbox) protected CheckBox visitedCheckBox; - @InjectView(R.id.name) protected AutoCompleteTextView waypointName; - @InjectView(R.id.type) protected Spinner waypointTypeSelector; - @InjectView(R.id.distance) protected EditText distanceView; - @InjectView(R.id.modify_cache_coordinates_group) protected RadioGroup coordinatesGroup; - @InjectView(R.id.modify_cache_coordinates_local_and_remote) protected RadioButton modifyBoth; - @InjectView(R.id.distanceUnit) protected Spinner distanceUnitSelector; - @InjectView(R.id.bearing) protected EditText bearing; - @InjectView(R.id.modify_cache_coordinates_local) protected RadioButton modifyLocal; - - private String geocode = null; - private int id = -1; + @ViewById(R.id.buttonLatitude) protected Button buttonLat; + @ViewById(R.id.buttonLongitude) protected Button buttonLon; + @ViewById(R.id.add_waypoint) protected Button addWaypoint; + @ViewById(R.id.note) protected EditText note; + @ViewById(R.id.wpt_visited_checkbox) protected CheckBox visitedCheckBox; + @ViewById(R.id.name) protected AutoCompleteTextView waypointName; + @ViewById(R.id.type) protected Spinner waypointTypeSelector; + @ViewById(R.id.distance) protected EditText distanceView; + @ViewById(R.id.modify_cache_coordinates_group) protected RadioGroup coordinatesGroup; + @ViewById(R.id.modify_cache_coordinates_local_and_remote) protected RadioButton modifyBoth; + @ViewById(R.id.distanceUnit) protected Spinner distanceUnitSelector; + @ViewById(R.id.bearing) protected EditText bearing; + @ViewById(R.id.modify_cache_coordinates_local) protected RadioButton modifyLocal; + + @Extra(Intents.EXTRA_GEOCODE) protected String geocode = null; + @Extra(Intents.EXTRA_WAYPOINT_ID) protected int id = -1; + /** + * number of waypoints that the corresponding cache has until now + */ + @Extra(Intents.EXTRA_COUNT) protected int wpCount = 0; + + @InstanceState protected int waypointTypeSelectorPosition = -1; private ProgressDialog waitDialog = null; private Waypoint waypoint = null; - private Geopoint gpTemp = null; - private WaypointType type = WaypointType.OWN; private String prefix = "OWN"; private String lookup = "---"; private boolean own = true; - private boolean visited = false; ArrayList<WaypointType> wpTypes = null; - String distanceUnit = ""; + ArrayList<String> distanceUnits = null; + private boolean initViews = true; - /** - * number of waypoints that the corresponding cache has until now - */ - private int wpCount = 0; private Handler loadWaypointHandler = new Handler() { @Override public void handleMessage(Message msg) { try { if (waypoint == null) { + Log.d("No waypoint loaded to edit. id= " + id); id = -1; } else { geocode = waypoint.getGeocode(); - type = waypoint.getWaypointType(); prefix = waypoint.getPrefix(); lookup = waypoint.getLookup(); own = waypoint.isUserDefined(); - visited = waypoint.isVisited(); - if (waypoint.getCoords() != null) { - buttonLat.setText(waypoint.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE)); - buttonLon.setText(waypoint.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE)); - } - waypointName.setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getName())).toString()); - if (BaseUtils.containsHtml(waypoint.getNote())) { - note.setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getNote())).toString()); - } - else { - note.setText(StringUtils.trimToEmpty(waypoint.getNote())); + if (initViews) { + visitedCheckBox.setChecked(waypoint.isVisited()); + if (waypoint.getCoords() != null) { + buttonLat.setText(waypoint.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE)); + buttonLon.setText(waypoint.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE)); + } + waypointName.setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getName())).toString()); + if (BaseUtils.containsHtml(waypoint.getNote())) { + note.setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getNote())).toString()); + } + else { + note.setText(StringUtils.trimToEmpty(waypoint.getNote())); + } } - Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_ONLY); + final Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_ONLY); setCoordsModificationVisibility(ConnectorFactory.getConnector(geocode), cache); } if (own) { initializeWaypointTypeSelector(); } - visitedCheckBox.setChecked(visited); - - initializeDistanceUnitSelector(); } catch (Exception e) { Log.e("EditWaypointActivity.loadWaypointHandler", e); } finally { @@ -128,14 +128,6 @@ public class EditWaypointActivity extends AbstractActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.editwaypoint_activity); - // get parameters - Bundle extras = getIntent().getExtras(); - if (extras != null) { - geocode = extras.getString(Intents.EXTRA_GEOCODE); - wpCount = extras.getInt(Intents.EXTRA_COUNT, 0); - id = extras.getInt(Intents.EXTRA_WAYPOINT_ID); - } - if (StringUtils.isBlank(geocode) && id <= 0) { showToast(res.getString(R.string.err_waypoint_cache_unknown)); @@ -152,7 +144,7 @@ public class EditWaypointActivity extends AbstractActivity { buttonLat.setOnClickListener(new CoordDialogListener()); buttonLon.setOnClickListener(new CoordDialogListener()); - addWaypoint.setOnClickListener(new CoordsListener()); + addWaypoint.setOnClickListener(new SaveWaypointListener()); List<String> wayPointNames = new ArrayList<String>(); for (WaypointType wpt : WaypointType.ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL) { @@ -161,28 +153,24 @@ public class EditWaypointActivity extends AbstractActivity { ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, wayPointNames); waypointName.setAdapter(adapter); - if (id > 0) { - waypointTypeSelector.setVisibility(View.GONE); + if (savedInstanceState != null) { + initViews = false; + } + if (id > 0) { // existing waypoint waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true); waitDialog.setCancelable(true); (new LoadWaypointThread()).start(); - } else { + + } else { // new waypoint initializeWaypointTypeSelector(); - } - if (geocode != null) { - Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); - IConnector con = ConnectorFactory.getConnector(geocode); - setCoordsModificationVisibility(con, cache); - } - visitedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - visited = isChecked; + if (geocode != null) { + final Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); + setCoordsModificationVisibility(ConnectorFactory.getConnector(geocode), cache); } - }); + } initializeDistanceUnitSelector(); @@ -204,15 +192,6 @@ public class EditWaypointActivity extends AbstractActivity { super.onResume(); geoDirHandler.startGeo(); - - if (id > 0) { - if (waitDialog == null) { - waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true); - waitDialog.setCancelable(true); - - (new LoadWaypointThread()).start(); - } - } } @Override @@ -227,29 +206,35 @@ public class EditWaypointActivity extends AbstractActivity { wpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); waypointTypeSelector.setAdapter(wpAdapter); - int typeIndex = wpTypes.indexOf(type); - if (typeIndex < 0) { - typeIndex = wpTypes.indexOf(WaypointType.WAYPOINT); - } + waypointTypeSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { + waypointTypeSelectorPosition = pos; + } - waypointTypeSelector.setSelection(typeIndex); - waypointTypeSelector.setOnItemSelectedListener(new ChangeWaypointType(this)); + @Override + public void onNothingSelected(AdapterView<?> parent) { + } + }); + + if (initViews) { + int typeIndex = -1; + if (waypoint != null) { + typeIndex = wpTypes.indexOf(waypoint.getWaypointType()); + } + waypointTypeSelector.setSelection(typeIndex >= 0 ? typeIndex : wpTypes.indexOf(WaypointType.WAYPOINT)); + } else { + waypointTypeSelector.setSelection(waypointTypeSelectorPosition); + } waypointTypeSelector.setVisibility(View.VISIBLE); } private void initializeDistanceUnitSelector() { - if (StringUtils.isBlank(distanceUnit)) { - if (Settings.isUseMetricUnits()) { - distanceUnitSelector.setSelection(0); // m - distanceUnit = res.getStringArray(R.array.distance_units)[0]; - } else { - distanceUnitSelector.setSelection(2); // ft - distanceUnit = res.getStringArray(R.array.distance_units)[2]; - } + distanceUnits = new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.distance_units))); + if (initViews) { + distanceUnitSelector.setSelection(Settings.isUseMetricUnits() ? 0 : 2); //0:m, 2:ft } - - distanceUnitSelector.setOnItemSelectedListener(new ChangeDistanceUnit(this)); } final private GeoDirHandler geoDirHandler = new GeoDirHandler() { @@ -287,10 +272,10 @@ public class EditWaypointActivity extends AbstractActivity { @Override public void onClick(View arg0) { Geopoint gp = null; - if (waypoint != null && waypoint.getCoords() != null) { - gp = waypoint.getCoords(); - } else if (gpTemp != null) { - gp = gpTemp; + try { + gp = new Geopoint(buttonLat.getText().toString(), buttonLon.getText().toString()); + } catch (Geopoint.ParseException e) { + // button text is blank when creating new waypoint } Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(EditWaypointActivity.this, cache, gp, app.currentGeo()); @@ -300,60 +285,12 @@ public class EditWaypointActivity extends AbstractActivity { public void update(final Geopoint gp) { buttonLat.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); buttonLon.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); - if (waypoint != null) { - waypoint.setCoords(gp); - } else { - gpTemp = gp; - } } }); coordsDialog.show(); } } - private static class ChangeWaypointType implements OnItemSelectedListener { - - private ChangeWaypointType(EditWaypointActivity wpView) { - this.wpView = wpView; - } - - private EditWaypointActivity wpView; - - @Override - public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, - long arg3) { - if (null != wpView.wpTypes) { - wpView.type = wpView.wpTypes.get(arg2); - } - } - - @Override - public void onNothingSelected(AdapterView<?> arg0) { - if (null != wpView.wpTypes) { - arg0.setSelection(wpView.wpTypes.indexOf(wpView.type)); - } - } - } - - private static class ChangeDistanceUnit implements OnItemSelectedListener { - - private ChangeDistanceUnit(EditWaypointActivity unitView) { - this.unitView = unitView; - } - - private EditWaypointActivity unitView; - - @Override - public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, - long arg3) { - unitView.distanceUnit = (String) arg0.getItemAtPosition(arg2); - } - - @Override - public void onNothingSelected(AdapterView<?> arg0) { - } - } - public static final int SUCCESS = 0; public static final int UPLOAD_START = 1; public static final int UPLOAD_ERROR = 2; @@ -361,13 +298,13 @@ public class EditWaypointActivity extends AbstractActivity { public static final int UPLOAD_SUCCESS = 4; public static final int SAVE_ERROR = 5; - private class CoordsListener implements View.OnClickListener { + private class SaveWaypointListener implements View.OnClickListener { @Override public void onClick(View arg0) { final String bearingText = bearing.getText().toString(); // combine distance from EditText and distanceUnit saved from Spinner - final String distanceText = distanceView.getText().toString() + distanceUnit; + final String distanceText = distanceView.getText().toString() + distanceUnits.get(distanceUnitSelector.getSelectedItemPosition()); final String latText = buttonLat.getText().toString(); final String lonText = buttonLon.getText().toString(); @@ -421,6 +358,8 @@ public class EditWaypointActivity extends AbstractActivity { final String name = StringUtils.isNotEmpty(givenName) ? givenName : res.getString(R.string.waypoint) + " " + (wpCount + 1); final String noteText = note.getText().toString().trim(); final Geopoint coordsToSave = coords; + final WaypointType type = wpTypes.get(waypointTypeSelector.getSelectedItemPosition()); + final boolean visited = visitedCheckBox.isChecked(); final ProgressDialog progress = ProgressDialog.show(EditWaypointActivity.this, getString(R.string.cache), getString(R.string.waypoint_being_saved), true); final Handler finishHandler = new Handler() { @@ -527,13 +466,10 @@ public class EditWaypointActivity extends AbstractActivity { } public static void startActivityEditWaypoint(final Context context, final int waypointId) { - context.startActivity(new Intent(context, EditWaypointActivity.class) - .putExtra(Intents.EXTRA_WAYPOINT_ID, waypointId)); + EditWaypointActivity_.intent(context).id(waypointId).start(); } public static void startActivityAddWaypoint(final Context context, final Geocache cache) { - context.startActivity(new Intent(context, EditWaypointActivity.class) - .putExtra(Intents.EXTRA_GEOCODE, cache.getGeocode()) - .putExtra(Intents.EXTRA_COUNT, cache.getWaypoints().size())); + EditWaypointActivity_.intent(context).geocode(cache.getGeocode()).wpCount(cache.getWaypoints().size()).start(); } } diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java index 9c3e89f..ff24322 100644 --- a/main/src/cgeo/geocaching/MainActivity.java +++ b/main/src/cgeo/geocaching/MainActivity.java @@ -4,7 +4,10 @@ import butterknife.InjectView; import butterknife.Views; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.connector.ConnectorFactory; +import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.gc.Login; +import cgeo.geocaching.connector.oc.OCApiLiveConnector; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; @@ -50,7 +53,8 @@ import java.util.List; import java.util.Locale; public class MainActivity extends AbstractActivity { - @InjectView(R.id.user_info) protected TextView userInfoView; + @InjectView(R.id.user_info_gc) protected TextView userInfoViewGc; + @InjectView(R.id.user_info_ocde) protected TextView userInfoViewOcDe; @InjectView(R.id.nav_satellites) protected TextView navSatellites; @InjectView(R.id.filter_button_title)protected TextView filterTitle; @InjectView(R.id.map) protected ImageView findOnMap; @@ -82,8 +86,8 @@ public class MainActivity extends AbstractActivity { @Override public void handleMessage(Message msg) { - StringBuilder userInfo = new StringBuilder("geocaching.com").append(Formatter.SEPARATOR); if (Settings.isGCConnectorActive()) { + StringBuilder userInfo = new StringBuilder("geocaching.com").append(Formatter.SEPARATOR); if (Login.isActualLoginStatus()) { userInfo.append(Login.getActualUserName()); if (Login.getActualCachesFound() >= 0) { @@ -92,12 +96,36 @@ public class MainActivity extends AbstractActivity { userInfo.append(Formatter.SEPARATOR); } userInfo.append(Login.getActualStatus()); + + userInfoViewGc.setText(userInfo.toString()); + userInfoViewGc.setVisibility(View.VISIBLE); + } + else { + userInfoViewGc.setVisibility(View.GONE); + } + + if (Settings.isOCConnectorActive()) { + StringBuilder userInfo = new StringBuilder("opencaching.de").append(Formatter.SEPARATOR); + IConnector conn = ConnectorFactory.getConnector("OCXXXX"); + if (conn instanceof OCApiLiveConnector) { + OCApiLiveConnector ocapiConn = (OCApiLiveConnector) conn; + if (ocapiConn.supportsPersonalization()) { + userInfo.append(ocapiConn.getUserName()); + int count = ocapiConn.getCachesFound(); + if (count >= 0) { + userInfo.append(" (").append(String.valueOf(count)).append(')'); + } + } else { + userInfo.append("Anonymous"); + } + } + userInfoViewOcDe.setText(userInfo.toString()); + userInfoViewOcDe.setVisibility(View.VISIBLE); } else { - userInfo.append("<disabled>"); // TODO this is just a quick fix. We need some better status implementation showing multiple connectors. + userInfoViewOcDe.setVisibility(View.GONE); } - userInfoView.setText(userInfo.toString()); } }; @@ -699,26 +727,34 @@ public class MainActivity extends AbstractActivity { return; } - if (!Settings.isGCConnectorActive()) { - return; - } - - // login - final StatusCode status = Login.login(); + if (Settings.isGCConnectorActive()) { + // login + final StatusCode status = Login.login(); - if (status == StatusCode.NO_ERROR) { - app.firstRun = false; - Login.detectGcCustomDate(); - updateUserInfoHandler.sendEmptyMessage(-1); - } + if (status == StatusCode.NO_ERROR) { + app.firstRun = false; + Login.detectGcCustomDate(); + updateUserInfoHandler.sendEmptyMessage(-1); + } - if (app.showLoginToast) { - firstLoginHandler.sendMessage(firstLoginHandler.obtainMessage(0, status)); - app.showLoginToast = false; + if (app.showLoginToast) { + firstLoginHandler.sendMessage(firstLoginHandler.obtainMessage(0, status)); + app.showLoginToast = false; - // invoke settings activity to insert login details - if (status == StatusCode.NO_LOGIN_INFO_STORED) { - SettingsActivity.startActivity(MainActivity.this); + // invoke settings activity to insert login details + if (status == StatusCode.NO_LOGIN_INFO_STORED) { + SettingsActivity.startActivity(MainActivity.this); + } + } + } + if (Settings.isOCConnectorActive()) { + IConnector conn = ConnectorFactory.getConnector("OCXXXX"); + if (conn instanceof OCApiLiveConnector) { + OCApiLiveConnector ocapiConn = (OCApiLiveConnector) conn; + if (ocapiConn.supportsPersonalization()) { + ocapiConn.retrieveUserInfo(); + } + updateUserInfoHandler.sendEmptyMessage(-1); } } } diff --git a/main/src/cgeo/geocaching/activity/Progress.java b/main/src/cgeo/geocaching/activity/Progress.java index 68ac272..34e7623 100644 --- a/main/src/cgeo/geocaching/activity/Progress.java +++ b/main/src/cgeo/geocaching/activity/Progress.java @@ -54,7 +54,7 @@ public class Progress { dialog = new CustomProgressDialog(context); } else { - dialog = new ProgressDialog(context, ActivityMixin.getDialogTheme()); + dialog = new ProgressDialog(context); } dialog.setTitle(title); dialog.setMessage(message); diff --git a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java index 59d0f56..4c6db97 100644 --- a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java +++ b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java @@ -8,6 +8,7 @@ import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.connector.ILoggingManager; import cgeo.geocaching.connector.capability.ISearchByCenter; import cgeo.geocaching.connector.capability.ISearchByViewPort; +import cgeo.geocaching.connector.oc.OkapiClient.UserInfo; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.utils.CryptUtils; @@ -19,6 +20,7 @@ import android.app.Activity; public class OCApiLiveConnector extends OCApiConnector implements ISearchByCenter, ISearchByViewPort { private String cS; + private UserInfo userInfo = new UserInfo(StringUtils.EMPTY, 0, false); public OCApiLiveConnector(String name, String host, String prefix, int cKResId, int cSResId, ApiSupport apiSupport) { super(name, host, prefix, CryptUtils.rot13(cgeoapplication.getInstance().getResources().getString(cKResId)), apiSupport); @@ -97,4 +99,21 @@ public class OCApiLiveConnector extends OCApiConnector implements ISearchByCente public boolean canLog(Geocache cache) { return true; } + + public boolean supportsPersonalization() { + return getSupportedAuthLevel() == OAuthLevel.Level3; + } + + public boolean retrieveUserInfo() { + userInfo = OkapiClient.getUserInfo(this); + return userInfo.isRetrieveSuccessful(); + } + + public Object getUserName() { + return userInfo.getName(); + } + + public int getCachesFound() { + return userInfo.getFinds(); + } } diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index 39f9ddf..3c99bc9 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -100,6 +100,8 @@ final public class OkapiClient { private static final String LOG_USER = "user"; private static final String USER_USERNAME = "username"; + private static final String USER_CACHES_FOUND = "caches_found"; + private static final String USER_INFO_FIELDS = "username|caches_found"; // the several realms of possible fields for cache retrieval: // Core: for livemap requests (L3 - only with level 3 auth) @@ -135,7 +137,6 @@ final public class OkapiClient { return parseCache(data); } - // Assumes level 3 OAuth public static List<Geocache> getCachesAround(final Geopoint center, OCApiConnector connector) { String centerString = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, center) + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, center); final Parameters params = new Parameters("search_method", METHOD_SEARCH_NEAREST); @@ -143,12 +144,7 @@ final public class OkapiClient { valueMap.put("center", centerString); valueMap.put("limit", "20"); - if (connector.getSupportedAuthLevel() != OAuthLevel.Level3) { - Log.e("Calling OkapiClient.getCachesAround with wrong connector"); - return Collections.emptyList(); - } - - addFilterParams(valueMap); + addFilterParams(valueMap, connector); params.add("search_params", new JSONObject(valueMap).toString()); @@ -178,13 +174,7 @@ final public class OkapiClient { final Map<String, String> valueMap = new LinkedHashMap<String, String>(); valueMap.put("bbox", bboxString); - // FIXME Why is this testing level 3? The to be used service is level 1 only. - if (connector.getSupportedAuthLevel() != OAuthLevel.Level3) { - Log.e("Calling OkapiClient.getCachesBBox with wrong connector"); - return Collections.emptyList(); - } - - addFilterParams(valueMap); + addFilterParams(valueMap, connector); params.add("search_params", new JSONObject(valueMap).toString()); @@ -639,12 +629,11 @@ final public class OkapiClient { return "en"; } - // assumes level 3 oauth - private static void addFilterParams(final Map<String, String> valueMap) { + private static void addFilterParams(final Map<String, String> valueMap, OCApiConnector connector) { if (!Settings.isExcludeDisabledCaches()) { valueMap.put("status", "Available|Temporarily unavailable"); } - if (Settings.isExcludeMyCaches()) { + if (Settings.isExcludeMyCaches() && connector.getSupportedAuthLevel() == OAuthLevel.Level3) { valueMap.put("exclude_my_own", "true"); valueMap.put("found_status", "notfound_only"); } @@ -678,4 +667,67 @@ final public class OkapiClient { } } + public static UserInfo getUserInfo(OCApiLiveConnector connector) { + final Parameters params = new Parameters("fields", USER_INFO_FIELDS); + + final JSONObject data = request(connector, OkapiService.SERVICE_USER, params); + + if (data == null) { + return new UserInfo(StringUtils.EMPTY, 0, false); + } + + String name = StringUtils.EMPTY; + int finds = 0; + boolean success = true; + + if (!data.isNull(USER_USERNAME)) { + try { + name = data.getString(USER_USERNAME); + } catch (JSONException e) { + Log.e("OkapiClient.getUserInfo - name", e); + success = false; + } + } else { + success = false; + } + + if (!data.isNull(USER_CACHES_FOUND)) { + try { + finds = data.getInt(USER_CACHES_FOUND); + } catch (JSONException e) { + Log.e("OkapiClient.getUserInfo - finds", e); + success = false; + } + } else { + success = false; + } + + return new UserInfo(name, finds, success); + } + + public static class UserInfo { + + private final String name; + private final int finds; + private final boolean retrieveSuccessful; + + UserInfo(String name, int finds, boolean retrieveSuccessful) { + this.name = name; + this.finds = finds; + this.retrieveSuccessful = retrieveSuccessful; + } + + public String getName() { + return name; + } + + public int getFinds() { + return finds; + } + + public boolean isRetrieveSuccessful() { + return retrieveSuccessful; + } + } + } diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiService.java b/main/src/cgeo/geocaching/connector/oc/OkapiService.java index 9b47596..ec09527 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiService.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiService.java @@ -7,7 +7,8 @@ enum OkapiService { SERVICE_CACHE("/okapi/services/caches/geocache", OAuthLevel.Level1), SERVICE_SEARCH_AND_RETRIEVE("/okapi/services/caches/shortcuts/search_and_retrieve", OAuthLevel.Level1), SERVICE_MARK_CACHE("/okapi/services/caches/mark", OAuthLevel.Level3), - SERVICE_SUBMIT_LOG("/okapi/services/logs/submit", OAuthLevel.Level3); + SERVICE_SUBMIT_LOG("/okapi/services/logs/submit", OAuthLevel.Level3), + SERVICE_USER("/okapi/services/users/user", OAuthLevel.Level1); final String methodName; final OAuthLevel level; diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 49b9d6e..1cfb2a3 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -76,7 +76,7 @@ public final class LocParser extends FileParser { if (StringUtils.isBlank(cache.getName())) { cache.setName(coord.getName()); } - cache.setOwnerDisplayName(coord.getOwnerDisplayName()); + cache.setOwnerUserId(coord.getOwnerUserId()); } static Map<String, Geocache> parseCoordinates(final String fileContent) { @@ -152,8 +152,8 @@ public final class LocParser extends FileParser { if (matcherName.find()) { final String name = matcherName.group(1).trim(); String ownerName = StringUtils.trim(StringUtils.substringAfterLast(name, NAME_OWNER_SEPARATOR)); - if (StringUtils.isEmpty(cache.getOwnerDisplayName()) && StringUtils.isNotEmpty(ownerName)) { - cache.setOwnerDisplayName(ownerName); + if (StringUtils.isEmpty(cache.getOwnerUserId()) && StringUtils.isNotEmpty(ownerName)) { + cache.setOwnerUserId(ownerName); } cache.setName(StringUtils.substringBeforeLast(name, NAME_OWNER_SEPARATOR).trim()); } else { diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index a377e38..c876192 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -586,11 +586,19 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto menu.findItem(R.id.submenu_strategy).setEnabled(isLiveEnabled); - Strategy strategy = Settings.getLiveMapStrategy(); - menu.findItem(R.id.menu_strategy_fastest).setChecked(strategy == Strategy.FASTEST); - menu.findItem(R.id.menu_strategy_fast).setChecked(strategy == Strategy.FAST); - menu.findItem(R.id.menu_strategy_auto).setChecked(strategy == Strategy.AUTO); - menu.findItem(R.id.menu_strategy_detailed).setChecked(strategy == Strategy.DETAILED); + switch (Settings.getLiveMapStrategy()) { + case FASTEST: + menu.findItem(R.id.menu_strategy_fastest).setChecked(true); + break; + case FAST: + menu.findItem(R.id.menu_strategy_fast).setChecked(true); + break; + case AUTO: + menu.findItem(R.id.menu_strategy_auto).setChecked(true); + break; + default: // DETAILED + menu.findItem(R.id.menu_strategy_detailed).setChecked(true); + } } catch (Exception e) { Log.e("CGeoMap.onPrepareOptionsMenu", e); } diff --git a/main/src/cgeo/geocaching/utils/HtmlUtils.java b/main/src/cgeo/geocaching/utils/HtmlUtils.java index 8d4eed1..89b1070 100644 --- a/main/src/cgeo/geocaching/utils/HtmlUtils.java +++ b/main/src/cgeo/geocaching/utils/HtmlUtils.java @@ -20,6 +20,9 @@ public class HtmlUtils { * @return */ public static String extractText(CharSequence html) { + if (StringUtils.isBlank(html)) { + return StringUtils.EMPTY; + } String result = html.toString(); // recognize images in textview HTML contents diff --git a/send2cgeo/send2cgeo.user.js b/send2cgeo/send2cgeo.user.js index b309b58..bd20f3a 100644 --- a/send2cgeo/send2cgeo.user.js +++ b/send2cgeo/send2cgeo.user.js @@ -4,9 +4,10 @@ // @description Add button "Send to c:geo" to geocaching.com // @include http://www.geocaching.com/seek/cache_details* // @include http://www.geocaching.com/map/* +// @include http://www.geocaching.com/geocache/* // @icon http://send2.cgeo.org/content/images/logo.png // @updateURL http://send2.cgeo.org/send2cgeo.user.js -// @version 0.26 +// @version 0.27 // ==/UserScript== // Inserts javascript that will be called by the s2cgeo button. The closure @@ -81,6 +82,7 @@ s.textContent = '(' + function() { + '/>'; $('#Download p:last').append(html); + $('#Download dd:last').append(html); } } + ')();'; diff --git a/tests/src/cgeo/geocaching/CacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index 20c7d9e..f3c9a65 100644 --- a/tests/src/cgeo/geocaching/CacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -6,7 +6,7 @@ import android.test.AndroidTestCase; import java.util.Date; -public class CacheTest extends AndroidTestCase { +public class GeocacheTest extends AndroidTestCase { final static private class MockedEventCache extends Geocache { public MockedEventCache(final Date date) { diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java index 50bf22a..410252f 100644 --- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java +++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java @@ -25,7 +25,7 @@ public class OkapiClientTest extends CGeoTestCase { public static void testOCSearchMustWorkWithoutOAuthAccessTokens() { final String geoCode = "OC1234"; Geocache cache = OkapiClient.getCache(geoCode); - assertNotNull(cache); + assertNotNull("You must have a valid OKAPI key installed for running this test (but you do not need to set credentials in the app).", cache); assertEquals("Wupper-Schein", cache.getName()); } } diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index 6e00b35..3039a1f 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -36,7 +36,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(cache); assertEquals("OC5952", cache.getGeocode()); assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); + assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords()); } @@ -47,7 +47,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(cache); assertEquals("GC1BKP3", cache.getGeocode()); assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); + assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords()); assertEquals(1.0f, cache.getDifficulty()); assertEquals(5.0f, cache.getTerrain()); @@ -61,7 +61,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(waymark); assertEquals("WM7BK7", waymark.getGeocode()); assertEquals("Römerstrasse Kornwestheim", waymark.getName()); - assertEquals("travelling", waymark.getOwnerDisplayName()); + assertEquals("travelling", waymark.getOwnerUserId()); assertEquals(new Geopoint(48.856733, 9.197683), waymark.getCoords()); // links are not yet stored for single caches // assertEquals("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim", waymark.getUrl()); diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java index 2e4660b..076f2c9 100644 --- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java +++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.geopoint; +import cgeo.geocaching.ui.Formatter; + import android.test.AndroidTestCase; public class GeoPointParserTest extends AndroidTestCase { @@ -49,6 +51,12 @@ public class GeoPointParserTest extends AndroidTestCase { assertTrue(goal1.isEqualTo(goal2, 1e-6)); } + public static void testParseOurOwnSeparator() { + final Geopoint separator = GeopointParser.parse("N 49° 43' 57\"" + Formatter.SEPARATOR + "E 2 12' 35"); + final Geopoint noSeparator = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); + assertTrue(separator.isEqualTo(noSeparator, 1e-6)); + } + public static void testInSentence() { final Geopoint p1 = GeopointParser.parse("Station3: N51 21.523 / E07 02.680"); final Geopoint p2 = GeopointParser.parse("N51 21.523", "E07 02.680"); diff --git a/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java new file mode 100644 index 0000000..3715c80 --- /dev/null +++ b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java @@ -0,0 +1,15 @@ +package cgeo.geocaching.utils; + +import org.apache.commons.lang3.StringUtils; + +import junit.framework.TestCase; + +public class HtmlUtilsTest extends TestCase { + + public static void testExtractText() { + assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(null)); + assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(StringUtils.EMPTY)); + assertEquals(StringUtils.EMPTY, HtmlUtils.extractText(" ")); + } + +} |