2021-06-08 23:14:09 +02:00
package com.jens.automation2 ;
import android.content.Context ;
import android.os.AsyncTask ;
import android.util.Log ;
import java.util.ArrayList ;
import java.util.Calendar ;
public class AsyncTasks
{
public static class AsyncTaskUpdateCheck extends AsyncTask < Context , Void , Boolean >
{
2021-06-09 22:41:47 +02:00
public static boolean checkRunning = false ;
2021-06-08 23:14:09 +02:00
@Override
protected Boolean doInBackground ( Context . . . contexts )
{
2021-06-09 22:41:47 +02:00
if ( checkRunning )
return false ;
else
checkRunning = true ;
2021-06-08 23:14:09 +02:00
try
{
2021-06-09 22:41:47 +02:00
String result = Miscellaneous . downloadURL ( " https://server47.de/automation/?action=getLatestVersionCode " , null , null ) . trim ( ) ;
2021-06-08 23:14:09 +02:00
int latestVersion = Integer . parseInt ( result ) ;
2021-06-09 22:41:47 +02:00
// At this point the update check itself has already been successful.
Settings . lastUpdateCheck = Calendar . getInstance ( ) . getTimeInMillis ( ) ;
Settings . writeSettings ( contexts [ 0 ] ) ;
2021-06-08 23:14:09 +02:00
if ( latestVersion > BuildConfig . VERSION_CODE )
{
// There's a new update
return true ;
}
}
catch ( Exception e )
{
Miscellaneous . logEvent ( " e " , " Error checking for update " , Log . getStackTraceString ( e ) , 3 ) ;
}
return false ;
}
@Override
protected void onPostExecute ( Boolean result )
{
try
{
ActivityMainScreen . getActivityMainScreenInstance ( ) . processUpdateCheckResult ( result ) ;
}
catch ( NullPointerException e )
{
2021-06-09 22:41:47 +02:00
Miscellaneous . logEvent ( " e " , " NewsDownload " , " There was a problem displaying the update check result, probably ActivityMainScreen isn't currently shown: " + Log . getStackTraceString ( e ) , 2 ) ;
2021-06-08 23:14:09 +02:00
}
catch ( Exception e )
{
2021-06-09 22:41:47 +02:00
Miscellaneous . logEvent ( " e " , " NewsDownload " , " There was a problem displaying the update check result: " + Log . getStackTraceString ( e ) , 2 ) ;
2021-06-08 23:14:09 +02:00
}
}
}
}