From 0f22833ad58f165c312dbf0dcb6c6b1ba72ae43b Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 2 Feb 2020 15:52:35 +0100 Subject: [PATCH 1/8] Save and restore whether pitch and tempo are unhooked or not Fixes #1536 --- .../helper/PlaybackParameterDialog.java | 24 ++++++++++++++----- app/src/main/res/values/settings_keys.xml | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 3ada3a6be..94fb412f7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -7,6 +7,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; + +import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.CheckBox; @@ -219,13 +221,23 @@ public class PlaybackParameterDialog extends DialogFragment { private void setupHookingControl(@NonNull View rootView) { unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox); if (unhookingCheckbox != null) { - unhookingCheckbox.setChecked(pitch != tempo); + // restore whether pitch and tempo are unhooked or not + unhookingCheckbox.setChecked(PreferenceManager.getDefaultSharedPreferences(getContext()) + .getBoolean(getString(R.string.playback_unhook_key), true)); + unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> { - if (isChecked) return; - // When unchecked, slide back to the minimum of current tempo or pitch - final double minimum = Math.min(getCurrentPitch(), getCurrentTempo()); - setSliders(minimum); - setCurrentPlaybackParameters(); + // save whether pitch and tempo are unhooked or not + PreferenceManager.getDefaultSharedPreferences(getContext()) + .edit() + .putBoolean(getString(R.string.playback_unhook_key), isChecked) + .apply(); + + if (!isChecked) { + // when unchecked, slide back to the minimum of current tempo or pitch + final double minimum = Math.min(getCurrentPitch(), getCurrentTempo()); + setSliders(minimum); + setCurrentPlaybackParameters(); + } }); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 1a7d61dae..e46904b6d 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -175,6 +175,7 @@ main_page_content enable_playback_resume enable_playback_state_lists + playback_unhook_key app_language_key enable_lock_screen_video_thumbnail From 244009a1cd06492518c2159a505dd8e5cc9a0bb6 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 2 Feb 2020 15:54:31 +0100 Subject: [PATCH 2/8] Change "Unlink" to "Unhook" in unhook_checkbox string "Unlink" is not an english word, and "Unhook" is used everywhere in the code --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 763eb7426..a35cbe804 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -492,7 +492,7 @@ Playback Speed Controls Tempo Pitch - Unlink (may cause distortion) + Unhook (may cause distortion) Fast-forward during silence Step Reset From 065faf31b65b2ea5fbb901ab05d3c9cda5f3fd59 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 22 Feb 2020 10:23:01 +0100 Subject: [PATCH 3/8] Add settings button back in dot menu --- app/src/main/res/menu/download_menu.xml | 3 +++ app/src/main/res/menu/menu_channel.xml | 17 ++++++++++++----- app/src/main/res/menu/menu_play_queue.xml | 9 +++++++-- app/src/main/res/menu/menu_playlist.xml | 17 ++++++++++++----- app/src/main/res/menu/video_detail_menu.xml | 7 +++++++ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/src/main/res/menu/download_menu.xml b/app/src/main/res/menu/download_menu.xml index 27d9bfe29..c74dc804a 100644 --- a/app/src/main/res/menu/download_menu.xml +++ b/app/src/main/res/menu/download_menu.xml @@ -27,4 +27,7 @@ android:title="@string/clear_download_history" app:showAsAction="ifRoom" /> + diff --git a/app/src/main/res/menu/menu_channel.xml b/app/src/main/res/menu/menu_channel.xml index cc6a9ed71..f8449d8b5 100644 --- a/app/src/main/res/menu/menu_channel.xml +++ b/app/src/main/res/menu/menu_channel.xml @@ -4,11 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" tools:context=".fragments.list.impl.ChannelFragment"> - - + + + + diff --git a/app/src/main/res/menu/menu_play_queue.xml b/app/src/main/res/menu/menu_play_queue.xml index 5413794be..be6cea46c 100644 --- a/app/src/main/res/menu/menu_play_queue.xml +++ b/app/src/main/res/menu/menu_play_queue.xml @@ -10,13 +10,18 @@ android:visible="true" app:showAsAction="ifRoom"/> + + diff --git a/app/src/main/res/menu/menu_playlist.xml b/app/src/main/res/menu/menu_playlist.xml index 4583ff719..5e62d40a3 100644 --- a/app/src/main/res/menu/menu_playlist.xml +++ b/app/src/main/res/menu/menu_playlist.xml @@ -3,11 +3,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> - - + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/video_detail_menu.xml b/app/src/main/res/menu/video_detail_menu.xml index fd44c7860..65e7bc4da 100644 --- a/app/src/main/res/menu/video_detail_menu.xml +++ b/app/src/main/res/menu/video_detail_menu.xml @@ -14,8 +14,15 @@ android:title="@string/share" app:showAsAction="ifRoom"/> + + From c7b470553827c696465d5b6e5d9de3261177ee69 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 22 Feb 2020 10:36:10 +0100 Subject: [PATCH 4/8] Implement Settings buttons --- .../schabi/newpipe/download/DownloadActivity.java | 8 +++++--- .../fragments/detail/VideoDetailFragment.java | 15 ++++++++++----- .../fragments/list/channel/ChannelFragment.java | 7 +++++-- .../fragments/list/playlist/PlaylistFragment.java | 7 +++++-- .../newpipe/player/ServicePlayerActivity.java | 3 +++ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index 00dd45ac9..2c54f75cf 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -12,6 +12,7 @@ import android.view.MenuItem; import android.view.ViewTreeObserver; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ThemeHelper; import us.shandian.giga.service.DownloadManagerService; @@ -76,11 +77,12 @@ public class DownloadActivity extends AppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case android.R.id.home: { + case android.R.id.home: onBackPressed(); return true; - } - + case R.id.action_settings: + NavigationHelper.openSettings(this); + return true; default: 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 7dd98003a..b28c71d72 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 @@ -600,22 +600,27 @@ public class VideoDetailFragment @Override public boolean onOptionsItemSelected(MenuItem item) { - if (isLoading.get()) { - // if is still loading block menu + int id = item.getItemId(); + if (id == R.id.action_settings) { + NavigationHelper.openSettings(requireContext()); + return true; + } + + if (isLoading.get()) { + // if still loading, block menu buttons related to video info return true; } - int id = item.getItemId(); switch (id) { case R.id.menu_item_share: { if (currentInfo != null) { - ShareUtils.shareUrl(this.getContext(), currentInfo.getName(), currentInfo.getOriginalUrl()); + ShareUtils.shareUrl(requireContext(), currentInfo.getName(), currentInfo.getOriginalUrl()); } return true; } case R.id.menu_item_openInBrowser: { if (currentInfo != null) { - ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl()); + ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getOriginalUrl()); } return true; } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 7b7a08a48..4742fcca1 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -175,17 +175,20 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_settings: + NavigationHelper.openSettings(requireContext()); + break; case R.id.menu_item_rss: openRssFeed(); break; case R.id.menu_item_openInBrowser: if (currentInfo != null) { - ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl()); + ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getOriginalUrl()); } break; case R.id.menu_item_share: if (currentInfo != null) { - ShareUtils.shareUrl(this.getContext(), name, currentInfo.getOriginalUrl()); + ShareUtils.shareUrl(requireContext(), name, currentInfo.getOriginalUrl()); } break; default: diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 6941741af..a992cd7ba 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -222,11 +222,14 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_settings: + NavigationHelper.openSettings(requireContext()); + break; case R.id.menu_item_openInBrowser: - ShareUtils.openUrlInBrowser(this.getContext(), url); + ShareUtils.openUrlInBrowser(requireContext(), url); break; case R.id.menu_item_share: - ShareUtils.shareUrl(this.getContext(), name, url); + ShareUtils.shareUrl(requireContext(), name, url); break; case R.id.menu_item_bookmark: onBookmarkClicked(); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 669d1c16c..aeba763be 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -156,6 +156,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity case android.R.id.home: finish(); return true; + case R.id.action_settings: + NavigationHelper.openSettings(this); + return true; case R.id.action_append_playlist: appendAllToPlaylist(); return true; From 8754cbb38ffac180ffe42543eb114da42e9c5c6f Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 22 Feb 2020 11:12:22 +0100 Subject: [PATCH 5/8] Remove Settings button from download activity --- .../java/org/schabi/newpipe/download/DownloadActivity.java | 3 --- app/src/main/res/menu/download_menu.xml | 4 ---- 2 files changed, 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index 2c54f75cf..de3df3527 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -80,9 +80,6 @@ public class DownloadActivity extends AppCompatActivity { case android.R.id.home: onBackPressed(); return true; - case R.id.action_settings: - NavigationHelper.openSettings(this); - return true; default: return super.onOptionsItemSelected(item); } diff --git a/app/src/main/res/menu/download_menu.xml b/app/src/main/res/menu/download_menu.xml index c74dc804a..d41434711 100644 --- a/app/src/main/res/menu/download_menu.xml +++ b/app/src/main/res/menu/download_menu.xml @@ -26,8 +26,4 @@ android:icon="?attr/ic_delete" android:title="@string/clear_download_history" app:showAsAction="ifRoom" /> - - From 6968dd266a6f8c0de34d9890efc3449f698d9f79 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 22 Feb 2020 11:30:57 +0100 Subject: [PATCH 6/8] Remove empty about menu --- .../main/java/org/schabi/newpipe/about/AboutActivity.java | 7 ------- app/src/main/res/menu/menu_about.xml | 6 ------ 2 files changed, 13 deletions(-) delete mode 100644 app/src/main/res/menu/menu_about.xml diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java index edfc54375..7fab44f8f 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -88,13 +88,6 @@ public class AboutActivity extends AppCompatActivity { } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_about, menu); - return true; - } - @Override public boolean onOptionsItemSelected(MenuItem item) { diff --git a/app/src/main/res/menu/menu_about.xml b/app/src/main/res/menu/menu_about.xml deleted file mode 100644 index dbe91a04f..000000000 --- a/app/src/main/res/menu/menu_about.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - From d65b8d7d18a953b98f11a7cdf9938d2516d96ed1 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 22 Feb 2020 11:34:08 +0100 Subject: [PATCH 7/8] Address @mauriciocolli suggestions in #2960 Simplify code to enable history button --- .../main/java/org/schabi/newpipe/MainActivity.java | 12 +++--------- .../main/java/org/schabi/newpipe/util/Constants.java | 2 -- 2 files changed, 3 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 7cd620faa..29dde41c1 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -453,15 +453,9 @@ public class MainActivity extends AppCompatActivity { NavigationHelper.openMainActivity(this); } - if (sharedPreferences.getBoolean(Constants.KEY_ENABLE_WATCH_HISTORY, true)) { - if (DEBUG) Log.d(TAG, "do not show History-menu as its disabled in settings"); - drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(true); - } - - if (!sharedPreferences.getBoolean(Constants.KEY_ENABLE_WATCH_HISTORY, true)) { - if (DEBUG) Log.d(TAG, "show History-menu as its enabled in settings"); - drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(false); - } + final boolean isHistoryEnabled = sharedPreferences.getBoolean( + getString(R.string.enable_watch_history_key), true); + drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(isHistoryEnabled); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/util/Constants.java b/app/src/main/java/org/schabi/newpipe/util/Constants.java index 50350651d..b01b6df6a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Constants.java +++ b/app/src/main/java/org/schabi/newpipe/util/Constants.java @@ -11,7 +11,5 @@ public class Constants { public static final String KEY_THEME_CHANGE = "key_theme_change"; public static final String KEY_MAIN_PAGE_CHANGE = "key_main_page_change"; - public static final String KEY_ENABLE_WATCH_HISTORY = "enable_watch_history"; - public static final int NO_SERVICE_ID = -1; } From 0bc769b9714db1fa163b41d07d52f6f1a2adfcaa Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sat, 22 Feb 2020 20:43:38 +0100 Subject: [PATCH 8/8] Fix regression: Unable to find explicit activity class See https://github.com/TeamNewPipe/NewPipe/issues/3114#issuecomment-589940878 for info on this crash. This reverts ef90493c27af898d8e79adbb5e8d449ef5d0ae35 partly. --- .../player/BackgroundPlayerActivity.java | 8 +++++++- .../player/PopupVideoPlayerActivity.java | 8 +++++++- .../newpipe/player/ServicePlayerActivity.java | 17 ++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java index 1b5b5d07c..59f6e1e6d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java @@ -55,7 +55,13 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity { return true; } - return switchTo(PopupVideoPlayer.class); + this.player.setRecovery(); + getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); + getApplicationContext().startService( + getSwitchIntent(PopupVideoPlayer.class) + .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()) + ); + return true; } return false; } diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayerActivity.java index b2af6d9d8..5000d07e2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayerActivity.java @@ -48,7 +48,13 @@ public final class PopupVideoPlayerActivity extends ServicePlayerActivity { @Override public boolean onPlayerOptionSelected(MenuItem item) { if (item.getItemId() == R.id.action_switch_background) { - return switchTo(BackgroundPlayer.class); + this.player.setRecovery(); + getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); + getApplicationContext().startService( + getSwitchIntent(BackgroundPlayer.class) + .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()) + ); + return true; } return false; } diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index aeba763be..7aa2be05d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -166,7 +166,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS)); return true; case R.id.action_switch_main: - return switchTo(MainVideoPlayer.class); + this.player.setRecovery(); + getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); + getApplicationContext().startActivity( + getSwitchIntent(MainVideoPlayer.class) + .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()) + ); + return true; } return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item); } @@ -190,14 +196,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity false, false ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()); - } - - protected boolean switchTo(final Class clazz) { - this.player.setRecovery(); - getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); - getApplicationContext().startActivity(getSwitchIntent(clazz)); - return true; + .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()); } ////////////////////////////////////////////////////////////////////////////