From 0fe4636fe19f51b4bc296940a0c4c169894ec230 Mon Sep 17 00:00:00 2001 From: antonio Date: Sun, 17 Sep 2023 18:51:22 +0200 Subject: [PATCH] feat: parameterized track sharing feature --- .../tempo/ui/dialog/PlaylistEditorDialog.java | 3 ++ .../ui/fragment/HomeTabMusicFragment.java | 33 +++++++++++-------- .../AlbumBottomSheetDialog.java | 3 ++ .../SongBottomSheetDialog.java | 3 ++ .../tempo/util/Preferences.kt | 6 ++++ .../res/layout/bottom_sheet_album_dialog.xml | 3 +- .../res/layout/bottom_sheet_song_dialog.xml | 3 +- .../res/layout/fragment_home_tab_music.xml | 3 +- app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/global_preferences.xml | 12 +++++++ 10 files changed, 55 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistEditorDialog.java b/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistEditorDialog.java index 5cf0ba50..5783f9dc 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistEditorDialog.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistEditorDialog.java @@ -22,6 +22,7 @@ import com.cappielloantonio.tempo.interfaces.PlaylistCallback; import com.cappielloantonio.tempo.ui.adapter.PlaylistDialogSongHorizontalAdapter; import com.cappielloantonio.tempo.util.Constants; import com.cappielloantonio.tempo.util.MusicUtil; +import com.cappielloantonio.tempo.util.Preferences; import com.cappielloantonio.tempo.viewmodel.PlaylistEditorViewModel; import java.util.Collections; @@ -111,6 +112,8 @@ public class PlaylistEditorDialog extends DialogFragment { clipboardManager.setPrimaryClip(clipData); }); }); + + bind.playlistShareButton.setVisibility(Preferences.isSharingEnabled() ? View.VISIBLE : View.GONE); } private void initSongsView() { diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java index 31f04973..126028b8 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/HomeTabMusicFragment.java @@ -672,20 +672,23 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback { shareHorizontalAdapter = new ShareHorizontalAdapter(this); bind.sharesRecyclerView.setAdapter(shareHorizontalAdapter); - homeViewModel.getShares(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), shares -> { - if (shares == null) { - if (bind != null) bind.sharesPlaceholder.placeholder.setVisibility(View.VISIBLE); - if (bind != null) bind.sharesSector.setVisibility(View.GONE); - } else { - if (bind != null) bind.sharesPlaceholder.placeholder.setVisibility(View.GONE); - if (bind != null) - bind.sharesSector.setVisibility(!shares.isEmpty() ? View.VISIBLE : View.GONE); - if (bind != null) - bind.sharesRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(shares.size(), 10), GridLayoutManager.HORIZONTAL, false)); + if (Preferences.isSharingEnabled()) { + homeViewModel.getShares(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), shares -> { + if (shares == null) { + if (bind != null) + bind.sharesPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.sharesSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.sharesPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) + bind.sharesSector.setVisibility(!shares.isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.sharesRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(shares.size(), 10), GridLayoutManager.HORIZONTAL, false)); - shareHorizontalAdapter.setItems(shares); - } - }); + shareHorizontalAdapter.setItems(shares); + } + }); + } SnapHelper starredTrackSnapHelper = new PagerSnapHelper(); starredTrackSnapHelper.attachToRecyclerView(bind.sharesRecyclerView); @@ -702,7 +705,9 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback { private void refreshSharesView() { final Handler handler = new Handler(); - final Runnable runnable = () -> homeViewModel.refreshShares(getViewLifecycleOwner()); + final Runnable runnable = () -> { + if (Preferences.isSharingEnabled()) homeViewModel.refreshShares(getViewLifecycleOwner()); + }; handler.postDelayed(runnable, 100); } diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/AlbumBottomSheetDialog.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/AlbumBottomSheetDialog.java index c3500cef..97c10fe7 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/AlbumBottomSheetDialog.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/AlbumBottomSheetDialog.java @@ -35,6 +35,7 @@ import com.cappielloantonio.tempo.util.Constants; import com.cappielloantonio.tempo.util.DownloadUtil; import com.cappielloantonio.tempo.util.MappingUtil; import com.cappielloantonio.tempo.util.MusicUtil; +import com.cappielloantonio.tempo.util.Preferences; import com.cappielloantonio.tempo.viewmodel.AlbumBottomSheetViewModel; import com.cappielloantonio.tempo.viewmodel.HomeViewModel; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; @@ -199,6 +200,8 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements dismissBottomSheet(); } })); + + share.setVisibility(Preferences.isSharingEnabled() ? View.VISIBLE : View.GONE); } @Override diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/SongBottomSheetDialog.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/SongBottomSheetDialog.java index de6ebbfc..782ad35a 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/SongBottomSheetDialog.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/SongBottomSheetDialog.java @@ -33,6 +33,7 @@ import com.cappielloantonio.tempo.util.Constants; import com.cappielloantonio.tempo.util.DownloadUtil; import com.cappielloantonio.tempo.util.MappingUtil; import com.cappielloantonio.tempo.util.MusicUtil; +import com.cappielloantonio.tempo.util.Preferences; import com.cappielloantonio.tempo.viewmodel.HomeViewModel; import com.cappielloantonio.tempo.viewmodel.SongBottomSheetViewModel; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; @@ -217,6 +218,8 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements dismissBottomSheet(); } })); + + share.setVisibility(Preferences.isSharingEnabled() ? View.VISIBLE : View.GONE); } @Override diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt index 00782079..05bf2643 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt @@ -39,6 +39,7 @@ object Preferences { private const val AUDIO_TRANSCODE_DOWNLOAD_PRIORITY = "audio_transcode_download_priority" private const val MAX_BITRATE_DOWNLOAD = "max_bitrate_download" private const val AUDIO_TRANSCODE_FORMAT_DOWNLOAD = "audio_transcode_format_download" + private const val SHARE = "share" @JvmStatic fun getServer(): String? { @@ -313,4 +314,9 @@ object Preferences { fun getAudioTranscodeFormatTranscodedDownload(): String { return App.getInstance().preferences.getString(AUDIO_TRANSCODE_FORMAT_DOWNLOAD, "raw")!! } + + @JvmStatic + fun isSharingEnabled(): Boolean { + return App.getInstance().preferences.getBoolean(SHARE, false) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_album_dialog.xml b/app/src/main/res/layout/bottom_sheet_album_dialog.xml index 168ac9d7..a6ed37a5 100644 --- a/app/src/main/res/layout/bottom_sheet_album_dialog.xml +++ b/app/src/main/res/layout/bottom_sheet_album_dialog.xml @@ -184,6 +184,7 @@ android:paddingTop="12dp" android:paddingEnd="20dp" android:paddingBottom="12dp" - android:text="@string/album_bottom_sheet_share" /> + android:text="@string/album_bottom_sheet_share" + android:visibility="gone"/> \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_song_dialog.xml b/app/src/main/res/layout/bottom_sheet_song_dialog.xml index c8a8f976..2105f941 100644 --- a/app/src/main/res/layout/bottom_sheet_song_dialog.xml +++ b/app/src/main/res/layout/bottom_sheet_song_dialog.xml @@ -206,6 +206,7 @@ android:paddingTop="12dp" android:paddingEnd="20dp" android:paddingBottom="12dp" - android:text="@string/song_bottom_sheet_share" /> + android:text="@string/song_bottom_sheet_share" + android:visibility="gone"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home_tab_music.xml b/app/src/main/res/layout/fragment_home_tab_music.xml index 83d47899..b5c02871 100644 --- a/app/src/main/res/layout/fragment_home_tab_music.xml +++ b/app/src/main/res/layout/fragment_home_tab_music.xml @@ -759,7 +759,8 @@ android:id="@+id/shares_sector" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" + android:visibility="gone"> Corners size Sets the magnitude of the curvature angle. Scan library + Enable music sharing Replay gain is a feature that allows you to adjust the volume level of audio tracks for a consistent listening experience. This setting is only effective if the track contains the necessary metadata. + Allows the user to share music via a link. The functionality must be supported and enabled server-side and is limited to individual tracks, albums and playlists. 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. Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed. Download transcoded media. If enabled, the download endpoint will not be used, but the following settings. \n\n If \"Transcode format\" is set to \"Direct play\" the bitrate of the file will not be changed. @@ -239,6 +241,7 @@ Data General Replay Gain + Share Syncing Transcoding Transcoding Download diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index 8f0a4f09..2b056dc2 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -212,6 +212,18 @@ + + + + + + +