Removed bottom buttons from PlayerControllerFragment

This commit is contained in:
CappielloAntonio 2022-01-10 12:41:41 +01:00
parent bc4d7251b0
commit 856cc04d4d
2 changed files with 51 additions and 174 deletions

View file

@ -22,41 +22,26 @@ import androidx.media3.session.SessionToken;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R; import com.cappielloantonio.play.R;
import com.cappielloantonio.play.databinding.InnerFragmentPlayerControllerBinding; 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.service.MediaService;
import com.cappielloantonio.play.ui.activity.MainActivity; 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.dialog.RatingDialog;
import com.cappielloantonio.play.ui.fragment.pager.PlayerControllerHorizontalPager; 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.util.MusicUtil;
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel; import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
public class PlayerControllerFragment extends Fragment { public class PlayerControllerFragment extends Fragment {
private static final String TAG = "PlayerCoverFragment"; private static final String TAG = "PlayerCoverFragment";
private InnerFragmentPlayerControllerBinding bind; private InnerFragmentPlayerControllerBinding bind;
private ImageView playerMoveDownBottomSheet; private ImageView playerMoveDownBottomSheet;
private ViewPager2 playerSongCoverViewPager; private ViewPager2 playerSongCoverViewPager;
private ImageButton buttonRating;
private ToggleButton buttonFavorite; private ToggleButton buttonFavorite;
private TextView playerSongTitleLabel; private TextView playerSongTitleLabel;
private TextView playerArtistNameLabel; private TextView playerArtistNameLabel;
private ImageButton buttonDownload;
private ImageButton buttonAddToPlaylist;
private ImageButton buttonStartMix;
private ImageButton buttonLyrics;
private MainActivity activity; private MainActivity activity;
private PlayerBottomSheetViewModel playerBottomSheetViewModel; private PlayerBottomSheetViewModel playerBottomSheetViewModel;
@ -75,7 +60,6 @@ public class PlayerControllerFragment extends Fragment {
initCoverLyricsSlideView(); initCoverLyricsSlideView();
initMediaListenable(); initMediaListenable();
initArtistLabelButton(); initArtistLabelButton();
initButtonRow();
return view; return view;
} }
@ -105,15 +89,9 @@ public class PlayerControllerFragment extends Fragment {
playerMoveDownBottomSheet = bind.getRoot().findViewById(R.id.player_move_down_bottom_sheet); playerMoveDownBottomSheet = bind.getRoot().findViewById(R.id.player_move_down_bottom_sheet);
playerSongCoverViewPager = bind.getRoot().findViewById(R.id.player_song_cover_view_pager); playerSongCoverViewPager = bind.getRoot().findViewById(R.id.player_song_cover_view_pager);
buttonFavorite = bind.getRoot().findViewById(R.id.button_favorite); buttonFavorite = bind.getRoot().findViewById(R.id.button_favorite);
buttonRating = bind.getRoot().findViewById(R.id.button_rating);
playerSongTitleLabel = bind.getRoot().findViewById(R.id.player_song_title_label); playerSongTitleLabel = bind.getRoot().findViewById(R.id.player_song_title_label);
playerArtistNameLabel = bind.getRoot().findViewById(R.id.player_artist_name_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()); playerMoveDownBottomSheet.setOnClickListener(view -> activity.collapseBottomSheet());
} }
@ -186,13 +164,15 @@ public class PlayerControllerFragment extends Fragment {
buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), song)); buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), song));
buttonRating.setOnClickListener(v -> { buttonFavorite.setOnLongClickListener(v -> {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable("song_object", song); bundle.putParcelable("song_object", song);
RatingDialog dialog = new RatingDialog(); RatingDialog dialog = new RatingDialog();
dialog.setArguments(bundle); dialog.setArguments(bundle);
dialog.show(requireActivity().getSupportFragmentManager(), null); dialog.show(requireActivity().getSupportFragmentManager(), null);
return false;
}); });
if (getActivity() != null) { if (getActivity() != null) {
@ -215,48 +195,11 @@ public class PlayerControllerFragment extends Fragment {
}); });
} }
private void initButtonRow() { public void goToControllerPage() {
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); playerSongCoverViewPager.setCurrentItem(0, false);
} }
public void goToLyricsPage() {
playerSongCoverViewPager.setCurrentItem(1, true);
}
} }

