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.FloatingActionButton;
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.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
@ -21,15 +21,7 @@ import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
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.ButterKnife;
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.PreferenceUtil;
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
AlbumDetailsContract.AlbumDetailsView {
AlbumDetailsContract.AlbumDetailsView {
public static final String EXTRA_ALBUM_ID = "extra_album_id";
private static final int TAG_EDITOR_REQUEST = 2001;
@BindView(R.id.image)
ImageView image;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.title)
TextView title;
@BindView(R.id.text)
TextView text;
@BindView(R.id.song_title)
AppCompatTextView songTitle;
@BindView(R.id.action_shuffle_all)
FloatingActionButton shuffleButton;
@BindView(R.id.collapsing_toolbar)
@Nullable
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.app_bar)
@Nullable
AppBarLayout appBarLayout;
@BindView(R.id.image_container)
@Nullable
View imageContainer;
@BindView(R.id.content)
View contentContainer;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.more_recycler_view)
RecyclerView moreRecyclerView;
@BindView(R.id.more_title)
TextView moreTitle;
@BindView(R.id.artist_image)
ImageView artistImage;
public static final String EXTRA_ALBUM_ID = "extra_album_id";
private static final int TAG_EDITOR_REQUEST = 2001;
@BindView(R.id.image)
ImageView image;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.title)
TextView title;
@BindView(R.id.text)
TextView text;
@BindView(R.id.song_title)
AppCompatTextView songTitle;
@BindView(R.id.action_shuffle_all)
FloatingActionButton shuffleButton;
@BindView(R.id.collapsing_toolbar)
@Nullable
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.app_bar)
@Nullable
AppBarLayout appBarLayout;
@BindView(R.id.image_container)
@Nullable
View imageContainer;
@BindView(R.id.content)
View contentContainer;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.more_recycler_view)
RecyclerView moreRecyclerView;
@BindView(R.id.more_title)
TextView moreTitle;
@BindView(R.id.artist_image)
ImageView artistImage;
private AlbumDetailsPresenter albumDetailsPresenter;
private Album album;
private SimpleSongAdapter adapter;
private AlbumDetailsPresenter albumDetailsPresenter;
private Album album;
private SimpleSongAdapter adapter;
@Override
protected View createContentView() {
return wrapSlidingMusicPanel(R.layout.activity_album);
@Override
protected View createContentView() {
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
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);
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);
}
private void setupToolbarMarginHeight() {
int primaryColor = ThemeStore.primaryColor(this);
TintHelper.setTintAuto(contentContainer, primaryColor, true);
if (collapsingToolbarLayout != null) {
collapsingToolbarLayout.setContentScrimColor(primaryColor);
collapsingToolbarLayout.setStatusBarScrimColor(ColorUtil.darkenColor(primaryColor));
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);
}
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()) {
case R.id.menu_close:
onBackPressed();
break;
case R.id.menu:
PopupMenu popupMenu = new PopupMenu(this, view);
popupMenu.inflate(R.menu.menu_album_detail);
MenuItem sortOrder = popupMenu.getMenu().findItem(R.id.action_sort_order);
setUpSortOrderMenu(sortOrder.getSubMenu());
popupMenu.setOnMenuItemClickListener(this::onOptionsItemSelected);
popupMenu.show();
break;
case R.id.action_shuffle_all:
MusicPlayerRemote.openAndShuffleQueue(album.songs, true);
break;
}
}
@OnClick({R.id.action_shuffle_all, R.id.artist_image})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.artist_image:
Pair<View, String> pair = new Pair<>(artistImage,
getString(R.string.transition_artist_image));
NavigationUtil.goToArtist(this, getAlbum().getArtistId(), pair);
break;
case R.id.action_shuffle_all:
MusicPlayerRemote.openAndShuffleQueue(album.songs, true);
break;
}
}
@Override
protected void onResume() {
super.onResume();
albumDetailsPresenter.subscribe();
@Override
protected void onResume() {
super.onResume();
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
protected void onPause() {
super.onPause();
albumDetailsPresenter.unsubscribe();
title.setText(album.getTitle());
text.setText(String.format("%s%s • %s", album.getArtistName(),
"" + MusicUtil.getYearString(album.getYear()),
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
public void loading() {
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;
}
@Override
public void showEmptyView() {
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);
}
});
}
@Override
public void completed() {
supportStartPostponedEnterTransition();
}
private void setColors(int color) {
int themeColor =
PreferenceUtil.getInstance(this).getAdaptiveColor() ? color : ThemeStore.accentColor(this);
songTitle.setTextColor(themeColor);
moreTitle.setTextColor(themeColor);
@Override
public void showData(Album album) {
if (album.songs.isEmpty()) {
finish();
return;
}
this.album = album;
TintHelper.setTintAuto(shuffleButton, themeColor, true);
findViewById(R.id.root).setBackgroundColor(ThemeStore.primaryColor(this));
}
title.setText(album.getTitle());
text.setText(String.format("%s%s • %s", album.getArtistName(), "" + MusicUtil.getYearString(album.getYear()),
MusicUtil.getReadableDurationString(MusicUtil.getTotalDuration(this, album.songs))));
@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;
}
loadAlbumCover();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return handleSortOrderMenuItem(item);
}
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(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());
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;
}
@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);
}
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;
}
private String getSavedSortOrder() {
return PreferenceUtil.getInstance(this).getAlbumDetailSongSortOrder();
}
private String getSavedSortOrder() {
return PreferenceUtil.getInstance(this).getAlbumDetailSongSortOrder();
}
private void setUpSortOrderMenu(@NonNull SubMenu sortOrder) {
switch (getSavedSortOrder()) {
case AlbumSongSortOrder.SONG_A_Z:
sortOrder.findItem(R.id.action_sort_order_title).setChecked(true);
break;
case AlbumSongSortOrder.SONG_Z_A:
sortOrder.findItem(R.id.action_sort_order_title_desc).setChecked(true);
break;
case AlbumSongSortOrder.SONG_TRACK_LIST:
sortOrder.findItem(R.id.action_sort_order_track_list).setChecked(true);
break;
case AlbumSongSortOrder.SONG_DURATION:
sortOrder.findItem(R.id.action_sort_order_artist_song_duration).setChecked(true);
break;
}
private void setUpSortOrderMenu(@NonNull SubMenu sortOrder) {
switch (getSavedSortOrder()) {
case AlbumSongSortOrder.SONG_A_Z:
sortOrder.findItem(R.id.action_sort_order_title).setChecked(true);
break;
case AlbumSongSortOrder.SONG_Z_A:
sortOrder.findItem(R.id.action_sort_order_title_desc).setChecked(true);
break;
case AlbumSongSortOrder.SONG_TRACK_LIST:
sortOrder.findItem(R.id.action_sort_order_track_list).setChecked(true);
break;
case AlbumSongSortOrder.SONG_DURATION:
sortOrder.findItem(R.id.action_sort_order_artist_song_duration).setChecked(true);
break;
}
}
private void setSaveSortOrder(String sortOrder) {
PreferenceUtil.getInstance(this).setAlbumDetailSongSortOrder(sortOrder);
reload();
}
private void setSaveSortOrder(String sortOrder) {
PreferenceUtil.getInstance(this).setAlbumDetailSongSortOrder(sortOrder);
reload();
}
@Override
public void onMediaStoreChanged() {
super.onMediaStoreChanged();
reload();
}
@Override
public void onMediaStoreChanged() {
super.onMediaStoreChanged();
reload();
}
private void reload() {
albumDetailsPresenter.subscribe();
}
private void reload() {
albumDetailsPresenter.subscribe();
}
}