mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Limited number of search items for each category
This commit is contained in:
parent
d6b5bf21c1
commit
55c335d7fc
14 changed files with 69 additions and 28 deletions
|
|
@ -22,8 +22,8 @@ public interface AlbumDao {
|
|||
@Query("SELECT * FROM album ORDER BY RANDOM() LIMIT :number;")
|
||||
LiveData<List<Album>> getSample(int number);
|
||||
|
||||
@Query("SELECT * FROM album WHERE title LIKE '%' || :name || '%'")
|
||||
LiveData<List<Album>> searchAlbum(String name);
|
||||
@Query("SELECT * FROM album WHERE title LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Album>> searchAlbum(String name, int limit);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(Album album);
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ public interface ArtistDao {
|
|||
@Query("SELECT * FROM artist ORDER BY RANDOM() LIMIT :number;")
|
||||
LiveData<List<Artist>> getSample(int number);
|
||||
|
||||
@Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%'")
|
||||
LiveData<List<Artist>> searchArtist(String name);
|
||||
@Query("SELECT * FROM artist WHERE name LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Artist>> searchArtist(String name, int limit);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Artist> artists);
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public interface GenreDao {
|
|||
@Query("DELETE FROM genre")
|
||||
void deleteAll();
|
||||
|
||||
@Query("SELECT * FROM genre WHERE name LIKE '%' || :name || '%'")
|
||||
LiveData<List<Genre>> searchGenre(String name);
|
||||
@Query("SELECT * FROM genre WHERE name LIKE '%' || :name || '%' LIMIT :limit")
|
||||
LiveData<List<Genre>> searchGenre(String name, int limit);
|
||||
|
||||
@Query("SELECT name FROM genre WHERE name LIKE :query || '%' OR name like '% ' || :query || '%' GROUP BY name LIMIT :number")
|
||||
List<String> searchSuggestions(String query, int number);
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ public interface SongDao {
|
|||
@Query("SELECT * FROM song")
|
||||
List<Song> getAllList();
|
||||
|
||||
@Query("SELECT * FROM song WHERE title LIKE '%' || :title || '%'")
|
||||
LiveData<List<Song>> searchSong(String title);
|
||||
@Query("SELECT * FROM song WHERE title LIKE '%' || :title || '%' LIMIT :limit")
|
||||
LiveData<List<Song>> searchSong(String title, int limit);
|
||||
|
||||
// Da utilizzare in caso si decidesse di migliorare il viewpager nella home
|
||||
@Query("SELECT * FROM song WHERE id IN (:pseudoRandomNumber)")
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ public class AlbumRepository {
|
|||
return listLiveSampleAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> searchListLiveAlbum(String name) {
|
||||
searchListLiveAlbum = albumDao.searchAlbum(name);
|
||||
public LiveData<List<Album>> searchListLiveAlbum(String name, int limit) {
|
||||
searchListLiveAlbum = albumDao.searchAlbum(name, limit);
|
||||
return searchListLiveAlbum;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ public class ArtistRepository {
|
|||
return listLiveSampleArtist;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> searchListLiveArtist(String name) {
|
||||
searchListLiveArtist = artistDao.searchArtist(name);
|
||||
public LiveData<List<Artist>> searchListLiveArtist(String name, int limit) {
|
||||
searchListLiveArtist = artistDao.searchArtist(name, limit);
|
||||
return searchListLiveArtist;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ public class GenreRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> searchListLiveGenre(String name) {
|
||||
searchListLiveGenre = genreDao.searchGenre(name);
|
||||
public LiveData<List<Genre>> searchListLiveGenre(String name, int limit) {
|
||||
searchListLiveGenre = genreDao.searchGenre(name, limit);
|
||||
return searchListLiveGenre;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ public class SongRepository {
|
|||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchListLiveSong(String title) {
|
||||
searchListLiveSongs = songDao.searchSong(title);
|
||||
public LiveData<List<Song>> searchListLiveSong(String title, int limit) {
|
||||
searchListLiveSongs = songDao.searchSong(title, limit);
|
||||
return searchListLiveSongs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.cappielloantonio.play.ui.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -26,6 +27,7 @@ import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
|||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.viewmodel.SearchViewModel;
|
||||
import com.paulrybitskyi.persistentsearchview.adapters.model.SuggestionItem;
|
||||
import com.paulrybitskyi.persistentsearchview.listeners.OnSuggestionChangeListener;
|
||||
|
|
@ -70,6 +72,8 @@ public class SearchFragment extends Fragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
inputFocus();
|
||||
|
||||
Log.i(TAG, "onResume: " + PreferenceUtil.getInstance(requireContext()).getSongNumber());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -179,19 +183,19 @@ public class SearchFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void performSearch(String query) {
|
||||
searchViewModel.searchSong(query).observe(requireActivity(), songs -> {
|
||||
searchViewModel.searchSong(query, requireContext()).observe(requireActivity(), songs -> {
|
||||
if(bind != null) bind.searchSongSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
songResultSearchAdapter.setItems(songs);
|
||||
});
|
||||
searchViewModel.searchAlbum(query).observe(requireActivity(), albums -> {
|
||||
searchViewModel.searchAlbum(query, requireContext()).observe(requireActivity(), albums -> {
|
||||
if(bind != null) bind.searchAlbumSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
albumAdapter.setItems(albums);
|
||||
});
|
||||
searchViewModel.searchArtist(query).observe(requireActivity(), artists -> {
|
||||
searchViewModel.searchArtist(query, requireContext()).observe(requireActivity(), artists -> {
|
||||
if(bind != null) bind.searchArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
artistAdapter.setItems(artists);
|
||||
});
|
||||
searchViewModel.searchGenre(query).observe(requireActivity(), genres -> {
|
||||
searchViewModel.searchGenre(query, requireContext()).observe(requireActivity(), genres -> {
|
||||
if(bind != null) bind.searchGenreSector.setVisibility(!genres.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
genreCatalogueAdapter.setItems(genres);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
public class PreferenceUtil {
|
||||
private static final String TAG = "PreferenceUtil";
|
||||
|
||||
public static final String SERVER = "server";
|
||||
public static final String USER = "user";
|
||||
public static final String TOKEN = "token";
|
||||
|
|
@ -24,6 +26,7 @@ public class PreferenceUtil {
|
|||
|
||||
public static final String SYNC = "sync";
|
||||
public static final String SONG_GENRE_SYNC = "song_genre_sync";
|
||||
public static final String SEARCH_ELEMENT_PER_CATEGORY = "search_element_per_category";
|
||||
|
||||
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
||||
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
|
||||
|
|
@ -141,6 +144,10 @@ public class PreferenceUtil {
|
|||
return Integer.parseInt(mPreferences.getString(INSTANT_MIX_SONG_NUMBER, "10"));
|
||||
}
|
||||
|
||||
public final int getSearchElementPerCategory() {
|
||||
return Integer.parseInt(mPreferences.getString(SEARCH_ELEMENT_PER_CATEGORY, "10"));
|
||||
}
|
||||
|
||||
public final String getTranscodeCodec() {
|
||||
return mPreferences.getString(TRANSCODE_CODEC, "aac");
|
||||
}
|
||||
|
|
@ -178,10 +185,16 @@ public class PreferenceUtil {
|
|||
return mPreferences.getBoolean(AUDIO_DUCKING, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Numero di canzoni salvate nel db
|
||||
*/
|
||||
public int getSongNumber() {
|
||||
return mPreferences.getInt(SONG_NUMBER, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Numero di canzoni salvate nel db
|
||||
*/
|
||||
public void setSongNumber(int number) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(SONG_NUMBER, number);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
|
|
@ -16,6 +17,7 @@ import com.cappielloantonio.play.repository.ArtistRepository;
|
|||
import com.cappielloantonio.play.repository.GenreRepository;
|
||||
import com.cappielloantonio.play.repository.RecentSearchRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -59,23 +61,23 @@ public class SearchViewModel extends AndroidViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchSong(String title) {
|
||||
searchSong = songRepository.searchListLiveSong(title);
|
||||
public LiveData<List<Song>> searchSong(String title, Context context) {
|
||||
searchSong = songRepository.searchListLiveSong(title, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchSong;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> searchAlbum(String name) {
|
||||
searchAlbum = albumRepository.searchListLiveAlbum(name);
|
||||
public LiveData<List<Album>> searchAlbum(String name, Context context) {
|
||||
searchAlbum = albumRepository.searchListLiveAlbum(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> searchArtist(String name) {
|
||||
searchArtist = artistRepository.searchListLiveArtist(name);
|
||||
public LiveData<List<Artist>> searchArtist(String name, Context context) {
|
||||
searchArtist = artistRepository.searchListLiveArtist(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchArtist;
|
||||
}
|
||||
|
||||
public LiveData<List<Genre>> searchGenre(String name) {
|
||||
searchGenre = genreRepository.searchListLiveGenre(name);
|
||||
public LiveData<List<Genre>> searchGenre(String name, Context context) {
|
||||
searchGenre = genreRepository.searchListLiveGenre(name, PreferenceUtil.getInstance(context).getSearchElementPerCategory());
|
||||
return searchGenre;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,4 +50,16 @@
|
|||
<item>25</item>
|
||||
<item>50</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="search_element_per_category_titles">
|
||||
<item>10</item>
|
||||
<item>20</item>
|
||||
<item>30</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="search_element_per_category_values">
|
||||
<item>10</item>
|
||||
<item>20</item>
|
||||
<item>30</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
<string name="label_dot_separator">•</string>
|
||||
<string name="save_filters">Save filters between sessions</string>
|
||||
<string name="instant_mix_song_number">Number of songs generated by Instant Mix</string>
|
||||
<string name="search_element_per_category">Number of items searched for each category</string>
|
||||
|
||||
<string name="sync_header">Synchronization</string>
|
||||
<string name="music_sync">Music sync</string>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,15 @@
|
|||
app:key="instant_mix_song_number"
|
||||
app:title="@string/instant_mix_song_number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="10"
|
||||
app:dialogTitle="@string/search_element_per_category"
|
||||
app:entries="@array/search_element_per_category_titles"
|
||||
app:entryValues="@array/search_element_per_category_values"
|
||||
app:key="search_element_per_category"
|
||||
app:title="@string/search_element_per_category"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/sync_header">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue