From a2ff770afca39876817367ca6d11530dc655dacc Mon Sep 17 00:00:00 2001 From: ktprograms Date: Mon, 11 Oct 2021 14:46:29 +0800 Subject: [PATCH 01/34] Added the 'Show Channel Details' menu item to the Queue long press menu Created a method in NavigationHelper that opens the channel fragment using an Intent to MainActivity instead of replacing fragments. --- .../java/org/schabi/newpipe/QueueItemMenuUtil.java | 8 ++++++-- .../org/schabi/newpipe/util/NavigationHelper.java | 12 ++++++++++++ app/src/main/res/menu/menu_play_queue_item.xml | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java index 9105ff992..f2f71730d 100644 --- a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java +++ b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java @@ -1,7 +1,5 @@ package org.schabi.newpipe; -import static org.schabi.newpipe.util.external_communication.ShareUtils.shareText; - import android.content.Context; import android.view.ContextThemeWrapper; import android.view.View; @@ -17,6 +15,8 @@ import org.schabi.newpipe.util.NavigationHelper; import java.util.Collections; +import static org.schabi.newpipe.util.external_communication.ShareUtils.shareText; + public final class QueueItemMenuUtil { public static void openPopupMenu(final PlayQueue playQueue, final PlayQueueItem item, @@ -55,6 +55,10 @@ public final class QueueItemMenuUtil { () -> PlaylistCreationDialog.newInstance(d) .show(fragmentManager, "QueueItemMenuUtil@append_playlist")); return true; + case R.id.menu_item_channel_details: + NavigationHelper.openChannelFragmentUsingIntent(context, item.getServiceId(), + item.getUploaderUrl(), item.getUploader()); + return true; case R.id.menu_item_share: shareText(context, item.getTitle(), item.getUrl(), item.getThumbnailUrl()); 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 afa826677..8852ef369 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -491,6 +491,18 @@ public final class NavigationHelper { context.startActivity(intent); } + public static void openChannelFragmentUsingIntent(final Context context, + final int serviceId, + final String url, + @NonNull final String title) { + final Intent intent = getOpenIntent(context, url, serviceId, + StreamingService.LinkType.CHANNEL); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Constants.KEY_TITLE, title); + + context.startActivity(intent); + } + public static void openMainActivity(final Context context) { final Intent mIntent = new Intent(context, MainActivity.class); mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/app/src/main/res/menu/menu_play_queue_item.xml b/app/src/main/res/menu/menu_play_queue_item.xml index ebb361be9..40c4849b4 100644 --- a/app/src/main/res/menu/menu_play_queue_item.xml +++ b/app/src/main/res/menu/menu_play_queue_item.xml @@ -10,6 +10,9 @@ + From afc8db8f816fb452aad407749ef032adaf9bf009 Mon Sep 17 00:00:00 2001 From: ktprograms Date: Thu, 14 Oct 2021 09:51:25 +0800 Subject: [PATCH 02/34] Add reasoning for separate openChannelFragmentUsingIntent method --- .../main/java/org/schabi/newpipe/util/NavigationHelper.java | 5 +++++ 1 file changed, 5 insertions(+) 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 8852ef369..9e6a3980c 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -491,6 +491,11 @@ public final class NavigationHelper { context.startActivity(intent); } + ///////////////////////////////////////////////////// + // PlayQueueActivity doesn't use fragments so the // + // openChannelFragment method can't be used // + // since that uses FragmentManager transactions. // + ///////////////////////////////////////////////////// public static void openChannelFragmentUsingIntent(final Context context, final int serviceId, final String url, From 2271ea4281ef1e05e08593e3d9e1314f09a2428d Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Fri, 15 Oct 2021 20:16:34 +0200 Subject: [PATCH 03/34] Improved documentation --- .../java/org/schabi/newpipe/QueueItemMenuUtil.java | 3 +++ .../org/schabi/newpipe/util/NavigationHelper.java | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java index f2f71730d..7d00d0027 100644 --- a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java +++ b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java @@ -56,6 +56,9 @@ public final class QueueItemMenuUtil { .show(fragmentManager, "QueueItemMenuUtil@append_playlist")); return true; case R.id.menu_item_channel_details: + // An intent must be used here. + // Opening with FragmentManager transactions is not working, + // as PlayQueueActivity doesn't use fragments. NavigationHelper.openChannelFragmentUsingIntent(context, item.getServiceId(), item.getUploaderUrl(), item.getUploader()); return true; 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 9e6a3980c..c70f6a9d0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -491,11 +491,15 @@ public final class NavigationHelper { context.startActivity(intent); } - ///////////////////////////////////////////////////// - // PlayQueueActivity doesn't use fragments so the // - // openChannelFragment method can't be used // - // since that uses FragmentManager transactions. // - ///////////////////////////////////////////////////// + /** + * Opens {@link ChannelFragment}. + * Use this instead of {@link #openChannelFragment(FragmentManager, int, String, String)} + * when no fragments are used / no FragmentManager is available. + * @param context + * @param serviceId + * @param url + * @param title + */ public static void openChannelFragmentUsingIntent(final Context context, final int serviceId, final String url, From 03d2ca9f9fe1c4ed55fb674cf88a6941fbf1f958 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Fri, 15 Oct 2021 20:18:52 +0200 Subject: [PATCH 04/34] Fixed format of code --- .../main/java/org/schabi/newpipe/QueueItemMenuUtil.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java index 7d00d0027..0201064b4 100644 --- a/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java +++ b/app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java @@ -1,5 +1,7 @@ package org.schabi.newpipe; +import static org.schabi.newpipe.util.external_communication.ShareUtils.shareText; + import android.content.Context; import android.view.ContextThemeWrapper; import android.view.View; @@ -15,9 +17,10 @@ import org.schabi.newpipe.util.NavigationHelper; import java.util.Collections; -import static org.schabi.newpipe.util.external_communication.ShareUtils.shareText; - public final class QueueItemMenuUtil { + private QueueItemMenuUtil() { + } + public static void openPopupMenu(final PlayQueue playQueue, final PlayQueueItem item, final View view, @@ -72,6 +75,4 @@ public final class QueueItemMenuUtil { popupMenu.show(); } - - private QueueItemMenuUtil() { } } From e7773d88077f57b4d37c0c4dd19449c9203fb1df Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Fri, 15 Oct 2021 16:48:44 -0400 Subject: [PATCH 05/34] Update plugins --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 4617611a8..1bcddd7cc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.5.30' + ext.kotlin_version = '1.5.31' repositories { google() mavenCentral() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' + classpath 'com.android.tools.build:gradle:7.0.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong From a55acd38dfad9027030f3668fbd895b947955448 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:32:38 +0200 Subject: [PATCH 06/34] Use a custom TextView everywhere to be able to share with ShareUtils the selected text This TextView class extends the AppCompatTextView class from androidx. These changes (only in XML ressources) allow us to share the selected text by using ShareUtils.shareText, which opens the Android system chooser instead of the Huawei system chooser on EMUI devices. --- .../schabi/newpipe/views/NewPipeTextView.java | 60 +++++++++ .../activity_player_queue_control.xml | 12 +- .../fragment_video_detail.xml | 40 +++--- app/src/main/res/layout-large-land/player.xml | 20 +-- app/src/main/res/layout/activity_error.xml | 20 +-- .../layout/activity_player_queue_control.xml | 122 +++++++++--------- app/src/main/res/layout/channel_header.xml | 6 +- .../res/layout/dialog_feed_group_create.xml | 8 +- .../res/layout/dialog_playback_parameter.xml | 35 ++--- app/src/main/res/layout/dialog_playlists.xml | 2 +- app/src/main/res/layout/dialog_title.xml | 4 +- app/src/main/res/layout/download_dialog.xml | 6 +- app/src/main/res/layout/drawer_header.xml | 4 +- app/src/main/res/layout/error_panel.xml | 6 +- .../res/layout/feed_group_add_new_item.xml | 2 +- .../main/res/layout/feed_group_card_item.xml | 2 +- .../res/layout/feed_group_reorder_item.xml | 2 +- .../res/layout/feed_import_export_group.xml | 6 +- app/src/main/res/layout/fragment_about.xml | 20 +-- app/src/main/res/layout/fragment_channel.xml | 6 +- .../main/res/layout/fragment_choose_tabs.xml | 2 +- app/src/main/res/layout/fragment_comments.xml | 4 +- .../main/res/layout/fragment_description.xml | 6 +- app/src/main/res/layout/fragment_feed.xml | 6 +- app/src/main/res/layout/fragment_import.xml | 2 +- .../res/layout/fragment_instance_list.xml | 2 +- app/src/main/res/layout/fragment_kiosk.xml | 4 +- app/src/main/res/layout/fragment_licenses.xml | 6 +- app/src/main/res/layout/fragment_playlist.xml | 4 +- .../res/layout/fragment_related_items.xml | 4 +- app/src/main/res/layout/fragment_search.xml | 8 +- .../main/res/layout/fragment_video_detail.xml | 40 +++--- .../main/res/layout/header_with_menu_item.xml | 2 +- .../main/res/layout/item_stream_segment.xml | 6 +- .../res/layout/list_choose_tabs_dialog.xml | 2 +- .../main/res/layout/list_comments_item.xml | 10 +- .../res/layout/list_comments_mini_item.xml | 8 +- app/src/main/res/layout/list_empty_view.xml | 4 +- .../res/layout/list_playlist_grid_item.xml | 6 +- .../main/res/layout/list_playlist_item.xml | 6 +- .../res/layout/list_playlist_mini_item.xml | 6 +- .../main/res/layout/list_stream_grid_item.xml | 8 +- app/src/main/res/layout/list_stream_item.xml | 8 +- .../main/res/layout/list_stream_mini_item.xml | 6 +- .../layout/list_stream_playlist_grid_item.xml | 6 +- .../res/layout/list_stream_playlist_item.xml | 6 +- .../main/res/layout/local_playlist_header.xml | 4 +- app/src/main/res/layout/main_bg.xml | 4 +- app/src/main/res/layout/mission_item.xml | 6 +- .../main/res/layout/mission_item_linear.xml | 6 +- app/src/main/res/layout/missions_header.xml | 2 +- .../res/layout/picker_subscription_item.xml | 2 +- app/src/main/res/layout/play_queue_item.xml | 6 +- app/src/main/res/layout/player.xml | 20 +-- app/src/main/res/layout/playlist_control.xml | 6 +- app/src/main/res/layout/playlist_header.xml | 6 +- .../main/res/layout/related_items_header.xml | 2 +- .../res/layout/select_channel_fragment.xml | 6 +- .../main/res/layout/select_channel_item.xml | 2 +- .../main/res/layout/select_kiosk_fragment.xml | 4 +- app/src/main/res/layout/select_kiosk_item.xml | 2 +- .../res/layout/select_playlist_fragment.xml | 4 +- .../settings_category_header_layout.xml | 2 +- .../layout/settings_category_header_title.xml | 2 +- .../main/res/layout/settings_notification.xml | 2 +- .../layout/settings_notification_action.xml | 4 +- .../res/layout/statistic_playlist_control.xml | 2 +- .../main/res/layout/stream_quality_item.xml | 6 +- .../subscription_import_export_item.xml | 2 +- 69 files changed, 362 insertions(+), 295 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java new file mode 100644 index 000000000..f69dfb33b --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java @@ -0,0 +1,60 @@ +package org.schabi.newpipe.views; + +import android.content.Context; +import android.text.Selection; +import android.text.Spannable; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; + +import org.schabi.newpipe.util.external_communication.ShareUtils; + +public class NewPipeTextView extends AppCompatTextView { + + public NewPipeTextView(@NonNull final Context context) { + super(context); + } + + public NewPipeTextView(@NonNull final Context context, @Nullable final AttributeSet attrs) { + super(context, attrs); + } + + public NewPipeTextView(@NonNull final Context context, + @Nullable final AttributeSet attrs, + final int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean onTextContextMenuItem(final int id) { + final CharSequence text = getText(); + if (id == android.R.id.shareText) { + final String selectedText = getSelectedText(text).toString(); + if (!selectedText.isEmpty()) { + ShareUtils.shareText(getContext(), "", selectedText); + } + final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; + Selection.setSelection(spannable, getSelectionEnd()); + return true; + } else { + return super.onTextContextMenuItem(id); + } + } + + @NonNull + private CharSequence getSelectedText(@NonNull final CharSequence charSequence) { + int min = 0; + int max = charSequence.length(); + + if (isFocused()) { + final int selStart = getSelectionStart(); + final int selEnd = getSelectionEnd(); + + min = Math.max(0, Math.min(selStart, selEnd)); + max = Math.max(0, Math.max(selStart, selEnd)); + } + return charSequence.subSequence(min, max); + } +} diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index 4b79d92f6..c2359552e 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -60,7 +60,7 @@ android:padding="8dp" tools:ignore="RtlHardcoded,RtlSymmetry"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -82,7 +82,7 @@ - - - - - - - + android:layout_above="@+id/playback_controls"> - + android:background="?attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" + android:orientation="vertical" + android:padding="8dp" + tools:ignore="RtlHardcoded,RtlSymmetry"> - + + + + + - + android:layout_centerInParent="true" + android:background="#c0000000" + android:paddingLeft="30dp" + android:paddingTop="5dp" + android:paddingRight="30dp" + android:paddingBottom="5dp" + android:textColor="@android:color/white" + android:textSize="22sp" + android:textStyle="bold" + android:visibility="gone" + tools:ignore="RtlHardcoded" + tools:text="1:06:29" + tools:visibility="visible" /> + + android:paddingRight="12dp"> - - - + diff --git a/app/src/main/res/layout/channel_header.xml b/app/src/main/res/layout/channel_header.xml index aebb5d613..9366faf2c 100644 --- a/app/src/main/res/layout/channel_header.xml +++ b/app/src/main/res/layout/channel_header.xml @@ -49,7 +49,7 @@ tools:visibility="visible" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -85,14 +85,14 @@ android:layout_gravity="end" android:text="@string/give_back" /> - - @@ -105,14 +105,14 @@ android:layout_gravity="end" android:text="@string/open_in_browser" /> - - diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 873f3c884..9e2257539 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -30,7 +30,7 @@ android:visibility="gone" tools:visibility="visible"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> - - - - --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + tools:listitem="@layout/select_channel_item" /> - - - + tools:listitem="@layout/select_kiosk_item" /> diff --git a/app/src/main/res/layout/select_kiosk_item.xml b/app/src/main/res/layout/select_kiosk_item.xml index 6cd04ae34..680767bba 100644 --- a/app/src/main/res/layout/select_kiosk_item.xml +++ b/app/src/main/res/layout/select_kiosk_item.xml @@ -22,7 +22,7 @@ app:tint="@color/contrastColor" tools:ignore="RtlHardcoded" /> - - - - diff --git a/app/src/main/res/layout/settings_category_header_title.xml b/app/src/main/res/layout/settings_category_header_title.xml index 679b9048c..c7d6920b0 100644 --- a/app/src/main/res/layout/settings_category_header_title.xml +++ b/app/src/main/res/layout/settings_category_header_title.xml @@ -1,5 +1,5 @@ - - - - - - - - - Date: Sat, 4 Sep 2021 19:40:24 +0200 Subject: [PATCH 07/34] Use a custom EditText everywhere to be able to share with ShareUtils the selected text This EditText class extends the AppCompatEditText class from androidx. These changes (only in XML ressources) allow us to share the selected text by using ShareUtils.shareText, which opens the Android system chooser instead of the Huawei system chooser on EMUI devices. --- .../schabi/newpipe/views/NewPipeEditText.java | 60 +++++++++++++++++++ app/src/main/res/layout/activity_error.xml | 2 +- app/src/main/res/layout/dialog_edit_text.xml | 2 +- .../res/layout/dialog_feed_group_create.xml | 2 +- app/src/main/res/layout/download_dialog.xml | 2 +- app/src/main/res/layout/fragment_import.xml | 2 +- .../main/res/layout/toolbar_search_layout.xml | 2 +- 7 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java new file mode 100644 index 000000000..15a70f360 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java @@ -0,0 +1,60 @@ +package org.schabi.newpipe.views; + +import android.content.Context; +import android.text.Selection; +import android.text.Spannable; +import android.util.AttributeSet; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatEditText; + +import org.schabi.newpipe.util.external_communication.ShareUtils; + +public class NewPipeEditText extends AppCompatEditText { + public NewPipeEditText(@NonNull final Context context) { + super(context); + } + + public NewPipeEditText(@NonNull final Context context, @Nullable final AttributeSet attrs) { + super(context, attrs); + } + + public NewPipeEditText(@NonNull final Context context, + @Nullable final AttributeSet attrs, + final int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean onTextContextMenuItem(final int id) { + final Spannable text = getText(); + if (id == android.R.id.shareText) { + if (text != null) { + final String selectedText = getSelectedText(text).toString(); + if (!selectedText.isEmpty()) { + ShareUtils.shareText(getContext(), "", selectedText); + } + Selection.setSelection(text, getSelectionEnd()); + } + return true; + } else { + return super.onTextContextMenuItem(id); + } + } + + @NonNull + private CharSequence getSelectedText(@NonNull final CharSequence charSequence) { + int min = 0; + int max = charSequence.length(); + + if (isFocused()) { + final int selStart = getSelectionStart(); + final int selEnd = getSelectionEnd(); + + min = Math.max(0, Math.min(selStart, selEnd)); + max = Math.max(0, Math.max(selStart, selEnd)); + } + return charSequence.subSequence(min, max); + } +} diff --git a/app/src/main/res/layout/activity_error.xml b/app/src/main/res/layout/activity_error.xml index a7b3c48a9..45101c1a1 100644 --- a/app/src/main/res/layout/activity_error.xml +++ b/app/src/main/res/layout/activity_error.xml @@ -109,7 +109,7 @@ android:text="@string/your_comment" android:textAppearance="?android:attr/textAppearanceMedium" /> - - - - - - Date: Tue, 14 Sep 2021 20:19:17 +0200 Subject: [PATCH 08/34] Add JavaDocs on created views --- .../java/org/schabi/newpipe/views/NewPipeEditText.java | 9 +++++++++ .../java/org/schabi/newpipe/views/NewPipeTextView.java | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java index 15a70f360..c7a397fbe 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java @@ -11,7 +11,16 @@ import androidx.appcompat.widget.AppCompatEditText; import org.schabi.newpipe.util.external_communication.ShareUtils; +/** + * An {@link AppCompatEditText} which uses {@link ShareUtils#shareText(Context, String, String)} + * when sharing selected text by using the {@code Share} command of the floating actions. + *

+ * This allows NewPipe to show Android share sheet instead of EMUI share sheet when sharing text + * from {@link AppCompatEditText} on EMUI devices. + *

+ */ public class NewPipeEditText extends AppCompatEditText { + public NewPipeEditText(@NonNull final Context context) { super(context); } diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java index f69dfb33b..321f1e34d 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java @@ -11,6 +11,14 @@ import androidx.appcompat.widget.AppCompatTextView; import org.schabi.newpipe.util.external_communication.ShareUtils; +/** + * An {@link AppCompatTextView} which uses {@link ShareUtils#shareText(Context, String, String)} + * when sharing selected text by using the {@code Share} command of the floating actions. + *

+ * This allows NewPipe to show Android share sheet instead of EMUI share sheet when sharing text + * from {@link AppCompatTextView} on EMUI devices. + *

+ */ public class NewPipeTextView extends AppCompatTextView { public NewPipeTextView(@NonNull final Context context) { From 3ded6feddb3921eeecf2b5b3030573bd39017a3a Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 18 Sep 2021 14:14:36 +0200 Subject: [PATCH 09/34] Improve code of created views Use the same logic as Android TextViews --- .../schabi/newpipe/views/NewPipeEditText.java | 33 ++++++++----------- .../schabi/newpipe/views/NewPipeTextView.java | 29 ++++++++-------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java index c7a397fbe..41d7640b6 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java @@ -37,33 +37,28 @@ public class NewPipeEditText extends AppCompatEditText { @Override public boolean onTextContextMenuItem(final int id) { - final Spannable text = getText(); if (id == android.R.id.shareText) { - if (text != null) { - final String selectedText = getSelectedText(text).toString(); - if (!selectedText.isEmpty()) { - ShareUtils.shareText(getContext(), "", selectedText); - } - Selection.setSelection(text, getSelectionEnd()); + final Spannable text = getText(); + final CharSequence selectedText = getSelectedText(text); + if (selectedText != null && selectedText.length() != 0) { + ShareUtils.shareText(getContext(), "", selectedText.toString()); } + Selection.setSelection(text, getSelectionEnd()); return true; } else { return super.onTextContextMenuItem(id); } } - @NonNull - private CharSequence getSelectedText(@NonNull final CharSequence charSequence) { - int min = 0; - int max = charSequence.length(); - - if (isFocused()) { - final int selStart = getSelectionStart(); - final int selEnd = getSelectionEnd(); - - min = Math.max(0, Math.min(selStart, selEnd)); - max = Math.max(0, Math.max(selStart, selEnd)); + @Nullable + private CharSequence getSelectedText(@Nullable final CharSequence text) { + if (!hasSelection() || text == null) { + return null; } - return charSequence.subSequence(min, max); + + final int start = getSelectionStart(); + final int end = getSelectionEnd(); + return String.valueOf(start > end ? text.subSequence(end, start) + : text.subSequence(start, end)); } } diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java index 321f1e34d..f333aae5d 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java @@ -37,11 +37,11 @@ public class NewPipeTextView extends AppCompatTextView { @Override public boolean onTextContextMenuItem(final int id) { - final CharSequence text = getText(); if (id == android.R.id.shareText) { - final String selectedText = getSelectedText(text).toString(); - if (!selectedText.isEmpty()) { - ShareUtils.shareText(getContext(), "", selectedText); + final CharSequence text = getText(); + final CharSequence selectedText = getSelectedText(text); + if (selectedText != null && selectedText.length() != 0) { + ShareUtils.shareText(getContext(), "", selectedText.toString()); } final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; Selection.setSelection(spannable, getSelectionEnd()); @@ -51,18 +51,15 @@ public class NewPipeTextView extends AppCompatTextView { } } - @NonNull - private CharSequence getSelectedText(@NonNull final CharSequence charSequence) { - int min = 0; - int max = charSequence.length(); - - if (isFocused()) { - final int selStart = getSelectionStart(); - final int selEnd = getSelectionEnd(); - - min = Math.max(0, Math.min(selStart, selEnd)); - max = Math.max(0, Math.max(selStart, selEnd)); + @Nullable + private CharSequence getSelectedText(@Nullable final CharSequence text) { + if (!hasSelection() || text == null) { + return null; } - return charSequence.subSequence(min, max); + + final int start = getSelectionStart(); + final int end = getSelectionEnd(); + return String.valueOf(start > end ? text.subSequence(end, start) + : text.subSequence(start, end)); } } From aab09c0c656e9f74ada7736a58306d086a08d4b0 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Fri, 24 Sep 2021 20:14:31 +0200 Subject: [PATCH 10/34] Merge the Share process of the two classes into one A new class has been added in the util package: NewPipeTextViewHelper. It shares the selected text of a TextView with ShareUtils#shareText (with the created shareSelectedTextWithShareUtils static method). Only this static method can be used by other classes, other methods are private. --- .../newpipe/util/NewPipeTextViewHelper.java | 86 +++++++++++++++++++ .../schabi/newpipe/views/NewPipeEditText.java | 27 +----- .../schabi/newpipe/views/NewPipeTextView.java | 28 +----- 3 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java diff --git a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java new file mode 100644 index 000000000..31c87f7df --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java @@ -0,0 +1,86 @@ +package org.schabi.newpipe.util; + +import android.content.Context; +import android.text.Selection; +import android.text.Spannable; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.schabi.newpipe.util.external_communication.ShareUtils; +import org.schabi.newpipe.views.NewPipeEditText; +import org.schabi.newpipe.views.NewPipeTextView; + +public final class NewPipeTextViewHelper { + private NewPipeTextViewHelper() { + } + + /** + * Share the selected text of {@link NewPipeTextView NewPipeTextViews} and + * {@link NewPipeEditText NewPipeEditTexts} with + * {@link ShareUtils#shareText(Context, String, String)}. + * + *

+ * This allows EMUI users to get the Android share sheet instead of the EMUI share sheet when + * using the {@code Share} command of the popup menu which appears when selecting text. + *

+ * + * @param textView the {@link TextView} on which sharing the selected text. It should be a + * {@link NewPipeTextView} or a {@link NewPipeEditText} (even if + * {@link TextView standard TextViews} are supported). + * + * @return true if no exceptions occurred when getting the selected text, sharing it and + * deselecting it, otherwise an exception + */ + public static boolean shareSelectedTextWithShareUtils(@NonNull final TextView textView) { + if (textView instanceof NewPipeTextView) { + final NewPipeTextView newPipeTextView = (NewPipeTextView) textView; + final CharSequence text = newPipeTextView.getText(); + final CharSequence selectedText = getSelectedText(newPipeTextView, text); + + shareSelectedTextIfNotNullAndNotEmpty(newPipeTextView, selectedText); + + final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; + Selection.setSelection(spannable, newPipeTextView.getSelectionEnd()); + } else if (textView instanceof NewPipeEditText) { + final NewPipeEditText editText = (NewPipeEditText) textView; + final Spannable text = editText.getText(); + + final CharSequence selectedText = getSelectedText(textView, text); + shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); + Selection.setSelection(text, editText.getSelectionEnd()); + } else { + final CharSequence text = textView.getText(); + final CharSequence selectedText = getSelectedText(textView, text); + + shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); + + final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; + Selection.setSelection(spannable, textView.getSelectionEnd()); + } + + return true; + } + + @Nullable + private static CharSequence getSelectedText(@NonNull final TextView textView, + @Nullable final CharSequence text) { + if (!textView.hasSelection() || text == null) { + return null; + } + + final int start = textView.getSelectionStart(); + final int end = textView.getSelectionEnd(); + return String.valueOf(start > end ? text.subSequence(end, start) + : text.subSequence(start, end)); + } + + private static void shareSelectedTextIfNotNullAndNotEmpty( + @NonNull final TextView textView, + @Nullable final CharSequence selectedText) { + if (selectedText != null && selectedText.length() != 0) { + ShareUtils.shareText(textView.getContext(), "", selectedText.toString()); + } + } +} diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java index 41d7640b6..cdb4f0041 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java @@ -1,8 +1,6 @@ package org.schabi.newpipe.views; import android.content.Context; -import android.text.Selection; -import android.text.Spannable; import android.util.AttributeSet; import androidx.annotation.NonNull; @@ -11,6 +9,8 @@ import androidx.appcompat.widget.AppCompatEditText; import org.schabi.newpipe.util.external_communication.ShareUtils; +import static org.schabi.newpipe.util.NewPipeTextViewHelper.shareSelectedTextWithShareUtils; + /** * An {@link AppCompatEditText} which uses {@link ShareUtils#shareText(Context, String, String)} * when sharing selected text by using the {@code Share} command of the floating actions. @@ -38,27 +38,8 @@ public class NewPipeEditText extends AppCompatEditText { @Override public boolean onTextContextMenuItem(final int id) { if (id == android.R.id.shareText) { - final Spannable text = getText(); - final CharSequence selectedText = getSelectedText(text); - if (selectedText != null && selectedText.length() != 0) { - ShareUtils.shareText(getContext(), "", selectedText.toString()); - } - Selection.setSelection(text, getSelectionEnd()); - return true; - } else { - return super.onTextContextMenuItem(id); + return shareSelectedTextWithShareUtils(this); } - } - - @Nullable - private CharSequence getSelectedText(@Nullable final CharSequence text) { - if (!hasSelection() || text == null) { - return null; - } - - final int start = getSelectionStart(); - final int end = getSelectionEnd(); - return String.valueOf(start > end ? text.subSequence(end, start) - : text.subSequence(start, end)); + return super.onTextContextMenuItem(id); } } diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java index f333aae5d..75fb8f161 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java @@ -1,8 +1,6 @@ package org.schabi.newpipe.views; import android.content.Context; -import android.text.Selection; -import android.text.Spannable; import android.util.AttributeSet; import androidx.annotation.NonNull; @@ -11,6 +9,8 @@ import androidx.appcompat.widget.AppCompatTextView; import org.schabi.newpipe.util.external_communication.ShareUtils; +import static org.schabi.newpipe.util.NewPipeTextViewHelper.shareSelectedTextWithShareUtils; + /** * An {@link AppCompatTextView} which uses {@link ShareUtils#shareText(Context, String, String)} * when sharing selected text by using the {@code Share} command of the floating actions. @@ -38,28 +38,8 @@ public class NewPipeTextView extends AppCompatTextView { @Override public boolean onTextContextMenuItem(final int id) { if (id == android.R.id.shareText) { - final CharSequence text = getText(); - final CharSequence selectedText = getSelectedText(text); - if (selectedText != null && selectedText.length() != 0) { - ShareUtils.shareText(getContext(), "", selectedText.toString()); - } - final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; - Selection.setSelection(spannable, getSelectionEnd()); - return true; - } else { - return super.onTextContextMenuItem(id); + return shareSelectedTextWithShareUtils(this); } - } - - @Nullable - private CharSequence getSelectedText(@Nullable final CharSequence text) { - if (!hasSelection() || text == null) { - return null; - } - - final int start = getSelectionStart(); - final int end = getSelectionEnd(); - return String.valueOf(start > end ? text.subSequence(end, start) - : text.subSequence(start, end)); + return super.onTextContextMenuItem(id); } } From 50b85a7734f9d463007e6352c5230349df4744ac Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Fri, 1 Oct 2021 23:39:14 +0200 Subject: [PATCH 11/34] Simplify code --- .../newpipe/util/NewPipeTextViewHelper.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java index 31c87f7df..5e3a790d0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java @@ -34,30 +34,30 @@ public final class NewPipeTextViewHelper { * deselecting it, otherwise an exception */ public static boolean shareSelectedTextWithShareUtils(@NonNull final TextView textView) { - if (textView instanceof NewPipeTextView) { - final NewPipeTextView newPipeTextView = (NewPipeTextView) textView; - final CharSequence text = newPipeTextView.getText(); - final CharSequence selectedText = getSelectedText(newPipeTextView, text); + if (!(textView instanceof NewPipeEditText)) { + final CharSequence textViewText; + if (textView instanceof NewPipeTextView) { + final NewPipeTextView newPipeTextView = (NewPipeTextView) textView; + textViewText = newPipeTextView.getText(); + } else { + textViewText = textView.getText(); + } - shareSelectedTextIfNotNullAndNotEmpty(newPipeTextView, selectedText); + final CharSequence selectedText = getSelectedText(textView, textViewText); + shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); - final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; - Selection.setSelection(spannable, newPipeTextView.getSelectionEnd()); - } else if (textView instanceof NewPipeEditText) { + final Spannable spannable = (textViewText instanceof Spannable) + ? (Spannable) textViewText : null; + if (spannable != null) { + Selection.setSelection(spannable, textView.getSelectionEnd()); + } + } else { final NewPipeEditText editText = (NewPipeEditText) textView; final Spannable text = editText.getText(); final CharSequence selectedText = getSelectedText(textView, text); shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); Selection.setSelection(text, editText.getSelectionEnd()); - } else { - final CharSequence text = textView.getText(); - final CharSequence selectedText = getSelectedText(textView, text); - - shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); - - final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null; - Selection.setSelection(spannable, textView.getSelectionEnd()); } return true; @@ -65,7 +65,7 @@ public final class NewPipeTextViewHelper { @Nullable private static CharSequence getSelectedText(@NonNull final TextView textView, - @Nullable final CharSequence text) { + @Nullable final CharSequence text) { if (!textView.hasSelection() || text == null) { return null; } From a744775fe771a9aad41668470ebe55193a83e5d7 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 2 Oct 2021 19:53:17 +0200 Subject: [PATCH 12/34] Adress requested changes and remove an unused return value in NewPipeTextViewHelper --- .../org/schabi/newpipe/util/NewPipeTextViewHelper.java | 7 +------ .../java/org/schabi/newpipe/views/NewPipeEditText.java | 6 +++--- .../java/org/schabi/newpipe/views/NewPipeTextView.java | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java index 5e3a790d0..6db016090 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java @@ -29,11 +29,8 @@ public final class NewPipeTextViewHelper { * @param textView the {@link TextView} on which sharing the selected text. It should be a * {@link NewPipeTextView} or a {@link NewPipeEditText} (even if * {@link TextView standard TextViews} are supported). - * - * @return true if no exceptions occurred when getting the selected text, sharing it and - * deselecting it, otherwise an exception */ - public static boolean shareSelectedTextWithShareUtils(@NonNull final TextView textView) { + public static void shareSelectedTextWithShareUtils(@NonNull final TextView textView) { if (!(textView instanceof NewPipeEditText)) { final CharSequence textViewText; if (textView instanceof NewPipeTextView) { @@ -59,8 +56,6 @@ public final class NewPipeTextViewHelper { shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); Selection.setSelection(text, editText.getSelectionEnd()); } - - return true; } @Nullable diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java index cdb4f0041..2adc28d0e 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeEditText.java @@ -7,10 +7,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatEditText; +import org.schabi.newpipe.util.NewPipeTextViewHelper; import org.schabi.newpipe.util.external_communication.ShareUtils; -import static org.schabi.newpipe.util.NewPipeTextViewHelper.shareSelectedTextWithShareUtils; - /** * An {@link AppCompatEditText} which uses {@link ShareUtils#shareText(Context, String, String)} * when sharing selected text by using the {@code Share} command of the floating actions. @@ -38,7 +37,8 @@ public class NewPipeEditText extends AppCompatEditText { @Override public boolean onTextContextMenuItem(final int id) { if (id == android.R.id.shareText) { - return shareSelectedTextWithShareUtils(this); + NewPipeTextViewHelper.shareSelectedTextWithShareUtils(this); + return true; } return super.onTextContextMenuItem(id); } diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java index 75fb8f161..8fdac32db 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeTextView.java @@ -7,10 +7,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatTextView; +import org.schabi.newpipe.util.NewPipeTextViewHelper; import org.schabi.newpipe.util.external_communication.ShareUtils; -import static org.schabi.newpipe.util.NewPipeTextViewHelper.shareSelectedTextWithShareUtils; - /** * An {@link AppCompatTextView} which uses {@link ShareUtils#shareText(Context, String, String)} * when sharing selected text by using the {@code Share} command of the floating actions. @@ -38,7 +37,8 @@ public class NewPipeTextView extends AppCompatTextView { @Override public boolean onTextContextMenuItem(final int id) { if (id == android.R.id.shareText) { - return shareSelectedTextWithShareUtils(this); + NewPipeTextViewHelper.shareSelectedTextWithShareUtils(this); + return true; } return super.onTextContextMenuItem(id); } From ddaafb68c8561bb740c086d72c3b04ee69a9c22f Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 16 Oct 2021 15:32:56 +0200 Subject: [PATCH 13/34] Adress new requested changes --- .../newpipe/util/NewPipeTextViewHelper.java | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java index 6db016090..cf1a9a03a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NewPipeTextViewHelper.java @@ -31,30 +31,10 @@ public final class NewPipeTextViewHelper { * {@link TextView standard TextViews} are supported). */ public static void shareSelectedTextWithShareUtils(@NonNull final TextView textView) { - if (!(textView instanceof NewPipeEditText)) { - final CharSequence textViewText; - if (textView instanceof NewPipeTextView) { - final NewPipeTextView newPipeTextView = (NewPipeTextView) textView; - textViewText = newPipeTextView.getText(); - } else { - textViewText = textView.getText(); - } - - final CharSequence selectedText = getSelectedText(textView, textViewText); - shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); - - final Spannable spannable = (textViewText instanceof Spannable) - ? (Spannable) textViewText : null; - if (spannable != null) { - Selection.setSelection(spannable, textView.getSelectionEnd()); - } - } else { - final NewPipeEditText editText = (NewPipeEditText) textView; - final Spannable text = editText.getText(); - - final CharSequence selectedText = getSelectedText(textView, text); - shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText); - Selection.setSelection(text, editText.getSelectionEnd()); + final CharSequence textViewText = textView.getText(); + shareSelectedTextIfNotNullAndNotEmpty(textView, getSelectedText(textView, textViewText)); + if (textViewText instanceof Spannable) { + Selection.setSelection((Spannable) textViewText, textView.getSelectionEnd()); } } From 51837ce36f512f0469acbc7fec7f63f3b6280522 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 16 Oct 2021 15:33:45 -0400 Subject: [PATCH 14/34] Get rid of setUserVisibleHint --- .../java/org/schabi/newpipe/BaseFragment.java | 10 +--------- .../newpipe/fragments/BlankFragment.java | 4 ++-- .../list/channel/ChannelFragment.java | 8 +++----- .../fragments/list/kiosk/KioskFragment.java | 18 ++++++------------ .../local/bookmark/BookmarkFragment.java | 6 +++--- .../history/StatisticsPlaylistFragment.java | 6 +++--- .../SubscriptionsImportFragment.java | 8 +++----- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 0be427648..16ddb8376 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -21,7 +21,6 @@ public abstract class BaseFragment extends Fragment { //These values are used for controlling fragments when they are part of the frontpage @State protected boolean useAsFrontPage = false; - private boolean mIsVisibleToUser = false; public void useAsFrontPage(final boolean value) { useAsFrontPage = value; @@ -85,12 +84,6 @@ public abstract class BaseFragment extends Fragment { AppWatcher.INSTANCE.getObjectWatcher().watch(this); } - @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - mIsVisibleToUser = isVisibleToUser; - } - /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ @@ -109,8 +102,7 @@ public abstract class BaseFragment extends Fragment { if (DEBUG) { Log.d(TAG, "setTitle() called with: title = [" + title + "]"); } - if ((!useAsFrontPage || mIsVisibleToUser) - && (activity != null && activity.getSupportActionBar() != null)) { + if (!useAsFrontPage && activity != null && activity.getSupportActionBar() != null) { activity.getSupportActionBar().setDisplayShowTitleEnabled(true); activity.getSupportActionBar().setTitle(title); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java index 0cccfa4fe..fe4eef37a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java @@ -20,8 +20,8 @@ public class BlankFragment extends BaseFragment { } @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); + public void onResume() { + super.onResume(); setTitle("NewPipe"); // leave this inline. Will make it harder for copy cats. // If you are a Copy cat FUCK YOU. 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 1d16559ac..30e38a966 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 @@ -98,11 +98,9 @@ public class ChannelFragment extends BaseListInfoFragment } @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - if (activity != null - && useAsFrontPage - && isVisibleToUser) { + public void onResume() { + super.onResume(); + if (activity != null && useAsFrontPage) { setTitle(currentInfo != null ? currentInfo.getName() : name); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index f37f487bf..c25f18e8b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -99,9 +99,12 @@ public class KioskFragment extends BaseListInfoFragment { } @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - if (useAsFrontPage && isVisibleToUser && activity != null) { + public void onResume() { + super.onResume(); + if (!Localization.getPreferredContentCountry(requireContext()).equals(contentCountry)) { + reloadContent(); + } + if (useAsFrontPage && activity != null) { try { setTitle(kioskTranslatedName); } catch (final Exception e) { @@ -117,15 +120,6 @@ public class KioskFragment extends BaseListInfoFragment { return inflater.inflate(R.layout.fragment_kiosk, container, false); } - @Override - public void onResume() { - super.onResume(); - - if (!Localization.getPreferredContentCountry(requireContext()).equals(contentCountry)) { - reloadContent(); - } - } - /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 794e5a33a..f272a8831 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -78,9 +78,9 @@ public final class BookmarkFragment extends BaseLocalListFragment Date: Sun, 17 Oct 2021 12:07:13 +0200 Subject: [PATCH 15/34] [Player] Fix resuming playback This was caused by #6872 --- app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java | 1 + 1 file changed, 1 insertion(+) 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 afa826677..1f2aa98ae 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -87,6 +87,7 @@ public final class NavigationHelper { } } intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); + intent.putExtra(Player.RESUME_PLAYBACK, true); return intent; } From 28c72e7f630013c93c599bf9350583c8dbb1f71c Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Oct 2021 12:54:56 +0200 Subject: [PATCH 16/34] Fix new version check still occassionally started in background --- app/src/main/java/org/schabi/newpipe/App.java | 9 +++++++++ .../java/org/schabi/newpipe/MainActivity.java | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index b44f7517d..7562c2a21 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -65,6 +65,7 @@ public class App extends MultiDexApplication { public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID; private static final String TAG = App.class.toString(); private static App app; + private static boolean wasAppInForeground = false; @NonNull public static App getApp() { @@ -254,4 +255,12 @@ public class App extends MultiDexApplication { protected boolean isDisposedRxExceptionsReported() { return false; } + + public static boolean wasAppInForeground() { + return wasAppInForeground; + } + + public static void setWasAppInForeground(final boolean wasAppInForeground) { + App.wasAppInForeground = wasAppInForeground; + } } diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 18ab69b7b..ed3826946 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -21,6 +21,7 @@ package org.schabi.newpipe; import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import android.content.BroadcastReceiver; import android.content.Context; @@ -93,8 +94,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; - public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @SuppressWarnings("ConstantConditions") @@ -165,9 +164,6 @@ public class MainActivity extends AppCompatActivity { FocusOverlayView.setupFocusObserver(this); } openMiniPlayerUponPlayerStarted(); - - // Check for new version - startNewVersionCheckService(); } private void setupDrawer() throws Exception { @@ -520,6 +516,19 @@ public class MainActivity extends AppCompatActivity { getString(R.string.enable_watch_history_key), true); drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY) .setVisible(isHistoryEnabled); + + if (!App.wasAppInForeground()) { + // Check for new app version + // The service searching for a new NewPipe version must not be started in background + // and therefore needs to be placed in onResume(). + // Only start the service once when app is started + // and not everytime onResume() is called. + if (DEBUG) { + Log.d(TAG, "App is in foreground for the first time"); + } + App.setWasAppInForeground(true); + startNewVersionCheckService(); + } } @Override From b79ea7b51b6451fc0133eb09602239753ee662d2 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Oct 2021 12:10:24 +0200 Subject: [PATCH 17/34] NewPipe 0.21.13 (979) --- app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/979.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/979.txt diff --git a/app/build.gradle b/app/build.gradle index e09395cff..468006578 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { resValue "string", "app_name", "NewPipe" minSdkVersion 19 targetSdkVersion 29 - versionCode 978 - versionName "0.21.12" + versionCode 979 + versionName "0.21.13" multiDexEnabled true diff --git a/fastlane/metadata/android/en-US/changelogs/979.txt b/fastlane/metadata/android/en-US/changelogs/979.txt new file mode 100644 index 000000000..4ba2a9f5a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/979.txt @@ -0,0 +1 @@ +Fixed resuming playback. \ No newline at end of file From b4950fcb2ee559e02282219dd331c6c9d3c6dab0 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 16 Oct 2021 16:04:51 -0400 Subject: [PATCH 18/34] Clean up .gitignore files --- .gitignore | 16 ++++++++-------- app/.gitignore | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 app/.gitignore diff --git a/.gitignore b/.gitignore index 5c6962be1..40e7d2c03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,15 @@ -.gitignore -.gradle -/local.properties +.gradle/ +local.properties .DS_Store -/build -/captures -/app/app.iml -/.idea -/*.iml +build/ +captures/ +.idea/ +*.iml *~ .weblate *.class +**/debug/ +**/release/ # vscode / eclipse files *.classpath diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 53edac5e4..000000000 --- a/app/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.gitignore -/build -*.iml From b6b19b474eba23369b5250c250ab7fe7e8adbef2 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Tue, 19 Oct 2021 17:31:59 -0400 Subject: [PATCH 19/34] Update RecyclerView & Groupie --- app/build.gradle | 7 +++++-- .../schabi/newpipe/fragments/list/BaseListFragment.java | 2 +- .../newpipe/fragments/list/search/SearchFragment.java | 4 ++-- .../newpipe/local/playlist/LocalPlaylistFragment.java | 4 ++-- .../local/subscription/dialog/FeedGroupReorderDialog.kt | 4 ++-- .../player/playqueue/PlayQueueItemTouchCallback.java | 2 +- .../newpipe/settings/PeertubeInstanceListFragment.java | 6 +++--- .../schabi/newpipe/settings/tabs/ChooseTabsFragment.java | 6 +++--- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 970cfa89d..f13483012 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -107,7 +107,7 @@ ext { icepickVersion = '3.2.0' exoPlayerVersion = '2.12.3' googleAutoServiceVersion = '1.0' - groupieVersion = '2.9.0' + groupieVersion = '2.10.0' markwonVersion = '4.6.2' leakCanaryVersion = '2.5' @@ -211,11 +211,14 @@ dependencies { implementation 'androidx.media:media:1.4.2' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.preference:preference:1.1.1' - implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation "androidx.room:room-runtime:${androidxRoomVersion}" implementation "androidx.room:room-rxjava3:${androidxRoomVersion}" kapt "androidx.room:room-compiler:${androidxRoomVersion}" implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' + // Newer version specified to prevent accessibility regressions with RecyclerView, see: + // https://developer.android.com/jetpack/androidx/releases/viewpager2#1.1.0-alpha01 + implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01' implementation 'androidx.webkit:webkit:1.4.0' implementation 'com.google.android.material:material:1.2.1' 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 c30b6fc05..037eb8f94 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 @@ -143,7 +143,7 @@ public abstract class BaseListFragment extends BaseStateFragment final View focusedItem = itemsList.getFocusedChild(); final RecyclerView.ViewHolder itemHolder = itemsList.findContainingViewHolder(focusedItem); - return itemHolder.getAdapterPosition(); + return itemHolder.getBindingAdapterPosition(); } catch (final NullPointerException e) { return -1; } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 7de212383..d4d73f74f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -1088,7 +1088,7 @@ public class SearchFragment extends BaseListFragment Date: Tue, 19 Oct 2021 17:36:36 -0400 Subject: [PATCH 20/34] Update AndroidX Media library --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 970cfa89d..bb269eef0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -208,7 +208,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-livedata:${androidxLifecycleVersion}" implementation "androidx.lifecycle:lifecycle-viewmodel:${androidxLifecycleVersion}" implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - implementation 'androidx.media:media:1.4.2' + implementation 'androidx.media:media:1.4.3' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.recyclerview:recyclerview:1.1.0' From ed86b1c572bd9ca0b495e34ac7b57969caea95dd Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Tue, 19 Oct 2021 17:39:38 -0400 Subject: [PATCH 21/34] Update pager workaround to Fragment 1.3.6 --- ...agmentStatePagerAdapterMenuWorkaround.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java index 433c155c2..639443377 100644 --- a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java +++ b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java @@ -51,8 +51,12 @@ import java.util.ArrayList; *
  • {@link #saveState()}
  • *
  • {@link #restoreState(Parcelable, ClassLoader)}
  • * + * + * @deprecated Switch to {@link androidx.viewpager2.widget.ViewPager2} and use + * {@link androidx.viewpager2.adapter.FragmentStateAdapter} instead. */ @SuppressWarnings("deprecation") +@Deprecated public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapter { private static final String TAG = "FragmentStatePagerAdapt"; private static final boolean DEBUG = false; @@ -86,9 +90,10 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt private final int mBehavior; private FragmentTransaction mCurTransaction = null; - private final ArrayList mSavedState = new ArrayList(); - private final ArrayList mFragments = new ArrayList(); + private final ArrayList mSavedState = new ArrayList<>(); + private final ArrayList mFragments = new ArrayList<>(); private Fragment mCurrentPrimaryItem = null; + private boolean mExecutingFinishUpdate; /** * Constructor for {@link FragmentStatePagerAdapterMenuWorkaround} @@ -208,7 +213,7 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt mFragments.set(position, null); mCurTransaction.remove(fragment); - if (fragment == mCurrentPrimaryItem) { + if (fragment.equals(mCurrentPrimaryItem)) { mCurrentPrimaryItem = null; } } @@ -247,7 +252,19 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt @Override public void finishUpdate(@NonNull final ViewGroup container) { if (mCurTransaction != null) { - mCurTransaction.commitNowAllowingStateLoss(); + // We drop any transactions that attempt to be committed + // from a re-entrant call to finishUpdate(). We need to + // do this as a workaround for Robolectric running measure/layout + // calls inline rather than allowing them to be posted + // as they would on a real device. + if (!mExecutingFinishUpdate) { + try { + mExecutingFinishUpdate = true; + mCurTransaction.commitNowAllowingStateLoss(); + } finally { + mExecutingFinishUpdate = false; + } + } mCurTransaction = null; } } From ac071b383f5fa63fed87f0d884ecac1a14d6ef49 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 20 Oct 2021 22:11:46 +0200 Subject: [PATCH 22/34] Revert part of #6872 and fix playback resuming --- .../fragments/detail/VideoDetailFragment.java | 2 +- .../schabi/newpipe/util/NavigationHelper.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) 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 5a30ea0f3..437cb2fdb 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 @@ -1181,7 +1181,7 @@ public final class VideoDetailFragment addVideoPlayerView(); final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(), - MainPlayer.class, queue, autoPlayEnabled); + MainPlayer.class, queue, true, autoPlayEnabled); ContextCompat.startForegroundService(activity, playerIntent); } 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 1f2aa98ae..cb796a7a6 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -77,7 +77,8 @@ public final class NavigationHelper { @NonNull public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, - @Nullable final PlayQueue playQueue) { + @Nullable final PlayQueue playQueue, + final boolean resumePlayback) { final Intent intent = new Intent(context, targetClazz); if (playQueue != null) { @@ -87,7 +88,7 @@ public final class NavigationHelper { } } intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); - intent.putExtra(Player.RESUME_PLAYBACK, true); + intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); return intent; } @@ -96,8 +97,9 @@ public final class NavigationHelper { public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue, + final boolean resumePlayback, final boolean playWhenReady) { - return getPlayerIntent(context, targetClazz, playQueue) + return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) .putExtra(Player.PLAY_WHEN_READY, playWhenReady); } @@ -105,7 +107,14 @@ public final class NavigationHelper { public static Intent getPlayerEnqueueIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue) { - return getPlayerIntent(context, targetClazz, playQueue) + // when enqueueing `resumePlayback` is always `false` since: + // - if there is a video already playing, the value of `resumePlayback` just doesn't make + // any difference. + // - if there is nothing already playing, it is useful for the enqueue action to have a + // slightly different behaviour than the normal play action: the latter resumes playback, + // the former doesn't. (note that enqueue can be triggered when nothing is playing only + // by long pressing the video detail fragment, playlist or channel controls + return getPlayerIntent(context, targetClazz, playQueue, false) .putExtra(Player.ENQUEUE, true); } @@ -113,7 +122,8 @@ public final class NavigationHelper { public static Intent getPlayerEnqueueNextIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue) { - return getPlayerIntent(context, targetClazz, playQueue) + // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false + return getPlayerIntent(context, targetClazz, playQueue, false) .putExtra(Player.ENQUEUE_NEXT, true); } From 768bb0bbcd11b7af894fd0c9d61dcaf3be1e5328 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Wed, 20 Oct 2021 23:55:14 +0200 Subject: [PATCH 23/34] Start service for update checks in onPastCreate() --- app/src/main/java/org/schabi/newpipe/App.java | 8 ------- .../schabi/newpipe/CheckForNewAppVersion.java | 17 ++++++++++++++ .../java/org/schabi/newpipe/MainActivity.java | 22 ++++++++----------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 7562c2a21..3785249b4 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -65,7 +65,6 @@ public class App extends MultiDexApplication { public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID; private static final String TAG = App.class.toString(); private static App app; - private static boolean wasAppInForeground = false; @NonNull public static App getApp() { @@ -256,11 +255,4 @@ public class App extends MultiDexApplication { return false; } - public static boolean wasAppInForeground() { - return wasAppInForeground; - } - - public static void setWasAppInForeground(final boolean wasAppInForeground) { - App.wasAppInForeground = wasAppInForeground; - } } diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 64874cd93..9c392be1e 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -235,6 +235,23 @@ public final class CheckForNewAppVersion extends IntentService { } } + /** + * Start a new service which + * checks if all conditions for performing a version check are met, + * fetches the API endpoint {@link #NEWPIPE_API_URL} containing info + * about the latest NewPipe version + * and displays a notification about ana available update. + *
    + * Following conditions need to be met, before data is request from the server: + *
      + *
    • The app is signed with the correct signing key (by TeamNewPipe / schabi). + * If the signing key differs from the one used upstream, the update cannot be installed.
    • + *
    • The user enabled searching for and notifying about updates in the settings.
    • + *
    • The app did not recently check for updates. + * We do not want to make unnecessary connections and DOS our servers.
    • + *
    + * Must not be executed when the app is in background. + */ public static void startNewVersionCheckService() { final Intent intent = new Intent(App.getApp().getApplicationContext(), CheckForNewAppVersion.class); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index ed3826946..2a8872e26 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -166,6 +166,15 @@ public class MainActivity extends AppCompatActivity { openMiniPlayerUponPlayerStarted(); } + @Override + protected void onPostCreate(final Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Start the service which is checking all conditions + // and eventually searching for a new version. + // The service searching for a new NewPipe version must not be started in background. + startNewVersionCheckService(); + } + private void setupDrawer() throws Exception { //Tabs final int currentServiceId = ServiceHelper.getSelectedServiceId(this); @@ -516,19 +525,6 @@ public class MainActivity extends AppCompatActivity { getString(R.string.enable_watch_history_key), true); drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY) .setVisible(isHistoryEnabled); - - if (!App.wasAppInForeground()) { - // Check for new app version - // The service searching for a new NewPipe version must not be started in background - // and therefore needs to be placed in onResume(). - // Only start the service once when app is started - // and not everytime onResume() is called. - if (DEBUG) { - Log.d(TAG, "App is in foreground for the first time"); - } - App.setWasAppInForeground(true); - startNewVersionCheckService(); - } } @Override From 5d59025b3c0fefe555393318a3fd147e536ed6d6 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Thu, 21 Oct 2021 20:30:10 +0200 Subject: [PATCH 24/34] Update changelog --- fastlane/metadata/android/en-US/changelogs/979.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastlane/metadata/android/en-US/changelogs/979.txt b/fastlane/metadata/android/en-US/changelogs/979.txt index 4ba2a9f5a..520d92993 100644 --- a/fastlane/metadata/android/en-US/changelogs/979.txt +++ b/fastlane/metadata/android/en-US/changelogs/979.txt @@ -1 +1,2 @@ -Fixed resuming playback. \ No newline at end of file +- Fixed resuming playback +- Improvements to ensure that the service which determines if NewPipe should check for a new version checks is not started in background \ No newline at end of file From 61972141aeeeacf2d921a28449413f65a524def8 Mon Sep 17 00:00:00 2001 From: mhmdanas Date: Sat, 23 Oct 2021 23:14:25 +0300 Subject: [PATCH 25/34] Add support for y2u.be links --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6510b31ab..6f2f24832 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -189,7 +189,7 @@ dependencies { // name and the commit hash with the commit hash of the (pushed) commit you want to test // This works thanks to JitPack: https://jitpack.io/ implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.21.11' + implementation 'com.github.TeamNewPipe:mhmdanas:3e8e2a1532681321c7c349342e032414baee5051' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d92d0b5bf..6a2700596 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -256,6 +256,21 @@ + + + + + + + + + + + + + + + From f6efd302dcf2510cbcecc566a84538438df1f201 Mon Sep 17 00:00:00 2001 From: Mohammed Anas Date: Sat, 23 Oct 2021 20:30:04 +0000 Subject: [PATCH 26/34] Fix extractor dependency --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6f2f24832..8da3bc596 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -189,7 +189,7 @@ dependencies { // name and the commit hash with the commit hash of the (pushed) commit you want to test // This works thanks to JitPack: https://jitpack.io/ implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.TeamNewPipe:mhmdanas:3e8e2a1532681321c7c349342e032414baee5051' + implementation 'com.github.mhmdanas:NewPipeExtractor:3e8e2a1532681321c7c349342e032414baee5051' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" From 25e120bec1233b2e5d8ed7644408c7c0f49727a1 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 18:47:48 +0200 Subject: [PATCH 27/34] Changed extractor dependency back to TeamNewPipe ...as the required PR was merged. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8da3bc596..880e93d26 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -189,7 +189,7 @@ dependencies { // name and the commit hash with the commit hash of the (pushed) commit you want to test // This works thanks to JitPack: https://jitpack.io/ implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.mhmdanas:NewPipeExtractor:3e8e2a1532681321c7c349342e032414baee5051' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:4f60225ddc8a29e7a36a4ed77d73b713ba3451d9' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" From 0bcc9bd3ba67b34ecf19aac98c4b1a65f85b4b6a Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 19:07:54 +0200 Subject: [PATCH 28/34] Try to fix jitpack not resolving dependency --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 880e93d26..2cbf3d9e5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -189,7 +189,7 @@ dependencies { // name and the commit hash with the commit hash of the (pushed) commit you want to test // This works thanks to JitPack: https://jitpack.io/ implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.TeamNewPipe:NewPipeExtractor:4f60225ddc8a29e7a36a4ed77d73b713ba3451d9' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:4f60225ddc' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" From 85fb5827aa30fb5f849b107e192e8529c0f1290b Mon Sep 17 00:00:00 2001 From: vhouriet Date: Fri, 22 Oct 2021 21:07:53 +0200 Subject: [PATCH 29/34] Add Check for updates button --- .../newpipe/settings/MainSettingsFragment.java | 7 +++++-- .../newpipe/settings/UpdateSettingsFragment.java | 13 +++++++++++++ app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/update_settings.xml | 7 +++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java index 2f65af4d6..0eebfb5a2 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -17,8 +17,11 @@ public class MainSettingsFragment extends BasePreferenceFragment { addPreferencesFromResource(R.xml.main_settings); if (!CheckForNewAppVersion.isGithubApk(App.getApp())) { - final Preference update = findPreference(getString(R.string.update_pref_screen_key)); - getPreferenceScreen().removePreference(update); + if (!DEBUG) { + final Preference update + = findPreference(getString(R.string.update_pref_screen_key)); + getPreferenceScreen().removePreference(update); + } defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply(); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java index d2f56b487..0fdf96757 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.settings; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import androidx.preference.Preference; @@ -9,6 +11,8 @@ import org.schabi.newpipe.R; import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; public class UpdateSettingsFragment extends BasePreferenceFragment { + private static final String RELEASES_URL = "https://github.com/TeamNewPipe/NewPipe/releases"; + private final Preference.OnPreferenceChangeListener updatePreferenceChange = (preference, checkForUpdates) -> { defaultPreferences.edit() @@ -24,11 +28,20 @@ public class UpdateSettingsFragment extends BasePreferenceFragment { return true; }; + private final Preference.OnPreferenceClickListener manualUpdateClick + = preference -> { + final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(RELEASES_URL)); + startActivity(browserIntent); + return true; + }; + @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResource(R.xml.update_settings); final String updateToggleKey = getString(R.string.update_app_key); + final String manualUpdateKey = getString(R.string.manual_update_key); findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange); + findPreference(manualUpdateKey).setOnPreferenceClickListener(manualUpdateClick); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 9489ef543..1c57178b4 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -383,6 +383,7 @@ update_app_key + manual_update_key update_pref_screen_key update_expiry_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 897ec0af8..9ab2d2643 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -517,6 +517,8 @@ Updates Show a notification to prompt app update when a new version is available + Check for updates + Manually check for new versions Minimize on app switch Action when switching to other app from main video player — %s diff --git a/app/src/main/res/xml/update_settings.xml b/app/src/main/res/xml/update_settings.xml index adaa47352..ef121ec4e 100644 --- a/app/src/main/res/xml/update_settings.xml +++ b/app/src/main/res/xml/update_settings.xml @@ -12,4 +12,11 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + From 5c9705d94e4821eb857f42a6af8a6903210b81c8 Mon Sep 17 00:00:00 2001 From: vhouriet Date: Sat, 23 Oct 2021 21:09:53 +0200 Subject: [PATCH 30/34] Change check for updates button to trigger a version check --- .../schabi/newpipe/CheckForNewAppVersion.java | 6 ++--- .../java/org/schabi/newpipe/MainActivity.java | 14 +++++++---- .../settings/MainSettingsFragment.java | 8 +++---- .../settings/UpdateSettingsFragment.java | 23 ++++++++++--------- app/src/main/res/values/strings.xml | 1 + 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 9c392be1e..7e5eb0f77 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -175,9 +175,8 @@ public final class CheckForNewAppVersion extends IntentService { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app); final NewVersionManager manager = new NewVersionManager(); - // Check if user has enabled/disabled update checking - // and if the current apk is a github one or not. - if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) || !isGithubApk(app)) { + // Check if the current apk is a github one or not. + if (!isGithubApk(app)) { return; } @@ -213,6 +212,7 @@ public final class CheckForNewAppVersion extends IntentService { // Parse the json from the response. try { + final JsonObject githubStableObject = JsonParser.object() .from(response.responseBody()).getObject("flavors") .getObject("github").getObject("stable"); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 1855d45cd..0a49e00e4 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -169,10 +169,16 @@ public class MainActivity extends AppCompatActivity { @Override protected void onPostCreate(final Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); - // Start the service which is checking all conditions - // and eventually searching for a new version. - // The service searching for a new NewPipe version must not be started in background. - startNewVersionCheckService(); + + final App app = App.getApp(); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app); + + if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) { + // Start the service which is checking all conditions + // and eventually searching for a new version. + // The service searching for a new NewPipe version must not be started in background. + startNewVersionCheckService(); + } } private void setupDrawer() throws ExtractionException { diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java index 0eebfb5a2..4d847056e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -17,11 +17,9 @@ public class MainSettingsFragment extends BasePreferenceFragment { addPreferencesFromResource(R.xml.main_settings); if (!CheckForNewAppVersion.isGithubApk(App.getApp())) { - if (!DEBUG) { - final Preference update - = findPreference(getString(R.string.update_pref_screen_key)); - getPreferenceScreen().removePreference(update); - } + final Preference update + = findPreference(getString(R.string.update_pref_screen_key)); + getPreferenceScreen().removePreference(update); defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply(); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java index 0fdf96757..339f6571b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -1,8 +1,7 @@ package org.schabi.newpipe.settings; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; +import android.widget.Toast; import androidx.preference.Preference; @@ -11,30 +10,32 @@ import org.schabi.newpipe.R; import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; public class UpdateSettingsFragment extends BasePreferenceFragment { - private static final String RELEASES_URL = "https://github.com/TeamNewPipe/NewPipe/releases"; - private final Preference.OnPreferenceChangeListener updatePreferenceChange = (preference, checkForUpdates) -> { defaultPreferences.edit() .putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply(); if ((boolean) checkForUpdates) { - // Search for updates immediately when update checks are enabled. - // Reset the expire time. This is necessary to check for an update immediately. - defaultPreferences.edit() - .putLong(getString(R.string.update_expiry_key), 0).apply(); - startNewVersionCheckService(); + checkNewVersionNow(); } return true; }; private final Preference.OnPreferenceClickListener manualUpdateClick = preference -> { - final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(RELEASES_URL)); - startActivity(browserIntent); + Toast.makeText(getContext(), R.string.checking_updates_toast, Toast.LENGTH_SHORT).show(); + checkNewVersionNow(); return true; }; + private void checkNewVersionNow() { + // Search for updates immediately when update checks are enabled. + // Reset the expire time. This is necessary to check for an update immediately. + defaultPreferences.edit() + .putLong(getString(R.string.update_expiry_key), 0).apply(); + startNewVersionCheckService(); + } + @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResource(R.xml.update_settings); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ab2d2643..2ad07b4c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -549,6 +549,7 @@ recovering Queue Action denied by the system + Checking for updates… Download failed From 467bd21de2995ccd3278a358524663ce2c86d694 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 19:23:48 +0200 Subject: [PATCH 31/34] Cleanup up some code --- .../settings/UpdateSettingsFragment.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java index 339f6571b..bc183d08a 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.settings; +import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; + import android.os.Bundle; import android.widget.Toast; @@ -7,17 +9,15 @@ import androidx.preference.Preference; import org.schabi.newpipe.R; -import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService; - public class UpdateSettingsFragment extends BasePreferenceFragment { private final Preference.OnPreferenceChangeListener updatePreferenceChange = (preference, checkForUpdates) -> { defaultPreferences.edit() .putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply(); - if ((boolean) checkForUpdates) { - checkNewVersionNow(); - } + if ((boolean) checkForUpdates) { + checkNewVersionNow(); + } return true; }; @@ -40,9 +40,9 @@ public class UpdateSettingsFragment extends BasePreferenceFragment { public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResource(R.xml.update_settings); - final String updateToggleKey = getString(R.string.update_app_key); - final String manualUpdateKey = getString(R.string.manual_update_key); - findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange); - findPreference(manualUpdateKey).setOnPreferenceClickListener(manualUpdateClick); + findPreference(getString(R.string.update_app_key)) + .setOnPreferenceChangeListener(updatePreferenceChange); + findPreference(getString(R.string.manual_update_key)) + .setOnPreferenceClickListener(manualUpdateClick); } } From 8dc34274a1682f4364b87c121df30b53bd453d13 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 19:26:47 +0200 Subject: [PATCH 32/34] Removed dead code --- .../java/org/schabi/newpipe/CheckForNewAppVersion.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 7e5eb0f77..76cd2988a 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.Signature; -import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; @@ -15,7 +14,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; -import androidx.core.content.ContextCompat; import androidx.core.content.pm.PackageInfoCompat; import androidx.preference.PreferenceManager; @@ -158,13 +156,6 @@ public final class CheckForNewAppVersion extends IntentService { } } - private static boolean isConnected(@NonNull final App app) { - final ConnectivityManager connectivityManager = - ContextCompat.getSystemService(app, ConnectivityManager.class); - return connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null - && connectivityManager.getActiveNetworkInfo().isConnected(); - } - public static boolean isGithubApk(@NonNull final App app) { return getCertificateSHA1Fingerprint(app).equals(GITHUB_APK_SHA1); } From e5fd24b0d19d35d56efb15219277821b4afd00d2 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 20:25:09 +0200 Subject: [PATCH 33/34] Make naming great again When we build APKs in PRs it's also a GITHUB_APK... --- .../java/org/schabi/newpipe/CheckForNewAppVersion.java | 9 +++++---- .../schabi/newpipe/settings/MainSettingsFragment.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 76cd2988a..173a24ab7 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -46,7 +46,8 @@ public final class CheckForNewAppVersion extends IntentService { private static final boolean DEBUG = MainActivity.DEBUG; private static final String TAG = CheckForNewAppVersion.class.getSimpleName(); - private static final String GITHUB_APK_SHA1 + // Public key of the certificate that is used in NewPipe release versions + private static final String RELEASE_CERT_PUBLIC_KEY_SHA1 = "B0:2E:90:7C:1C:D6:FC:57:C3:35:F0:88:D0:8F:50:5F:94:E4:D2:15"; private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json"; @@ -156,8 +157,8 @@ public final class CheckForNewAppVersion extends IntentService { } } - public static boolean isGithubApk(@NonNull final App app) { - return getCertificateSHA1Fingerprint(app).equals(GITHUB_APK_SHA1); + public static boolean isReleaseApk(@NonNull final App app) { + return getCertificateSHA1Fingerprint(app).equals(RELEASE_CERT_PUBLIC_KEY_SHA1); } private void checkNewVersion() throws IOException, ReCaptchaException { @@ -167,7 +168,7 @@ public final class CheckForNewAppVersion extends IntentService { final NewVersionManager manager = new NewVersionManager(); // Check if the current apk is a github one or not. - if (!isGithubApk(app)) { + if (!isReleaseApk(app)) { return; } diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java index 4d847056e..12599b828 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -16,7 +16,7 @@ public class MainSettingsFragment extends BasePreferenceFragment { public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResource(R.xml.main_settings); - if (!CheckForNewAppVersion.isGithubApk(App.getApp())) { + if (!CheckForNewAppVersion.isReleaseApk(App.getApp())) { final Preference update = findPreference(getString(R.string.update_pref_screen_key)); getPreferenceScreen().removePreference(update); From 403154b2e1341a9127380ae22883c04ed1dac606 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Oct 2021 20:29:03 +0200 Subject: [PATCH 34/34] Less indents and code -> better readable Also removed a useless variable --- .../schabi/newpipe/CheckForNewAppVersion.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java index 173a24ab7..9e43394ac 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java @@ -128,33 +128,33 @@ public final class CheckForNewAppVersion extends IntentService { final String versionName, final String apkLocationUrl, final int versionCode) { - final int notificationId = 2000; - - if (BuildConfig.VERSION_CODE < versionCode) { - // A pending intent to open the apk location url in the browser. - final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - final PendingIntent pendingIntent - = PendingIntent.getActivity(application, 0, intent, 0); - - final String channelId = application - .getString(R.string.app_update_notification_channel_id); - final NotificationCompat.Builder notificationBuilder - = new NotificationCompat.Builder(application, channelId) - .setSmallIcon(R.drawable.ic_newpipe_update) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setContentIntent(pendingIntent) - .setAutoCancel(true) - .setContentTitle(application - .getString(R.string.app_update_notification_content_title)) - .setContentText(application - .getString(R.string.app_update_notification_content_text) - + " " + versionName); - - final NotificationManagerCompat notificationManager - = NotificationManagerCompat.from(application); - notificationManager.notify(notificationId, notificationBuilder.build()); + if (BuildConfig.VERSION_CODE >= versionCode) { + return; } + + // A pending intent to open the apk location url in the browser. + final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(apkLocationUrl)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + final PendingIntent pendingIntent + = PendingIntent.getActivity(application, 0, intent, 0); + + final String channelId = application + .getString(R.string.app_update_notification_channel_id); + final NotificationCompat.Builder notificationBuilder + = new NotificationCompat.Builder(application, channelId) + .setSmallIcon(R.drawable.ic_newpipe_update) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setContentIntent(pendingIntent) + .setAutoCancel(true) + .setContentTitle(application + .getString(R.string.app_update_notification_content_title)) + .setContentText(application + .getString(R.string.app_update_notification_content_text) + + " " + versionName); + + final NotificationManagerCompat notificationManager + = NotificationManagerCompat.from(application); + notificationManager.notify(2000, notificationBuilder.build()); } public static boolean isReleaseApk(@NonNull final App app) {