diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index b6bd09691..9e8f3fa76 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -106,7 +106,7 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { final DrawerLayout drawer = findViewById(R.id.drawer_layout); final NavigationView drawerItems = findViewById(R.id.navigation); - drawerItems.setItemIconTintList(null); + //drawerItems.setItemIconTintList(null); // Set null to use the original icon drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true); if (!BuildConfig.BUILD_TYPE.equals("release")) { @@ -204,8 +204,36 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { } else super.onBackPressed(); } + /** + * Implement the following diagram behavior for the up button: + *
+ * +---------------+ + * | Main Screen +----+ + * +-------+-------+ | + * | | + * ▲ Up | Search Button + * | | + * +----+-----+ | + * +------------+ Search |◄-----+ + * | +----+-----+ + * | Open | + * | something ▲ Up + * | | + * | +------------+-------------+ + * | | | + * | | Video <-> Channel | + * +---►| Channel <-> Playlist | + * | Video <-> .... | + * | | + * +--------------------------+ + *+ */ private void onHomeButtonPressed() { - NavigationHelper.gotoMainFragment(getSupportFragmentManager()); + // If search fragment wasn't found in the backstack... + if (!NavigationHelper.tryGotoSearchFragment(getSupportFragmentManager())) { + // ...go to the main fragment + NavigationHelper.gotoMainFragment(getSupportFragmentManager()); + } } /*////////////////////////////////////////////////////////////////////////// @@ -239,11 +267,6 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { return true; } - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - return super.onPrepareOptionsMenu(menu); - } - @Override public boolean onOptionsItemSelected(MenuItem item) { if (DEBUG) Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]"); diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index ee000104d..8894af9df 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -51,6 +51,7 @@ import java.util.ArrayList; @SuppressWarnings({"unused", "WeakerAccess"}) public class NavigationHelper { public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag"; + public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag"; /*////////////////////////////////////////////////////////////////////////// // Players @@ -244,11 +245,21 @@ public class NavigationHelper { .commit(); } + public static boolean tryGotoSearchFragment(FragmentManager fragmentManager) { + if (MainActivity.DEBUG) { + for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) { + Log.d("NavigationHelper", "tryGoToSearchFragment() [" + i + "] = [" + fragmentManager.getBackStackEntryAt(i) + "]"); + } + } + + return fragmentManager.popBackStackImmediate(SEARCH_FRAGMENT_TAG, 0); + } + public static void openSearchFragment(FragmentManager fragmentManager, int serviceId, String query) { fragmentManager.beginTransaction() .setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out, R.animator.custom_fade_in, R.animator.custom_fade_out) .replace(R.id.fragment_holder, SearchFragment.getInstance(serviceId, query)) - .addToBackStack(null) + .addToBackStack(SEARCH_FRAGMENT_TAG) .commit(); } diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index e8a051849..ce1491ba4 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -18,9 +18,9 @@ public class ServiceHelper { public static int getIcon(int serviceId) { switch (serviceId) { case 0: - return R.drawable.youtube; + return R.drawable.place_holder_youtube; case 1: - return R.drawable.soundcloud; + return R.drawable.place_holder_circle; default: return R.drawable.service; } diff --git a/app/src/main/res/drawable-nodpi/place_holder_circle.png b/app/src/main/res/drawable-nodpi/place_holder_circle.png new file mode 100644 index 000000000..704729e8f Binary files /dev/null and b/app/src/main/res/drawable-nodpi/place_holder_circle.png differ diff --git a/app/src/main/res/drawable-nodpi/place_holder_youtube.png b/app/src/main/res/drawable-nodpi/place_holder_youtube.png new file mode 100644 index 000000000..c4113e005 Binary files /dev/null and b/app/src/main/res/drawable-nodpi/place_holder_youtube.png differ diff --git a/app/src/main/res/menu/drawer_items.xml b/app/src/main/res/menu/drawer_items.xml index b5ad324c5..ae4598edd 100644 --- a/app/src/main/res/menu/drawer_items.xml +++ b/app/src/main/res/menu/drawer_items.xml @@ -4,11 +4,11 @@ android:id="@+id/menu_services_group">