Search in sources :

Example 86 with FragmentManager

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);
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Example 87 with FragmentManager

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);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) AudioPlayerFragment(de.danoeh.antennapod.fragment.AudioPlayerFragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavDrawerFragment(de.danoeh.antennapod.fragment.NavDrawerFragment)

Example 88 with FragmentManager

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());
}
Also used : ViewPagerTabs(de.schildbach.wallet.util.ViewPagerTabs) Address(org.bitcoinj.core.Address) FragmentManager(androidx.fragment.app.FragmentManager) ViewPager2(androidx.viewpager2.widget.ViewPager2) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ZoomOutPageTransformer(de.schildbach.wallet.util.ZoomOutPageTransformer)

Example 89 with FragmentManager

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();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Fragment(androidx.fragment.app.Fragment) YouTubeFragment(com.zype.android.ui.video_details.fragments.video.YouTubeFragment) ThumbnailFragment(com.zype.android.ui.player.ThumbnailFragment) ChromecastCheckStatusFragment(com.zype.android.ui.chromecast.ChromecastCheckStatusFragment) ChromecastFragment(com.zype.android.ui.chromecast.ChromecastFragment) PlayerFragment(com.zype.android.ui.player.PlayerFragment)

Example 90 with FragmentManager

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();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) MediaControlInterface(com.zype.android.ui.video_details.fragments.video.MediaControlInterface) FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Aggregations

FragmentManager (androidx.fragment.app.FragmentManager)163 FragmentTransaction (androidx.fragment.app.FragmentTransaction)55 Fragment (androidx.fragment.app.Fragment)42 Bundle (android.os.Bundle)28 Test (org.junit.Test)15 Intent (android.content.Intent)13 FragmentActivity (androidx.fragment.app.FragmentActivity)10 Activity (android.app.Activity)6 View (android.view.View)6 DialogFragment (androidx.fragment.app.DialogFragment)6 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)5 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)3 LayoutInflater (android.view.LayoutInflater)3 MenuInflater (android.view.MenuInflater)3 Window (android.view.Window)3 TextView (android.widget.TextView)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3