Skip to content

Commit

Permalink
Close DrawerLayout on back button press
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander committed Oct 7, 2019
1 parent 9f0e689 commit 40e4839
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.schabi.newpipe;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
Expand All @@ -39,6 +40,7 @@
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -58,6 +60,7 @@
import org.schabi.newpipe.fragments.list.search.SearchFragment;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.FireTvUtils;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
Expand Down Expand Up @@ -407,13 +410,20 @@ protected void onNewIntent(Intent intent) {
public void onBackPressed() {
if (DEBUG) Log.d(TAG, "onBackPressed() called");

if (FireTvUtils.isFireTv()) {
View drawerPanel = findViewById(R.id.navigation_layout);
if (drawer.isDrawerOpen(drawerPanel)) {
drawer.closeDrawers();
return;
}
}

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
// 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;
}


if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
finish();
} else super.onBackPressed();
Expand Down

0 comments on commit 40e4839

Please sign in to comment.