From 69434c39972ce18677459c597f9b58017027ad4a Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Sat, 29 Feb 2020 02:01:43 +0530 Subject: [PATCH 1/9] Replaced back button with navigation in VideoDetails, BaseListFragment --- .../java/org/schabi/newpipe/MainActivity.java | 25 ++++++++++++++++--- .../fragments/detail/VideoDetailFragment.java | 1 - .../fragments/list/BaseListFragment.java | 5 ---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 29dde41c138..63a2e03d949 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -478,6 +478,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; @@ -607,6 +614,8 @@ private void updateDrawerNavigation() { final DrawerLayout drawer = findViewById(R.id.drawer_layout); final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); + + //If it's MainFragment enable the Navigation Drawer again if (fragment instanceof MainFragment) { getSupportActionBar().setDisplayHomeAsUpEnabled(false); if (toggle != null) { @@ -614,10 +623,18 @@ private void updateDrawerNavigation() { 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; + } + + //We need to enable the home button for the search fragment to go back to MainFragment + if (fragment instanceof SearchFragment) { + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + if (toggle != null) { + drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed()); + } + return; } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index b28c71d7216..91b0c98040e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -585,7 +585,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null) { - supportActionBar.setDisplayHomeAsUpEnabled(true); supportActionBar.setDisplayShowTitleEnabled(false); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index d6fd1dd0083..094a8617788 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -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); - } } } From 5df4151f4829462edf3766fb712c1198db9e275a Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Sat, 29 Feb 2020 02:29:16 +0530 Subject: [PATCH 2/9] Added home button to drawer --- .../java/org/schabi/newpipe/MainActivity.java | 18 +++++++++++++----- app/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 63a2e03d949..e9fad0c501b 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -92,11 +92,13 @@ 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_HOME = - 1; + private static final int ITEM_ID_SUBSCRIPTIONS = - 2; + private static final int ITEM_ID_FEED = - 3; + private static final int ITEM_ID_BOOKMARKS = - 4; + private static final int ITEM_ID_DOWNLOADS = - 5; + private static final int ITEM_ID_HISTORY = - 6; private static final int ITEM_ID_SETTINGS = 0; private static final int ITEM_ID_ABOUT = 1; @@ -142,6 +144,9 @@ private void setupDrawer() throws Exception { drawer = findViewById(R.id.drawer_layout); drawerItems = findViewById(R.id.navigation); + //Home button + drawerItems.getMenu().add(R.id.menu_tabs_group, ITEM_ID_HOME, ORDER, R.string.tab_home); + //Tabs int currentServiceId = ServiceHelper.getSelectedServiceId(this); StreamingService service = NewPipe.getService(currentServiceId); @@ -236,6 +241,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; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42b4b77c594..66eb06f100a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -593,6 +593,7 @@ App language System default %s seconds + Home %s seconds From 5fb6fbfd981ae642dcde41179ccac0e8fa2e53a1 Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Sat, 29 Feb 2020 13:30:41 +0530 Subject: [PATCH 3/9] Added the home icon to 'Home tab' in drawer (ic_kiosk_local) --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index e9fad0c501b..f88ec33fad2 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -145,7 +145,8 @@ private void setupDrawer() throws Exception { drawerItems = findViewById(R.id.navigation); //Home button - drawerItems.getMenu().add(R.id.menu_tabs_group, ITEM_ID_HOME, ORDER, R.string.tab_home); + 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)); //Tabs int currentServiceId = ServiceHelper.getSelectedServiceId(this); From c4230c63ef794cd1791bf0c4883583f41aa59aa2 Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Sat, 29 Feb 2020 14:14:59 +0530 Subject: [PATCH 4/9] Fixed 'Home button disappearing after changing service' issue --- .../java/org/schabi/newpipe/MainActivity.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index f88ec33fad2..af24381b1ab 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -144,11 +144,15 @@ private void setupDrawer() throws Exception { drawer = findViewById(R.id.drawer_layout); drawerItems = findViewById(R.id.navigation); + + + //Tabs + //Home button - drawerItems.getMenu().add(R.id.menu_tabs_group, ITEM_ID_HOME, ORDER, R.string.tab_home) + 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)); - //Tabs int currentServiceId = ServiceHelper.getSelectedServiceId(this); StreamingService service = NewPipe.getService(currentServiceId); @@ -161,6 +165,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)); @@ -382,6 +387,12 @@ private void showTabs() throws ExtractionException { serviceArrow.setImageResource(R.drawable.ic_arrow_down_white); //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); From 0e559acec4c3950459ee6d5426b77ff1fcdb785b Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Wed, 4 Mar 2020 02:30:44 +0530 Subject: [PATCH 5/9] Changed minute suggested changes, removed Home button on Home Fragment --- .../java/org/schabi/newpipe/MainActivity.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index af24381b1ab..312c85c3712 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -93,12 +93,12 @@ public class MainActivity extends AppCompatActivity { private ImageView serviceArrow; - private static final int ITEM_ID_HOME = - 1; - private static final int ITEM_ID_SUBSCRIPTIONS = - 2; - private static final int ITEM_ID_FEED = - 3; - private static final int ITEM_ID_BOOKMARKS = - 4; - private static final int ITEM_ID_DOWNLOADS = - 5; - private static final int ITEM_ID_HISTORY = - 6; + 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 ITEM_ID_SETTINGS = 0; private static final int ITEM_ID_ABOUT = 1; @@ -144,14 +144,15 @@ private void setupDrawer() throws Exception { drawer = findViewById(R.id.drawer_layout); drawerItems = findViewById(R.id.navigation); - - //Tabs + Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); //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)); + if (!(fragment instanceof MainFragment)) {//We don't need to show the Home button when on home + 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); @@ -247,7 +248,7 @@ private void changeService(MenuItem item) { private void tabSelected(MenuItem item) throws ExtractionException { switch(item.getItemId()) { - case ITEM_ID_HOME: + case ITEM_ID_HOME: NavigationHelper.openMainFragment(getSupportFragmentManager()); break; case ITEM_ID_SUBSCRIPTIONS: @@ -648,7 +649,6 @@ private void updateDrawerNavigation() { //We need to enable the home button for the search fragment to go back to MainFragment if (fragment instanceof SearchFragment) { - getSupportActionBar().setDisplayHomeAsUpEnabled(false); if (toggle != null) { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); getSupportActionBar().setDisplayHomeAsUpEnabled(true); From 4c06105844d6201c6519c134ec706054b21289f7 Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Wed, 4 Mar 2020 02:37:31 +0530 Subject: [PATCH 6/9] Removed the 'home button disabling on HomeFragment' code --- .../main/java/org/schabi/newpipe/MainActivity.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 312c85c3712..1bedefda2ed 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -145,14 +145,11 @@ private void setupDrawer() throws Exception { drawerItems = findViewById(R.id.navigation); //Tabs - Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); - //Home button - if (!(fragment instanceof MainFragment)) {//We don't need to show the Home button when on home - 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)); - } + 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); From c0e93f001024521e56f74ce90c7869b8ee7fe195 Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Thu, 5 Mar 2020 14:04:42 +0530 Subject: [PATCH 7/9] Small refactoring/reorder of code --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 1bedefda2ed..af77b50b885 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -92,15 +92,15 @@ public class MainActivity extends AppCompatActivity { private boolean servicesShown = false; private ImageView serviceArrow; - + 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 ITEM_ID_SETTINGS = 0; - private static final int ITEM_ID_ABOUT = 1; + private static final int ORDER = 0; From b71690230f8df15d82cb2ad2d07555e746dc163c Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Thu, 5 Mar 2020 15:53:03 +0530 Subject: [PATCH 8/9] Fixed Menue not appearing in video details fragment when we go from search fragment --- .../java/org/schabi/newpipe/MainActivity.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index af77b50b885..1e7778161f0 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -633,23 +633,20 @@ private void updateDrawerNavigation() { final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); - //If it's MainFragment enable the Navigation Drawer again - if (fragment instanceof MainFragment) { - getSupportActionBar().setDisplayHomeAsUpEnabled(false); - if (toggle != null) { - toggle.syncState(); - toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START)); - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); - } - return; - } - //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); toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed()); + return; + } + }else{ + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + if (toggle != null) { + toggle.syncState(); + toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START)); + drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); } return; } From 391460653794f8c7a5b1cad9cd247ce4e0a5c317 Mon Sep 17 00:00:00 2001 From: Hashik Donthineni Date: Thu, 5 Mar 2020 17:49:58 +0530 Subject: [PATCH 9/9] minor refactoring --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 1e7778161f0..4c46387dcf9 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -641,9 +641,9 @@ private void updateDrawerNavigation() { toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed()); return; } - }else{ - getSupportActionBar().setDisplayHomeAsUpEnabled(false); + } else { if (toggle != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(false); toggle.syncState(); toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START)); drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);