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);
}
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);
}
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);
}
Aggregations