Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making drawer accesable for easy navigation #3156

53 changes: 42 additions & 11 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ public class MainActivity extends AppCompatActivity {
private boolean servicesShown = false;
private ImageView serviceArrow;

private static final int ITEM_ID_SUBSCRIPTIONS = - 1;
private static final int ITEM_ID_FEED = - 2;
private static final int ITEM_ID_BOOKMARKS = - 3;
private static final int ITEM_ID_DOWNLOADS = - 4;
private static final int ITEM_ID_HISTORY = - 5;
private static final int ITEM_ID_SETTINGS = 0;
private static final int ITEM_ID_ABOUT = 1;
private static final int ITEM_ID_HOME = 2;
private static final int ITEM_ID_SUBSCRIPTIONS = 3;
private static final int ITEM_ID_FEED = 4;
private static final int ITEM_ID_BOOKMARKS = 5;
private static final int ITEM_ID_DOWNLOADS = 6;
private static final int ITEM_ID_HISTORY = 7;


private static final int ORDER = 0;

Expand Down Expand Up @@ -143,6 +145,12 @@ private void setupDrawer() throws Exception {
drawerItems = findViewById(R.id.navigation);

//Tabs
//Home button
drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_HOME, ORDER, R.string.tab_home)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_kiosk_local));


int currentServiceId = ServiceHelper.getSelectedServiceId(this);
StreamingService service = NewPipe.getService(currentServiceId);

Expand All @@ -155,6 +163,7 @@ private void setupDrawer() throws Exception {
kioskId ++;
}


drawerItems.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, R.string.tab_subscriptions)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
Expand Down Expand Up @@ -236,6 +245,9 @@ private void changeService(MenuItem item) {

private void tabSelected(MenuItem item) throws ExtractionException {
switch(item.getItemId()) {
case ITEM_ID_HOME:
NavigationHelper.openMainFragment(getSupportFragmentManager());
break;
case ITEM_ID_SUBSCRIPTIONS:
NavigationHelper.openSubscriptionFragment(getSupportFragmentManager());
break;
Expand Down Expand Up @@ -373,6 +385,12 @@ private void showTabs() throws ExtractionException {
serviceArrow.setImageResource(R.drawable.ic_arrow_down_white);

//Tabs

//Home button
drawerItems.getMenu()
Stypox marked this conversation as resolved.
Show resolved Hide resolved
.add(R.id.menu_tabs_group, ITEM_ID_HOME, ORDER, R.string.tab_home)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_kiosk_local));

int currentServiceId = ServiceHelper.getSelectedServiceId(this);
StreamingService service = NewPipe.getService(currentServiceId);

Expand Down Expand Up @@ -478,6 +496,13 @@ public void onBackPressed() {
if (DEBUG) Log.d(TAG, "onBackPressed() called");

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);

//If Drawer is open close it when back is pressed (PlayStore style)
if (drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START);
return;
}

// If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it
if (fragment instanceof BackPressable) {
if (((BackPressable) fragment).onBackPressed()) return;
Expand Down Expand Up @@ -607,17 +632,23 @@ private void updateDrawerNavigation() {
final DrawerLayout drawer = findViewById(R.id.drawer_layout);

final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
if (fragment instanceof MainFragment) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);

//We need to enable the home button for the search fragment to go back to MainFragment
if (fragment instanceof SearchFragment) {
if (toggle != null) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Hashik-Donthineni marked this conversation as resolved.
Show resolved Hide resolved
toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed());
return;
}
} else {
if (toggle != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
toggle.syncState();
toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START));
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
}
} else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed());
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

ActionBar supportActionBar = activity.getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayHomeAsUpEnabled(true);
supportActionBar.setDisplayShowTitleEnabled(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
ActionBar supportActionBar = activity.getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayShowTitleEnabled(true);
if (useAsFrontPage) {
supportActionBar.setDisplayHomeAsUpEnabled(false);
} else {
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@
<string name="app_language_title">App language</string>
<string name="systems_language">System default</string>
<string name="dynamic_seek_duration_description">%s seconds</string>
<string name="tab_home">Home</string>
<string name="new_seek_duration_toast">Due to ExoPlayer constraints the seek duration was set to %d seconds</string>
<plurals name="dynamic_seek_duration_description">
<item quantity="other">%s seconds</item>
</plurals>
</resources>
</resources>