Fix XMPP start/stop infinite loop.
This commit is contained in:
parent
d253dbd765
commit
192838b585
|
|
@ -171,6 +171,15 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
changeStatusTrace();
|
||||
try {
|
||||
if (serviceTrackingDog.isTraceurActivated()) {
|
||||
serviceTrackingDog.sendXmppCommandStartTrail();
|
||||
} else {
|
||||
serviceTrackingDog.sendXmppCommandStopTrail();
|
||||
}
|
||||
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
||||
|
|
@ -390,7 +399,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
// Update distance
|
||||
distance = serviceTrackingDog.calculTrailDistance();
|
||||
if (distance != 0) {
|
||||
updateDistance();
|
||||
updatePlaceholder();
|
||||
}
|
||||
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
||||
|
|
@ -489,7 +498,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
this.add_object.setVisibility(View.VISIBLE);
|
||||
this.add_object.setText(R.string.trail_object);
|
||||
this.start_stop_dog_trace.setVisibility(View.GONE);
|
||||
updateDistance();
|
||||
updatePlaceholder();
|
||||
} else {
|
||||
this.start_stop_trace.setText(R.string.trail_start);
|
||||
this.add_object.setVisibility(View.GONE);
|
||||
|
|
@ -505,7 +514,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
this.add_object.setText(R.string.dog_object);
|
||||
this.start_stop_trace.setVisibility(View.GONE);
|
||||
this.textViewCurrentLocation.setVisibility(View.GONE);
|
||||
updateDistance();
|
||||
updatePlaceholder();
|
||||
} else {
|
||||
this.start_stop_dog_trace.setText(R.string.dog_start);
|
||||
this.add_object.setVisibility(View.GONE);
|
||||
|
|
@ -676,17 +685,12 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
if (serviceTrackingDog.isTraceurActivated()) {
|
||||
updateTrailTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += onNewLocation.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
distance = serviceTrackingDog.calculTrailDistance();
|
||||
updatePlaceholder();
|
||||
lastLocation = onNewLocation;
|
||||
} else if (serviceTrackingDog.isDogActivated()) {
|
||||
updateDogTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += onNewLocation.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
updatePlaceholder();
|
||||
lastLocation = onNewLocation;
|
||||
}
|
||||
|
||||
|
|
@ -707,7 +711,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Placeholder management">
|
||||
private void updateDistance() {
|
||||
private void updatePlaceholder() {
|
||||
String text = null;
|
||||
if (serviceTrackingDog.isTraceurActivated()) {
|
||||
text = getTextTraceur();
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ public class ServiceTrackingDog implements Observer {
|
|||
if (name != null) {
|
||||
if (name.equals(ServiceGps.class.getName())) {
|
||||
serviceGps.addObserver(observer);
|
||||
} else if (name.equals(ServiceXmpp.class.getName())) {
|
||||
serviceXmpp.addObserver(observer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -128,17 +130,6 @@ public class ServiceTrackingDog implements Observer {
|
|||
traces.toggleTraceurActivation();
|
||||
if (!isTraceurActivated()) {
|
||||
exportTrailTraceToGpx();
|
||||
try {
|
||||
sendXmppCommandStopTrail();
|
||||
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
sendXmppCommandStartTrail();
|
||||
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean isTraceurActivated() {
|
||||
|
|
@ -254,9 +245,9 @@ public class ServiceTrackingDog implements Observer {
|
|||
MyLocation location = new MyLocation((Location) notification.getExtra(ServiceGps.NOTIF_NEW_LOCATION_VALUE_LOCATION));
|
||||
onNewLocation(location);
|
||||
shouldVibrate();
|
||||
if (serviceXmpp != null && location != null) {
|
||||
if (serviceXmpp != null && location != null && isTraceurActivated()) {
|
||||
try {
|
||||
serviceXmpp.sendCommandLocationTrail(location.getLatitude(), location.getLongitude(), location.getTime());
|
||||
sendXmppCommandLocationTrail(location.getLatitude(), location.getLongitude(), location.getTime());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
|
@ -367,12 +358,12 @@ public class ServiceTrackingDog implements Observer {
|
|||
}
|
||||
}
|
||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||
private void sendXmppCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
public void sendXmppCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandStartTrail();
|
||||
}
|
||||
}
|
||||
private void sendXmppCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
public void sendXmppCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandStopTrail();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue