fixed artist download option

This commit is contained in:
h4h13 2018-07-30 22:52:29 +05:30
parent 4910b3fdc6
commit 8a731b5073

View file

@ -8,7 +8,7 @@ import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView; import android.support.v4.util.Pair;
import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.GridLayoutManager;
@ -21,15 +21,7 @@ import android.view.SubMenu;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.util.ArrayList;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
@ -63,352 +55,354 @@ import code.name.monkey.retromusic.util.MusicUtil;
import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.RetroUtil; import code.name.monkey.retromusic.util.RetroUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.util.ArrayList;
public class AlbumDetailsActivity extends AbsSlidingMusicPanelActivity implements public class AlbumDetailsActivity extends AbsSlidingMusicPanelActivity implements
AlbumDetailsContract.AlbumDetailsView { AlbumDetailsContract.AlbumDetailsView {
public static final String EXTRA_ALBUM_ID = "extra_album_id"; public static final String EXTRA_ALBUM_ID = "extra_album_id";
private static final int TAG_EDITOR_REQUEST = 2001; private static final int TAG_EDITOR_REQUEST = 2001;
@BindView(R.id.image) @BindView(R.id.image)
ImageView image; ImageView image;
@BindView(R.id.recycler_view) @BindView(R.id.recycler_view)
RecyclerView recyclerView; RecyclerView recyclerView;
@BindView(R.id.title) @BindView(R.id.title)
TextView title; TextView title;
@BindView(R.id.text) @BindView(R.id.text)
TextView text; TextView text;
@BindView(R.id.song_title) @BindView(R.id.song_title)
AppCompatTextView songTitle; AppCompatTextView songTitle;
@BindView(R.id.action_shuffle_all) @BindView(R.id.action_shuffle_all)
FloatingActionButton shuffleButton; FloatingActionButton shuffleButton;
@BindView(R.id.collapsing_toolbar) @BindView(R.id.collapsing_toolbar)
@Nullable @Nullable
CollapsingToolbarLayout collapsingToolbarLayout; CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.app_bar) @BindView(R.id.app_bar)
@Nullable @Nullable
AppBarLayout appBarLayout; AppBarLayout appBarLayout;
@BindView(R.id.image_container) @BindView(R.id.image_container)
@Nullable @Nullable
View imageContainer; View imageContainer;
@BindView(R.id.content) @BindView(R.id.content)
View contentContainer; View contentContainer;
@BindView(R.id.toolbar) @BindView(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;
@BindView(R.id.more_recycler_view) @BindView(R.id.more_recycler_view)
RecyclerView moreRecyclerView; RecyclerView moreRecyclerView;
@BindView(R.id.more_title) @BindView(R.id.more_title)
TextView moreTitle; TextView moreTitle;
@BindView(R.id.artist_image) @BindView(R.id.artist_image)
ImageView artistImage; ImageView artistImage;
private AlbumDetailsPresenter albumDetailsPresenter; private AlbumDetailsPresenter albumDetailsPresenter;
private Album album; private Album album;
private SimpleSongAdapter adapter; private SimpleSongAdapter adapter;
@Override @Override
protected View createContentView() { protected View createContentView() {
return wrapSlidingMusicPanel(R.layout.activity_album); return wrapSlidingMusicPanel(R.layout.activity_album);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setDrawUnderStatusbar(true);
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
supportPostponeEnterTransition();
setupToolbarMarginHeight();
setBottomBarVisibility(View.GONE);
setLightNavigationBar(true);
setNavigationbarColorAuto();
int albumId = getIntent().getIntExtra(EXTRA_ALBUM_ID, -1);
albumDetailsPresenter = new AlbumDetailsPresenter(this, albumId);
}
private void setupToolbarMarginHeight() {
int primaryColor = ThemeStore.primaryColor(this);
TintHelper.setTintAuto(contentContainer, primaryColor, true);
if (collapsingToolbarLayout != null) {
collapsingToolbarLayout.setContentScrimColor(primaryColor);
collapsingToolbarLayout.setStatusBarScrimColor(ColorUtil.darkenColor(primaryColor));
} }
@Override toolbar.setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp);
protected void onCreate(Bundle savedInstanceState) { setSupportActionBar(toolbar);
setDrawUnderStatusbar(true); //noinspection ConstantConditions
super.onCreate(savedInstanceState); getSupportActionBar().setTitle(null);
ButterKnife.bind(this);
supportPostponeEnterTransition();
setupToolbarMarginHeight();
setBottomBarVisibility(View.GONE);
setLightNavigationBar(true);
setNavigationbarColorAuto();
int albumId = getIntent().getIntExtra(EXTRA_ALBUM_ID, -1);
albumDetailsPresenter = new AlbumDetailsPresenter(this, albumId);
if (toolbar != null && !PreferenceUtil.getInstance(this).getFullScreenMode()) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar
.getLayoutParams();
params.topMargin = RetroUtil.getStatusBarHeight(this);
toolbar.setLayoutParams(params);
} }
private void setupToolbarMarginHeight() { if (appBarLayout != null) {
int primaryColor = ThemeStore.primaryColor(this); appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
TintHelper.setTintAuto(contentContainer, primaryColor, true); @Override
if (collapsingToolbarLayout != null) { public void onStateChanged(AppBarLayout appBarLayout, State state) {
collapsingToolbarLayout.setContentScrimColor(primaryColor); int color;
collapsingToolbarLayout.setStatusBarScrimColor(ColorUtil.darkenColor(primaryColor)); switch (state) {
case COLLAPSED:
setLightStatusbar(!ATHUtil.isWindowBackgroundDark(AlbumDetailsActivity.this));
color = ATHUtil.resolveColor(AlbumDetailsActivity.this, R.attr.iconColor);
break;
default:
case EXPANDED:
case IDLE:
setLightStatusbar(false);
color = ContextCompat.getColor(AlbumDetailsActivity.this, R.color.md_white_1000);
break;
}
ToolbarContentTintHelper.colorizeToolbar(toolbar, color, AlbumDetailsActivity.this);
} }
});
toolbar.setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp);
setSupportActionBar(toolbar);
//noinspection ConstantConditions
getSupportActionBar().setTitle(null);
if (toolbar != null && !PreferenceUtil.getInstance(this).getFullScreenMode()) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
params.topMargin = RetroUtil.getStatusBarHeight(this);
toolbar.setLayoutParams(params);
}
if (appBarLayout != null) {
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
int color;
switch (state) {
case COLLAPSED:
setLightStatusbar(!ATHUtil.isWindowBackgroundDark(AlbumDetailsActivity.this));
color = ATHUtil.resolveColor(AlbumDetailsActivity.this, R.attr.iconColor);
break;
default:
case EXPANDED:
case IDLE:
setLightStatusbar(false);
color = ContextCompat.getColor(AlbumDetailsActivity.this, R.color.md_white_1000);
break;
}
ToolbarContentTintHelper.colorizeToolbar(toolbar, color, AlbumDetailsActivity.this);
}
});
}
} }
@OnClick({R.id.action_shuffle_all}) }
public void onViewClicked(View view) {
switch (view.getId()) { @OnClick({R.id.action_shuffle_all, R.id.artist_image})
case R.id.menu_close: public void onViewClicked(View view) {
onBackPressed(); switch (view.getId()) {
break; case R.id.artist_image:
case R.id.menu: Pair<View, String> pair = new Pair<>(artistImage,
PopupMenu popupMenu = new PopupMenu(this, view); getString(R.string.transition_artist_image));
popupMenu.inflate(R.menu.menu_album_detail); NavigationUtil.goToArtist(this, getAlbum().getArtistId(), pair);
MenuItem sortOrder = popupMenu.getMenu().findItem(R.id.action_sort_order); break;
setUpSortOrderMenu(sortOrder.getSubMenu()); case R.id.action_shuffle_all:
popupMenu.setOnMenuItemClickListener(this::onOptionsItemSelected); MusicPlayerRemote.openAndShuffleQueue(album.songs, true);
popupMenu.show(); break;
break;
case R.id.action_shuffle_all:
MusicPlayerRemote.openAndShuffleQueue(album.songs, true);
break;
}
} }
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
albumDetailsPresenter.subscribe(); albumDetailsPresenter.subscribe();
}
@Override
protected void onPause() {
super.onPause();
albumDetailsPresenter.unsubscribe();
}
@Override
public void loading() {
}
@Override
public void showEmptyView() {
}
@Override
public void completed() {
supportStartPostponedEnterTransition();
}
@Override
public void showData(Album album) {
if (album.songs.isEmpty()) {
finish();
return;
} }
this.album = album;
@Override title.setText(album.getTitle());
protected void onPause() { text.setText(String.format("%s%s • %s", album.getArtistName(),
super.onPause(); "" + MusicUtil.getYearString(album.getYear()),
albumDetailsPresenter.unsubscribe(); MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, album.songs))));
loadAlbumCover();
adapter = new SimpleSongAdapter(this, this.album.songs, R.layout.item_song);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
recyclerView.setNestedScrollingEnabled(false);
loadMoreFrom(album);
}
private void loadMoreFrom(Album album) {
ArtistGlideRequest.Builder.from(Glide.with(this),
ArtistLoader.getArtist(this, album.getArtistId()).blockingFirst())
.forceDownload(false)
.generatePalette(this).build()
.dontAnimate()
.into(new RetroMusicColoredTarget(artistImage) {
@Override
public void onColorReady(int color) {
setColors(color);
}
});
ArrayList<Album> albums = ArtistLoader.getArtist(this, album.getArtistId())
.blockingFirst().albums;
albums.remove(album);
if (!albums.isEmpty()) {
moreTitle.setVisibility(View.VISIBLE);
moreRecyclerView.setVisibility(View.VISIBLE);
} else {
return;
} }
moreTitle.setText(String.format("More from %s", album.getArtistName()));
@Override AlbumAdapter albumAdapter = new HorizontalAlbumAdapter(this, albums,
public void loading() { false, null);
moreRecyclerView
.setLayoutManager(new GridLayoutManager(this, 1, GridLayoutManager.HORIZONTAL, false));
moreRecyclerView.setAdapter(albumAdapter);
}
} public Album getAlbum() {
return album;
}
@Override private void loadAlbumCover() {
public void showEmptyView() { SongGlideRequest.Builder.from(Glide.with(this), getAlbum().safeGetFirstSong())
.checkIgnoreMediaStore(this)
.generatePalette(this).build()
.dontAnimate()
.listener(new RequestListener<Object, BitmapPaletteWrapper>() {
@Override
public boolean onException(Exception e, Object model, Target<BitmapPaletteWrapper> target,
boolean isFirstResource) {
supportStartPostponedEnterTransition();
return false;
}
} @Override
public boolean onResourceReady(BitmapPaletteWrapper resource, Object model,
Target<BitmapPaletteWrapper> target, boolean isFromMemoryCache,
boolean isFirstResource) {
supportStartPostponedEnterTransition();
return false;
}
})
.into(new RetroMusicColoredTarget(image) {
@Override
public void onColorReady(int color) {
setColors(color);
}
});
}
@Override private void setColors(int color) {
public void completed() { int themeColor =
supportStartPostponedEnterTransition(); PreferenceUtil.getInstance(this).getAdaptiveColor() ? color : ThemeStore.accentColor(this);
} songTitle.setTextColor(themeColor);
moreTitle.setTextColor(themeColor);
@Override TintHelper.setTintAuto(shuffleButton, themeColor, true);
public void showData(Album album) { findViewById(R.id.root).setBackgroundColor(ThemeStore.primaryColor(this));
if (album.songs.isEmpty()) { }
finish();
return;
}
this.album = album;
title.setText(album.getTitle()); @Override
text.setText(String.format("%s%s • %s", album.getArtistName(), "" + MusicUtil.getYearString(album.getYear()), public boolean onCreateOptionsMenu(Menu menu) {
MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, album.songs)))); getMenuInflater().inflate(R.menu.menu_album_detail, menu);
MenuItem sortOrder = menu.findItem(R.id.action_sort_order);
setUpSortOrderMenu(sortOrder.getSubMenu());
return true;
}
loadAlbumCover(); @Override
public boolean onOptionsItemSelected(MenuItem item) {
return handleSortOrderMenuItem(item);
}
adapter = new SimpleSongAdapter(this, this.album.songs, R.layout.item_song); private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
String sortOrder = null;
recyclerView.setLayoutManager(new LinearLayoutManager(this)); final ArrayList<Song> songs = adapter.getDataSet();
recyclerView.setItemAnimator(new DefaultItemAnimator()); switch (item.getItemId()) {
recyclerView.setAdapter(adapter); case R.id.action_play_next:
recyclerView.setNestedScrollingEnabled(false); MusicPlayerRemote.playNext(songs);
loadMoreFrom(album);
}
private void loadMoreFrom(Album album) {
ArtistGlideRequest.Builder.from(Glide.with(this),
ArtistLoader.getArtist(this, album.getArtistId()).blockingFirst())
.forceDownload(true)
.generatePalette(this).build()
.dontAnimate()
.into(new RetroMusicColoredTarget(artistImage) {
@Override
public void onColorReady(int color) {
setColors(color);
}
});
ArrayList<Album> albums = ArtistLoader.getArtist(this, album.getArtistId()).blockingFirst().albums;
albums.remove(album);
if (!albums.isEmpty()) {
moreTitle.setVisibility(View.VISIBLE);
moreRecyclerView.setVisibility(View.VISIBLE);
} else {
return;
}
moreTitle.setText(String.format("More from %s", album.getArtistName()));
AlbumAdapter albumAdapter = new HorizontalAlbumAdapter(this, albums,
false, null);
moreRecyclerView.setLayoutManager(new GridLayoutManager(this, 1, GridLayoutManager.HORIZONTAL, false));
moreRecyclerView.setAdapter(albumAdapter);
}
public Album getAlbum() {
return album;
}
private void loadAlbumCover() {
SongGlideRequest.Builder.from(Glide.with(this), getAlbum().safeGetFirstSong())
.checkIgnoreMediaStore(this)
.generatePalette(this).build()
.dontAnimate()
.listener(new RequestListener<Object, BitmapPaletteWrapper>() {
@Override
public boolean onException(Exception e, Object model, Target<BitmapPaletteWrapper> target,
boolean isFirstResource) {
supportStartPostponedEnterTransition();
return false;
}
@Override
public boolean onResourceReady(BitmapPaletteWrapper resource, Object model,
Target<BitmapPaletteWrapper> target, boolean isFromMemoryCache,
boolean isFirstResource) {
supportStartPostponedEnterTransition();
return false;
}
})
.into(new RetroMusicColoredTarget(image) {
@Override
public void onColorReady(int color) {
setColors(color);
}
});
}
private void setColors(int color) {
int themeColor = PreferenceUtil.getInstance(this).getAdaptiveColor() ? color : ThemeStore.accentColor(this);
songTitle.setTextColor(themeColor);
moreTitle.setTextColor(themeColor);
TintHelper.setTintAuto(shuffleButton, themeColor, true);
findViewById(R.id.root).setBackgroundColor(ThemeStore.primaryColor(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_album_detail, menu);
MenuItem sortOrder = menu.findItem(R.id.action_sort_order);
setUpSortOrderMenu(sortOrder.getSubMenu());
return true; return true;
} case R.id.action_add_to_current_playing:
MusicPlayerRemote.enqueue(songs);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return handleSortOrderMenuItem(item);
}
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
String sortOrder = null;
final ArrayList<Song> songs = adapter.getDataSet();
switch (item.getItemId()) {
case R.id.action_play_next:
MusicPlayerRemote.playNext(songs);
return true;
case R.id.action_add_to_current_playing:
MusicPlayerRemote.enqueue(songs);
return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(songs).show(getSupportFragmentManager(), "ADD_PLAYLIST");
return true;
case R.id.action_delete_from_device:
DeleteSongsDialog.create(songs).show(getSupportFragmentManager(), "DELETE_SONGS");
return true;
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.action_tag_editor:
Intent intent = new Intent(this, AlbumTagEditorActivity.class);
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, getAlbum().getId());
startActivityForResult(intent, TAG_EDITOR_REQUEST);
return true;
case R.id.action_go_to_artist:
NavigationUtil.goToArtist(this, getAlbum().getArtistId());
return true;
/*Sort*/
case R.id.action_sort_order_title:
sortOrder = AlbumSongSortOrder.SONG_A_Z;
break;
case R.id.action_sort_order_title_desc:
sortOrder = AlbumSongSortOrder.SONG_Z_A;
break;
case R.id.action_sort_order_track_list:
sortOrder = AlbumSongSortOrder.SONG_TRACK_LIST;
break;
case R.id.action_sort_order_artist_song_duration:
sortOrder = AlbumSongSortOrder.SONG_DURATION;
break;
}
if (sortOrder != null) {
item.setChecked(true);
setSaveSortOrder(sortOrder);
}
return true; return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(songs).show(getSupportFragmentManager(), "ADD_PLAYLIST");
return true;
case R.id.action_delete_from_device:
DeleteSongsDialog.create(songs).show(getSupportFragmentManager(), "DELETE_SONGS");
return true;
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.action_tag_editor:
Intent intent = new Intent(this, AlbumTagEditorActivity.class);
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, getAlbum().getId());
startActivityForResult(intent, TAG_EDITOR_REQUEST);
return true;
case R.id.action_go_to_artist:
NavigationUtil.goToArtist(this, getAlbum().getArtistId());
return true;
/*Sort*/
case R.id.action_sort_order_title:
sortOrder = AlbumSongSortOrder.SONG_A_Z;
break;
case R.id.action_sort_order_title_desc:
sortOrder = AlbumSongSortOrder.SONG_Z_A;
break;
case R.id.action_sort_order_track_list:
sortOrder = AlbumSongSortOrder.SONG_TRACK_LIST;
break;
case R.id.action_sort_order_artist_song_duration:
sortOrder = AlbumSongSortOrder.SONG_DURATION;
break;
} }
if (sortOrder != null) {
item.setChecked(true);
setSaveSortOrder(sortOrder);
}
return true;
}
private String getSavedSortOrder() { private String getSavedSortOrder() {
return PreferenceUtil.getInstance(this).getAlbumDetailSongSortOrder(); return PreferenceUtil.getInstance(this).getAlbumDetailSongSortOrder();
} }
private void setUpSortOrderMenu(@NonNull SubMenu sortOrder) { private void setUpSortOrderMenu(@NonNull SubMenu sortOrder) {
switch (getSavedSortOrder()) { switch (getSavedSortOrder()) {
case AlbumSongSortOrder.SONG_A_Z: case AlbumSongSortOrder.SONG_A_Z:
sortOrder.findItem(R.id.action_sort_order_title).setChecked(true); sortOrder.findItem(R.id.action_sort_order_title).setChecked(true);
break; break;
case AlbumSongSortOrder.SONG_Z_A: case AlbumSongSortOrder.SONG_Z_A:
sortOrder.findItem(R.id.action_sort_order_title_desc).setChecked(true); sortOrder.findItem(R.id.action_sort_order_title_desc).setChecked(true);
break; break;
case AlbumSongSortOrder.SONG_TRACK_LIST: case AlbumSongSortOrder.SONG_TRACK_LIST:
sortOrder.findItem(R.id.action_sort_order_track_list).setChecked(true); sortOrder.findItem(R.id.action_sort_order_track_list).setChecked(true);
break; break;
case AlbumSongSortOrder.SONG_DURATION: case AlbumSongSortOrder.SONG_DURATION:
sortOrder.findItem(R.id.action_sort_order_artist_song_duration).setChecked(true); sortOrder.findItem(R.id.action_sort_order_artist_song_duration).setChecked(true);
break; break;
}
} }
}
private void setSaveSortOrder(String sortOrder) { private void setSaveSortOrder(String sortOrder) {
PreferenceUtil.getInstance(this).setAlbumDetailSongSortOrder(sortOrder); PreferenceUtil.getInstance(this).setAlbumDetailSongSortOrder(sortOrder);
reload(); reload();
} }
@Override @Override
public void onMediaStoreChanged() { public void onMediaStoreChanged() {
super.onMediaStoreChanged(); super.onMediaStoreChanged();
reload(); reload();
} }
private void reload() { private void reload() {
albumDetailsPresenter.subscribe(); albumDetailsPresenter.subscribe();
} }
} }