From 45dc6f4a0d531cfe908096bb209fbf35a190ce64 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 29 Jan 2013 21:33:15 -0800 Subject: Added one time update logic that can be selectively applied when updating past a certain version --- .../daneren2005/dsub/activity/MainActivity.java | 2 + .../dsub/activity/SubsonicTabActivity.java | 13 ++++ .../github/daneren2005/dsub/updates/Updater.java | 76 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 subsonic-android/src/github/daneren2005/dsub/updates/Updater.java (limited to 'subsonic-android/src/github') 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 . + + 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 updaters = new ArrayList(); + + 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 { + @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) { + + } +} -- cgit v1.2.3