aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/res/menu/nowplaying.xml4
-rw-r--r--subsonic-android/res/values/strings.xml2
-rw-r--r--subsonic-android/res/xml/settings.xml7
-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
7 files changed, 38 insertions, 40 deletions
diff --git a/subsonic-android/res/menu/nowplaying.xml b/subsonic-android/res/menu/nowplaying.xml
index 859fb108..62097751 100644
--- a/subsonic-android/res/menu/nowplaying.xml
+++ b/subsonic-android/res/menu/nowplaying.xml
@@ -26,6 +26,10 @@
android:showAsAction="ifRoom|withText"/>
<item
+ android:id="@+id/menu_toggle_timer"
+ android:title="@string/download.start_timer"/>
+
+ <item
android:id="@+id/menu_toggle_now_playing"
android:title="@string/download.show_downloading"/>
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index fa632b24..5e6b7371 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -122,6 +122,8 @@
<string name="download.jukebox_not_authorized">Remote control is not allowed. Please enable jukebox mode in <b>Users &gt; Settings</b> on your Subsonic server.</string>
<string name="download.show_downloading">Show Downloading</string>
<string name="download.show_now_playing">Show Now Playing</string>
+ <string name="download.start_timer">Start Timer</string>
+ <string name="download.stop_timer">Stop Timer</string>
<string name="starring_content_starred">Starred \"%s\"</string>
<string name="starring_content_unstarred">Unstarred \"%s\"</string>
diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml
index 2764091d..294f7601 100644
--- a/subsonic-android/res/xml/settings.xml
+++ b/subsonic-android/res/xml/settings.xml
@@ -155,13 +155,6 @@
android:key="randomSize"
android:defaultValue="20"
android:digits="0123456789"/>
-
- <ListPreference
- android:title="@string/settings.sleep_timer_title"
- android:key="sleepTimer"
- android:defaultValue="0"
- android:entryValues="@array/sleepTimerValues"
- android:entries="@array/sleepTimerNames"/>
<EditTextPreference
android:title="@string/settings.sleep_timer_duration_title"
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);