mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
commit
cc5abd150a
4 changed files with 52 additions and 5 deletions
|
|
@ -145,7 +145,7 @@ public class AlbumListPageFragment extends Fragment implements ClickCallback {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.toolbar_menu, menu);
|
||||
inflater.inflate(R.menu.artist_list_menu, menu);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.action_search);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.view.inputmethod.EditorInfo;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -24,6 +25,8 @@ import androidx.navigation.Navigation;
|
|||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.tempo.R;
|
||||
import com.cappielloantonio.tempo.databinding.FragmentArtistCatalogueBinding;
|
||||
import com.cappielloantonio.tempo.helper.recyclerview.GridItemDecoration;
|
||||
|
|
@ -32,6 +35,10 @@ import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
|||
import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
|
||||
import com.cappielloantonio.tempo.util.Constants;
|
||||
import com.cappielloantonio.tempo.viewmodel.ArtistCatalogueViewModel;
|
||||
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UnstableApi
|
||||
public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
|
||||
|
|
@ -125,23 +132,50 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
|
|||
|
||||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
|
||||
searchView.setQueryHint(getString(R.string.filter_artist));
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
searchView.clearFocus();
|
||||
return false;
|
||||
// this toast may be overkill...
|
||||
Toast.makeText(requireContext(), "Search: " + query, Toast.LENGTH_SHORT).show();
|
||||
filterArtists(query);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
artistAdapter.getFilter().filter(newText);
|
||||
return false;
|
||||
filterArtists(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setPadding(-32, 0, 0, 0);
|
||||
}
|
||||
|
||||
private void filterArtists(String query) {
|
||||
List<ArtistID3> allArtists = artistCatalogueViewModel.getArtistList().getValue();
|
||||
|
||||
if (allArtists == null || allArtists.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (query == null || query.trim().isEmpty()) {
|
||||
artistAdapter.setItems(allArtists);
|
||||
} else {
|
||||
String searchQuery = query.toLowerCase().trim();
|
||||
List<ArtistID3> filteredArtists = new ArrayList<>();
|
||||
|
||||
for (ArtistID3 artist : allArtists) {
|
||||
if (artist.getName() != null &&
|
||||
artist.getName().toLowerCase().contains(searchQuery)) {
|
||||
filteredArtists.add(artist);
|
||||
}
|
||||
}
|
||||
artistAdapter.setItems(filteredArtists);
|
||||
}
|
||||
}
|
||||
|
||||
private void hideKeyboard(View view) {
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
|
|
|
|||
12
app/src/main/res/menu/artist_list_menu.xml
Normal file
12
app/src/main/res/menu/artist_list_menu.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:title="@string/search_title_artist"
|
||||
android:icon="@drawable/ic_search"
|
||||
app:showAsAction="ifRoom|collapseActionView"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView" />
|
||||
|
||||
</menu>
|
||||
|
|
@ -90,6 +90,7 @@
|
|||
<string name="exo_download_notification_channel_name">Downloads</string>
|
||||
<string name="filter_info_selection">Select two or more filters</string>
|
||||
<string name="filter_title">Filter</string>
|
||||
<string name="filter_artist">Filter artists</string>
|
||||
<string name="filter_title_expanded">Filter Genres</string>
|
||||
<string name="generic_list_page_count">(%1$d)</string>
|
||||
<string name="generic_list_page_count_unknown">(+%1$d)</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue