use of androidx.fragment.app.FragmentManager in project AntennaPod by AntennaPod.
the class MainActivity method loadFragment.
private void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
// clear back stack
for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) {
fragmentManager.popBackStack();
}
FragmentTransaction t = fragmentManager.beginTransaction();
t.replace(R.id.main_view, fragment, MAIN_FRAGMENT_TAG);
fragmentManager.popBackStack();
// TODO: we have to allow state loss here
// since this function can get called from an AsyncTask which
// could be finishing after our app has already committed state
// and is about to get shutdown. What we *should* do is
// not commit anything in an AsyncTask, but that's a bigger
// change than we want now.
t.commitAllowingStateLoss();
if (drawerLayout != null) {
// Tablet layout does not have a drawer
drawerLayout.closeDrawer(navDrawer);
}
}
use of androidx.fragment.app.FragmentManager in project AntennaPod by AntennaPod.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
lastTheme = UserPreferences.getNoTitleTheme();
setTheme(lastTheme);
if (savedInstanceState != null) {
ensureGeneratedViewIdGreaterThan(savedInstanceState.getInt(KEY_GENERATED_VIEW_ID, 0));
}
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
setContentView(R.layout.main);
recycledViewPool.setMaxRecycledViews(R.id.view_type_episode_item, 25);
drawerLayout = findViewById(R.id.drawer_layout);
navDrawer = findViewById(R.id.navDrawerFragment);
setNavDrawerSize();
final FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
String lastFragment = NavDrawerFragment.getLastNavFragment(this);
if (ArrayUtils.contains(NavDrawerFragment.NAV_DRAWER_TAGS, lastFragment)) {
loadFragment(lastFragment, null);
} else {
try {
loadFeedFragmentById(Integer.parseInt(lastFragment), null);
} catch (NumberFormatException e) {
// it's not a number, this happens if we removed
// a label from the NAV_DRAWER_TAGS
// give them a nice default...
loadFragment(QueueFragment.TAG, null);
}
}
}
FragmentTransaction transaction = fm.beginTransaction();
NavDrawerFragment navDrawerFragment = new NavDrawerFragment();
transaction.replace(R.id.navDrawerFragment, navDrawerFragment, NavDrawerFragment.TAG);
AudioPlayerFragment audioPlayerFragment = new AudioPlayerFragment();
transaction.replace(R.id.audioplayerFragment, audioPlayerFragment, AudioPlayerFragment.TAG);
transaction.commit();
checkFirstLaunch();
PreferenceUpgrader.checkUpgrades(this);
View bottomSheet = findViewById(R.id.audioplayerFragment);
sheetBehavior = (LockableBottomSheetBehavior) BottomSheetBehavior.from(bottomSheet);
sheetBehavior.setPeekHeight((int) getResources().getDimension(R.dimen.external_player_height));
sheetBehavior.setHideable(false);
sheetBehavior.setBottomSheetCallback(bottomSheetCallback);
}
use of androidx.fragment.app.FragmentManager in project bitcoin-wallet by bitcoin-wallet.
the class AddressBookActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final FragmentManager fragmentManager = getSupportFragmentManager();
setContentView(R.layout.address_book_content);
final ViewPager2 pager = findViewById(R.id.address_book_pager);
final ViewPagerTabs pagerTabs = findViewById(R.id.address_book_pager_tabs);
pagerTabs.addTabLabels(TAB_LABELS);
final boolean twoPanes = getResources().getBoolean(R.bool.address_book_two_panes);
walletActivityViewModel = new ViewModelProvider(this).get(AbstractWalletActivityViewModel.class);
walletActivityViewModel.wallet.observe(this, wallet -> invalidateOptionsMenu());
viewModel = new ViewModelProvider(this).get(AddressBookViewModel.class);
viewModel.pageTo.observe(this, new Event.Observer<Integer>() {
@Override
protected void onEvent(final Integer position) {
if (!twoPanes)
pager.setCurrentItem(position, true);
}
});
viewModel.showEditAddressBookEntryDialog.observe(this, new Event.Observer<Address>() {
@Override
protected void onEvent(final Address address) {
EditAddressBookEntryFragment.edit(fragmentManager, address);
}
});
viewModel.showScanOwnAddressDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
dialog.singleDismissButton(null);
dialog.show();
}
});
viewModel.showScanInvalidDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
dialog.singleDismissButton(null);
dialog.show();
}
});
if (twoPanes) {
final RecyclerView recyclerView = (RecyclerView) pager.getChildAt(0);
recyclerView.setClipToPadding(false);
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
final int width = recyclerView.getWidth();
recyclerView.setPadding(0, 0, width / 2, 0);
pager.setCurrentItem(0);
});
pager.setUserInputEnabled(false);
pagerTabs.setMode(ViewPagerTabs.Mode.STATIC);
} else {
pager.setPageTransformer(new ZoomOutPageTransformer());
pager.registerOnPageChangeCallback(pagerTabs.getPageChangeCallback());
pagerTabs.setMode(ViewPagerTabs.Mode.DYNAMIC);
}
pager.setOffscreenPageLimit(1);
pager.setAdapter(new AddressBookActivity.PagerAdapter());
}
use of androidx.fragment.app.FragmentManager in project zype-android by zype.
the class BaseVideoActivity method hideVideoLayout.
protected void hideVideoLayout() {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_PLAYER);
fragmentManager.beginTransaction().hide(fragment).commit();
}
use of androidx.fragment.app.FragmentManager in project zype-android by zype.
the class BaseVideoActivity method showFragment.
private void showFragment(Fragment fragment) {
Logger.d("showFragment()");
hideProgress();
if (mInterface != null) {
mInterface.stop();
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (fragment instanceof MediaControlInterface) {
mInterface = (MediaControlInterface) fragment;
}
fragmentTransaction.replace(R.id.video_container, fragment, FRAGMENT_TAG_PLAYER);
fragmentTransaction.commit();
}
Aggregations