mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added play/pause toggle button and seekbar text
This commit is contained in:
parent
54bc709317
commit
898f23b9a1
4 changed files with 90 additions and 14 deletions
|
|
@ -23,6 +23,7 @@ import com.cappielloantonio.play.helper.MusicProgressViewUpdateHelper;
|
|||
import com.cappielloantonio.play.interfaces.MusicServiceEventListener;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
|
||||
|
||||
public class PlayerBottomSheetFragment extends Fragment implements MusicServiceEventListener, MusicProgressViewUpdateHelper.Callback {
|
||||
|
|
@ -56,6 +57,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
initQueueSlideView();
|
||||
initQueueRecyclerView();
|
||||
initFavoriteButtonClick();
|
||||
initToggleButtonSongState();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
@ -121,6 +123,16 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
bind.playerBodyLayout.buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite());
|
||||
}
|
||||
|
||||
private void initToggleButtonSongState() {
|
||||
bind.playerHeaderLayout.playerHeaderButton.setOnClickListener(v -> {
|
||||
if (MusicPlayerRemote.isPlaying()) {
|
||||
MusicPlayerRemote.pauseSong();
|
||||
} else {
|
||||
MusicPlayerRemote.resumePlaying();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initSeekBar() {
|
||||
bind.playerBodyLayout.playerBigSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
|
|
@ -155,6 +167,14 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
bind.playerBodyLayout.buttonFavorite.setChecked(song.isFavorite());
|
||||
}
|
||||
|
||||
protected void updatePlayPauseState() {
|
||||
if (MusicPlayerRemote.isPlaying()) {
|
||||
bind.playerHeaderLayout.playerHeaderButton.setChecked(false);
|
||||
} else {
|
||||
bind.playerHeaderLayout.playerHeaderButton.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpMusicControllers() {
|
||||
// setUpPrevNext();
|
||||
// setUpRepeatButton();
|
||||
|
|
@ -177,7 +197,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
|
||||
@Override
|
||||
public void onServiceConnected() {
|
||||
|
||||
updatePlayPauseState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -197,7 +217,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
updatePlayPauseState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -209,5 +229,8 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
public void onUpdateProgressViews(int progress, int total) {
|
||||
bind.playerBodyLayout.playerBigSeekBar.setMax(total);
|
||||
bind.playerBodyLayout.playerBigSeekBar.setProgress(progress);
|
||||
|
||||
bind.playerBodyLayout.playerBigSongTimeIn.setText(MusicUtil.getReadableDurationString(progress));
|
||||
bind.playerBodyLayout.playerBigSongDuration.setText(MusicUtil.getReadableDurationString(total));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import com.cappielloantonio.play.model.Song;
|
|||
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class MusicUtil {
|
||||
public static String getSongFileUri(Song song) {
|
||||
ApiClient apiClient = App.getApiClientInstance(App.getInstance());
|
||||
|
|
@ -51,4 +53,17 @@ public class MusicUtil {
|
|||
Log.i(MusicUtil.class.getName(), "playing audio: " + builder);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String getReadableDurationString(long songDurationMillis) {
|
||||
long minutes = (songDurationMillis / 1000) / 60;
|
||||
long seconds = (songDurationMillis / 1000) % 60;
|
||||
|
||||
if (minutes < 60) {
|
||||
return String.format(Locale.getDefault(), "%01d:%02d", minutes, seconds);
|
||||
} else {
|
||||
long hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
return String.format(Locale.getDefault(), "%d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,24 +32,58 @@
|
|||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/collapse_bottom_sheet_button" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/player_big_seek_bar"
|
||||
<LinearLayout
|
||||
android:id="@+id/player_big_timer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="28dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_marginEnd="28dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_song_cover_view_pager" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_song_cover_view_pager">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_big_song_time_in"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/label_placeholder"
|
||||
android:textColor="@color/titleTextColor"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/player_big_seek_bar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center"
|
||||
android:paddingRight="12dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:paddingLeft="12dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/player_big_song_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:text="@string/label_placeholder"
|
||||
android:textColor="@color/titleTextColor"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/head_title_favorite_linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_big_seek_bar"
|
||||
app:layout_constraintTop_toBottomOf="@+id/player_big_timer"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,16 @@
|
|||
android:elevation="2dp"
|
||||
android:background="@color/almostCardColor">
|
||||
|
||||
<ImageView
|
||||
<ToggleButton
|
||||
android:id="@+id/player_header_button"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_width="38dp"
|
||||
android:layout_height="38dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:src="@drawable/ic_play"
|
||||
android:background="@drawable/button_play_pause_selector"
|
||||
android:checked="true"
|
||||
android:text=""
|
||||
android:textOff=""
|
||||
android:textOn=""
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue