Automatic update check for APK version.

This commit is contained in:
Jens 2021-06-09 22:41:47 +02:00
parent bb2f5c9842
commit 7b88e7a612
6 changed files with 34 additions and 8 deletions

View File

@ -641,6 +641,8 @@ public class ActivityMainScreen extends ActivityGeneric
{ {
if(result && !updateNoteDisplayed) if(result && !updateNoteDisplayed)
{ {
updateNoteDisplayed = true;
AlertDialog.Builder updateNoteBuilder = new AlertDialog.Builder(ActivityMainScreen.this); AlertDialog.Builder updateNoteBuilder = new AlertDialog.Builder(ActivityMainScreen.this);
updateNoteBuilder.setMessage(getResources().getString(R.string.updateAvailable)); updateNoteBuilder.setMessage(getResources().getString(R.string.updateAvailable));
updateNoteBuilder.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() updateNoteBuilder.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
@ -651,10 +653,21 @@ public class ActivityMainScreen extends ActivityGeneric
String url = "https://server47.de/automation/"; String url = "https://server47.de/automation/";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent); startActivity(browserIntent);
updateNoteDisplayed = false;
}
});
updateNoteBuilder.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
updateNoteDisplayed = false;
} }
}); });
updateNoteBuilder.setNegativeButton(getResources().getString(R.string.no), null);
updateNoteBuilder.show(); updateNoteBuilder.show();
} }
AsyncTasks.AsyncTaskUpdateCheck.checkRunning = false;
} }
} }

View File

@ -20,7 +20,7 @@ public class ActivitySettings extends PreferenceActivity
if(BuildConfig.FLAVOR.equals("apkFlavor")) if(BuildConfig.FLAVOR.equals("apkFlavor"))
{ {
chkPrefUpdateCheck = (CheckBoxPreference) findPreference("chkPrefUpdateCheck"); chkPrefUpdateCheck = (CheckBoxPreference) findPreference("automaticUpdateCheck");
chkPrefUpdateCheck.setEnabled(true); chkPrefUpdateCheck.setEnabled(true);
} }
} }

View File

@ -11,14 +11,26 @@ public class AsyncTasks
{ {
public static class AsyncTaskUpdateCheck extends AsyncTask<Context, Void, Boolean> public static class AsyncTaskUpdateCheck extends AsyncTask<Context, Void, Boolean>
{ {
public static boolean checkRunning = false;
@Override @Override
protected Boolean doInBackground(Context... contexts) protected Boolean doInBackground(Context... contexts)
{ {
if(checkRunning)
return false;
else
checkRunning = true;
try try
{ {
String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null); String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null).trim();
int latestVersion = Integer.parseInt(result); int latestVersion = Integer.parseInt(result);
// At this point the update check itself has already been successful.
Settings.lastUpdateCheck = Calendar.getInstance().getTimeInMillis();
Settings.writeSettings(contexts[0]);
if (latestVersion > BuildConfig.VERSION_CODE) if (latestVersion > BuildConfig.VERSION_CODE)
{ {
// There's a new update // There's a new update
@ -42,11 +54,11 @@ public class AsyncTasks
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
Miscellaneous.logEvent("e", "NewsDownload", "There was a problem displaying the already downloded news, probably ActivityMainScreen isn't currently shown: " + Log.getStackTraceString(e), 2); Miscellaneous.logEvent("e", "NewsDownload", "There was a problem displaying the update check result, probably ActivityMainScreen isn't currently shown: " + Log.getStackTraceString(e), 2);
} }
catch (Exception e) catch (Exception e)
{ {
Miscellaneous.logEvent("e", "NewsDownload", "There was a problem displaying the already downloded news: " + Log.getStackTraceString(e), 2); Miscellaneous.logEvent("e", "NewsDownload", "There was a problem displaying the update check result: " + Log.getStackTraceString(e), 2);
} }
} }
} }

View File

@ -258,6 +258,7 @@ public class AutomationService extends Service implements OnInitListener
case reloadSettings: case reloadSettings:
Settings.readFromPersistentStorage(this); Settings.readFromPersistentStorage(this);
applySettingsAndRules(); applySettingsAndRules();
if(myLocationProvider != null)
myLocationProvider.applySettingsAndRules(); myLocationProvider.applySettingsAndRules();
break; break;
case updateNotification: case updateNotification:

View File

@ -255,7 +255,7 @@ public class Settings implements SharedPreferences
startScreen = Integer.parseInt(prefs.getString("startScreen", String.valueOf(default_startScreen))); startScreen = Integer.parseInt(prefs.getString("startScreen", String.valueOf(default_startScreen)));
executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick); executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick);
automaticUpdateCheck = prefs.getBoolean("chkPrefUpdateCheck", default_automaticUpdateCheck); automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck);
displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen); displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges); lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges);

View File

@ -57,7 +57,7 @@
android:title="@string/executeRulesAndProfilesWithSingleClickTitle" /> android:title="@string/executeRulesAndProfilesWithSingleClickTitle" />
<CheckBoxPreference <CheckBoxPreference
android:id="@+id/chkPrefUpdateCheck" android:key="automaticUpdateCheck"
android:enabled="false" android:enabled="false"
android:title="@string/automaticUpdateCheck" android:title="@string/automaticUpdateCheck"
android:summary="@string/automaticUpdateCheckSummary"/> android:summary="@string/automaticUpdateCheckSummary"/>