diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-29 21:33:15 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-29 21:33:15 -0800 |
commit | 45dc6f4a0d531cfe908096bb209fbf35a190ce64 (patch) | |
tree | 5f75e267a5fa5ec4479b1c4d73ed45cd8605bc24 /subsonic-android/src | |
parent | baaa8deb363261af488a2ca736fc0a402aa41bca (diff) | |
download | dsub-45dc6f4a0d531cfe908096bb209fbf35a190ce64.tar.gz dsub-45dc6f4a0d531cfe908096bb209fbf35a190ce64.tar.bz2 dsub-45dc6f4a0d531cfe908096bb209fbf35a190ce64.zip |
Added one time update logic that can be selectively applied when updating past a certain version
Diffstat (limited to 'subsonic-android/src')
3 files changed, 91 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index edd9b779..fd2f31d4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -139,6 +139,8 @@ public class MainActivity extends SubsonicTabActivity { // Title: Subsonic setTitle(R.string.common_appname); showInfoDialog(); + + checkUpdates(); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 297bd6f4..d2c61b59 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -47,6 +47,7 @@ import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.*;
+import github.daneren2005.dsub.updates.Updater;
import github.daneren2005.dsub.util.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -528,6 +529,18 @@ public class SubsonicTabActivity extends SherlockActivity { .setMessage(msg)
.show();
}
+
+ public void checkUpdates() {
+ try {
+ String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
+ int ver = Integer.parseInt(version.replace(".", ""));
+ Updater updater = new Updater(ver);
+ updater.checkUpdates(SubsonicTabActivity.this);
+ }
+ catch(Exception e) {
+
+ }
+ }
private void setUncaughtExceptionHandler() {
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
diff --git a/subsonic-android/src/github/daneren2005/dsub/updates/Updater.java b/subsonic-android/src/github/daneren2005/dsub/updates/Updater.java new file mode 100644 index 00000000..356e7958 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/updates/Updater.java @@ -0,0 +1,76 @@ +/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package github.daneren2005.dsub.updates;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+import android.util.Log;
+import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.Util;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author Scott
+ */
+public class Updater {
+ protected String TAG = Updater.class.getSimpleName();
+ protected int version;
+ protected Context context;
+
+ public Updater(int version) {
+ this.version = version;
+ }
+
+ public void checkUpdates(Context context) {
+ this.context = context;
+ List<Updater> updaters = new ArrayList<Updater>();
+
+ SharedPreferences prefs = Util.getPreferences(context);
+ int lastVersion = prefs.getInt(Constants.LAST_VERSION, 372);
+ if(version > lastVersion) {
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putInt(Constants.LAST_VERSION, version);
+
+ Log.i(TAG, "Updating from version " + lastVersion + " to " + version);
+ for(Updater updater: updaters) {
+ if(updater.shouldUpdate(lastVersion)) {
+ new BackgroundUpdate().execute(updater);
+ }
+ }
+ }
+ }
+
+ private class BackgroundUpdate extends AsyncTask<Updater, Void, Void> {
+ @Override
+ protected Void doInBackground(Updater... params) {
+ params[0].update(context);
+ return null;
+ }
+ }
+
+ public boolean shouldUpdate(int version) {
+ return this.version > version;
+ }
+ public void update(Context context) {
+
+ }
+}
|