Tweak periodic checking Kodi version

This commit is contained in:
Synced Synapse 2019-02-08 17:25:21 +00:00 committed by Martijn Brekhof
parent c043c04264
commit b824930d8e
2 changed files with 15 additions and 17 deletions

View File

@ -474,41 +474,39 @@ public class HostManager {
} }
} }
// Check Kodi's version every 2 days // Check Kodi's version every 2 hours
private final static long KODI_VERSION_CHECK_INTERVAL_MILLIS = 2 * DateUtils.DAY_IN_MILLIS; private final static long KODI_VERSION_CHECK_INTERVAL_MILLIS = 2 * DateUtils.HOUR_IN_MILLIS;
/** /**
* Periodic checks Kodi's version and updates the DB to reflect that. * Periodic checks Kodi's version and updates the DB to reflect that.
* This should be called somewhere that gets executed periodically * This should be called somewhere that gets executed periodically
* *
* @param hostInfo Host for which to check version
*/ */
public void checkAndUpdateKodiVersion(final HostInfo hostInfo) { public void checkAndUpdateKodiVersion() {
if (hostInfo == null) return; if (currentHostInfo == null) {
currentHostInfo = getHostInfo();
if (currentHostInfo == null) return;
}
if (hostInfo.getUpdated() + KODI_VERSION_CHECK_INTERVAL_MILLIS < java.lang.System.currentTimeMillis()) { if (currentHostInfo.getUpdated() + KODI_VERSION_CHECK_INTERVAL_MILLIS < java.lang.System.currentTimeMillis()) {
LogUtils.LOGD(TAG, "Checking Kodi version..."); LogUtils.LOGD(TAG, "Checking Kodi version...");
final HostConnection hostConnection = new HostConnection(hostInfo);
final Application.GetProperties getProperties = new Application.GetProperties(Application.GetProperties.VERSION); final Application.GetProperties getProperties = new Application.GetProperties(Application.GetProperties.VERSION);
getProperties.execute(hostConnection, new ApiCallback<ApplicationType.PropertyValue>() { getProperties.execute(getConnection(), new ApiCallback<ApplicationType.PropertyValue>() {
@Override @Override
public void onSuccess(ApplicationType.PropertyValue result) { public void onSuccess(ApplicationType.PropertyValue result) {
LogUtils.LOGD(TAG, "Successfully checked Kodi version."); LogUtils.LOGD(TAG, "Successfully checked Kodi version.");
hostInfo.setKodiVersionMajor(result.version.major); currentHostInfo.setKodiVersionMajor(result.version.major);
hostInfo.setKodiVersionMinor(result.version.minor); currentHostInfo.setKodiVersionMinor(result.version.minor);
hostInfo.setKodiVersionRevision(result.version.revision); currentHostInfo.setKodiVersionRevision(result.version.revision);
hostInfo.setKodiVersionTag(result.version.tag); currentHostInfo.setKodiVersionTag(result.version.tag);
editHost(hostInfo.getId(), hostInfo); currentHostInfo = editHost(currentHostInfo.getId(), currentHostInfo);
hostConnection.disconnect();
} }
@Override @Override
public void onError(int errorCode, String description) { public void onError(int errorCode, String description) {
// Couldn't get Kodi version... Ignore // Couldn't get Kodi version... Ignore
LogUtils.LOGD(TAG, "Couldn't get Kodi version. Error: " + description); LogUtils.LOGD(TAG, "Couldn't get Kodi version. Error: " + description);
hostConnection.disconnect();
} }
}, new Handler()); }, new Handler());
} }

View File

@ -151,7 +151,7 @@ public class RemoteActivity extends BaseActivity
setupActionBar(); setupActionBar();
// Periodic Check of Kodi version // Periodic Check of Kodi version
hostManager.checkAndUpdateKodiVersion(hostManager.getHostInfo()); hostManager.checkAndUpdateKodiVersion();
// If we should start playing something // If we should start playing something