display list of genres on main activity
This commit is contained in:
parent
96ded5b957
commit
fb43666488
7 changed files with 54 additions and 51 deletions
|
|
@ -91,7 +91,7 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
|
|||
@Override
|
||||
public String getSectionName(int position) {
|
||||
final Genre genre = dataSet.get(position);
|
||||
return genre.id == -1 ? "" : MusicUtil.getSectionName(dataSet.get(position).name);
|
||||
return genre.id.hashCode() == -1 ? "" : MusicUtil.getSectionName(dataSet.get(position).name);
|
||||
}
|
||||
|
||||
public class ViewHolder extends MediaEntryViewHolder {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,21 @@ package com.kabouzeid.gramophone.model;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
||||
public class Genre implements Parcelable {
|
||||
public final int id;
|
||||
public final String id;
|
||||
public final String name;
|
||||
public final int songCount;
|
||||
|
||||
public Genre(BaseItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.songCount = itemDto.getSongCount() != null ? itemDto.getSongCount() : 0;
|
||||
}
|
||||
|
||||
public Genre(final int id, final String name, final int songCount) {
|
||||
this.id = id;
|
||||
this.id = Integer.toString(id);
|
||||
this.name = name;
|
||||
this.songCount = songCount;
|
||||
}
|
||||
|
|
@ -28,12 +36,12 @@ public class Genre implements Parcelable {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -43,13 +51,13 @@ public class Genre implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.id);
|
||||
dest.writeString(this.id);
|
||||
dest.writeString(this.name);
|
||||
dest.writeInt(this.songCount);
|
||||
}
|
||||
|
||||
protected Genre(Parcel in) {
|
||||
this.id = in.readInt();
|
||||
this.id = in.readString();
|
||||
this.name = in.readString();
|
||||
this.songCount = in.readInt();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ public class GenreDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
|
||||
@Override
|
||||
public List<Song> loadInBackground() {
|
||||
return GenreLoader.getSongs(getContext(), genre.id);
|
||||
return GenreLoader.getSongs(getContext(), genre.id.hashCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,9 +153,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity {
|
|||
libraries = (List<BaseItemDto>) media;
|
||||
menu.clear();
|
||||
|
||||
menu.add(R.id.navigation_drawer_menu_category_sections, R.id.nav_library, menu.size(), R.string.all);
|
||||
menu.getItem(0).setIcon(R.drawable.ic_library_music_white_24dp);
|
||||
|
||||
for (BaseItemDto itemDto : libraries) {
|
||||
if (itemDto.getCollectionType() == null || !itemDto.getCollectionType().equals("music")) continue;
|
||||
menu.add(R.id.navigation_drawer_menu_category_sections, itemDto.getId().hashCode(), menu.size(), itemDto.getName());
|
||||
|
|
|
|||
|
|
@ -1,30 +1,22 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivity.library.pager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.GenreAdapter;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.loader.GenreLoader;
|
||||
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
|
||||
import com.kabouzeid.gramophone.interfaces.MediaCallback;
|
||||
import com.kabouzeid.gramophone.model.Genre;
|
||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenresFragment extends AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager> implements LoaderManager.LoaderCallbacks<List<Genre>> {
|
||||
|
||||
private static final int LOADER_ID = LoaderIds.GENRES_FRAGMENT;
|
||||
|
||||
public class GenresFragment extends AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager> {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getLoaderManager().initLoader(LOADER_ID, null, this);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -39,6 +31,14 @@ public class GenresFragment extends AbsLibraryPagerRecyclerViewFragment<GenreAda
|
|||
List<Genre> dataSet = getAdapter() == null ? new ArrayList<>() : getAdapter().getDataSet();
|
||||
|
||||
GenreAdapter adapter = new GenreAdapter(getLibraryFragment().getMainActivity(), dataSet, R.layout.item_list_no_image);
|
||||
QueryUtil.getGenres(new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
dataSet.addAll((List<Genre>) media);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
|
@ -49,33 +49,5 @@ public class GenresFragment extends AbsLibraryPagerRecyclerViewFragment<GenreAda
|
|||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
getLoaderManager().restartLoader(LOADER_ID, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Loader<List<Genre>> onCreateLoader(int id, Bundle args) {
|
||||
return new GenresFragment.AsyncGenreLoader(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(@NonNull Loader<List<Genre>> loader, List<Genre> data) {
|
||||
getAdapter().swapDataSet(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(@NonNull Loader<List<Genre>> loader) {
|
||||
getAdapter().swapDataSet(new ArrayList<>());
|
||||
}
|
||||
|
||||
private static class AsyncGenreLoader extends WrappedAsyncTaskLoader<List<Genre>> {
|
||||
public AsyncGenreLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Genre> loadInBackground() {
|
||||
return GenreLoader.getAllGenres(getContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import com.kabouzeid.gramophone.App;
|
|||
import com.kabouzeid.gramophone.interfaces.MediaCallback;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.Genre;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
import org.jellyfin.apiclient.model.querying.ArtistsQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemsByNameQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemsResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -37,6 +39,30 @@ public class QueryUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void getGenres(MediaCallback callback) {
|
||||
ItemsByNameQuery query = new ItemsByNameQuery();
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
query.setLimit(100);
|
||||
query.setRecursive(true);
|
||||
if (currentLibrary != null && query.getParentId() == null) query.setParentId(currentLibrary.getId());
|
||||
App.getApiClient().GetGenresAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
List<Genre> genres = new ArrayList<>();
|
||||
for (BaseItemDto itemDto : result.getItems()) {
|
||||
genres.add(new Genre(itemDto));
|
||||
}
|
||||
|
||||
callback.onLoadMedia(genres);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getAlbums(ItemQuery query, MediaCallback callback) {
|
||||
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<item
|
||||
android:id="@+id/nav_library"
|
||||
android:icon="@drawable/ic_library_music_white_24dp"
|
||||
android:title="@string/library" />
|
||||
android:title="@string/all" />
|
||||
</group>
|
||||
|
||||
<group
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue