diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index 056db3500..7bc1747bb 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -28,8 +28,13 @@ import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
@@ -85,8 +90,50 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
initFragments();
}
- Toolbar toolbar = findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
+ final DrawerLayout drawer = findViewById(R.id.drawer_layout);
+ final NavigationView drawerItems = findViewById(R.id.navigation);
setSupportActionBar(toolbar);
+
+ final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close);
+ toggle.syncState();
+ drawer.addDrawerListener(toggle);
+
+ getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
+ @Override
+ public void onBackStackChanged() {
+ if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onBackPressed();
+ }
+ });
+ } else {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);
+ toggle.syncState();
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ drawer.openDrawer(GravityCompat.START);
+ }
+ });
+ }
+ }
+ });
+
+ drawerItems.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
+ editor.putString("service", item.getTitle().toString());
+ editor.apply();
+ drawer.closeDrawers();
+ return true;
+ }
+ });
+
+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
initHistory();
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
index a3beb712c..f01807bf2 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
@@ -30,13 +30,10 @@ import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
import org.schabi.newpipe.fragments.subscription.SubscriptionFragment;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
-import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ThemeHelper;
-import java.util.concurrent.ExecutionException;
-
public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener {
private ViewPager viewPager;
private boolean showBlankTab = false;
@@ -139,7 +136,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
- NavigationHelper.openSearchFragment(getFragmentManager(), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("service", "0")), "");
+ NavigationHelper.openSearchFragment(getFragmentManager(), NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("service", "YouTube")), "");
return true;
}
return super.onOptionsItemSelected(item);
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 88a015e81..7eafc6c69 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,18 +1,30 @@
-