View file

@ -9,18 +9,14 @@
android:id="@+id/appbar" android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.Material3.Dark.ActionBar"
app:elevation="0dp"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:background="@color/colorPrimary"
app:popupTheme="@style/ThemeOverlay.Material3.Light">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -44,7 +40,7 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:text="@string/player_bottom_sheet_title" /> android:text="@string/player_bottom_sheet_title" />
</LinearLayout> </LinearLayout>
</androidx.appcompat.widget.Toolbar> </com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2 <androidx.viewpager2.widget.ViewPager2
@ -63,34 +59,19 @@
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintGuide_percent="0.60" /> app:layout_constraintGuide_percent="0.60" />
<ImageButton
android:id="@+id/button_rating"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_marginStart="24dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/player_song_title_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/player_song_title_label"
app:srcCompat="@drawable/ic_rating" />
<TextView <TextView
android:id="@+id/player_song_title_label" android:id="@+id/player_song_title_label"
style="@style/TitleTextView" style="@style/TitleTextView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginStart="24dp"
android:layout_weight="1" android:layout_marginTop="24dp"
android:ellipsize="marquee" android:layout_marginEnd="24dp"
android:marqueeRepeatLimit="marquee_forever" android:ellipsize="end"
android:paddingStart="8dp" android:maxLines="2"
android:paddingEnd="8dp"
android:singleLine="true"
android:text="@string/label_placeholder" android:text="@string/label_placeholder"
android:textAlignment="center"
app:layout_constraintEnd_toStartOf="@+id/button_favorite" app:layout_constraintEnd_toStartOf="@+id/button_favorite"
app:layout_constraintStart_toEndOf="@+id/button_rating" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" /> app:layout_constraintTop_toBottomOf="@+id/guideline" />
<ToggleButton <ToggleButton
@ -100,7 +81,6 @@
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:background="@drawable/button_favorite_selector" android:background="@drawable/button_favorite_selector"
android:checked="false" android:checked="false"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:text="" android:text=""
android:textOff="" android:textOff=""
android:textOn="" android:textOn=""
@ -113,14 +93,11 @@
style="@style/SubheadTextView" style="@style/SubheadTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginStart="24dp"
android:ellipsize="marquee" android:layout_marginEnd="24dp"
android:marqueeRepeatLimit="marquee_forever" android:ellipsize="end"
android:paddingStart="24dp" android:maxLines="2"
android:paddingEnd="24dp"
android:singleLine="true"
android:text="@string/label_placeholder" android:text="@string/label_placeholder"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/player_song_title_label" /> app:layout_constraintTop_toBottomOf="@+id/player_song_title_label" />
@ -136,25 +113,23 @@
android:textColor="@color/titleTextColor" android:textColor="@color/titleTextColor"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/exo_progress" app:layout_constraintTop_toBottomOf="@+id/exo_progress" />
app:layout_constraintBottom_toBottomOf="@+id/exo_progress"/>
<androidx.media3.ui.DefaultTimeBar <androidx.media3.ui.DefaultTimeBar
android:id="@id/exo_progress" android:id="@id/exo_progress"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="16dp"
android:layout_marginTop="12dp" android:layout_marginTop="18dp"
android:layout_marginEnd="4dp" android:layout_marginEnd="16dp"
app:bar_height="2dp" app:bar_height="2dp"
app:buffered_color="@color/seekBarBufferedColor" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/exo_duration" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/exo_position"
app:layout_constraintTop_toBottomOf="@+id/player_artist_name_label" app:layout_constraintTop_toBottomOf="@+id/player_artist_name_label"
app:played_color="@color/seekBarPlayedColor" app:buffered_color="?attr/colorOnSecondaryContainer"
app:scrubber_color="@color/seekBarPlayedColor" app:played_color="?attr/colorOnPrimaryContainer"
app:scrubber_dragged_size="8dp" app:scrubber_color="?attr/colorOnPrimaryContainer"
app:unplayed_color="@color/seekBarUnPlayedColor" /> app:unplayed_color="?attr/colorPrimaryContainer"/>
<TextView <TextView
android:id="@+id/exo_duration" android:id="@+id/exo_duration"
@ -168,17 +143,18 @@
android:textColor="@color/titleTextColor" android:textColor="@color/titleTextColor"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/exo_progress" app:layout_constraintTop_toBottomOf="@+id/exo_progress" />
app:layout_constraintBottom_toBottomOf="@+id/exo_progress" />
<View <View
android:id="@+id/player_play_pause_placeholder_view" android:id="@+id/player_play_pause_placeholder_view"
android:layout_width="70dp" android:layout_width="70dp"
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_progress" /> app:layout_constraintTop_toBottomOf="@+id/exo_progress"
app:layout_constraintVertical_bias=".60" />
<ImageButton <ImageButton
android:id="@+id/exo_shuffle" android:id="@+id/exo_shuffle"
@ -191,7 +167,8 @@
app:layout_constraintEnd_toStartOf="@+id/exo_prev" app:layout_constraintEnd_toStartOf="@+id/exo_prev"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/exo_prev" app:layout_constraintTop_toTopOf="@+id/exo_prev"
app:srcCompat="@drawable/ic_shuffle" /> app:srcCompat="@drawable/ic_shuffle"
app:tint="?attr/colorOnPrimaryContainer" />
<ImageButton <ImageButton
android:id="@+id/exo_prev" android:id="@+id/exo_prev"
@ -203,7 +180,8 @@
app:layout_constraintEnd_toStartOf="@+id/player_play_pause_placeholder_view" app:layout_constraintEnd_toStartOf="@+id/player_play_pause_placeholder_view"
app:layout_constraintStart_toEndOf="@id/exo_shuffle" app:layout_constraintStart_toEndOf="@id/exo_shuffle"
app:layout_constraintTop_toTopOf="@+id/player_play_pause_placeholder_view" app:layout_constraintTop_toTopOf="@+id/player_play_pause_placeholder_view"
app:srcCompat="@drawable/ic_skip_previous" /> app:srcCompat="@drawable/ic_skip_previous"
app:tint="?attr/colorOnPrimaryContainer" />
<ImageButton <ImageButton
android:id="@id/exo_play" android:id="@id/exo_play"
@ -214,9 +192,12 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/ic_play_circle" android:src="@drawable/ic_play_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_progress" /> app:layout_constraintTop_toBottomOf="@+id/exo_progress"
app:layout_constraintVertical_bias=".60"
app:tint="?attr/colorOnPrimaryContainer" />
<ImageButton <ImageButton
android:id="@id/exo_pause" android:id="@id/exo_pause"
@ -227,9 +208,12 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/ic_pause_circle" android:src="@drawable/ic_pause_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exo_progress" /> app:layout_constraintTop_toBottomOf="@+id/exo_progress"
app:layout_constraintVertical_bias=".60"
app:tint="?attr/colorOnPrimaryContainer" />
<ImageButton <ImageButton
android:id="@+id/exo_next" android:id="@+id/exo_next"
@ -241,7 +225,8 @@
app:layout_constraintEnd_toStartOf="@id/exo_repeat_toggle" app:layout_constraintEnd_toStartOf="@id/exo_repeat_toggle"
app:layout_constraintStart_toEndOf="@+id/player_play_pause_placeholder_view" app:layout_constraintStart_toEndOf="@+id/player_play_pause_placeholder_view"
app:layout_constraintTop_toTopOf="@+id/player_play_pause_placeholder_view" app:layout_constraintTop_toTopOf="@+id/player_play_pause_placeholder_view"
app:srcCompat="@drawable/ic_skip_next" /> app:srcCompat="@drawable/ic_skip_next"
app:tint="?attr/colorOnPrimaryContainer" />
<ImageButton <ImageButton
android:id="@+id/exo_repeat_toggle" android:id="@+id/exo_repeat_toggle"
@ -254,58 +239,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/exo_next" app:layout_constraintStart_toEndOf="@+id/exo_next"
app:layout_constraintTop_toTopOf="@+id/exo_next" app:layout_constraintTop_toTopOf="@+id/exo_next"
app:srcCompat="@drawable/ic_repeat" /> app:srcCompat="@drawable/ic_repeat"
app:tint="?attr/colorOnPrimaryContainer" />
<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> </androidx.constraintlayout.widget.ConstraintLayout>