Added the ability to sort items in the genre catalogue

This commit is contained in:
antonio 2022-03-24 22:22:15 +01:00
parent e6b997bc35
commit 3eee78ad4e
5 changed files with 73 additions and 4 deletions

View file

@ -13,11 +13,14 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.MusicUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAdapter.ViewHolder> implements Filterable {
@ -129,4 +132,17 @@ public class GenreCatalogueAdapter extends RecyclerView.Adapter<GenreCatalogueAd
}
}
}
public void sort(String order) {
switch (order) {
case Genre.ORDER_BY_NAME:
genres.sort(Comparator.comparing(Genre::getName));
break;
case Genre.ORDER_BY_RANDOM:
Collections.shuffle(genres);
break;
}
notifyDataSetChanged();
}
}