Search in sources :

Example 1 with PagerAdapter

use of com.simplecity.amp_library.ui.adapters.PagerAdapter in project Shuttle by timusus.

the class LibraryController method setupViewPager.

private void setupViewPager() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    CategoryItem.getCategoryItems(sharedPreferences);
    if (pagerAdapter != null && refreshPagerAdapter) {
        pagerAdapter.removeAllChildFragments();
        refreshPagerAdapter = false;
        pager.setAdapter(null);
    }
    int defaultPage = 1;
    pagerAdapter = new PagerAdapter(getChildFragmentManager());
    List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
    int defaultPageType = settingsManager.getDefaultPageType();
    for (int i = 0; i < categoryItems.size(); i++) {
        CategoryItem categoryItem = categoryItems.get(i);
        pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
        if (categoryItem.type == defaultPageType) {
            defaultPage = i;
        }
    }
    int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
    pager.setCurrentItem(currentPage);
    slidingTabLayout.setupWithViewPager(pager);
    pager.postDelayed(() -> {
        if (pager != null) {
            new RatingSnackbar(settingsManager, analyticsManager).show(pager, () -> {
                ShuttleUtils.openShuttleLink(getActivity(), getActivity().getPackageName(), getActivity().getPackageManager());
                return Unit.INSTANCE;
            });
        }
    }, 1000);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) NavigationEventRelay(com.simplecity.amp_library.ui.screens.drawer.NavigationEventRelay) Bundle(android.os.Bundle) PlaylistDetailFragment(com.simplecity.amp_library.ui.screens.playlist.detail.PlaylistDetailFragment) AlbumDetailFragment(com.simplecity.amp_library.ui.screens.album.detail.AlbumDetailFragment) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) CategoryItem(com.simplecity.amp_library.model.CategoryItem) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) BindView(butterknife.BindView) Aesthetic(com.afollestad.aesthetic.Aesthetic) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) Unbinder(butterknife.Unbinder) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CastManager(com.simplecity.amp_library.cast.CastManager) AlbumListFragment(com.simplecity.amp_library.ui.screens.album.list.AlbumListFragment) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseFragment(com.simplecity.amp_library.ui.common.BaseFragment) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Unit(kotlin.Unit) SearchFragment(com.simplecity.amp_library.ui.screens.search.SearchFragment) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) AppBarLayout(android.support.design.widget.AppBarLayout) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ButterKnife(butterknife.ButterKnife) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) ViewPager(android.support.v4.view.ViewPager) NonNull(android.support.annotation.NonNull) ArtistDetailFragment(com.simplecity.amp_library.ui.screens.artist.detail.ArtistDetailFragment) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) GenreDetailFragment(com.simplecity.amp_library.ui.screens.genre.detail.GenreDetailFragment) GenreListFragment(com.simplecity.amp_library.ui.screens.genre.list.GenreListFragment) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) CastButtonFactory(com.google.android.gms.cast.framework.CastButtonFactory) PlaylistListFragment(com.simplecity.amp_library.ui.screens.playlist.list.PlaylistListFragment) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) ToolbarListener(com.simplecity.amp_library.ui.common.ToolbarListener) SuggestedFragment(com.simplecity.amp_library.ui.screens.suggested.SuggestedFragment) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) AlbumArtistListFragment(com.simplecity.amp_library.ui.screens.artist.list.AlbumArtistListFragment) SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) CategoryItem(com.simplecity.amp_library.model.CategoryItem) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar)

Example 2 with PagerAdapter

use of com.simplecity.amp_library.ui.adapters.PagerAdapter in project Shuttle by timusus.

