aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-17 20:48:31 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-17 20:48:31 -0700
commit1bd41a3b92d871445dbdc17e3f86ee1504f23a90 (patch)
tree524e2f45b4c7cf9a7a827d8b49c84c7c098046e3 /subsonic-android/src
parent3ff9f2d3214e280df56a988db744c210ab53ad5e (diff)
downloaddsub-1bd41a3b92d871445dbdc17e3f86ee1504f23a90.tar.gz
dsub-1bd41a3b92d871445dbdc17e3f86ee1504f23a90.tar.bz2
dsub-1bd41a3b92d871445dbdc17e3f86ee1504f23a90.zip
Reworked Sleep Timer
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java11
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java7
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java6
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java41
4 files changed, 32 insertions, 33 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index 70120574..604966a9 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -35,6 +35,7 @@ import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.Display;
import android.view.GestureDetector;
@@ -78,6 +79,7 @@ import static github.daneren2005.dsub.domain.PlayerState.*;
import java.util.ArrayList;
public class DownloadActivity extends SubsonicTabActivity implements OnGestureListener {
+ private static final String TAG = DownloadActivity.class.getSimpleName();
private static final int DIALOG_SAVE_PLAYLIST = 100;
private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 5;
@@ -532,6 +534,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
togglePlaying.setTitle(nowPlaying ? R.string.download_show_downloading : R.string.download_show_now_playing);
MenuItem shuffle = menu.findItem(R.id.menu_shuffle);
shuffle.setVisible(nowPlaying);
+ MenuItem timer = menu.findItem(R.id.menu_toggle_timer);
+ timer.setTitle(getDownloadService().getSleepTimer() ? R.string.download_stop_timer : R.string.download_start_timer);
return super.onPrepareOptionsMenu(menu);
}
@@ -624,6 +628,13 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
toggleNowPlaying();
invalidateOptionsMenu();
return true;
+ case R.id.menu_toggle_timer:
+ if(getDownloadService().getSleepTimer()) {
+ getDownloadService().stopSleepTimer();
+ } else {
+ getDownloadService().startSleepTimer();
+ }
+ return true;
case R.id.menu_exit:
intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index bf079448..febfedca 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -57,7 +57,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private EditTextPreference cacheLocation;
private ListPreference preloadCount;
private EditTextPreference randomSize;
- private ListPreference sleepTimer;
private EditTextPreference sleepTimerDuration;
@Override
@@ -73,7 +72,6 @@ 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() {
@@ -143,10 +141,6 @@ 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")));
@@ -166,7 +160,6 @@ 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 55bd195d..b1fa732d 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
@@ -117,7 +117,9 @@ public interface DownloadService {
void setSleepTimerDuration(int duration);
- void setSleepTimerStatus(int status);
-
void startSleepTimer();
+
+ void stopSleepTimer();
+
+ boolean getSleepTimer();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 6218209d..496bd757 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -110,7 +110,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private Timer sleepTimer;
private int timerDuration;
- private int timerStatus;
static {
try {
@@ -175,7 +174,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
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;
@@ -517,7 +515,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void play(int index) {
- Log.d(TAG, "Play");
play(index, true);
}
@@ -625,8 +622,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void start() {
try {
- if(timerStatus > 0)
- startSleepTimer();
if (jukeboxEnabled) {
jukeboxService.start();
} else {
@@ -830,8 +825,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
if (start) {
- if(timerStatus > 0)
- startSleepTimer();
mediaPlayer.start();
setPlayerState(STARTED);
} else {
@@ -847,22 +840,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public void setSleepTimerDuration(int duration){
timerDuration = duration;
- if(this.playerState == PlayerState.STARTED && timerStatus > 0)
- startSleepTimer();
- }
-
- @Override
- public void setSleepTimerStatus(int status){
- timerStatus = status;
- if(this.playerState == PlayerState.STARTED && timerStatus > 0)
- startSleepTimer();
}
@Override
public void startSleepTimer(){
- final SharedPreferences prefs = Util.getPreferences(this);
- final SharedPreferences.Editor editor = prefs.edit();
-
if(sleepTimer != null){
sleepTimer.cancel();
sleepTimer.purge();
@@ -874,15 +855,27 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public void run() {
pause();
- if(timerStatus == 1){
- timerStatus = 0;
- editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER, String.valueOf(timerStatus));
- editor.commit();
- }
+ sleepTimer.cancel();
+ sleepTimer.purge();
+ sleepTimer = null;
}
}, timerDuration * 60 * 1000);
}
+
+ @Override
+ public void stopSleepTimer() {
+ if(sleepTimer != null){
+ sleepTimer.cancel();
+ sleepTimer.purge();
+ }
+ sleepTimer = null;
+ }
+
+ @Override
+ public boolean getSleepTimer() {
+ return sleepTimer != null;
+ }
private void handleError(Exception x) {
Log.w(TAG, "Media player error: " + x, x);