use of org.openhab.habdroid.util.AsyncServiceResolver in project openhab-android by openhab.
the class OpenHABMainActivity method onConnectionChanged.
@Override
public void onConnectionChanged() {
Connection newConnection;
ConnectionException failureReason;
try {
newConnection = ConnectionFactory.getUsableConnection();
failureReason = null;
} catch (ConnectionException e) {
newConnection = null;
failureReason = e;
}
if (newConnection != null && newConnection == mConnection) {
return;
}
mConnection = newConnection;
mNotifySettings = null;
hideSnackbar();
mSitemapList.clear();
mSelectedSitemap = null;
// Execute pending NFC action if initial connection determination finished
if (mPendingNfcData != null && (mConnection != null || failureReason != null)) {
onNfcTag(mPendingNfcData);
mPendingNfcData = null;
}
if (newConnection != null) {
handleConnectionChange();
mController.updateConnection(newConnection, null);
} else {
if (failureReason instanceof NoUrlInformationException) {
NoUrlInformationException nuie = (NoUrlInformationException) failureReason;
// no local connection is configured yes
if (nuie.wouldHaveUsedLocalConnection() && ConnectionFactory.getConnection(Connection.TYPE_LOCAL) == null) {
if (mServiceResolver == null) {
mServiceResolver = new AsyncServiceResolver(this, this, getString(R.string.openhab_service_type));
mServiceResolver.start();
mController.updateConnection(null, getString(R.string.resolving_openhab));
}
} else {
mController.indicateMissingConfiguration();
}
} else if (failureReason != null) {
final String message;
if (failureReason instanceof NetworkNotSupportedException) {
NetworkInfo info = ((NetworkNotSupportedException) failureReason).getNetworkInfo();
message = getString(R.string.error_network_type_unsupported, info.getTypeName());
} else {
message = getString(R.string.error_network_not_available);
}
mController.indicateNoNetwork(message);
} else {
mController.updateConnection(null, null);
}
}
mViewPool.clear();
updateSitemapDrawerItems();
invalidateOptionsMenu();
updateTitle();
}
Aggregations