Player graphical adjustments

This commit is contained in:
CappielloAntonio 2022-01-03 23:21:49 +01:00
parent 22d9e70595
commit c1a0601106
8 changed files with 201 additions and 37 deletions

View file

@ -22,17 +22,27 @@ import androidx.media3.session.SessionToken;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager2.widget.ViewPager2;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.databinding.InnerFragmentPlayerControllerBinding;
import com.cappielloantonio.play.interfaces.MediaCallback;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.service.MediaManager;
import com.cappielloantonio.play.service.MediaService;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.ui.dialog.PlaylistChooserDialog;
import com.cappielloantonio.play.ui.dialog.RatingDialog;
import com.cappielloantonio.play.ui.fragment.pager.PlayerControllerHorizontalPager;
import com.cappielloantonio.play.util.DownloadUtil;
import com.cappielloantonio.play.util.MappingUtil;
import com.cappielloantonio.play.util.MusicUtil;
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
public class PlayerControllerFragment extends Fragment {
private static final String TAG = "PlayerCoverFragment";
@ -43,6 +53,10 @@ public class PlayerControllerFragment extends Fragment {
private ToggleButton buttonFavorite;
private TextView playerSongTitleLabel;
private TextView playerArtistNameLabel;
private ImageButton buttonDownload;
private ImageButton buttonAddToPlaylist;
private ImageButton buttonStartMix;
private ImageButton buttonLyrics;
private MainActivity activity;
private PlayerBottomSheetViewModel playerBottomSheetViewModel;
@ -61,6 +75,7 @@ public class PlayerControllerFragment extends Fragment {
initCoverLyricsSlideView();
initMediaListenable();
initArtistLabelButton();
initButtonRow();
return view;
}
@ -94,6 +109,11 @@ public class PlayerControllerFragment extends Fragment {
playerSongTitleLabel = bind.getRoot().findViewById(R.id.player_song_title_label);
playerArtistNameLabel = bind.getRoot().findViewById(R.id.player_artist_name_label);
buttonDownload = bind.getRoot().findViewById(R.id.button_download);
buttonAddToPlaylist = bind.getRoot().findViewById(R.id.button_playlist);
buttonStartMix = bind.getRoot().findViewById(R.id.button_mix);
buttonLyrics = bind.getRoot().findViewById(R.id.button_lyrics);
playerMoveDownBottomSheet.setOnClickListener(view -> activity.collapseBottomSheet());
}
@ -190,6 +210,47 @@ public class PlayerControllerFragment extends Fragment {
});
}
private void initButtonRow() {
playerBottomSheetViewModel.getLiveSong().observe(requireActivity(), song -> {
if (song != null) {
buttonDownload.setOnClickListener(view -> DownloadUtil
.getDownloadTracker(requireContext())
.download(
MappingUtil.mapMediaItem(requireContext(), song, false),
MappingUtil.mapDownload(song, null, null)
));
buttonAddToPlaylist.setOnClickListener(view -> {
Bundle bundle = new Bundle();
bundle.putParcelable("song_object", song);
PlaylistChooserDialog dialog = new PlaylistChooserDialog();
dialog.setArguments(bundle);
dialog.show(requireActivity().getSupportFragmentManager(), null);
});
buttonStartMix.setOnClickListener(view -> {
MediaManager.startQueue(mediaBrowserListenableFuture, requireContext(), song);
SongRepository songRepository = new SongRepository(App.getInstance());
songRepository.getInstantMix(song, 20, new MediaCallback() {
@Override
public void onError(Exception exception) {
Log.e(TAG, "onError() " + exception.getMessage());
}
@Override
public void onLoadMedia(List<?> media) {
MediaManager.enqueue(mediaBrowserListenableFuture, requireContext(), (List<Song>) media, true);
}
});
});
}
});
buttonLyrics.setOnClickListener(view -> playerSongCoverViewPager.setCurrentItem(1, true));
}
public void goBackToFirstPage() {
playerSongCoverViewPager.setCurrentItem(0, false);
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true">
<path
android:fillColor="@color/titleTextColor"
android:pathData="M21,11.01L3,11v2h18zM3,16h12v2H3zM21,6H3v2.01L21,8z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true">
<path
android:fillColor="@color/titleTextColor"
android:pathData="M16,6l2.29,2.29 -4.88,4.88 -4,-4L2,16.59 3.41,18l6,-6 4,4 6.3,-6.29L22,12V6h-6z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true">
<path
android:fillColor="@color/titleTextColor"
android:pathData="M14,10H3v2h11V10zM14,6H3v2h11V6zM18,14v-4h-2v4h-4v2h4v4h2v-4h4v-2H18zM3,16h7v-2H3V16z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:autoMirrored="true">
<path
android:fillColor="@color/titleTextColor"
android:pathData="M22,6h-5v8.18C16.69,14.07 16.35,14 16,14c-1.66,0 -3,1.34 -3,3s1.34,3 3,3s3,-1.34 3,-3V8h3V6zM15,6H3v2h12V6zM15,10H3v2h12V10zM11,14H3v2h8V14z"/>
</vector>

View file

@ -52,11 +52,18 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="12dp"
app:layout_constraintBottom_toTopOf="@id/player_song_title_label"
app:layout_constraintBottom_toTopOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appbar" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.60" />
<ImageButton
android:id="@+id/button_rating"
android:layout_width="26dp"
@ -81,9 +88,9 @@
android:paddingEnd="24dp"
android:text="@string/label_placeholder"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@+id/player_artist_name_label"
app:layout_constraintEnd_toStartOf="@+id/button_favorite"
app:layout_constraintStart_toEndOf="@+id/button_rating" />
app:layout_constraintStart_toEndOf="@+id/button_rating"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
<ToggleButton
android:id="@+id/button_favorite"
@ -110,39 +117,36 @@
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:text="@string/label_placeholder"
app:layout_constraintBottom_toTopOf="@+id/exo_progress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/player_song_title_label" />
<TextView
android:id="@+id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:text="@string/label_placeholder"
android:textColor="@color/titleTextColor"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/exo_progress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/exo_progress" />
app:layout_constraintTop_toBottomOf="@+id/exo_progress" />
<androidx.media3.ui.DefaultTimeBar
android:id="@id/exo_progress"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="12dp"
android:layout_weight="1"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="20dp"
app:bar_height="2dp"
app:buffered_color="@color/seekBarBufferedColor"
app:layout_constraintBottom_toTopOf="@+id/player_play_pause_placeholder_view"
app:layout_constraintEnd_toStartOf="@+id/exo_duration"
app:layout_constraintStart_toEndOf="@+id/exo_position"
app:layout_constraintTop_toBottomOf="@+id/player_artist_name_label"
app:played_color="@color/seekBarPlayedColor"
app:scrubber_color="@color/seekBarPlayedColor"
app:scrubber_dragged_size="8dp"
@ -153,30 +157,29 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:text="@string/label_placeholder"
android:textColor="@color/titleTextColor"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/exo_progress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/exo_progress" />
app:layout_constraintTop_toBottomOf="@+id/exo_progress" />
<View
android:id="@+id/player_play_pause_placeholder_view"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="24dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_duration" />
<ImageButton
android:id="@+id/exo_shuffle"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="12dp"
android:layout_marginStart="24dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/exo_prev"
@ -200,28 +203,28 @@
<ImageButton
android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="24dp"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="4dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
android:src="@drawable/ic_play_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_duration" />
<ImageButton
android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="24dp"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="4dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
android:src="@drawable/ic_pause_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_duration" />
<ImageButton
android:id="@+id/exo_next"
@ -239,7 +242,7 @@
android:id="@+id/exo_repeat_toggle"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="12dp"
android:layout_marginEnd="24dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/exo_next"
@ -248,4 +251,56 @@
app:layout_constraintTop_toTopOf="@+id/exo_next"
app:srcCompat="@drawable/ic_repeat" />
<LinearLayout
android:id="@+id/player_button_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/player_play_pause_placeholder_view">
<ImageButton
android:id="@+id/button_download"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_file_download" />
<ImageButton
android:id="@+id/button_playlist"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_playlist_add" />
<ImageButton
android:id="@+id/button_mix"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_mix_from_here" />
<ImageButton
android:id="@+id/button_lyrics"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_lyrics" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -8,7 +8,7 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingTop="12dp"
android:paddingTop="4dp"
android:paddingBottom="@dimen/global_padding_bottom" />
</com.cappielloantonio.play.helper.recyclerview.NestedScrollableHost>