the class MainFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    boolean showGenres = prefs.getBoolean(SHOW_GENRES, true);
    boolean showSuggested = prefs.getBoolean(SHOW_SUGGESTED, true);
    boolean showArtists = prefs.getBoolean(SHOW_ARTISTS, true);
    boolean showAlbums = prefs.getBoolean(SHOW_ALBUMS, true);
    boolean showSongs = prefs.getBoolean(SHOW_SONGS, true);
    boolean showFolders = prefs.getBoolean(SHOW_FOLDERS, false);
    if (!ShuttleUtils.isUpgraded()) {
        showFolders = false;
    }
    boolean showPlaylists = prefs.getBoolean(SHOW_PLAYLISTS, false);
    int genresOrder = prefs.getInt(GENRES_ORDER, 0);
    int suggestedOrder = prefs.getInt(SUGGESTED_ORDER, 1);
    int artistsOrder = prefs.getInt(ARTISTS_ORDER, 2);
    int albumsOrder = prefs.getInt(ALBUMS_ORDER, 3);
    int songsOrder = prefs.getInt(SONGS_ORDER, 4);
    int foldersOrder = prefs.getInt(FOLDERS_ORDER, 5);
    int playlistsOrder = prefs.getInt(PLAYLISTS_ORDER, 6);
    adapter = new PagerAdapter(getChildFragmentManager());
    for (int i = 0; i < 8; i++) {
        if (genresOrder == i) {
            if (showGenres) {
                adapter.addFragment(GenreFragment.newInstance(getString(R.string.genres_title)));
            }
        } else if (suggestedOrder == i) {
            if (showSuggested) {
                adapter.addFragment(SuggestedFragment.newInstance(getString(R.string.suggested_title)));
            }
        } else if (artistsOrder == i) {
            if (showArtists) {
                adapter.addFragment(AlbumArtistFragment.newInstance(getString(R.string.artists_title)));
            }
        } else if (albumsOrder == i) {
            if (showAlbums) {
                adapter.addFragment(AlbumFragment.newInstance(getString(R.string.albums_title)));
            }
        } else if (songsOrder == i) {
            if (showSongs) {
                adapter.addFragment(SongFragment.newInstance(getString(R.string.tracks_title)));
            }
        } else if (foldersOrder == i) {
            if (showFolders) {
                adapter.addFragment(FolderFragment.newInstance(getString(R.string.folders_title)));
            }
        } else if (playlistsOrder == i) {
            if (showPlaylists) {
                adapter.addFragment(PlaylistFragment.newInstance(getString(R.string.playlists_title)));
            }
        }
    }
    defaultPage = 2;
    String defaultPage = prefs.getString("pref_default_page", null);
    for (int i = 0; i < adapter.getCount(); i++) {
        if (adapter.getPageTitle(i).equals(defaultPage)) {
            this.defaultPage = i;
        }
    }
    if (this.defaultPage > adapter.getCount()) {
        if (adapter.getCount() > 3) {
            this.defaultPage = 2;
        } else {
            this.defaultPage = 0;
        }
    }
    sharedPreferenceChangeListener = (sharedPreferences, key) -> {
        if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
            themeUIComponents();
        }
    };
    this.prefs.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
Also used : SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter)

Example 3 with PagerAdapter

use of com.simplecity.amp_library.ui.adapters.PagerAdapter in project Shuttle by timusus.

the class LibraryController method setupViewPager.

private void setupViewPager() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    CategoryItem.getCategoryItems(sharedPreferences);
    if (pagerAdapter != null && refreshPagerAdapter) {
        pagerAdapter.removeAllChildFragments();
        refreshPagerAdapter = false;
        pager.setAdapter(null);
    }
    int defaultPage = 1;
    pagerAdapter = new PagerAdapter(getChildFragmentManager());
    List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
    int defaultPageType = SettingsManager.getInstance().getDefaultPageType();
    for (int i = 0; i < categoryItems.size(); i++) {
        CategoryItem categoryItem = categoryItems.get(i);
        pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
        if (categoryItem.type == defaultPageType) {
            defaultPage = i;
        }
    }
    int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
    pager.setCurrentItem(currentPage);
    slidingTabLayout.setupWithViewPager(pager);
    pager.postDelayed(() -> {
        if (pager != null) {
            DialogUtils.showRateSnackbar(getActivity(), pager);
        }
    }, 1000);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) BaseDetailFragment(com.simplecity.amp_library.ui.detail.BaseDetailFragment) Bundle(android.os.Bundle) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) CategoryItem(com.simplecity.amp_library.model.CategoryItem) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) BindView(butterknife.BindView) Aesthetic(com.afollestad.aesthetic.Aesthetic) ToolbarListener(com.simplecity.amp_library.ui.activities.ToolbarListener) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) Unbinder(butterknife.Unbinder) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) GenreDetailFragment(com.simplecity.amp_library.ui.detail.GenreDetailFragment) 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) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) ArtistDetailFragment(com.simplecity.amp_library.ui.detail.ArtistDetailFragment) AppBarLayout(android.support.design.widget.AppBarLayout) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) ButterKnife(butterknife.ButterKnife) AlbumDetailFragment(com.simplecity.amp_library.ui.detail.AlbumDetailFragment) ViewPager(android.support.v4.view.ViewPager) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) SearchFragment(com.simplecity.amp_library.search.SearchFragment) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) PlaylistDetailFragment(com.simplecity.amp_library.ui.detail.PlaylistDetailFragment) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) CategoryItem(com.simplecity.amp_library.model.CategoryItem)

Aggregations

SharedPreferences (android.content.SharedPreferences)3 PagerAdapter (com.simplecity.amp_library.ui.adapters.PagerAdapter)3 IntentFilter (android.content.IntentFilter)2 Bundle (android.os.Bundle)2 PreferenceManager (android.preference.PreferenceManager)2 Nullable (android.support.annotation.Nullable)2 AppBarLayout (android.support.design.widget.AppBarLayout)2 TabLayout (android.support.design.widget.TabLayout)2 Pair (android.support.v4.util.Pair)2 ViewCompat (android.support.v4.view.ViewCompat)2 ViewPager (android.support.v4.view.ViewPager)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 Toolbar (android.support.v7.widget.Toolbar)2 Transition (android.transition.Transition)2 TransitionInflater (android.transition.TransitionInflater)2 LayoutInflater (android.view.LayoutInflater)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2