Search in sources :

Example 1 with MainFragment

use of com.simplecity.amp_library.ui.fragments.MainFragment in project Shuttle by timusus.

the class MainActivity method onBackPressed.

@Override
public void onBackPressed() {
    Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
    if (playingFragment != null) {
        Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
        if (childFragment != null && childFragment instanceof QueueFragment) {
            ((PlayerFragment) playingFragment).toggleQueue();
            toggleQueue(false);
            return;
        }
    }
    if (mIsSlidingEnabled) {
        if (mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
            mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true);
            return;
        }
    }
    boolean isShowingFolders = false;
    Fragment containerFragment = getSupportFragmentManager().findFragmentById(R.id.main_container);
    if (containerFragment != null && containerFragment instanceof FolderFragment) {
        isShowingFolders = true;
    } else if (containerFragment instanceof MainFragment) {
        Fragment currentPagerFragment = ((MainFragment) containerFragment).getCurrentFragment();
        if (currentPagerFragment != null && currentPagerFragment instanceof FolderFragment) {
            isShowingFolders = true;
        }
    }
    if (isShowingFolders) {
        if (mBackPressListenerReference != null && mBackPressListenerReference.get() != null) {
            if (mBackPressListenerReference.get().onBackPressed()) {
                return;
            }
        }
    }
    super.onBackPressed();
    if (isShowingFolders || containerFragment instanceof MainFragment) {
        if (mNavigationDrawerFragment != null) {
            mNavigationDrawerFragment.setDrawerItem(0);
        }
        mTitle = getString(R.string.library_title);
        supportInvalidateOptionsMenu();
    }
}
Also used : FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) Fragment(android.support.v4.app.Fragment) QueuePagerFragment(com.simplecity.amp_library.ui.fragments.QueuePagerFragment) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) AlbumArtistFragment(com.simplecity.amp_library.ui.fragments.AlbumArtistFragment) NavigationDrawerFragment(com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment) PlaylistFragment(com.simplecity.amp_library.ui.fragments.PlaylistFragment) GenreFragment(com.simplecity.amp_library.ui.fragments.GenreFragment) DetailFragment(com.simplecity.amp_library.ui.fragments.DetailFragment) SuggestedFragment(com.simplecity.amp_library.ui.fragments.SuggestedFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) AlbumFragment(com.simplecity.amp_library.ui.fragments.AlbumFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)

Example 2 with MainFragment

use of com.simplecity.amp_library.ui.fragments.MainFragment in project Shuttle by timusus.

the class MainActivity method onItemClicked.

@Override
public void onItemClicked(DrawerGroupItem drawerGroupItem) {
    switch(drawerGroupItem.type) {
        case DrawerGroupItem.Type.LIBRARY:
            if (getCurrentFragment() instanceof MainFragment) {
                return;
            } else {
                for (int i = 0, count = getSupportFragmentManager().getBackStackEntryCount(); i < count; i++) {
                    try {
                        getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                    } catch (IllegalStateException e) {
                        Log.e(TAG, "Error popping backstack: " + e);
                        CrashlyticsCore.getInstance().logException(e);
                    }
                }
                mTitle = getString(R.string.library_title);
            }
            break;
        case DrawerGroupItem.Type.FOLDERS:
            if (getCurrentFragment() instanceof FolderFragment) {
                return;
            }
            if (ShuttleUtils.isUpgraded()) {
                //Folder
                swapFragments(FolderFragment.newInstance(null), true);
            } else {
                DialogUtils.showUpgradeDialog(this, (materialDialog, dialogAction) -> {
                    if (ShuttleUtils.isAmazonBuild()) {
                        ShuttleUtils.openShuttleLink(MainActivity.this, "com.simplecity.amp_pro");
                    } else {
                        AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.FOLDER);
                        purchasePremiumUpgrade();
                    }
                });
            }
            break;
        case DrawerGroupItem.Type.SETTINGS:
            startActivity(new Intent(this, SettingsActivity.class));
            break;
        case DrawerGroupItem.Type.SUPPORT:
            Intent intent = new Intent(this, SettingsActivity.class);
            intent.putExtra(SettingsActivity.EXTRA_SUPPORT, true);
            startActivity(intent);
            break;
    }
}
Also used : FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Aggregations

FolderFragment (com.simplecity.amp_library.ui.fragments.FolderFragment)2 MainFragment (com.simplecity.amp_library.ui.fragments.MainFragment)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Fragment (android.support.v4.app.Fragment)1 AlbumArtistFragment (com.simplecity.amp_library.ui.fragments.AlbumArtistFragment)1 AlbumFragment (com.simplecity.amp_library.ui.fragments.AlbumFragment)1 DetailFragment (com.simplecity.amp_library.ui.fragments.DetailFragment)1 GenreFragment (com.simplecity.amp_library.ui.fragments.GenreFragment)1 MiniPlayerFragment (com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)1 NavigationDrawerFragment (com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment)1 PlayerFragment (com.simplecity.amp_library.ui.fragments.PlayerFragment)1 PlaylistFragment (com.simplecity.amp_library.ui.fragments.PlaylistFragment)1 QueueFragment (com.simplecity.amp_library.ui.fragments.QueueFragment)1 QueuePagerFragment (com.simplecity.amp_library.ui.fragments.QueuePagerFragment)1 SuggestedFragment (com.simplecity.amp_library.ui.fragments.SuggestedFragment)1