mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Add "Go to artist" button in playerBottomSheetFragment
This commit is contained in:
parent
1089512983
commit
b2b081947f
3 changed files with 26 additions and 3 deletions
|
|
@ -230,10 +230,14 @@ public class MainActivity extends BaseActivity {
|
|||
goToLogin();
|
||||
}
|
||||
|
||||
public void collapseBottomSheet() {
|
||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
|
||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
collapseBottomSheet();
|
||||
else
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
|
@ -77,6 +78,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
initQueueRecyclerView();
|
||||
initFavoriteButtonClick();
|
||||
initMusicCommandButton();
|
||||
initArtistLabelButton();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
@ -249,6 +251,15 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
headerBind.playerHeaderNextSongButton.setOnClickListener(v -> MusicPlayerRemote.playNextSong());
|
||||
}
|
||||
|
||||
private void initArtistLabelButton() {
|
||||
bodyBind.playerArtistNameLabel.setOnClickListener(view -> playerBottomSheetViewModel.getArtist().observe(requireActivity(), artist -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artist);
|
||||
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
|
||||
activity.collapseBottomSheet();
|
||||
}));
|
||||
}
|
||||
|
||||
private void initSeekBar() {
|
||||
bodyBind.playerBigSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||
|
|
@ -22,6 +24,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
private static final String TAG = "PlayerBottomSheetViewModel";
|
||||
|
||||
private final SongRepository songRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
private final QueueRepository queueRepository;
|
||||
|
||||
private final LiveData<List<Queue>> queueSong;
|
||||
|
|
@ -30,6 +33,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
super(application);
|
||||
|
||||
songRepository = new SongRepository(application);
|
||||
artistRepository = new ArtistRepository(application);
|
||||
queueRepository = new QueueRepository(application);
|
||||
|
||||
queueSong = queueRepository.getLiveQueue();
|
||||
|
|
@ -43,9 +47,8 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
return MusicPlayerRemote.getCurrentSong();
|
||||
}
|
||||
|
||||
|
||||
public void setFavorite(Context context) {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
Song song = getCurrentSong();
|
||||
|
||||
if (song != null) {
|
||||
if (song.isFavorite()) {
|
||||
|
|
@ -69,4 +72,9 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
public void removeSong(int position) {
|
||||
queueRepository.deleteByPosition(position);
|
||||
}
|
||||
|
||||
public LiveData<Artist> getArtist() {
|
||||
Song song = getCurrentSong();
|
||||
return artistRepository.getArtist(song.getArtistId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue