use of com.simplecity.amp_library.ui.modelviews.ShuffleView in project Shuttle by timusus.
the class AlbumFragment method onCreateView.
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (recyclerView == null) {
int spanCount = SettingsManager.getInstance().getAlbumColumnCount(getResources());
layoutManager = new GridLayoutManager(getContext(), spanCount);
spanSizeLookup = new SpanSizeLookup(adapter, spanCount);
spanSizeLookup.setSpanIndexCacheEnabled(true);
layoutManager.setSpanSizeLookup(spanSizeLookup);
recyclerView = (FastScrollRecyclerView) inflater.inflate(R.layout.fragment_recycler, container, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new GridDividerDecoration(getResources(), 4, true));
recyclerView.setRecyclerListener(new RecyclerListener());
}
if (recyclerView.getAdapter() != adapter) {
recyclerView.setAdapter(adapter);
}
shuffleView = new ShuffleView();
shuffleView.setTitleResId(R.string.shuffle_albums);
shuffleView.setClickListener(this);
return recyclerView;
}
use of com.simplecity.amp_library.ui.modelviews.ShuffleView in project Shuttle by timusus.
the class AlbumFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
boolean ascending = SortManager.getInstance().getAlbumsAscending();
subscription = DataManager.getInstance().getAlbumsRelay().skipWhile(albums -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView).count() == albums.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(albums -> {
// Sort
SortManager.getInstance().sortAlbums(albums);
// Reverse if required
if (!ascending) {
Collections.reverse(albums);
}
return Observable.fromIterable(albums).map(album -> {
// Look for an existing AlbumView wrapping the album, we'll reuse it if it exists.
AlbumView albumView = (AlbumView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof AlbumView && (((AlbumView) viewModel).album.equals(album))).findFirst().orElse(null);
if (albumView == null) {
albumView = new AlbumView(album, albumDisplayType, requestManager);
albumView.setClickListener(this);
}
return (ViewModel) albumView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_albums)));
} else {
items.add(0, shuffleView);
adapter.setItems(items);
}
// Move the RV back to the top if we've had a sort order change.
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
}, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
}
});
}
use of com.simplecity.amp_library.ui.modelviews.ShuffleView in project Shuttle by timusus.
the class SongFragment method onCreate.
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
setHasOptionsMenu(true);
adapter = new SectionedAdapter();
shuffleView = new ShuffleView();
shuffleView.setClickListener(this);
}
use of com.simplecity.amp_library.ui.modelviews.ShuffleView in project Shuttle by timusus.
the class SongFragment method refreshAdapterItems.
void refreshAdapterItems(boolean force) {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
boolean ascending = SortManager.getInstance().getSongsAscending();
disposable = DataManager.getInstance().getSongsRelay().skipWhile(songs -> !force && Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView).count() == songs.size()).debounce(150, TimeUnit.MILLISECONDS).flatMapSingle(songs -> {
// Sort
SortManager.getInstance().sortSongs(songs);
// Reverse if required
if (!ascending) {
Collections.reverse(songs);
}
return Observable.fromIterable(songs).map(song -> {
// Look for an existing SongView wrapping the song, we'll reuse it if it exists.
SongView songView = (SongView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof SongView && (((SongView) viewModel).song.equals(song))).findFirst().orElse(null);
if (songView == null) {
songView = new SongView(song, null);
songView.setClickListener(this);
}
return (ViewModel) songView;
}).toList();
}).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
if (items.isEmpty()) {
adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_songlist)));
} else {
items.add(0, shuffleView);
adapter.setItems(items);
}
// Move the RV back to the top if we've had a sort order change.
if (sortOrderChanged) {
recyclerView.scrollToPosition(0);
}
sortOrderChanged = false;
}, error -> LogUtils.logException(TAG, "Error refreshing adapter items", error));
}
});
}
Aggregations