use of androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback in project Hentoid by avluis.
the class LibraryActivity method initUI.
/**
* Initialize the UI components
*/
private void initUI() {
// Permissions alert bar
alertTxt = findViewById(R.id.library_alert_txt);
alertIcon = findViewById(R.id.library_alert_icon);
alertFixBtn = findViewById(R.id.library_alert_fix_btn);
// Search bar
searchSortBar = findViewById(R.id.advanced_search_background);
// "Group by" menu
View groupByButton = findViewById(R.id.group_by_btn);
groupByButton.setOnClickListener(this::onGroupByButtonClick);
// Link to advanced search
advancedSearchButton = findViewById(R.id.advanced_search_btn);
advancedSearchButton.setOnClickListener(v -> onAdvancedSearchButtonClick());
// "Show artists/groups" menu (group tab only when Grouping.ARTIST is on)
showArtistsGroupsButton = findViewById(R.id.groups_visibility_btn);
showArtistsGroupsButton.setText(getArtistsGroupsTextFromPrefs());
showArtistsGroupsButton.setOnClickListener(this::onGroupsVisibilityButtonClick);
// Clear search
searchClearButton = findViewById(R.id.search_clear_btn);
searchClearButton.setOnClickListener(v -> {
query = "";
metadata.clear();
actionSearchView.setQuery("", false);
hideSearchSortBar(false);
signalCurrentFragment(EV_SEARCH, "");
});
// Sort controls
sortDirectionButton = findViewById(R.id.sort_direction_btn);
sortReshuffleButton = findViewById(R.id.sort_reshuffle_btn);
sortFieldButton = findViewById(R.id.sort_field_btn);
// Main tabs
viewPager = findViewById(R.id.library_pager);
// Disable swipe to change tabs
viewPager.setUserInputEnabled(false);
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
enableCurrentFragment();
hideSearchSortBar(false);
updateToolbar();
updateSelectionToolbar(0, 0, 0, 0);
}
});
viewPager.setAdapter(pagerAdapter);
updateDisplay();
}
use of androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback in project Stundenplaner.FHE_EAH by avinotec.
the class NavigationDialogView method initializeView.
public void initializeView(@NonNull final FragmentManager _Manager, @NonNull final Lifecycle _Lifecycle) {
// set up tab layout
final TabLayout tabLayout = findViewById(R.id.tablayout_navigation_dialog);
final ViewPager2 viewPager = findViewById(R.id.viewpager_navigation_dialog);
viewPager.setAdapter(new NavigationDialogPagerAdapter(_Manager, _Lifecycle));
tabLayout.addTab(tabLayout.newTab().setText(R.string.tablayout_tabtext_roomsearch));
// todo: person search
tabLayout.addTab(tabLayout.newTab().setText(R.string.tablayout_tabtext_personsearch));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(final TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(final TabLayout.Tab tab) {
}
@Override
public void onTabReselected(final TabLayout.Tab tab) {
}
});
viewPager.registerOnPageChangeCallback(new OnPageChangeCallback() {
@Override
public void onPageSelected(final int position) {
tabLayout.selectTab(tabLayout.getTabAt(position));
}
});
}
use of androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback in project android-sdk-widgets by salemove.
the class AuthorizationFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
int item = sharedPreferences.getInt(getString(R.string.pref_authorization_type), AuthorizationType.DEFAULT);
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
sharedPreferences.edit().putInt(getString(R.string.pref_authorization_type), authorizationPages.get(position).getAuthType()).apply();
}
});
viewPager.post(() -> viewPager.setCurrentItem(item, false));
}
use of androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback in project Infinity-For-Reddit by Docile-Alligator.
the class MainActivity method bindView.
private void bindView() {
if (isDestroyed()) {
return;
}
if (showBottomAppBar) {
int optionCount = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4);
int option1 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS);
int option2 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS);
bottomAppBar.setVisibility(View.VISIBLE);
if (optionCount == 2) {
linearLayoutBottomAppBar.setWeightSum(3);
option1BottomAppBar.setVisibility(View.GONE);
option3BottomAppBar.setVisibility(View.GONE);
option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1));
option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));
option2BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option1);
});
option4BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option2);
});
} else {
int option3 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_REFRESH : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX);
int option4 = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, mAccessToken == null ? SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_CHANGE_SORT_TYPE : SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE);
option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1));
option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));
option3BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option3));
option4BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option4));
option1BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option1);
});
option2BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option2);
});
option3BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option3);
});
option4BottomAppBar.setOnClickListener(view -> {
bottomAppBarOptionAction(option4);
});
}
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.setAnchorId(View.NO_ID);
lp.gravity = Gravity.END | Gravity.BOTTOM;
fab.setLayoutParams(lp);
}
fabOption = mBottomAppBarSharedPreference.getInt((mAccessToken == null ? "-" : "") + SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
switch(fabOption) {
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH:
fab.setImageResource(R.drawable.ic_refresh_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE:
fab.setImageResource(R.drawable.ic_sort_toolbar_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT:
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER:
fab.setImageResource(R.drawable.ic_user_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM:
fab.setImageResource(R.drawable.ic_random_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_hide_read_posts_24dp);
}
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
fab.setImageResource(R.drawable.ic_filter_24dp);
break;
default:
if (mAccessToken == null) {
fab.setImageResource(R.drawable.ic_filter_24dp);
fabOption = SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS;
} else {
fab.setImageResource(R.drawable.ic_add_day_night_24dp);
}
break;
}
fab.setOnClickListener(view -> {
switch(fabOption) {
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH:
{
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.refresh();
}
break;
}
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE:
{
changeSortType();
break;
}
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT:
{
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
break;
}
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH:
{
Intent intent = new Intent(this, SearchActivity.class);
startActivity(intent);
break;
}
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
goToSubreddit();
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_USER:
goToUser();
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_RANDOM:
randomThing();
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.hideReadPosts();
}
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_FILTER_POSTS:
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.filterPosts();
}
break;
default:
PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
break;
}
});
fab.setOnLongClickListener(view -> {
FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null);
fabMoreOptionsBottomSheetFragment.setArguments(bundle);
fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
return true;
});
fab.setVisibility(View.VISIBLE);
adapter = new NavigationDrawerRecyclerViewMergedAdapter(this, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mNavigationDrawerSharedPreferences, mCustomThemeWrapper, mAccountName, new NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener() {
@Override
public void onMenuClick(int stringId) {
Intent intent = null;
if (stringId == R.string.profile) {
intent = new Intent(MainActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
} else if (stringId == R.string.subscriptions) {
if (mAccessToken != null) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
} else {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
}
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
} else if (stringId == R.string.rpan) {
intent = new Intent(MainActivity.this, RPANActivity.class);
} else if (stringId == R.string.trending) {
intent = new Intent(MainActivity.this, TrendingActivity.class);
} else if (stringId == R.string.upvoted) {
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_UPVOTED);
} else if (stringId == R.string.downvoted) {
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_DOWNVOTED);
} else if (stringId == R.string.hidden) {
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_HIDDEN);
} else if (stringId == R.string.account_saved_thing_activity_label) {
intent = new Intent(MainActivity.this, AccountSavedThingActivity.class);
} else if (stringId == R.string.gilded) {
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_GILDED);
} else if (stringId == R.string.light_theme) {
mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "0").apply();
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT);
} else if (stringId == R.string.dark_theme) {
mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "1").apply();
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED);
} else {
mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK);
}
} else if (stringId == R.string.enable_nsfw) {
if (sectionsPagerAdapter != null) {
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, true).apply();
sectionsPagerAdapter.changeNSFW(true);
}
} else if (stringId == R.string.disable_nsfw) {
if (sectionsPagerAdapter != null) {
mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false).apply();
sectionsPagerAdapter.changeNSFW(false);
}
} else if (stringId == R.string.settings) {
intent = new Intent(MainActivity.this, SettingsActivity.class);
} else if (stringId == R.string.add_account) {
Intent addAccountIntent = new Intent(MainActivity.this, LoginActivity.class);
startActivityForResult(addAccountIntent, LOGIN_ACTIVITY_REQUEST_CODE);
} else if (stringId == R.string.anonymous_account) {
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences, mExecutor, new Handler(), false, () -> {
Intent anonymousIntent = new Intent(MainActivity.this, MainActivity.class);
startActivity(anonymousIntent);
finish();
});
} else if (stringId == R.string.log_out) {
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences, mExecutor, new Handler(), true, () -> {
Intent logOutIntent = new Intent(MainActivity.this, MainActivity.class);
startActivity(logOutIntent);
finish();
});
}
if (intent != null) {
startActivity(intent);
}
drawer.closeDrawers();
}
@Override
public void onSubscribedSubredditClick(String subredditName) {
Intent intent = new Intent(MainActivity.this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
startActivity(intent);
}
@Override
public void onAccountClick(String accountName) {
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences, mExecutor, new Handler(), accountName, newAccount -> {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
finish();
});
}
});
adapter.setInboxCount(inboxCount);
navDrawerRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
navDrawerRecyclerView.setAdapter(adapter.getConcatAdapter());
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3);
mShowFavoriteMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false);
mShowMultiReddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false);
mShowFavoriteSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false);
mShowSubscribedSubreddits = mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false);
sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits, mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(1);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
} else {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch(position) {
case 0:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)));
break;
case 1:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)));
break;
case 2:
Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
break;
}
if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) && sectionsPagerAdapter != null) {
if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) {
Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName());
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) {
Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.multiReddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()).getName());
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) {
Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size()).getName());
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) {
Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName());
}
}
}).attach();
} else {
tabLayout.setVisibility(View.GONE);
}
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
if (mAccessToken != null) {
if (showBottomAppBar) {
bottomAppBar.performShow();
}
}
fab.show();
sectionsPagerAdapter.displaySortTypeInToolbar();
}
});
fixViewPager2Sensitivity(viewPager2);
loadSubscriptions();
multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)).get(MultiRedditViewModel.class);
multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> {
if (mShowFavoriteMultiReddits && sectionsPagerAdapter != null) {
sectionsPagerAdapter.setFavoriteMultiReddits(multiReddits);
}
});
multiRedditViewModel.getAllMultiReddits().observe(this, multiReddits -> {
if (mShowMultiReddits && sectionsPagerAdapter != null) {
sectionsPagerAdapter.setMultiReddits(multiReddits);
}
});
subscribedSubredditViewModel = new ViewModelProvider(this, new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)).get(SubscribedSubredditViewModel.class);
subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> {
adapter.setSubscribedSubreddits(subscribedSubredditData);
if (mShowSubscribedSubreddits && sectionsPagerAdapter != null) {
sectionsPagerAdapter.setSubscribedSubreddits(subscribedSubredditData);
}
});
subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> {
adapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
if (mShowFavoriteSubscribedSubreddits && sectionsPagerAdapter != null) {
sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
}
});
accountViewModel = new ViewModelProvider(this, new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
accountViewModel.getAccountsExceptCurrentAccountLiveData().observe(this, adapter::changeAccountsDataset);
accountViewModel.getCurrentAccountLiveData().observe(this, account -> {
if (account != null) {
adapter.updateAccountInfo(account.getProfileImageUrl(), account.getBannerImageUrl(), account.getKarma());
}
});
loadUserData();
if (mAccessToken != null) {
if (mMessageFullname != null) {
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
@Override
public void readSuccess() {
mMessageFullname = null;
}
@Override
public void readFailed() {
}
});
}
}
}
use of androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback in project edx-app-android by openedx.
the class WhatsNewFragment method initViewPager.
private void initViewPager() {
try {
final String whatsNewJson = FileUtil.loadTextFileFromResources(getContext(), R.raw.whats_new);
final Type type = new TypeToken<List<WhatsNewModel>>() {
}.getType();
final List<WhatsNewModel> whatsNewModels = new Gson().fromJson(whatsNewJson, type);
final List<WhatsNewItemModel> items = WhatsNewUtil.getWhatsNewItems(BuildConfig.VERSION_NAME, whatsNewModels);
if (items == null) {
getActivity().finish();
return;
}
noOfPages = items.size();
binding.viewPager2.setAdapter(new WhatsNewAdapter(this.getActivity(), items));
binding.viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
indicatorController.selectPosition(position);
if (position == noOfPages - 1) {
binding.doneBtn.setVisibility(View.VISIBLE);
} else {
binding.doneBtn.setVisibility(View.GONE);
}
final int pageNumber = position + 1;
if (pageNumber >= totalPagesViewed) {
totalPagesViewed = pageNumber;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
// Enforce to intercept single scrolling direction
UiUtils.INSTANCE.enforceSingleScrollDirection(binding.viewPager2);
} catch (IOException e) {
// Submit crash report and end the activity
logger.error(e, true);
getActivity().finish();
}
}
Aggregations