Search in sources :

Example 6 with EmptyView

use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.

the class SuggestedFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (recyclerView == null) {
        recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_suggested, container, false);
        recyclerView.addItemDecoration(new SuggestedDividerDecoration(getResources()));
        recyclerView.setRecyclerListener(new RecyclerListener());
        int spanCount = ShuttleUtils.isTablet() ? 12 : 6;
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), spanCount);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                if (!adapter.items.isEmpty() && position >= 0) {
                    ViewModel item = adapter.items.get(position);
                    if (item instanceof HorizontalRecyclerView || item instanceof SuggestedHeaderView || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST) || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST_SMALL) || item instanceof EmptyView) {
                        return spanCount;
                    }
                    if (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_CARD_LARGE) {
                        return 3;
                    }
                }
                return 2;
            }
        });
        recyclerView.setLayoutManager(gridLayoutManager);
    }
    if (recyclerView.getAdapter() != adapter) {
        recyclerView.setAdapter(adapter);
    }
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)

Example 7 with EmptyView

use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.

the class SearchFragment method onCreate.

@SuppressLint("InlinedApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    searchPresenter = new SearchPresenter(new PrefixHighlighter(), Glide.with(this));
    query = getArguments().getString(ARG_QUERY);
    loadingView = new LoadingView();
    emptyView = new EmptyView(R.string.empty_search);
    emptyView.setHeight(ResourceUtils.toPixels(96));
    adapter = new ViewModelAdapter();
}
Also used : PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) LoadingView(com.simplecity.amp_library.ui.modelviews.LoadingView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) SuppressLint(android.annotation.SuppressLint)

Example 8 with EmptyView

use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.

the class DialogUtils method showWhitelistDialog.

