mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Added settings for play queue sync functionality
This commit is contained in:
parent
74ff105eee
commit
a130fb38cc
8 changed files with 115 additions and 40 deletions
|
|
@ -33,6 +33,7 @@ import com.cappielloantonio.play.subsonic.models.PlayQueue;
|
|||
import com.cappielloantonio.play.ui.fragment.pager.PlayerControllerVerticalPager;
|
||||
import com.cappielloantonio.play.util.Constants;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.cappielloantonio.play.util.Preferences;
|
||||
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
|
||||
import com.google.android.material.elevation.SurfaceColors;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
|
@ -255,38 +256,40 @@ public class PlayerBottomSheetFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void setHeaderBookmarksButton() {
|
||||
playerBottomSheetViewModel.getPlayQueue().observeForever(new Observer<PlayQueue>() {
|
||||
@Override
|
||||
public void onChanged(PlayQueue playQueue) {
|
||||
playerBottomSheetViewModel.getPlayQueue().removeObserver(this);
|
||||
if (Preferences.isSyncronizationEnabled()) {
|
||||
playerBottomSheetViewModel.getPlayQueue().observeForever(new Observer<PlayQueue>() {
|
||||
@Override
|
||||
public void onChanged(PlayQueue playQueue) {
|
||||
playerBottomSheetViewModel.getPlayQueue().removeObserver(this);
|
||||
|
||||
if (bind == null) return;
|
||||
if (bind == null) return;
|
||||
|
||||
if (playQueue != null && !playQueue.getEntries().isEmpty()) {
|
||||
int index = IntStream.range(0, playQueue.getEntries().size()).filter(ix -> playQueue.getEntries().get(ix).getId().equals(playQueue.getCurrent())).findFirst().orElse(-1);
|
||||
if (playQueue != null && !playQueue.getEntries().isEmpty()) {
|
||||
int index = IntStream.range(0, playQueue.getEntries().size()).filter(ix -> playQueue.getEntries().get(ix).getId().equals(playQueue.getCurrent())).findFirst().orElse(-1);
|
||||
|
||||
if (index != -1) {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.VISIBLE);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnClickListener(v -> {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, playQueue.getEntries(), index);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
});
|
||||
if (index != -1) {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.VISIBLE);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnClickListener(v -> {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, playQueue.getEntries(), index);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnClickListener(null);
|
||||
}
|
||||
} else {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnLongClickListener(v -> {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
return false;
|
||||
});
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
if (bind != null)
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnLongClickListener(v -> {
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
}, 5000);
|
||||
return false;
|
||||
});
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
if (bind != null)
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
}, Preferences.getSyncCountdownTimer() * 1000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.cappielloantonio.play.ui.dialog.PlaylistChooserDialog;
|
|||
import com.cappielloantonio.play.util.Constants;
|
||||
import com.cappielloantonio.play.util.DownloadUtil;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.Preferences;
|
||||
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
|
@ -86,6 +87,9 @@ public class PlayerCoverFragment extends Fragment {
|
|||
|
||||
TransitionManager.beginDelayedTransition(bind.getRoot(), transition);
|
||||
bind.nowPlayingSongCoverButtonGroup.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
||||
|
||||
bind.innerButtonBottomRight.setVisibility(Preferences.isSyncronizationEnabled() ? View.VISIBLE : View.GONE);
|
||||
bind.innerButtonBottomRightAlternative.setVisibility(Preferences.isSyncronizationEnabled() ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private void initInnerButton() {
|
||||
|
|
@ -119,6 +123,15 @@ public class PlayerCoverFragment extends Fragment {
|
|||
Snackbar.make(requireView(), "Salvato", Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
bind.innerButtonBottomRightAlternative.setOnClickListener(view -> {
|
||||
if (getActivity() != null) {
|
||||
PlayerBottomSheetFragment playerBottomSheetFragment = (PlayerBottomSheetFragment) requireActivity().getSupportFragmentManager().findFragmentByTag("PlayerBottomSheet");
|
||||
if (playerBottomSheetFragment != null) {
|
||||
playerBottomSheetFragment.goToLyricsPage();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.cappielloantonio.play.util
|
||||
|
||||
import com.cappielloantonio.play.App
|
||||
import com.cappielloantonio.play.helper.ThemeHelper
|
||||
|
||||
object Preferences {
|
||||
const val THEME = "theme"
|
||||
|
|
@ -24,6 +23,8 @@ object Preferences {
|
|||
private const val DATA_SAVING_MODE = "data_saving_mode"
|
||||
private const val SERVER_UNREACHABLE = "server_unreachable"
|
||||
private const val SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use"
|
||||
private const val QUEUE_SYNCING = "queue_syncing"
|
||||
private const val QUEUE_SYNCING_COUNTDOWN = "queue_syncing_countdown"
|
||||
|
||||
@JvmStatic
|
||||
fun getServer(): String? {
|
||||
|
|
@ -112,14 +113,12 @@ object Preferences {
|
|||
|
||||
@JvmStatic
|
||||
fun setSkipSilenceMode(isSkipSilenceMode: Boolean) {
|
||||
App.getInstance().preferences.edit().putBoolean(SKIP_SILENCE, isSkipSilenceMode)
|
||||
.apply()
|
||||
App.getInstance().preferences.edit().putBoolean(SKIP_SILENCE, isSkipSilenceMode).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getImageCacheSize(): Int {
|
||||
return App.getInstance().preferences.getString(IMAGE_CACHE_SIZE, "500")!!
|
||||
.toInt()
|
||||
return App.getInstance().preferences.getString(IMAGE_CACHE_SIZE, "500")!!.toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
|
@ -159,14 +158,13 @@ object Preferences {
|
|||
|
||||
@JvmStatic
|
||||
fun setDataSavingMode(isDataSavingModeEnabled: Boolean) {
|
||||
App.getInstance().preferences.edit()
|
||||
.putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled).apply()
|
||||
App.getInstance().preferences.edit().putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled)
|
||||
.apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isStarredSyncEnabled(): Boolean {
|
||||
return App.getInstance().preferences
|
||||
.getBoolean(SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, false)
|
||||
return App.getInstance().preferences.getBoolean(SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
|
@ -179,14 +177,22 @@ object Preferences {
|
|||
@JvmStatic
|
||||
fun showServerUnreachableDialog(): Boolean {
|
||||
return App.getInstance().preferences.getLong(
|
||||
SERVER_UNREACHABLE,
|
||||
0
|
||||
SERVER_UNREACHABLE, 0
|
||||
) + 360000 < System.currentTimeMillis()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setServerUnreachableDatetime(datetime: Long) {
|
||||
App.getInstance().preferences.edit()
|
||||
.putLong(SERVER_UNREACHABLE, datetime).apply()
|
||||
App.getInstance().preferences.edit().putLong(SERVER_UNREACHABLE, datetime).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isSyncronizationEnabled(): Boolean {
|
||||
return App.getInstance().preferences.getBoolean(QUEUE_SYNCING, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getSyncCountdownTimer(): Int {
|
||||
return App.getInstance().preferences.getString(QUEUE_SYNCING_COUNTDOWN, "5")!!.toInt()
|
||||
}
|
||||
}
|
||||
|
|
@ -102,5 +102,20 @@
|
|||
app:layout_constraintStart_toEndOf="@+id/vertical_guideline"
|
||||
app:layout_constraintTop_toBottomOf="@+id/horizontal_guideline" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/inner_button_bottom_right_alternative"
|
||||
style="@style/Widget.Material3.Button.TonalButton.Icon"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:layout_margin="4dp"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="0dp"
|
||||
app:cornerRadius="30dp"
|
||||
app:icon="@drawable/ic_lyrics"
|
||||
app:layout_constraintStart_toEndOf="@+id/vertical_guideline"
|
||||
app:layout_constraintTop_toBottomOf="@+id/horizontal_guideline" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -71,6 +71,7 @@
|
|||
android:layout_marginEnd="12dp"
|
||||
android:background="@drawable/ic_bookmark_sync"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/player_header_seek_bar"
|
||||
app:layout_constraintEnd_toStartOf="@+id/player_header_button"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -119,4 +119,15 @@
|
|||
<item>mp3</item>
|
||||
<item>flac</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="queue_syncing_countdown_titles">
|
||||
<item>Ten seconds</item>
|
||||
<item>Five seconds</item>
|
||||
<item>Two seconds</item>
|
||||
</string-array>
|
||||
<string-array name="queue_syncing_countdown_values">
|
||||
<item>10</item>
|
||||
<item>5</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
@ -156,13 +156,18 @@
|
|||
<string name="settings_max_bitrate_wifi">Bitrate in Wi-Fi</string>
|
||||
<string name="settings_max_bitrate_mobile">Bitrate in mobile</string>
|
||||
<string name="settings_media_cache">Size of media file cache</string>
|
||||
<string name="settings_queue_syncing_title">Sync play queue for this user</string>
|
||||
<string name="settings_queue_syncing_countdown">Sync timer</string>
|
||||
<string name="settings_queue_syncing_summary">If enabled, the user will have the ability to save their play queue and will have the ability to load state when opening the application.</string>
|
||||
<string name="settings_scan_title">Scan library</string>
|
||||
<string name="settings_summary_syncing">Returns the state of the play queue for this user. This includes the tracks in the play queue, the currently playing track, and the position within this track. The server must support this feature.</string>
|
||||
<string name="settings_summary_transcoding">Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed.</string>
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_summary">If enabled, starred tracks will be downloaded for offline use</string>
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_summary">If enabled, starred tracks will be downloaded for offline use.</string>
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_title">Sync starred tracks for offline use</string>
|
||||
<string name="settings_theme">Theme</string>
|
||||
<string name="settings_title_data">Data</string>
|
||||
<string name="settings_title_general">General</string>
|
||||
<string name="settings_title_syncing">Syncing</string>
|
||||
<string name="settings_title_transcoding">Transcoding</string>
|
||||
<string name="settings_version_summary">3.1.0</string>
|
||||
<string name="settings_version_title">Version</string>
|
||||
|
|
|
|||
|
|
@ -104,6 +104,27 @@
|
|||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/settings_title_syncing">
|
||||
<Preference
|
||||
app:selectable="false"
|
||||
app:summary="@string/settings_summary_syncing" />
|
||||
|
||||
<SwitchPreference
|
||||
android:title="@string/settings_queue_syncing_title"
|
||||
android:defaultValue="false"
|
||||
android:summary="@string/settings_sync_starred_tracks_for_offline_use_summary"
|
||||
android:key="queue_syncing" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="5"
|
||||
app:dialogTitle="@string/settings_queue_syncing_countdown"
|
||||
app:entries="@array/queue_syncing_countdown_titles"
|
||||
app:entryValues="@array/queue_syncing_countdown_values"
|
||||
app:key="queue_syncing_countdown"
|
||||
app:title="@string/settings_queue_syncing_countdown"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/settings_about_title">
|
||||
<Preference
|
||||
app:selectable="false"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue