1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
package cgeo.geocaching.connector.ec;
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.ICache;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.connector.capability.ILogin;
import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.connector.capability.ISearchByViewPort;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.SettingsActivity;
import cgeo.geocaching.utils.CancellableHandler;
import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.os.Handler;
import java.util.Collection;
import java.util.regex.Pattern;
public class ECConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter, ISearchByViewPort, ILogin {
private static final String CACHE_URL = "http://extremcaching.com/index.php/output-2/";
/**
* Pattern for EC codes
*/
private final static Pattern PATTERN_EC_CODE = Pattern.compile("EC[0-9]+", Pattern.CASE_INSENSITIVE);
private ECConnector() {
// singleton
}
/**
* initialization on demand holder pattern
*/
private static class Holder {
private static final ECConnector INSTANCE = new ECConnector();
}
public static ECConnector getInstance() {
return Holder.INSTANCE;
}
@Override
public boolean canHandle(String geocode) {
if (geocode == null) {
return false;
}
return ECConnector.PATTERN_EC_CODE.matcher(geocode).matches();
}
@Override
public String getCacheUrl(Geocache cache) {
return CACHE_URL + cache.getGeocode().replace("EC", "");
}
@Override
public String getName() {
return "extremcaching.com";
}
@Override
public String getHost() {
return "extremcaching.com";
}
@Override
public SearchResult searchByGeocode(final String geocode, final String guid, final CancellableHandler handler) {
CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage);
final Geocache cache = ECApi.searchByGeoCode(geocode);
if (cache == null) {
return null;
}
final SearchResult searchResult = new SearchResult(cache);
return searchResult;
}
@Override
public SearchResult searchByViewport(Viewport viewport, String[] tokens) {
final Collection<Geocache> caches = ECApi.searchByBBox(viewport);
if (caches == null) {
return null;
}
final SearchResult searchResult = new SearchResult(caches);
return searchResult.filterSearchResults(false, false, Settings.getCacheType());
}
@Override
public SearchResult searchByCenter(Geopoint center) {
final Collection<Geocache> caches = ECApi.searchByCenter(center);
if (caches == null) {
return null;
}
final SearchResult searchResult = new SearchResult(caches);
return searchResult.filterSearchResults(false, false, Settings.getCacheType());
}
@Override
public boolean isOwner(final ICache cache) {
//return StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), Settings.getUsername());
return false;
}
@Override
protected String getCacheUrlPrefix() {
return CACHE_URL;
}
@Override
public boolean isActivated() {
return Settings.isECConnectorActive();
}
@Override
public boolean login(Handler handler, Context fromActivity) {
// login
final StatusCode status = ECLogin.login();
if (status == StatusCode.NO_ERROR) {
CgeoApplication.getInstance().checkLogin = false;
}
if (CgeoApplication.getInstance().showLoginToast && handler != null) {
handler.sendMessage(handler.obtainMessage(0, status));
CgeoApplication.getInstance().showLoginToast = false;
// invoke settings activity to insert login details
if (status == StatusCode.NO_LOGIN_INFO_STORED && fromActivity != null) {
SettingsActivity.jumpToServicesPage(fromActivity);
}
}
return status == StatusCode.NO_ERROR;
}
@Override
public String getUserName() {
return ECLogin.getActualUserName();
}
@Override
public int getCachesFound() {
return ECLogin.getActualCachesFound();
}
@Override
public String getLoginStatusString() {
return ECLogin.getActualStatus();
}
@Override
public boolean isLoggedIn() {
return ECLogin.isActualLoginStatus();
}
@Override
public int getCacheMapMarkerId(boolean disabled) {
final String icons = Settings.getECIconSet();
if (StringUtils.equals(icons, "1")) {
if (disabled) {
return R.drawable.marker_disabled_other;
}
return R.drawable.marker_other;
}
if (disabled) {
return R.drawable.marker_disabled_oc;
}
return R.drawable.marker_oc;
}
@Override
public String getLicenseText(final Geocache cache) {
// NOT TO BE TRANSLATED
return "© " + cache.getOwnerDisplayName() + ", <a href=\"" + getCacheUrl(cache) + "\">" + getName() + "</a>, CC BY-NC-ND 3.0, alle Logeinträge © jeweiliger Autor";
}
}
|