Fixed the mechanism of showing the connection error messages
This commit is contained in:
parent
b970468abb
commit
27515fea3b
8 changed files with 63 additions and 76 deletions
|
@ -132,11 +132,11 @@ public class OsMoControlDevice implements OsMoReactor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionError() {
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
for(OsMoDevice d : storage.getMainGroup().getGroupUsers(null)) {
|
||||
if(d.isEnabled()) {
|
||||
connectDeviceImpl(d);
|
||||
|
@ -103,7 +103,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connectionError() {
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
private String connectGroupImpl(OsMoGroup g) {
|
||||
|
|
|
@ -59,6 +59,7 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -70,7 +71,6 @@ import android.view.ViewGroup;
|
|||
import android.view.WindowManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
@ -95,7 +95,7 @@ import com.actionbarsherlock.view.Window;
|
|||
*
|
||||
*/
|
||||
public class OsMoGroupsActivity extends OsmandExpandableListActivity implements OsmAndCompassListener,
|
||||
OsmAndLocationListener, OsMoGroupsUIListener, OsMoService.ConnectionListener {
|
||||
OsmAndLocationListener, OsMoGroupsUIListener {
|
||||
|
||||
public static final int CONNECT_TO = 1;
|
||||
protected static final int DELETE_ACTION_ID = 2;
|
||||
|
@ -383,7 +383,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
adapter.synchronizeGroups();
|
||||
}
|
||||
osMoPlugin.setGroupsActivity(this);
|
||||
checkToShowNoConnectionMsg();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1485,22 +1484,25 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionError() {
|
||||
checkToShowNoConnectionMsg();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
checkToShowNoConnectionMsg();
|
||||
}
|
||||
|
||||
private void checkToShowNoConnectionMsg() {
|
||||
public void handleConnect() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (osMoPlugin.getService().isConnectionError()) {
|
||||
if (getExpandableListView().getFooterViewsCount() > 0) {
|
||||
getExpandableListView().removeFooterView(footer);
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleDisconnect(final String msg) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TextUtils.isEmpty(msg)) {
|
||||
CompoundButton srvc = (CompoundButton) header.findViewById(R.id.enable_service);
|
||||
if (srvc.isChecked()) {
|
||||
if (getExpandableListView().getFooterViewsCount() == 0) {
|
||||
|
@ -1508,14 +1510,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
adapter.clear();
|
||||
}
|
||||
} else {
|
||||
if (getExpandableListView().getFooterViewsCount() > 0) {
|
||||
getExpandableListView().removeFooterView(footer);
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ import android.preference.Preference.OnPreferenceClickListener;
|
|||
import android.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices {
|
||||
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices, OsMoReactor {
|
||||
|
||||
private OsmandApplication app;
|
||||
public static final String ID = "osmand.osmo";
|
||||
|
@ -91,11 +91,6 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
|
||||
public void setGroupsActivity(OsMoGroupsActivity groupsActivity) {
|
||||
this.groupsActivity = groupsActivity;
|
||||
if (groupsActivity == null) {
|
||||
service.setOnConnectionErrorListener(null);
|
||||
} else {
|
||||
service.setOnConnectionErrorListener(this.groupsActivity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -502,5 +497,28 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptCommand(String command, String id, String data, JSONObject obj, OsMoThread tread) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextSendCommand(OsMoThread tracker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
if (groupsActivity != null) {
|
||||
groupsActivity.handleConnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
if (groupsActivity != null) {
|
||||
groupsActivity.handleDisconnect(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ public interface OsMoReactor {
|
|||
|
||||
public String nextSendCommand(OsMoThread tracker);
|
||||
|
||||
public void reconnect();
|
||||
public void onConnected();
|
||||
|
||||
public void connectionError();
|
||||
public void onDisconnected(String msg);
|
||||
|
||||
}
|
|
@ -63,13 +63,6 @@ public class OsMoService implements OsMoReactor {
|
|||
private Notification notification;
|
||||
public final static String OSMO_REGISTER_AGAIN = "OSMO_REGISTER_AGAIN"; //$NON-NLS-1$
|
||||
private final static int SIMPLE_NOTFICATION_ID = 5;
|
||||
private Boolean isConnectionError = false;
|
||||
|
||||
public interface ConnectionListener {
|
||||
void onConnectionError();
|
||||
void onConnectionEstablished();
|
||||
}
|
||||
private ConnectionListener connectionListener = null;
|
||||
|
||||
|
||||
|
||||
|
@ -77,6 +70,7 @@ public class OsMoService implements OsMoReactor {
|
|||
this.app = app;
|
||||
this.plugin = plugin;
|
||||
listReactors.add(this);
|
||||
listReactors.add(plugin);
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -97,7 +91,7 @@ public class OsMoService implements OsMoReactor {
|
|||
public Void doInBackground(Void... voids ) {
|
||||
try {
|
||||
registerOsmoDeviceKey();
|
||||
reconnect();
|
||||
onConnected();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -107,7 +101,7 @@ public class OsMoService implements OsMoReactor {
|
|||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return thread != null && thread.isConnected() && !isConnectionError;
|
||||
return thread != null && thread.isConnected();
|
||||
}
|
||||
|
||||
|
||||
|
@ -423,38 +417,14 @@ public class OsMoService implements OsMoReactor {
|
|||
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
pushCommand("TRACK_GET");
|
||||
boolean changed = false;
|
||||
synchronized (isConnectionError) {
|
||||
if (isConnectionError) {
|
||||
isConnectionError = false;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if ((connectionListener != null) && changed) {
|
||||
connectionListener.onConnectionEstablished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionError() {
|
||||
boolean changed = false;
|
||||
synchronized (isConnectionError) {
|
||||
if (!isConnectionError) {
|
||||
isConnectionError = true;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if ((connectionListener != null) && changed) {
|
||||
connectionListener.onConnectionError();
|
||||
}
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
public boolean isConnectionError() {
|
||||
return isConnectionError;
|
||||
}
|
||||
|
||||
|
||||
public void reconnectToServer() {
|
||||
if(thread != null) {
|
||||
thread.reconnect();
|
||||
|
@ -466,8 +436,4 @@ public class OsMoService implements OsMoReactor {
|
|||
String userName = app.getSettings().OSMO_USER_NAME.get();
|
||||
return ((!TextUtils.isEmpty(psswd) && !TextUtils.isEmpty(userName)));
|
||||
}
|
||||
|
||||
public void setOnConnectionErrorListener(ConnectionListener onConnectionErrorListener) {
|
||||
this.connectionListener = onConnectionErrorListener;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class OsMoThread {
|
|||
this.activeChannel = activeChannel;
|
||||
key.attach(new Integer(++activeConnectionId));
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.reconnect();
|
||||
sender.onConnected();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -171,8 +171,9 @@ public class OsMoThread {
|
|||
if (activeChannel != null && !activeChannel.isConnected()) {
|
||||
activeChannel = null;
|
||||
}
|
||||
String msg = e.getMessage();
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.connectionError();
|
||||
sender.onDisconnected(msg);
|
||||
}
|
||||
delay = HEARTBEAT_FAILED_DELAY;
|
||||
if(lastSendCommand != 0 && System.currentTimeMillis() - lastSendCommand > TIMEOUT_TO_RECONNECT ) {
|
||||
|
@ -183,6 +184,9 @@ public class OsMoThread {
|
|||
}
|
||||
if (stopThread) {
|
||||
stopChannel();
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.onDisconnected(null);
|
||||
}
|
||||
serviceThread.getLooper().quit();
|
||||
} else {
|
||||
scheduleHeartbeat(delay);
|
||||
|
|
|
@ -213,14 +213,14 @@ public class OsMoTracker implements OsMoReactor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
if(autoStart.get() || startSendingLocations) {
|
||||
enableTracker();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionError() {
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue