Fixed saving position in track, improvement with service binding, temporary new default album art.
This commit is contained in:
parent
1cccaad0f4
commit
cfa6ddaa2e
12 changed files with 140 additions and 61 deletions
|
|
@ -111,16 +111,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
setNavigationBarColor(DialogUtils.resolveColor(this, R.attr.default_bar_color));
|
||||
}
|
||||
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
int albumId = -1;
|
||||
if (intentExtras != null) {
|
||||
albumId = intentExtras.getInt(EXTRA_ALBUM_ID);
|
||||
}
|
||||
album = AlbumLoader.getAlbum(this, albumId);
|
||||
if (album.id == -1) {
|
||||
finish();
|
||||
}
|
||||
|
||||
getAlbumFromIntentExtras();
|
||||
setUpObservableListViewParams();
|
||||
setUpToolBar();
|
||||
setUpViews();
|
||||
|
|
@ -180,6 +171,15 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
}
|
||||
};
|
||||
|
||||
private void getAlbumFromIntentExtras() {
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
final int albumId = intentExtras.getInt(EXTRA_ALBUM_ID);
|
||||
album = AlbumLoader.getAlbum(this, albumId);
|
||||
if (album.id == -1) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
|
||||
lastFMRestClient = new LastFMRestClient(this);
|
||||
|
||||
getIntentExtras();
|
||||
getArtistFromIntentExtras();
|
||||
initViews();
|
||||
setUpObservableListViewParams();
|
||||
setUpViews();
|
||||
|
|
@ -430,11 +430,11 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
notifyTaskColorChange(toolbarColor);
|
||||
}
|
||||
|
||||
private void getIntentExtras() {
|
||||
private void getArtistFromIntentExtras() {
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
final int artistId = intentExtras.getInt(EXTRA_ARTIST_ID);
|
||||
artist = ArtistLoader.getArtist(this, artistId);
|
||||
if (artist == null) {
|
||||
if (artist.id == -1) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import butterknife.Optional;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsFabActivity extends AbsPlaybackStatusActivity {
|
||||
public abstract class AbsFabActivity extends AbsPlaybackControlActivity {
|
||||
public static final String TAG = AbsFabActivity.class.getSimpleName();
|
||||
|
||||
@Optional
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package com.kabouzeid.gramophone.ui.activities.base;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
|
|
@ -13,7 +17,8 @@ import java.lang.ref.WeakReference;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsPlaybackStatusActivity extends AbsBaseActivity {
|
||||
public abstract class AbsPlaybackControlActivity extends AbsBaseActivity {
|
||||
private MusicPlayerRemote.ServiceToken serviceToken;
|
||||
private PlaybackStatusReceiver playbackStatusReceiver;
|
||||
|
||||
public void onPlayingMetaChanged() {
|
||||
|
|
@ -36,23 +41,32 @@ public abstract class AbsPlaybackStatusActivity extends AbsBaseActivity {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
serviceToken = MusicPlayerRemote.bindToService(this, new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
AbsPlaybackControlActivity.this.onServiceConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
|
||||
}
|
||||
});
|
||||
playbackStatusReceiver = new PlaybackStatusReceiver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
playbackStatusReceiver = new PlaybackStatusReceiver(this);
|
||||
|
||||
// ensures that onServiceConnected() is called even if the service is already connected and wont sent the Intent again.
|
||||
if (MusicPlayerRemote.isServiceConnected()) {
|
||||
onServiceConnected();
|
||||
}
|
||||
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(MusicService.PLAY_STATE_CHANGED);
|
||||
filter.addAction(MusicService.SHUFFLE_MODE_CHANGED);
|
||||
filter.addAction(MusicService.REPEAT_MODE_CHANGED);
|
||||
filter.addAction(MusicService.META_CHANGED);
|
||||
filter.addAction(MusicPlayerRemote.SERVICE_BOUND);
|
||||
|
||||
registerReceiver(playbackStatusReceiver, filter);
|
||||
}
|
||||
|
|
@ -66,11 +80,17 @@ public abstract class AbsPlaybackStatusActivity extends AbsBaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
MusicPlayerRemote.unbindFromService(serviceToken);
|
||||
}
|
||||
|
||||
private static final class PlaybackStatusReceiver extends BroadcastReceiver {
|
||||
|
||||
private final WeakReference<AbsPlaybackStatusActivity> reference;
|
||||
private final WeakReference<AbsPlaybackControlActivity> reference;
|
||||
|
||||
public PlaybackStatusReceiver(final AbsPlaybackStatusActivity activity) {
|
||||
public PlaybackStatusReceiver(final AbsPlaybackControlActivity activity) {
|
||||
reference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
|
|
@ -90,9 +110,6 @@ public abstract class AbsPlaybackStatusActivity extends AbsBaseActivity {
|
|||
case MusicService.SHUFFLE_MODE_CHANGED:
|
||||
reference.get().onShuffleModeChanged();
|
||||
break;
|
||||
case MusicPlayerRemote.SERVICE_BOUND:
|
||||
reference.get().onServiceConnected();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue