Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0cd1f300eb
4 changed files with 66 additions and 39 deletions
|
@ -0,0 +1,7 @@
|
|||
package net.osmand.plus.osmo;
|
||||
|
||||
public class OsMoConnectionException extends RuntimeException {
|
||||
public OsMoConnectionException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
|
@ -134,7 +134,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
private Paint white;
|
||||
private View header;
|
||||
private View footer;
|
||||
private CompoundButton srvc;
|
||||
|
||||
private int connections = 0;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -213,7 +215,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
});
|
||||
updateTrackerButton();
|
||||
|
||||
CompoundButton srvc = (CompoundButton) header.findViewById(R.id.enable_service);
|
||||
srvc = (CompoundButton) header.findViewById(R.id.enable_service);
|
||||
srvc.setChecked(osMoPlugin.getService().isEnabled());
|
||||
srvc.setText(R.string.osmo_start_service);
|
||||
srvc.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
@ -1537,9 +1539,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
public void handleConnect() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
connections++;
|
||||
if (getExpandableListView().getFooterViewsCount() > 0) {
|
||||
getExpandableListView().removeFooterView(footer);
|
||||
}
|
||||
|
@ -1553,13 +1555,18 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TextUtils.isEmpty(msg)) {
|
||||
if (!TextUtils.isEmpty(msg) && connections > 0) {
|
||||
CompoundButton srvc = (CompoundButton) header.findViewById(R.id.enable_service);
|
||||
if (srvc.isChecked()) {
|
||||
if (connections == 1) {
|
||||
if (getExpandableListView().getFooterViewsCount() == 0) {
|
||||
getExpandableListView().addFooterView(footer);
|
||||
}
|
||||
adapter.clear();
|
||||
connections--;
|
||||
} else {
|
||||
connections = 1;
|
||||
}
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
|
|
|
@ -30,19 +30,16 @@ import org.json.JSONObject;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class OsMoService implements OsMoReactor {
|
||||
private static final String HTTP_API_PREPARE = "http://api.osmo.mobi/prepare";
|
||||
|
@ -237,7 +234,7 @@ public class OsMoService implements OsMoReactor {
|
|||
final JSONObject obj = new JSONObject(r);
|
||||
if(obj.has("error")) {
|
||||
lastRegistrationError = obj.getString("error");
|
||||
throw new RuntimeException(obj.getString("error"));
|
||||
throw new OsMoConnectionException(obj.getString("error"));
|
||||
}
|
||||
app.getSettings().OSMO_DEVICE_KEY.set(obj.getString("key"));
|
||||
return obj.getString("key");
|
||||
|
@ -475,4 +472,8 @@ public class OsMoService implements OsMoReactor {
|
|||
String userName = app.getSettings().OSMO_USER_NAME.get();
|
||||
return ((!TextUtils.isEmpty(psswd) && !TextUtils.isEmpty(userName)));
|
||||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ package net.osmand.plus.osmo;
|
|||
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.osmo.OsMoService.SessionInfo;
|
||||
|
@ -175,17 +177,27 @@ public class OsMoThread {
|
|||
if (activeChannel != null && !activeChannel.isConnected()) {
|
||||
activeChannel = null;
|
||||
}
|
||||
String msg = e.getMessage();
|
||||
final String msg = e.getMessage();
|
||||
for(OsMoReactor sender : getReactors()) {
|
||||
sender.onDisconnected(msg);
|
||||
}
|
||||
delay = HEARTBEAT_FAILED_DELAY;
|
||||
if (e instanceof OsMoConnectionException) {
|
||||
stopThread = true;
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(service.getMyApplication(), msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (lastSendCommand != 0 && System.currentTimeMillis() - lastSendCommand > TIMEOUT_TO_RECONNECT) {
|
||||
reconnect = true;
|
||||
} else if (failures++ > LIMIT_OF_FAILURES_RECONNECT) {
|
||||
reconnect = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stopThread) {
|
||||
stopChannel();
|
||||
for(OsMoReactor sender : getReactors()) {
|
||||
|
|
Loading…
Reference in a new issue