public static void showWhitelistDialog(final Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
    final MaterialDialog.Builder builder = getBuilder(context).title(R.string.whitelist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_whitelist).onNegative((materialDialog, dialogAction) -> {
        WhitelistHelper.deleteAllFolders();
        Toast.makeText(context, R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
    });
    final Dialog dialog = builder.build();
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    final WhitelistAdapter whitelistadapter = new WhitelistAdapter();
    whitelistadapter.setWhitelistListener((v, position, songWhitelist) -> {
        WhitelistHelper.deleteFolder(songWhitelist);
        whitelistadapter.removeItem(position);
        if (whitelistadapter.items.size() == 0) {
            dialog.dismiss();
        }
    });
    recyclerView.setAdapter(whitelistadapter);
    Subscription subscription = WhitelistHelper.getWhitelistFolders().map(whitelistFolders -> Stream.of(whitelistFolders).map(folder -> (AdaptableItem) new WhitelistView(folder)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(whitelistViews -> {
        if (whitelistViews.size() == 0) {
            whitelistadapter.addItem(0, new EmptyView(R.string.whitelist_empty));
        } else {
            whitelistadapter.setItems(whitelistViews);
        }
    });
    dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
    dialog.show();
}
Also used : WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Subscription(rx.Subscription) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 9 with EmptyView

use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.

the class SuggestedFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            subscription = new CompositeSubscription();
            Observable<Playlist> mostPlayedPlaylistObservable = Observable.fromCallable(Playlist::mostPlayedPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> mostPlayedSongsObservable = mostPlayedPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> mostPlayedItemsObservable = mostPlayedPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader mostPlayedHeader = new SuggestedHeader(getString(R.string.mostplayed), getString(R.string.suggested_most_played_songs_subtitle), playlist);
                SuggestedHeaderView mostPlayedHeaderView = new SuggestedHeaderView(mostPlayedHeader);
                return mostPlayedSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(mostPlayedHeaderView);
                        items.add(mostPlayedRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyPlayedAlbums = Observable.fromCallable(Playlist::recentlyPlayedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyPlayedHeader = new SuggestedHeader(getString(R.string.suggested_recent_title), getString(R.string.suggested_recent_subtitle), playlist);
                SuggestedHeaderView recentlyPlayedHeaderView = new SuggestedHeaderView(recentlyPlayedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).limit(6).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyPlayedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<Playlist> favouritesPlaylistObservable = Observable.fromCallable(Playlist::favoritesPlaylist).subscribeOn(Schedulers.io()).cache();
            Observable<List<Song>> favouritesSongsObservable = favouritesPlaylistObservable.filter(playlist -> playlist != null).flatMap(playlist -> playlist.getSongsObservable(getContext())).cache();
            Observable<List<AdaptableItem>> favoriteSongsItemsObservable = favouritesPlaylistObservable.flatMap(playlist -> {
                SuggestedHeader favoriteHeader = new SuggestedHeader(getString(R.string.fav_title), getString(R.string.suggested_favorite_subtitle), playlist);
                SuggestedHeaderView favoriteHeaderView = new SuggestedHeaderView(favoriteHeader);
                return favouritesSongsObservable.map(songs -> {
                    List<AdaptableItem> items = new ArrayList<>();
                    if (!songs.isEmpty()) {
                        items.add(favoriteHeaderView);
                        items.add(favoriteRecyclerView);
                    }
                    return items;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable<List<AdaptableItem>> recentlyAddedAlbums = Observable.fromCallable(Playlist::recentlyAddedPlaylist).subscribeOn(Schedulers.io()).filter(playlist -> playlist != null).flatMap(playlist -> {
                SuggestedHeader recentlyAddedHeader = new SuggestedHeader(getString(R.string.recentlyadded), getString(R.string.suggested_recently_added_subtitle), playlist);
                SuggestedHeaderView recentlyAddedHeaderView = new SuggestedHeaderView(recentlyAddedHeader);
                return playlist.getSongsObservable(getContext()).flatMap(songs -> Observable.just(Operators.songsToAlbums(songs))).flatMap(Observable::from).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).limit(4).flatMap(album -> album.getSongsObservable().map(songs -> {
                    album.numSongs = songs.size();
                    return album;
                })).sorted((a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded)).filter(album -> album.numSongs > 0).map(album -> (AdaptableItem) new AlbumView(album, ViewType.ALBUM_LIST_SMALL, requestManager)).toList().map(adaptableItems -> {
                    if (!adaptableItems.isEmpty()) {
                        adaptableItems.add(0, recentlyAddedHeaderView);
                    }
                    return adaptableItems;
                });
            }).switchIfEmpty(Observable.just(Collections.emptyList()));
            Observable.merge(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums);
            subscription.add(Observable.combineLatest(mostPlayedItemsObservable, recentlyPlayedAlbums, favoriteSongsItemsObservable, recentlyAddedAlbums, (mostPlayedSongs1, recentlyPlayedAlbums1, favoriteSongs1, recentlyAddedAlbums1) -> {
                List<AdaptableItem> items = new ArrayList<>();
                items.addAll(mostPlayedSongs1);
                items.addAll(recentlyPlayedAlbums1);
                items.addAll(favoriteSongs1);
                items.addAll(recentlyAddedAlbums1);
                return items;
            }).debounce(250, TimeUnit.MILLISECONDS).switchIfEmpty(Observable.just(new ArrayList<>())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                if (adaptableItems.isEmpty()) {
                    suggestedAdapter.setEmpty(new EmptyView(R.string.empty_suggested));
                } else {
                    suggestedAdapter.setItems(adaptableItems);
                }
            }));
            subscription.add(mostPlayedSongsObservable.map(songs -> {
                Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(b.playCount, a.playCount));
                return Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList());
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                mostPlayedRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
            subscription.add(favouritesSongsObservable.map(songs -> Stream.of(songs).map(song -> (AdaptableItem) new SuggestedSongView(song, requestManager)).limit(20).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
                favoriteRecyclerView.itemAdapter.setItems(adaptableItems);
            }));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Context(android.content.Context) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) Intent(android.content.Intent) ArrayList(java.util.ArrayList) Observable(rx.Observable) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) SuggestedAdapter(com.simplecity.amp_library.ui.adapters.SuggestedAdapter) Toast(android.widget.Toast) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) SuggestedSongView(com.simplecity.amp_library.ui.modelviews.SuggestedSongView) Playlist(com.simplecity.amp_library.model.Playlist) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) CompositeSubscription(rx.subscriptions.CompositeSubscription) List(java.util.List) ArrayList(java.util.ArrayList) SuggestedHeader(com.simplecity.amp_library.model.SuggestedHeader) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 10 with EmptyView

use of com.simplecity.amp_library.ui.modelviews.EmptyView in project Shuttle by timusus.

the class AlbumFragment method refreshAdapterItems.

void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            int albumDisplayType = SettingsManager.getInstance().getAlbumDisplayType();
            boolean ascending = SortManager.getInstance().getAlbumsAscending();
            subscription = DataManager.getInstance().getAlbumsRelay().flatMap(albums -> {
                SortManager.getInstance().sortAlbums(albums);
                if (!ascending) {
                    Collections.reverse(albums);
                }
                return Observable.from(albums).map(album -> (AdaptableItem) new AlbumView(album, albumDisplayType, requestManager, multiSelector)).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    albumAdapter.setEmpty(new EmptyView(R.string.empty_albums));
                } else {
                    albumAdapter.setItems(items);
                }
                if (sortOrderChanged) {
                    recyclerView.scrollToPosition(0);
                }
                sortOrderChanged = false;
            });
        }
    });
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Observable(rx.Observable) SuppressLint(android.annotation.SuppressLint) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) RecyclerView(android.support.v7.widget.RecyclerView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) GridDividerDecoration(com.simplecity.amp_library.ui.recyclerview.GridDividerDecoration) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) DataManager(com.simplecity.amp_library.utils.DataManager) Collections(java.util.Collections) AlbumAdapter(com.simplecity.amp_library.ui.adapters.AlbumAdapter) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint)

Aggregations

EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)12 View (android.view.View)10 LayoutInflater (android.view.LayoutInflater)9 Stream (com.annimon.stream.Stream)9 R (com.simplecity.amp_library.R)9 Context (android.content.Context)8 Collections (java.util.Collections)8 Bundle (android.os.Bundle)7 PopupMenu (android.support.v7.widget.PopupMenu)7 ViewGroup (android.view.ViewGroup)7 DataManager (com.simplecity.amp_library.utils.DataManager)7 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)7 PermissionUtils (com.simplecity.amp_library.utils.PermissionUtils)7 List (java.util.List)7 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 RecyclerView (android.support.v7.widget.RecyclerView)6 Toast (android.widget.Toast)6 TimeUnit (java.util.concurrent.TimeUnit)6 Menu (android.view.Menu)5