mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
fix: Fix issues with AlbumCatalogue
This commit is contained in:
parent
ae82bcd7bf
commit
c6d08d6a3f
3 changed files with 38 additions and 8 deletions
|
|
@ -23,6 +23,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAdapter.ViewHolder> implements Filterable {
|
public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAdapter.ViewHolder> implements Filterable {
|
||||||
private final ClickCallback click;
|
private final ClickCallback click;
|
||||||
|
private String currentFilter;
|
||||||
|
|
||||||
private final Filter filtering = new Filter() {
|
private final Filter filtering = new Filter() {
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
|
|
@ -32,6 +34,7 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
||||||
filteredList.addAll(albumsFull);
|
filteredList.addAll(albumsFull);
|
||||||
} else {
|
} else {
|
||||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||||
|
currentFilter = filterPattern;
|
||||||
|
|
||||||
for (AlbumID3 item : albumsFull) {
|
for (AlbumID3 item : albumsFull) {
|
||||||
if (item.getName().toLowerCase().contains(filterPattern)) {
|
if (item.getName().toLowerCase().contains(filterPattern)) {
|
||||||
|
|
@ -48,8 +51,7 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
albums.clear();
|
albums = (List) results.values;
|
||||||
albums.addAll((List) results.values);
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -60,6 +62,8 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
||||||
public AlbumCatalogueAdapter(ClickCallback click) {
|
public AlbumCatalogueAdapter(ClickCallback click) {
|
||||||
this.click = click;
|
this.click = click;
|
||||||
this.albums = Collections.emptyList();
|
this.albums = Collections.emptyList();
|
||||||
|
this.albumsFull = Collections.emptyList();
|
||||||
|
this.currentFilter = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -92,9 +96,8 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(List<AlbumID3> albums) {
|
public void setItems(List<AlbumID3> albums) {
|
||||||
this.albums = albums;
|
|
||||||
this.albumsFull = new ArrayList<>(albums);
|
this.albumsFull = new ArrayList<>(albums);
|
||||||
notifyDataSetChanged();
|
filtering.filter(currentFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,12 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
|
||||||
initData();
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
albumCatalogueViewModel.stopLoading();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
activity = (MainActivity) getActivity();
|
activity = (MainActivity) getActivity();
|
||||||
|
|
@ -73,7 +79,7 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
|
||||||
|
|
||||||
private void initData() {
|
private void initData() {
|
||||||
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
||||||
albumCatalogueViewModel.loadAlbums(500);
|
albumCatalogueViewModel.loadAlbums();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.cappielloantonio.tempo.viewmodel;
|
package com.cappielloantonio.tempo.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
|
@ -22,6 +23,7 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
private final MutableLiveData<List<AlbumID3>> albumList = new MutableLiveData<>(new ArrayList<>());
|
private final MutableLiveData<List<AlbumID3>> albumList = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
private int page = 0;
|
private int page = 0;
|
||||||
|
private Status status = Status.STOPPED;
|
||||||
|
|
||||||
public AlbumCatalogueViewModel(@NonNull Application application) {
|
public AlbumCatalogueViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -31,7 +33,19 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
return albumList;
|
return albumList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadAlbums(int size) {
|
public void loadAlbums() {
|
||||||
|
page = 0;
|
||||||
|
albumList.setValue(new ArrayList<>());
|
||||||
|
albumList.setValue(new ArrayList<>());
|
||||||
|
status = Status.RUNNING;
|
||||||
|
loadAlbums(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopLoading() {
|
||||||
|
status = Status.STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAlbums(int size) {
|
||||||
retrieveAlbums(new MediaCallback() {
|
retrieveAlbums(new MediaCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception exception) {
|
public void onError(Exception exception) {
|
||||||
|
|
@ -39,9 +53,11 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
List<AlbumID3> liveAlbum = albumList.getValue();
|
if (status == Status.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (liveAlbum == null) liveAlbum = new ArrayList<>();
|
List<AlbumID3> liveAlbum = albumList.getValue();
|
||||||
|
|
||||||
liveAlbum.addAll((List<AlbumID3>) media);
|
liveAlbum.addAll((List<AlbumID3>) media);
|
||||||
albumList.setValue(liveAlbum);
|
albumList.setValue(liveAlbum);
|
||||||
|
|
@ -73,4 +89,9 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Status {
|
||||||
|
RUNNING,
|
||||||
|
STOPPED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue