mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Merge pull request #40 from eddyizm/18-show-rating-on-song-view
feat: show rating on song view
This commit is contained in:
commit
06a52afa18
4 changed files with 63 additions and 5 deletions
|
|
@ -11,7 +11,7 @@ android {
|
|||
targetSdk 35
|
||||
|
||||
versionCode 27
|
||||
versionName '3.11.2'
|
||||
versionName '3.11.3'
|
||||
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.widget.Button;
|
|||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
import android.widget.RatingBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
|
@ -36,6 +37,7 @@ import com.cappielloantonio.tempo.util.Constants;
|
|||
import com.cappielloantonio.tempo.util.MusicUtil;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel;
|
||||
import com.cappielloantonio.tempo.viewmodel.RatingViewModel;
|
||||
import com.google.android.material.chip.Chip;
|
||||
import com.google.android.material.elevation.SurfaceColors;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
|
@ -53,6 +55,8 @@ public class PlayerControllerFragment extends Fragment {
|
|||
private InnerFragmentPlayerControllerBinding bind;
|
||||
private ViewPager2 playerMediaCoverViewPager;
|
||||
private ToggleButton buttonFavorite;
|
||||
private RatingViewModel ratingViewModel;
|
||||
private RatingBar songRatingBar;
|
||||
private TextView playerMediaTitleLabel;
|
||||
private TextView playerArtistNameLabel;
|
||||
private Button playbackSpeedButton;
|
||||
|
|
@ -75,6 +79,7 @@ public class PlayerControllerFragment extends Fragment {
|
|||
View view = bind.getRoot();
|
||||
|
||||
playerBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(PlayerBottomSheetViewModel.class);
|
||||
ratingViewModel = new ViewModelProvider(requireActivity()).get(RatingViewModel.class);
|
||||
|
||||
init();
|
||||
initQuickActionView();
|
||||
|
|
@ -117,6 +122,7 @@ public class PlayerControllerFragment extends Fragment {
|
|||
playerQuickActionView = bind.getRoot().findViewById(R.id.player_quick_action_view);
|
||||
playerOpenQueueButton = bind.getRoot().findViewById(R.id.player_open_queue_button);
|
||||
playerTrackInfo = bind.getRoot().findViewById(R.id.player_info_track);
|
||||
songRatingBar = bind.getRoot().findViewById(R.id.song_rating_bar);
|
||||
}
|
||||
|
||||
private void initQuickActionView() {
|
||||
|
|
@ -313,6 +319,7 @@ public class PlayerControllerFragment extends Fragment {
|
|||
private void initMediaListenable() {
|
||||
playerBottomSheetViewModel.getLiveMedia().observe(getViewLifecycleOwner(), media -> {
|
||||
if (media != null) {
|
||||
ratingViewModel.setSong(media);
|
||||
buttonFavorite.setChecked(media.getStarred() != null);
|
||||
buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), media));
|
||||
buttonFavorite.setOnLongClickListener(v -> {
|
||||
|
|
@ -323,9 +330,29 @@ public class PlayerControllerFragment extends Fragment {
|
|||
dialog.setArguments(bundle);
|
||||
dialog.show(requireActivity().getSupportFragmentManager(), null);
|
||||
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Integer currentRating = media.getUserRating();
|
||||
|
||||
if (currentRating != null) {
|
||||
songRatingBar.setRating(currentRating);
|
||||
} else {
|
||||
songRatingBar.setRating(0);
|
||||
}
|
||||
|
||||
songRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
|
||||
@Override
|
||||
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
|
||||
if (fromUser) {
|
||||
ratingViewModel.rate((int) rating);
|
||||
media.setUserRating((int) rating);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (getActivity() != null) {
|
||||
playerBottomSheetViewModel.refreshMediaInfo(requireActivity(), media);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
favoriteRepository.starLater(media.getId(), null, null, false);
|
||||
}
|
||||
});
|
||||
|
||||
media.setStarred(null);
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
public LiveData<String> getLiveLyrics() {
|
||||
public LiveData<String> getLiveLyrics() {
|
||||
return lyricsLiveData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,37 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_media_title_label" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rating_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_artist_name_label">
|
||||
|
||||
<RatingBar
|
||||
android:id="@+id/song_rating_bar"
|
||||
style="?android:attr/ratingBarStyleIndicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:numStars="5"
|
||||
android:stepSize="1"
|
||||
android:rating="0"
|
||||
android:isIndicator="false" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rating_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:text=""/>
|
||||
</LinearLayout>
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/button_favorite"
|
||||
android:layout_width="26dp"
|
||||
|
|
@ -136,13 +167,14 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:bar_height="2dp"
|
||||
app:buffered_color="?attr/colorOnSecondaryContainer"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_artist_name_label"
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@+id/rating_container"
|
||||
app:played_color="?attr/colorOnPrimaryContainer"
|
||||
app:scrubber_color="?attr/colorOnPrimaryContainer"
|
||||
app:unplayed_color="?attr/colorPrimaryContainer" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue