aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-08-05 21:48:25 -0700
committerScott Jackson <daneren2005@gmail.com>2013-08-05 21:48:25 -0700
commit970a7c2752461d2ffd4394fc787a290b1bde0653 (patch)
treec19e0fefd8408a7be8411c9fb763cb521323d142 /src
parent4f669ae430bdb8744693baf16bd5d48bd47a51d4 (diff)
downloaddsub-970a7c2752461d2ffd4394fc787a290b1bde0653.tar.gz
dsub-970a7c2752461d2ffd4394fc787a290b1bde0653.tar.bz2
dsub-970a7c2752461d2ffd4394fc787a290b1bde0653.zip
Changed hard coded jukebox methods to abstract remote methods
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java7
-rw-r--r--src/github/daneren2005/dsub/fragments/DownloadFragment.java9
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java7
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceImpl.java35
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java4
-rw-r--r--src/github/daneren2005/dsub/service/JukeboxService.java3
-rw-r--r--src/github/daneren2005/dsub/util/Util.java5
7 files changed, 36 insertions, 34 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index d8158f7d..611a19ee 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -23,9 +23,8 @@ import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
+
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.fragments.SubsonicFragment;
import github.daneren2005.dsub.service.DownloadService;
@@ -155,10 +154,10 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
- boolean isJukebox = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
+ boolean isJukebox = getDownloadService() != null && getDownloadService().isRemoteEnabled();
if (isVolumeAdjust && isJukebox) {
- getDownloadService().adjustJukeboxVolume(isVolumeUp);
+ getDownloadService().setRemoteVolume(isVolumeUp);
return true;
}
return super.onKeyDown(keyCode, event);
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
index 1940d426..48102539 100644
--- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -42,6 +42,7 @@ import com.actionbarsherlock.view.MenuInflater;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
+import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
@@ -351,8 +352,8 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
jukeboxButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
- getDownloadService().setJukeboxEnabled(jukeboxEnabled);
+ boolean jukeboxEnabled = !getDownloadService().isRemoteEnabled();
+ getDownloadService().setRemoteEnabled(jukeboxEnabled ? RemoteControlState.JUKEBOX_SERVER : RemoteControlState.LOCAL);
updateButtons();
Util.toast(context, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
setControlsVisible(true);
@@ -777,7 +778,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
}
- boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
+ boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isRemoteEnabled();
jukeboxButton.setTextColor(jukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
}
@@ -966,7 +967,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe
@Override
protected Void doInBackground() throws Throwable {
downloadService = getDownloadService();
- isJukeboxEnabled = downloadService.isJukeboxEnabled();
+ isJukeboxEnabled = downloadService.isRemoteEnabled();
millisPlayed = Math.max(0, downloadService.getPlayerPosition());
duration = downloadService.getPlayerDuration();
playerState = getDownloadService().getPlayerState();
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 328cc962..7e8c8c81 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -24,6 +24,7 @@ import github.daneren2005.dsub.audiofx.EqualizerController;
import github.daneren2005.dsub.audiofx.VisualizerController;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
+import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.domain.RepeatMode;
/**
@@ -121,11 +122,11 @@ public interface DownloadService {
VisualizerController getVisualizerController();
- boolean isJukeboxEnabled();
+ boolean isRemoteEnabled();
- void setJukeboxEnabled(boolean b);
+ void setRemoteEnabled(RemoteControlState newState);
- void adjustJukeboxVolume(boolean up);
+ void setRemoteVolume(boolean up);
void setSleepTimerDuration(int duration);
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 04875f34..dfb161a6 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -30,6 +30,7 @@ import github.daneren2005.dsub.audiofx.EqualizerController;
import github.daneren2005.dsub.audiofx.VisualizerController;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
+import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.util.CancellableTask;
@@ -120,7 +121,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private EqualizerController equalizerController;
private VisualizerController visualizerController;
private boolean showVisualization;
- private boolean jukeboxEnabled;
+ private RemoteControlState remoteState = RemoteControlState.LOCAL;
private PositionCache positionCache;
private StreamProxy proxy;
@@ -322,7 +323,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
private void updateJukeboxPlaylist() {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.updatePlaylist();
}
}
@@ -652,7 +653,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
setCurrentPlaying(index, start);
if (start) {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.skip(getCurrentPlayingIndex(), 0);
setPlayerState(STARTED);
} else {
@@ -712,7 +713,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void seekTo(int position) {
try {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.skip(getCurrentPlayingIndex(), position / 1000);
} else {
mediaPlayer.seekTo(position);
@@ -769,7 +770,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
public synchronized void pause() {
try {
if (playerState == STARTED) {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.stop();
} else {
mediaPlayer.pause();
@@ -785,7 +786,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
public synchronized void stop() {
try {
if (playerState == STARTED) {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.stop();
} else {
mediaPlayer.pause();
@@ -802,7 +803,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void start() {
try {
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
jukeboxService.start();
} else {
mediaPlayer.start();
@@ -834,7 +835,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) {
return 0;
}
- if (jukeboxEnabled) {
+ if (remoteState != RemoteControlState.LOCAL) {
return jukeboxService.getPositionSeconds() * 1000;
} else {
return cachedPosition;
@@ -1008,15 +1009,15 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
@Override
- public boolean isJukeboxEnabled() {
- return jukeboxEnabled;
+ public boolean isRemoteEnabled() {
+ return remoteState != RemoteControlState.LOCAL;
}
@Override
- public void setJukeboxEnabled(boolean jukeboxEnabled) {
- this.jukeboxEnabled = jukeboxEnabled;
- jukeboxService.setEnabled(jukeboxEnabled);
- if (jukeboxEnabled) {
+ public void setRemoteEnabled(RemoteControlState newState) {
+ remoteState = newState;
+ jukeboxService.setEnabled(remoteState != RemoteControlState.LOCAL);
+ if (remoteState != RemoteControlState.LOCAL) {
reset();
// Cancel current download, if necessary.
@@ -1027,7 +1028,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
@Override
- public void adjustJukeboxVolume(boolean up) {
+ public void setRemoteVolume(boolean up) {
jukeboxService.adjustVolume(up);
}
@@ -1274,7 +1275,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
int currentPlayingIndex = getCurrentPlayingIndex();
DownloadFile movedSong = list.remove(from);
list.add(to, movedSong);
- if(jukeboxEnabled && mainList) {
+ if(remoteState != RemoteControlState.LOCAL && mainList) {
updateJukeboxPlaylist();
} else if(mainList && (movedSong == nextPlaying || (currentPlayingIndex + 1) == to)) {
// Moving next playing or moving a song to be next playing
@@ -1302,7 +1303,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
checkShufflePlay();
}
- if (jukeboxEnabled || !Util.isNetworkConnected(this)) {
+ if (remoteState != RemoteControlState.LOCAL || !Util.isNetworkConnected(this)) {
return;
}
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index ae378865..93eefeeb 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -113,7 +113,7 @@ public class DownloadServiceLifecycleSupport {
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Headset event for: " + intent.getExtras().get("name"));
if (intent.getExtras().getInt("state") == 0) {
- if(!downloadService.isJukeboxEnabled()) {
+ if(!downloadService.isRemoteEnabled()) {
downloadService.pause();
}
}
@@ -298,7 +298,7 @@ public class DownloadServiceLifecycleSupport {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
case TelephonyManager.CALL_STATE_OFFHOOK:
- if (downloadService.getPlayerState() == PlayerState.STARTED && !downloadService.isJukeboxEnabled()) {
+ if (downloadService.getPlayerState() == PlayerState.STARTED && !downloadService.isRemoteEnabled()) {
resumeAfterCall = true;
downloadService.pause();
}
diff --git a/src/github/daneren2005/dsub/service/JukeboxService.java b/src/github/daneren2005/dsub/service/JukeboxService.java
index 96b82336..c44b98c4 100644
--- a/src/github/daneren2005/dsub/service/JukeboxService.java
+++ b/src/github/daneren2005/dsub/service/JukeboxService.java
@@ -29,6 +29,7 @@ import android.widget.Toast;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.JukeboxStatus;
import github.daneren2005.dsub.domain.PlayerState;
+import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.service.parser.SubsonicRESTException;
import github.daneren2005.dsub.util.Util;
@@ -145,7 +146,7 @@ public class JukeboxService {
Util.toast(downloadService, resourceId, false);
}
});
- downloadService.setJukeboxEnabled(false);
+ downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
}
public void updatePlaylist() {
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index a6fdd987..a22c28b0 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -40,7 +40,6 @@ import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
-import android.support.v4.app.NotificationCompat;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
@@ -1014,7 +1013,7 @@ public final class Util {
audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
DownloadServiceImpl downloadService = (DownloadServiceImpl)context;
- if((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isJukeboxEnabled()) {
+ if((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isRemoteEnabled()) {
if(downloadService.getPlayerState() == PlayerState.STARTED) {
SharedPreferences prefs = getPreferences(context);
int lossPref = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1"));
@@ -1034,7 +1033,7 @@ public final class Util {
lowerFocus = false;
downloadService.setVolume(1.0f);
}
- } else if(focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isJukeboxEnabled()) {
+ } else if(focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isRemoteEnabled()) {
hasFocus = false;
downloadService.pause();
audioManager.abandonAudioFocus(this);