mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added shuffle and play button in song's list page
This commit is contained in:
parent
3fcc9242b3
commit
7f1b7a4ae3
2 changed files with 64 additions and 2 deletions
|
|
@ -4,18 +4,25 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentSongListPageBinding;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.SongListPageViewModel;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SongListPageFragment extends Fragment {
|
||||
|
||||
private FragmentSongListPageBinding bind;
|
||||
|
|
@ -34,6 +41,7 @@ public class SongListPageFragment extends Fragment {
|
|||
|
||||
init();
|
||||
initAppBar();
|
||||
initButtons();
|
||||
initSongListView();
|
||||
|
||||
return view;
|
||||
|
|
@ -121,6 +129,34 @@ public class SongListPageFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
songListPageViewModel.getSongList().observe(requireActivity(), songs -> {
|
||||
if(bind != null) {
|
||||
bind.songListPlayImageView.setOnClickListener(v -> {
|
||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||
queueRepository.insertAllAndStartNew(songs);
|
||||
|
||||
activity.isBottomSheetInPeek(true);
|
||||
activity.setBottomSheetMusicInfo(songs.get(0));
|
||||
|
||||
MusicPlayerRemote.openQueue(songs, 0, true);
|
||||
});
|
||||
|
||||
bind.songListShuffleImageView.setOnClickListener(v -> {
|
||||
Collections.shuffle(songs);
|
||||
|
||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||
queueRepository.insertAllAndStartNew(songs);
|
||||
|
||||
activity.isBottomSheetInPeek(true);
|
||||
activity.setBottomSheetMusicInfo(songs.get(0));
|
||||
|
||||
MusicPlayerRemote.openQueue(songs, 0, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initSongListView() {
|
||||
bind.songListRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.songListRecyclerView.setHasFixedSize(true);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<TextView
|
||||
android:id="@+id/page_title_label"
|
||||
style="@style/HeadlineTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
|
|
@ -41,8 +41,34 @@
|
|||
android:paddingBottom="24dp"
|
||||
android:text="@string/label_placeholder"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/song_list_shuffle_image_view"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/song_list_play_image_view"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:background="@drawable/ic_play"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="parent" />
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/song_list_shuffle_image_view"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:background="@drawable/ic_shuffle"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
app:layout_constraintEnd_toStartOf="@+id/song_list_play_image_view"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue