forked from jens/Automation
		
	Automatic update check for APK version.
This commit is contained in:
		| @@ -641,6 +641,8 @@ public class ActivityMainScreen extends ActivityGeneric | ||||
| 	{ | ||||
| 		if(result && !updateNoteDisplayed) | ||||
| 		{ | ||||
| 			updateNoteDisplayed = true; | ||||
|  | ||||
| 			AlertDialog.Builder updateNoteBuilder = new AlertDialog.Builder(ActivityMainScreen.this); | ||||
| 			updateNoteBuilder.setMessage(getResources().getString(R.string.updateAvailable)); | ||||
| 			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/"; | ||||
| 					Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | ||||
| 					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(); | ||||
| 		} | ||||
|  | ||||
| 		AsyncTasks.AsyncTaskUpdateCheck.checkRunning = false; | ||||
| 	} | ||||
| } | ||||
| @@ -20,7 +20,7 @@ public class ActivitySettings extends PreferenceActivity | ||||
|  | ||||
| 		if(BuildConfig.FLAVOR.equals("apkFlavor")) | ||||
| 		{ | ||||
| 			chkPrefUpdateCheck = (CheckBoxPreference) findPreference("chkPrefUpdateCheck"); | ||||
| 			chkPrefUpdateCheck = (CheckBoxPreference) findPreference("automaticUpdateCheck"); | ||||
| 			chkPrefUpdateCheck.setEnabled(true); | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -11,14 +11,26 @@ public class AsyncTasks | ||||
| { | ||||
|     public static class AsyncTaskUpdateCheck extends AsyncTask<Context, Void, Boolean> | ||||
|     { | ||||
|         public static boolean checkRunning = false; | ||||
|  | ||||
|         @Override | ||||
|         protected Boolean doInBackground(Context... contexts) | ||||
|         { | ||||
|             if(checkRunning) | ||||
|                 return false; | ||||
|             else | ||||
|                 checkRunning = true; | ||||
|  | ||||
|             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); | ||||
|  | ||||
|                 // 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) | ||||
|                 { | ||||
|                     // There's a new update | ||||
| @@ -42,11 +54,11 @@ public class AsyncTasks | ||||
|             } | ||||
|             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) | ||||
|             { | ||||
|                 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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -258,7 +258,8 @@ public class AutomationService extends Service implements OnInitListener | ||||
| 			case reloadSettings: | ||||
| 				Settings.readFromPersistentStorage(this); | ||||
| 				applySettingsAndRules(); | ||||
| 				myLocationProvider.applySettingsAndRules(); | ||||
| 				if(myLocationProvider != null) | ||||
| 					myLocationProvider.applySettingsAndRules(); | ||||
| 				break; | ||||
| 			case updateNotification: | ||||
| 				this.updateNotification(); | ||||
|   | ||||
| @@ -255,7 +255,7 @@ public class Settings implements SharedPreferences | ||||
| 			startScreen = Integer.parseInt(prefs.getString("startScreen", String.valueOf(default_startScreen))); | ||||
|  | ||||
| 			executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick); | ||||
| 			automaticUpdateCheck = prefs.getBoolean("chkPrefUpdateCheck", default_automaticUpdateCheck); | ||||
| 			automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck); | ||||
| 			displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen); | ||||
|  | ||||
| 			lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges); | ||||
|   | ||||
| @@ -57,7 +57,7 @@ | ||||
| 			android:title="@string/executeRulesAndProfilesWithSingleClickTitle" /> | ||||
|  | ||||
| 		<CheckBoxPreference | ||||
| 			android:id="@+id/chkPrefUpdateCheck" | ||||
| 			android:key="automaticUpdateCheck" | ||||
| 			android:enabled="false" | ||||
| 			android:title="@string/automaticUpdateCheck" | ||||
| 			android:summary="@string/automaticUpdateCheckSummary"/> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user