diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 056db3500..f5a43fa63 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; @@ -45,6 +50,7 @@ import org.schabi.newpipe.database.history.dao.WatchHistoryDAO; import org.schabi.newpipe.database.history.model.HistoryEntry; import org.schabi.newpipe.database.history.model.SearchHistoryEntry; import org.schabi.newpipe.database.history.model.WatchHistoryEntry; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.StreamInfo; @@ -69,6 +75,7 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { private static final String TAG = "MainActivity"; public static final boolean DEBUG = false; private SharedPreferences sharedPreferences; + private ActionBarDrawerToggle toggle = null; /*////////////////////////////////////////////////////////////////////////// // Activity's LifeCycle @@ -76,7 +83,8 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { @Override protected void onCreate(Bundle savedInstanceState) { - if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); + if (DEBUG) + Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); ThemeHelper.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -85,8 +93,59 @@ 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); + + drawerItems.getMenu().getItem(NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("service", "YouTube"))).setChecked(true); + + if (!BuildConfig.BUILD_TYPE.equals("release")) { + toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close); + toggle.syncState(); + drawer.addDrawerListener(toggle); + + drawerItems.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + drawerItems.getMenu().getItem(NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("service", "YouTube"))).setChecked(false); + SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); + editor.putString("service", item.getTitle().toString()); + editor.apply(); + drawer.closeDrawers(); + drawerItems.getMenu().getItem(NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("service", "YouTube"))).setChecked(true); + return true; + } + }); + } else { + drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + } + + 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); + if (toggle != null) { + toggle.syncState(); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + drawer.openDrawer(GravityCompat.START); + } + }); + } + } + } + }); + 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 e220654a4..be3422706 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -138,7 +138,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(), 0, ""); + NavigationHelper.openSearchFragment(getFragmentManager(), NewPipe.getIdOfService(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("service", "YouTube")), ""); return true; } return super.onOptionsItemSelected(item); 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 802389a95..665a8f7f9 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 @@ -342,7 +342,11 @@ public class VideoDetailFragment extends BaseStateFragment implement } break; case R.id.detail_thumbnail_root_layout: - openVideoPlayer(); + if (currentInfo.video_streams.isEmpty() && currentInfo.video_only_streams.isEmpty()) { + openBackgroundPlayer(false); + } else { + openVideoPlayer(); + } break; case R.id.detail_title_root_layout: toggleTitleAndDescription(); @@ -1158,6 +1162,13 @@ public class VideoDetailFragment extends BaseStateFragment implement showSnackBarError(info.getErrors(), UserAction.REQUESTED_STREAM, NewPipe.getNameOfService(info.getServiceId()), info.getUrl(), 0); } + if (info.video_streams.isEmpty() && info.video_only_streams.isEmpty()) { + detailControlsBackground.setVisibility(View.GONE); + detailControlsPopup.setVisibility(View.GONE); + spinnerToolbar.setVisibility(View.GONE); + thumbnailPlayButton.setImageResource(R.drawable.ic_headset_white_24dp); + } + if (autoPlayEnabled) { openVideoPlayer(); // Only auto play in the first open @@ -1201,4 +1212,4 @@ public class VideoDetailFragment extends BaseStateFragment implement showError(getString(R.string.blocked_by_gema), false, R.drawable.gruese_die_gema); } -} \ No newline at end of file +} 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 @@ - + android:layout_height="match_parent"> + android:orientation="vertical" + tools:context="org.schabi.newpipe.MainActivity"> + - + + - + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_video_detail.xml b/app/src/main/res/layout/fragment_video_detail.xml index 86e8d6ad9..8c445adcd 100644 --- a/app/src/main/res/layout/fragment_video_detail.xml +++ b/app/src/main/res/layout/fragment_video_detail.xml @@ -273,7 +273,7 @@ android:paddingBottom="6dp" android:paddingTop="6dp" android:text="@string/controls_background_title" - android:textSize="12sp"/> + android:textSize="12sp" /> diff --git a/app/src/main/res/menu/drawer_items.xml b/app/src/main/res/menu/drawer_items.xml new file mode 100644 index 000000000..2f82327c3 --- /dev/null +++ b/app/src/main/res/menu/drawer_items.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index d5c78d4ed..f0c496aa2 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -46,6 +46,13 @@ 144p + + @string/youtube + @string/soundcloud + + service + @string/youtube + video_mp4 video_webm video_3gp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 16bfcbb1a..6a6014a29 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -84,6 +84,7 @@ Show tip when background or popup button is pressed on video details page URL not supported Default content country + Service Default content language Player Behavior @@ -329,4 +330,10 @@ Start Playing Here Start Here on Background Start Here on Popup + + + Open Drawer + Close Drawer + YouTube + SoundCloud diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 15088494d..22269eef6 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -2,7 +2,6 @@ - -