mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: Added support for skipping duplicates (#135)
This commit is contained in:
commit
ec19e8c401
7 changed files with 75 additions and 44 deletions
|
|
@ -81,20 +81,24 @@ public class PlaylistRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSongToPlaylist(String playlistId, ArrayList<String> songsId) {
|
public void addSongToPlaylist(String playlistId, ArrayList<String> songsId) {
|
||||||
App.getSubsonicClientInstance(false)
|
if (songsId.isEmpty()) {
|
||||||
.getPlaylistClient()
|
Toast.makeText(App.getContext(), App.getContext().getString(R.string.playlist_chooser_dialog_toast_all_skipped), Toast.LENGTH_SHORT).show();
|
||||||
.updatePlaylist(playlistId, null, true, songsId, null)
|
} else{
|
||||||
.enqueue(new Callback<ApiResponse>() {
|
App.getSubsonicClientInstance(false)
|
||||||
@Override
|
.getPlaylistClient()
|
||||||
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
.updatePlaylist(playlistId, null, true, songsId, null)
|
||||||
Toast.makeText(App.getContext(), App.getContext().getString(R.string.playlist_chooser_dialog_toast_add_success), Toast.LENGTH_SHORT).show();
|
.enqueue(new Callback<ApiResponse>() {
|
||||||
}
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||||
|
Toast.makeText(App.getContext(), App.getContext().getString(R.string.playlist_chooser_dialog_toast_add_success), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
||||||
Toast.makeText(App.getContext(), App.getContext().getString(R.string.playlist_chooser_dialog_toast_add_failure), Toast.LENGTH_SHORT).show();
|
Toast.makeText(App.getContext(), App.getContext().getString(R.string.playlist_chooser_dialog_toast_add_failure), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPlaylist(String playlistId, String name, ArrayList<String> songsId) {
|
public void createPlaylist(String playlistId, String name, ArrayList<String> songsId) {
|
||||||
|
|
@ -131,23 +135,6 @@ public class PlaylistRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlaylist(String playlistId, String name, boolean isPublic, ArrayList<String> songIdToAdd, ArrayList<Integer> songIndexToRemove) {
|
|
||||||
App.getSubsonicClientInstance(false)
|
|
||||||
.getPlaylistClient()
|
|
||||||
.updatePlaylist(playlistId, name, isPublic, songIdToAdd, songIndexToRemove)
|
|
||||||
.enqueue(new Callback<ApiResponse>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePlaylist(String playlistId) {
|
public void deletePlaylist(String playlistId) {
|
||||||
App.getSubsonicClientInstance(false)
|
App.getSubsonicClientInstance(false)
|
||||||
.getPlaylistClient()
|
.getPlaylistClient()
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public class PlaylistChooserDialog extends DialogFragment implements ClickCallba
|
||||||
|
|
||||||
private PlaylistDialogHorizontalAdapter playlistDialogHorizontalAdapter;
|
private PlaylistDialogHorizontalAdapter playlistDialogHorizontalAdapter;
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
@ -100,8 +101,7 @@ public class PlaylistChooserDialog extends DialogFragment implements ClickCallba
|
||||||
public void onPlaylistClick(Bundle bundle) {
|
public void onPlaylistClick(Bundle bundle) {
|
||||||
if (playlistChooserViewModel.getSongsToAdd() != null && !playlistChooserViewModel.getSongsToAdd().isEmpty()) {
|
if (playlistChooserViewModel.getSongsToAdd() != null && !playlistChooserViewModel.getSongsToAdd().isEmpty()) {
|
||||||
Playlist playlist = bundle.getParcelable(Constants.PLAYLIST_OBJECT);
|
Playlist playlist = bundle.getParcelable(Constants.PLAYLIST_OBJECT);
|
||||||
playlistChooserViewModel.addSongsToPlaylist(playlist.getId());
|
playlistChooserViewModel.addSongsToPlaylist(this, getDialog(), playlist.getId());
|
||||||
dismiss();
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(requireContext(), R.string.playlist_chooser_dialog_toast_add_failure, Toast.LENGTH_SHORT).show();
|
Toast.makeText(requireContext(), R.string.playlist_chooser_dialog_toast_add_failure, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,8 @@ object Preferences {
|
||||||
private const val NEXT_UPDATE_CHECK = "next_update_check"
|
private const val NEXT_UPDATE_CHECK = "next_update_check"
|
||||||
private const val CONTINUOUS_PLAY = "continuous_play"
|
private const val CONTINUOUS_PLAY = "continuous_play"
|
||||||
private const val LAST_INSTANT_MIX = "last_instant_mix"
|
private const val LAST_INSTANT_MIX = "last_instant_mix"
|
||||||
|
private const val ALLOW_PLAYLIST_DUPLICATES = "allow_playlist_duplicates"
|
||||||
|
|
||||||
private const val EQUALIZER_ENABLED = "equalizer_enabled"
|
private const val EQUALIZER_ENABLED = "equalizer_enabled"
|
||||||
private const val EQUALIZER_BAND_LEVELS = "equalizer_band_levels"
|
private const val EQUALIZER_BAND_LEVELS = "equalizer_band_levels"
|
||||||
private const val MINI_SHUFFLE_BUTTON_VISIBILITY = "mini_shuffle_button_visibility"
|
private const val MINI_SHUFFLE_BUTTON_VISIBILITY = "mini_shuffle_button_visibility"
|
||||||
|
|
@ -599,6 +601,16 @@ object Preferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
fun setAllowPlaylistDuplicates(allowDuplicates: Boolean) {
|
||||||
|
return App.getInstance().preferences.edit().putString(
|
||||||
|
ALLOW_PLAYLIST_DUPLICATES,
|
||||||
|
allowDuplicates.toString()
|
||||||
|
).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun allowPlaylistDuplicates(): Boolean {
|
||||||
|
return App.getInstance().preferences.getBoolean(ALLOW_PLAYLIST_DUPLICATES, false)
|
||||||
fun setEqualizerEnabled(enabled: Boolean) {
|
fun setEqualizerEnabled(enabled: Boolean) {
|
||||||
App.getInstance().preferences.edit().putBoolean(EQUALIZER_ENABLED, enabled).apply()
|
App.getInstance().preferences.edit().putBoolean(EQUALIZER_ENABLED, enabled).apply()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.cappielloantonio.tempo.viewmodel;
|
package com.cappielloantonio.tempo.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
|
@ -11,10 +13,10 @@ import androidx.lifecycle.MutableLiveData;
|
||||||
import com.cappielloantonio.tempo.repository.PlaylistRepository;
|
import com.cappielloantonio.tempo.repository.PlaylistRepository;
|
||||||
import com.cappielloantonio.tempo.subsonic.models.Child;
|
import com.cappielloantonio.tempo.subsonic.models.Child;
|
||||||
import com.cappielloantonio.tempo.subsonic.models.Playlist;
|
import com.cappielloantonio.tempo.subsonic.models.Playlist;
|
||||||
|
import com.cappielloantonio.tempo.util.Preferences;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlaylistChooserViewModel extends AndroidViewModel {
|
public class PlaylistChooserViewModel extends AndroidViewModel {
|
||||||
|
|
@ -34,8 +36,21 @@ public class PlaylistChooserViewModel extends AndroidViewModel {
|
||||||
return playlists;
|
return playlists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSongsToPlaylist(String playlistId) {
|
public void addSongsToPlaylist(LifecycleOwner owner, Dialog dialog, String playlistId) {
|
||||||
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(Lists.transform(toAdd, Child::getId)));
|
List<String> songIds = Lists.transform(toAdd, Child::getId);
|
||||||
|
if (Preferences.allowPlaylistDuplicates()) {
|
||||||
|
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(songIds));
|
||||||
|
dialog.dismiss();
|
||||||
|
} else {
|
||||||
|
playlistRepository.getPlaylistSongs(playlistId).observe(owner, playlistSongs -> {
|
||||||
|
if (playlistSongs != null) {
|
||||||
|
List<String> playlistSongIds = Lists.transform(playlistSongs, Child::getId);
|
||||||
|
songIds.removeAll(playlistSongIds);
|
||||||
|
}
|
||||||
|
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(songIds));
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSongsToAdd(ArrayList<Child> songs) {
|
public void setSongsToAdd(ArrayList<Child> songs) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/playlist_dialog_recycler_view"
|
android:id="@+id/playlist_dialog_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:clipToPadding="false" />
|
android:clipToPadding="false" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -225,8 +225,9 @@
|
||||||
<string name="playlist_chooser_dialog_negative_button">Cancel</string>
|
<string name="playlist_chooser_dialog_negative_button">Cancel</string>
|
||||||
<string name="playlist_chooser_dialog_neutral_button">Create</string>
|
<string name="playlist_chooser_dialog_neutral_button">Create</string>
|
||||||
<string name="playlist_chooser_dialog_title">Add to a playlist</string>
|
<string name="playlist_chooser_dialog_title">Add to a playlist</string>
|
||||||
<string name="playlist_chooser_dialog_toast_add_success">Added song to playlist</string>
|
<string name="playlist_chooser_dialog_toast_add_success">Added song(s) to playlist</string>
|
||||||
<string name="playlist_chooser_dialog_toast_add_failure">Failed to add song to playlist</string>
|
<string name="playlist_chooser_dialog_toast_add_failure">Failed to add song(s) to playlist</string>
|
||||||
|
<string name="playlist_chooser_dialog_toast_all_skipped">All songs were skipped as duplicates</string>
|
||||||
<string name="playlist_counted_tracks">%1$d tracks • %2$s</string>
|
<string name="playlist_counted_tracks">%1$d tracks • %2$s</string>
|
||||||
<string name="playlist_duration">Duration • %1$s</string>
|
<string name="playlist_duration">Duration • %1$s</string>
|
||||||
<string name="playlist_editor_dialog_action_delete_toast">Long press to delete</string>
|
<string name="playlist_editor_dialog_action_delete_toast">Long press to delete</string>
|
||||||
|
|
@ -293,6 +294,8 @@
|
||||||
<string name="settings_about_summary">Tempo is an open source and lightweight music client for Subsonic, designed and built natively for Android.</string>
|
<string name="settings_about_summary">Tempo is an open source and lightweight music client for Subsonic, designed and built natively for Android.</string>
|
||||||
<string name="settings_about_title">About</string>
|
<string name="settings_about_title">About</string>
|
||||||
<string name="settings_always_on_display">Always on display</string>
|
<string name="settings_always_on_display">Always on display</string>
|
||||||
|
<string name="settings_allow_playlist_duplicates">Allow adding duplicates to playlist</string>
|
||||||
|
<string name="settings_allow_playlist_duplicates_summary">If enabled, duplicates won\'t be checked while adding to a playlist.</string>
|
||||||
<string name="settings_audio_transcode_download_format">Transcode format</string>
|
<string name="settings_audio_transcode_download_format">Transcode format</string>
|
||||||
<string name="settings_audio_transcode_download_priority_summary">If enabled, Tempo will not force download the track with the transcode settings below.</string>
|
<string name="settings_audio_transcode_download_priority_summary">If enabled, Tempo will not force download the track with the transcode settings below.</string>
|
||||||
<string name="settings_audio_transcode_download_priority_title">Prioritize server settings used for streaming in downloads</string>
|
<string name="settings_audio_transcode_download_priority_title">Prioritize server settings used for streaming in downloads</string>
|
||||||
|
|
@ -380,6 +383,7 @@
|
||||||
<string name="settings_theme">Theme</string>
|
<string name="settings_theme">Theme</string>
|
||||||
<string name="settings_title_data">Data</string>
|
<string name="settings_title_data">Data</string>
|
||||||
<string name="settings_title_general">General</string>
|
<string name="settings_title_general">General</string>
|
||||||
|
<string name="settings_title_playlist">Playlist</string>
|
||||||
<string name="settings_title_rating">Rating</string>
|
<string name="settings_title_rating">Rating</string>
|
||||||
<string name="settings_title_replay_gain">Replay Gain</string>
|
<string name="settings_title_replay_gain">Replay Gain</string>
|
||||||
<string name="settings_title_scrobble">Scrobble</string>
|
<string name="settings_title_scrobble">Scrobble</string>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<PreferenceCategory app:title="@string/settings_title_general">
|
<PreferenceCategory app:title="@string/settings_title_general">
|
||||||
<Preference
|
<Preference
|
||||||
android:key="system_equalizer"
|
android:key="system_equalizer"
|
||||||
android:title="@string/settings_system_equalizer_title"
|
android:title="@string/settings_system_equalizer_title"
|
||||||
android:summary="@string/settings_system_equalizer_summary" />
|
android:summary="@string/settings_system_equalizer_summary" />
|
||||||
|
|
@ -22,12 +22,14 @@
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/settings_title_ui">
|
<PreferenceCategory app:title="@string/settings_title_ui">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
|
android:layout_height="match_parent"
|
||||||
app:defaultValue="default"
|
app:defaultValue="default"
|
||||||
app:dialogTitle="@string/settings_language"
|
app:dialogTitle="@string/settings_language"
|
||||||
app:key="language"
|
app:key="language"
|
||||||
app:title="@string/settings_language"/>
|
app:title="@string/settings_language" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
|
android:layout_height="wrap_content"
|
||||||
app:defaultValue="default"
|
app:defaultValue="default"
|
||||||
app:dialogTitle="@string/settings_theme"
|
app:dialogTitle="@string/settings_theme"
|
||||||
app:entries="@array/theme_list_titles"
|
app:entries="@array/theme_list_titles"
|
||||||
|
|
@ -42,10 +44,11 @@
|
||||||
android:key="always_on_display" />
|
android:key="always_on_display" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:title="@string/settings_rounded_corner"
|
android:layout_height="match_parent"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
android:key="rounded_corner"
|
||||||
android:summary="@string/settings_rounded_corner_summary"
|
android:summary="@string/settings_rounded_corner_summary"
|
||||||
android:key="rounded_corner" />
|
android:title="@string/settings_rounded_corner" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="6"
|
app:defaultValue="6"
|
||||||
|
|
@ -57,10 +60,11 @@
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:title="@string/settings_audio_quality"
|
android:layout_height="wrap_content"
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
|
android:key="audio_quality_per_item"
|
||||||
android:summary="@string/settings_audio_quality_summary"
|
android:summary="@string/settings_audio_quality_summary"
|
||||||
android:key="audio_quality_per_item" />
|
android:title="@string/settings_audio_quality" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:title="@string/settings_song_rating"
|
android:title="@string/settings_song_rating"
|
||||||
|
|
@ -106,6 +110,14 @@
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory app:title="@string/settings_title_playlist">
|
||||||
|
<SwitchPreference
|
||||||
|
android:title="@string/settings_allow_playlist_duplicates"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:summary="@string/settings_allow_playlist_duplicates_summary"
|
||||||
|
android:key="allow_playlist_duplicates" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/settings_title_data">
|
<PreferenceCategory app:title="@string/settings_title_data">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="256"
|
app:defaultValue="256"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue