aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-15 20:29:08 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-15 20:29:08 -0700
commitcbc10200e39f3f4b00b6005295e9a4b456e87c03 (patch)
treeca97a3defb725471801c85115dbce30220240128 /subsonic-android/src
parent7663fb1729b02f1177d75f37fa6a1fdacec10861 (diff)
downloaddsub-cbc10200e39f3f4b00b6005295e9a4b456e87c03.tar.gz
dsub-cbc10200e39f3f4b00b6005295e9a4b456e87c03.tar.bz2
dsub-cbc10200e39f3f4b00b6005295e9a4b456e87c03.zip
Merged Sleep Timer functionality from tombriden + normalized naming with rest of app
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java14
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java6
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java55
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java2
4 files changed, 77 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index efbbb1f2..bf079448 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -57,6 +57,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private EditTextPreference cacheLocation;
private ListPreference preloadCount;
private EditTextPreference randomSize;
+ private ListPreference sleepTimer;
+ private EditTextPreference sleepTimerDuration;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -71,6 +73,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
randomSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_RANDOM_SIZE);
+ sleepTimer = (ListPreference) findPreference(Constants.PREFERENCES_KEY_SLEEP_TIMER);
+ sleepTimerDuration = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION);
findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@@ -139,6 +143,14 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) {
setCacheLocation(sharedPreferences.getString(key, ""));
}
+ else if(Constants.PREFERENCES_KEY_SLEEP_TIMER.equals(key)){
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ downloadService.setSleepTimerStatus(Integer.parseInt(sharedPreferences.getString(key, "0")));
+ }
+ else if (Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION.equals(key)){
+ DownloadService downloadService = DownloadServiceImpl.getInstance();
+ downloadService.setSleepTimerDuration(Integer.parseInt(sharedPreferences.getString(key, "60")));
+ }
}
private void update() {
@@ -154,6 +166,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
cacheLocation.setSummary(cacheLocation.getText());
preloadCount.setSummary(preloadCount.getEntry());
randomSize.setSummary(randomSize.getText());
+ sleepTimer.setSummary(sleepTimer.getEntry());
+ sleepTimerDuration.setSummary(sleepTimerDuration.getText());
for (ServerSettings ss : serverSettings.values()) {
ss.update();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
index a2f2868f..55bd195d 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
@@ -114,4 +114,10 @@ public interface DownloadService {
void setJukeboxEnabled(boolean b);
void adjustJukeboxVolume(boolean up);
+
+ void setSleepTimerDuration(int duration);
+
+ void setSleepTimerStatus(int status);
+
+ void startSleepTimer();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 09cbb40f..87ffb629 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -45,6 +45,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
import android.app.Service;
import android.content.ComponentName;
@@ -105,6 +107,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private VisualizerController visualizerController;
private boolean showVisualization;
private boolean jukeboxEnabled;
+
+ private Timer sleepTimer;
+ private int timerDuration;
+ private int timerStatus;
static {
try {
@@ -166,6 +172,11 @@ public class DownloadServiceImpl extends Service implements DownloadService {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
wakeLock.setReferenceCounted(false);
+
+ SharedPreferences prefs = Util.getPreferences(this);
+ timerDuration = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "60"));
+ timerStatus = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER, "0"));
+ sleepTimer = null;
instance = this;
lifecycleSupport.onCreate();
@@ -181,6 +192,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public void onDestroy() {
super.onDestroy();
+ if(sleepTimer != null){
+ sleepTimer.cancel();
+ sleepTimer.purge();
+ }
lifecycleSupport.onDestroy();
mediaPlayer.release();
shufflePlayBuffer.shutdown();
@@ -609,6 +624,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void start() {
try {
+ if(timerStatus > 0)
+ startSleepTimer();
if (jukeboxEnabled) {
jukeboxService.start();
} else {
@@ -812,6 +829,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
if (start) {
+ if(timerStatus > 0)
+ startSleepTimer();
mediaPlayer.start();
setPlayerState(STARTED);
} else {
@@ -823,6 +842,42 @@ public class DownloadServiceImpl extends Service implements DownloadService {
handleError(x);
}
}
+
+ @Override
+ public void setSleepTimerDuration(int duration){
+ timerDuration = duration;
+ }
+
+ @Override
+ public void setSleepTimerStatus(int status){
+ timerStatus = status;
+ }
+
+ @Override
+ public void startSleepTimer(){
+ final SharedPreferences prefs = Util.getPreferences(this);
+ final SharedPreferences.Editor editor = prefs.edit();
+
+ if(sleepTimer != null){
+ sleepTimer.cancel();
+ sleepTimer.purge();
+ }
+
+ sleepTimer = new Timer();
+
+ sleepTimer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ pause();
+ if(timerStatus == 1){
+ timerStatus = 0;
+ editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER, String.valueOf(timerStatus));
+ editor.commit();
+ }
+ }
+
+ }, timerDuration * 60 * 1000);
+ }
private void handleError(Exception x) {
Log.w(TAG, "Media player error: " + x, x);
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index 863edf79..a761614f 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -76,6 +76,8 @@ public final class Constants {
public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode";
public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload";
public static final String PREFERENCES_KEY_RANDOM_SIZE = "randomSize";
+ public static final String PREFERENCES_KEY_SLEEP_TIMER = "sleepTimer";
+ public static final String PREFERENCES_KEY_SLEEP_TIMER_DURATION = "sleepTimerDuration";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";