Reorganized and cleaned up the playback service a bit. Added the ability to fade a song in/out on play/pause.
This commit is contained in:
parent
b32feb38fe
commit
257791eff6
13 changed files with 324 additions and 174 deletions
|
|
@ -43,7 +43,6 @@ import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
|
|||
import com.kabouzeid.gramophone.loader.AlbumSongLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.MusicRemoteEvent;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.model.UIPreferenceChangedEvent;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
|
||||
|
|
@ -300,11 +299,9 @@ public class MainActivity extends AbsFabActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
super.onMusicRemoteEvent(event);
|
||||
if (event.getAction() == MusicRemoteEvent.STATE_RESTORED || event.getAction() == MusicRemoteEvent.TRACK_CHANGED) {
|
||||
updateNavigationDrawerHeader();
|
||||
}
|
||||
public void onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged();
|
||||
updateNavigationDrawerHeader();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import com.kabouzeid.gramophone.helper.bitmapblur.StackBlurManager;
|
|||
import com.kabouzeid.gramophone.loader.SongFilePathLoader;
|
||||
import com.kabouzeid.gramophone.misc.AppKeys;
|
||||
import com.kabouzeid.gramophone.misc.SmallTransitionListener;
|
||||
import com.kabouzeid.gramophone.model.MusicRemoteEvent;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
|
||||
|
|
@ -469,19 +468,21 @@ public class MusicControllerActivity extends AbsFabActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
super.onMusicRemoteEvent(event);
|
||||
switch (event.getAction()) {
|
||||
case MusicRemoteEvent.TRACK_CHANGED:
|
||||
updateCurrentSong();
|
||||
break;
|
||||
case MusicRemoteEvent.REPEAT_MODE_CHANGED:
|
||||
updateRepeatState();
|
||||
break;
|
||||
case MusicRemoteEvent.SHUFFLE_MODE_CHANGED:
|
||||
updateShuffleState();
|
||||
break;
|
||||
}
|
||||
public void onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged();
|
||||
updateCurrentSong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeatModeChanged() {
|
||||
super.onRepeatModeChanged();
|
||||
updateRepeatState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShuffleModeChanged() {
|
||||
super.onShuffleModeChanged();
|
||||
updateShuffleState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import com.squareup.otto.Subscribe;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsBaseActivity extends ThemeBaseActivity implements KabViewsDisableAble {
|
||||
public abstract class AbsBaseActivity extends AbsThemeActivity implements KabViewsDisableAble {
|
||||
|
||||
private App app;
|
||||
private boolean areViewsEnabled;
|
||||
|
|
|
|||
|
|
@ -12,39 +12,28 @@ import android.view.View;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.misc.SmallOnGestureListener;
|
||||
import com.kabouzeid.gramophone.model.MusicRemoteEvent;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
import com.kabouzeid.gramophone.views.PlayPauseDrawable;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsFabActivity extends AbsBaseActivity {
|
||||
public abstract class AbsFabActivity extends AbsPlaybackStatusActivity {
|
||||
public static final String TAG = AbsFabActivity.class.getSimpleName();
|
||||
|
||||
private FloatingActionButton fab;
|
||||
private PlayPauseDrawable playPauseDrawable;
|
||||
private final Object busEventListener = new Object() {
|
||||
@Subscribe
|
||||
public void onBusEvent(MusicRemoteEvent event) {
|
||||
onMusicRemoteEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
try {
|
||||
App.bus.register(busEventListener);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
setUpFab();
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +105,14 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
protected void animateUpdateFabState() {
|
||||
if (MusicPlayerRemote.isPlaying()) {
|
||||
setFabPause();
|
||||
} else {
|
||||
setFabPlay();
|
||||
}
|
||||
}
|
||||
|
||||
protected FloatingActionButton getFab() {
|
||||
if (fab == null) {
|
||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
|
|
@ -145,33 +142,11 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
|
|||
return sharedViewsWithFab;
|
||||
}
|
||||
|
||||
@DebugLog
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
try {
|
||||
App.bus.unregister(busEventListener);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MusicRemoteEvent.PLAY:
|
||||
setFabPause();
|
||||
break;
|
||||
case MusicRemoteEvent.PAUSE:
|
||||
setFabPlay();
|
||||
break;
|
||||
case MusicRemoteEvent.RESUME:
|
||||
setFabPause();
|
||||
break;
|
||||
case MusicRemoteEvent.STOP:
|
||||
setFabPlay();
|
||||
break;
|
||||
case MusicRemoteEvent.QUEUE_COMPLETED:
|
||||
setFabPlay();
|
||||
break;
|
||||
}
|
||||
public void onPlayStateChanged() {
|
||||
super.onPlayStateChanged();
|
||||
animateUpdateFabState();
|
||||
}
|
||||
|
||||
private void setFabPlay() {
|
||||
|
|
@ -181,8 +156,4 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
|
|||
private void setFabPause() {
|
||||
playPauseDrawable.animatedPause();
|
||||
}
|
||||
|
||||
private void setFabColor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
package com.kabouzeid.gramophone.ui.activities.base;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsPlaybackStatusActivity extends AbsBaseActivity {
|
||||
private PlaybackStatus playbackStatus;
|
||||
|
||||
public void onPlayingMetaChanged() {
|
||||
|
||||
}
|
||||
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
}
|
||||
|
||||
public void onRepeatModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
public void onShuffleModeChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
playbackStatus = new PlaybackStatus(this);
|
||||
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(MusicService.PLAYSTATE_CHANGED);
|
||||
filter.addAction(MusicService.SHUFFLEMODE_CHANGED);
|
||||
filter.addAction(MusicService.REPEATMODE_CHANGED);
|
||||
filter.addAction(MusicService.META_CHANGED);
|
||||
|
||||
registerReceiver(playbackStatus, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
try {
|
||||
unregisterReceiver(playbackStatus);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PlaybackStatus extends BroadcastReceiver {
|
||||
|
||||
private final WeakReference<AbsPlaybackStatusActivity> reference;
|
||||
|
||||
public PlaybackStatus(final AbsPlaybackStatusActivity activity) {
|
||||
reference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
switch (action) {
|
||||
case MusicService.META_CHANGED:
|
||||
reference.get().onPlayingMetaChanged();
|
||||
break;
|
||||
case MusicService.PLAYSTATE_CHANGED:
|
||||
reference.get().onPlayStateChanged();
|
||||
break;
|
||||
case MusicService.REPEATMODE_CHANGED:
|
||||
reference.get().onRepeatModeChanged();
|
||||
break;
|
||||
case MusicService.SHUFFLEMODE_CHANGED:
|
||||
reference.get().onShuffleModeChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ import com.kabouzeid.gramophone.util.Util;
|
|||
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
||||
public abstract class ThemeBaseActivity extends AppCompatActivity implements KabViewsDisableAble {
|
||||
public abstract class AbsThemeActivity extends AppCompatActivity implements KabViewsDisableAble {
|
||||
private int colorPrimary;
|
||||
private int colorPrimaryDarker;
|
||||
private int colorAccent;
|
||||
Loading…
Add table
Add a link
Reference in a new issue