Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enqueue background choice for share service. #5850

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 72 additions & 10 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
import androidx.core.widget.TextViewCompat;
Expand All @@ -35,7 +37,6 @@

import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
Expand Down Expand Up @@ -324,13 +325,54 @@ protected void onSuccess() {
}
}

/**
* Toggle the visibility for advanced options view.
* @param dialogView Main view of the dialog.
* @param visible State of the visibility.
*/
private void toggleAdvancedOptions(final View dialogView, final boolean visible) {
final AppCompatButton toggle = dialogView.findViewById(R.id.toggle_adv);
final SwitchCompat prioritizeEnqueue = dialogView.findViewById(R.id.prioritize_enqueue);

final int visibility = (visible
? View.VISIBLE
: View.GONE);
final int icon = (visible
? R.drawable.ic_arrow_drop_down
: R.drawable.ic_arrow_drop_right);

prioritizeEnqueue.setVisibility(visibility);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(toggle,
AppCompatResources.getDrawable(getApplicationContext(), icon),
null, null, null);
};

private void showDialog(final List<AdapterChoiceItem> choices) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Context themeWrapperContext = getThemeWrapperContext();

final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext);
final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(getLayoutInflater())
.list;
final View dialogView = View.inflate(themeWrapperContext, R.layout.dialog_share_context,
null);
final RadioGroup radioGroup = dialogView.findViewById(R.id.player_group);
final AppCompatButton toggle = dialogView.findViewById(R.id.toggle_adv);
final SwitchCompat prioritizeEnqueue = dialogView.findViewById(R.id.prioritize_enqueue);

/* Initialize component states. */
toggleAdvancedOptions(dialogView, false);
prioritizeEnqueue.setChecked(preferences.getBoolean(
getString(R.string.prioritize_enqueue),
false));

/* Save linked preference when changed. */
prioritizeEnqueue.setOnCheckedChangeListener((v, checked) -> {
preferences.edit().putBoolean(getString(R.string.prioritize_enqueue), checked).apply();
});
/* Toggle advanced options view. */
toggle.setOnClickListener(v -> {
toggleAdvancedOptions(dialogView,
prioritizeEnqueue.getVisibility() != View.VISIBLE);
});

final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> {
final int indexOfChild = radioGroup.indexOfChild(
Expand All @@ -349,7 +391,7 @@ private void showDialog(final List<AdapterChoiceItem> choices) {

alertDialogChoice = new AlertDialog.Builder(themeWrapperContext)
.setTitle(R.string.preferred_open_action_share_menu_title)
.setView(radioGroup)
.setView(dialogView)
.setCancelable(true)
.setNegativeButton(R.string.just_once, dialogButtonsClickListener)
.setPositiveButton(R.string.always, dialogButtonsClickListener)
Expand Down Expand Up @@ -796,12 +838,32 @@ public Consumer<Info> getResultHandler(final Choice choice) {
return;
}

if (choice.playerChoice.equals(videoPlayerKey)) {
NavigationHelper.playOnMainPlayer(this, playQueue, false);
} else if (choice.playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.playOnBackgroundPlayer(this, playQueue, true);
} else if (choice.playerChoice.equals(popupPlayerKey)) {
NavigationHelper.playOnPopupPlayer(this, playQueue, true);
final boolean prioritizeEnqueue = preferences.getBoolean(
getString(R.string.prioritize_enqueue),
false);
// BUG: getType() always return null if main view is not open.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check after rebasing if this is still a thing 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rebased the code and updated the repo. Please let me know if there's anything I can do on my side. Thanks!

// final MainPlayer.PlayerType type = PlayerHolder.getType();

/* If prioritize_enqueue is enabled and we have running player, then enqueue
this stream. Otherwise, open preferred player instead. */
if (prioritizeEnqueue /* && type != null*/) {
if (choice.playerChoice.equals(videoPlayerKey)) {
NavigationHelper.enqueueOnPlayer(this, playQueue,
MainPlayer.PlayerType.VIDEO);
} else if (choice.playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.enqueueOnPlayer(this, playQueue);
} else if (choice.playerChoice.equals(popupPlayerKey)) {
NavigationHelper.enqueueOnPlayer(this, playQueue,
MainPlayer.PlayerType.POPUP);
}
} else {
if (choice.playerChoice.equals(videoPlayerKey)) {
NavigationHelper.playOnMainPlayer(this, playQueue, false);
} else if (choice.playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.playOnBackgroundPlayer(this, playQueue, true);
} else if (choice.playerChoice.equals(popupPlayerKey)) {
NavigationHelper.playOnPopupPlayer(this, playQueue, true);
}
}
};
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_arrow_drop_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,17l5,-5 -5,-5v10z" />
</vector>
62 changes: 62 additions & 0 deletions app/src/main/res/layout/dialog_share_context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="221dp">

<RadioGroup
android:id="@+id/player_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</RadioGroup>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/toggle_adv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@android:color/transparent"
android:lines="1"
android:maxLines="1"
android:text="@string/advanced_options"
android:textAllCaps="false" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:background="?android:attr/listDivider" />
</LinearLayout>

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/prioritize_enqueue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:text="@string/prioritize_enqueue_title"
android:visibility="gone" />

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
<string name="peertube_selected_instance_key" translatable="false">peertube_selected_instance</string>
<string name="peertube_instance_list_key" translatable="false">peertube_instance_list</string>
<string name="content_country_key" translatable="false">content_country</string>
<string name="prioritize_enqueue" translatable="false">prioritize_enqueue</string>
<string name="show_age_restricted_content" translatable="false">show_age_restricted_content</string>
<string name="youtube_restricted_mode_enabled" translatable="false">youtube_restricted_mode_enabled</string>
<string name="enable_search_history_key" translatable="false">enable_search_history</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
<string name="background_player_playing_toast">Playing in background</string>
<string name="popup_playing_toast">Playing in popup mode</string>
<string name="content">Content</string>
<string name="prioritize_enqueue_title">Prioritize stream queuing</string>
<string name="prioritize_enqueue_summary">Attempt to enqueue streams for shared URLs instead of playing them immediately</string>
<string name="show_age_restricted_content_title">Show age restricted content</string>
<string name="show_age_restricted_content_summary">Show content possibly unsuitable for children because it has an age limit (like 18+)</string>
<string name="youtube_restricted_mode_enabled_title">Turn on YouTube\'s \"Restricted Mode\"</string>
Expand Down Expand Up @@ -704,4 +706,5 @@
<!-- Show Channel Details -->
<string name="error_show_channel_details">Error at Show Channel Details</string>
<string name="loading_channel_details">Loading Channel Details…</string>
<string name="advanced_options">Advanced Options</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/prioritize_enqueue"
android:summary="@string/prioritize_enqueue_summary"
android:title="@string/prioritize_enqueue_title"
app:iconSpaceReserved="false" />

<ListPreference
android:defaultValue="@string/minimize_on_exit_value"
android:entries="@array/minimize_on_exit_action_description"
Expand Down