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

Share/Open with newpipe" add enqueue choice for players #7266

Closed
Closed
Show file tree
Hide file tree
Changes from 5 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
113 changes: 103 additions & 10 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
import static org.schabi.newpipe.ktx.ViewUtils.animateRotation;

import android.annotation.SuppressLint;
import android.app.IntentService;
Expand All @@ -10,13 +11,15 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
Expand All @@ -27,6 +30,7 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
import androidx.core.widget.TextViewCompat;
Expand All @@ -35,7 +39,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 @@ -329,8 +332,12 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
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 DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> {
final int indexOfChild = radioGroup.indexOfChild(
Expand All @@ -347,9 +354,11 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
}
};

initAdvancedOptions(dialogView);

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 @@ -423,6 +432,65 @@ private void showDialog(final List<AdapterChoiceItem> choices) {
}
}

private void initAdvancedOptions(final View dialogView) {
final SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(this);

final LinearLayout layoutAdvancedOptionsContent =
dialogView.findViewById(R.id.advanced_options_content);
final SwitchCompat prioritizeEnqueue = dialogView.findViewById(R.id.prioritize_enqueue);

/* Initialize component states. */
setVisibilityOfAdvancedOptions(
dialogView,
false,
false
);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// It's not possible to add secondary text / it would be to much for the small dialog
// -> Use a tooltip (only works on Android 8+/Oreo - API 26+)
prioritizeEnqueue.setTooltipText(getString(R.string.prioritize_enqueue_summary));
}
prioritizeEnqueue.setChecked(
preferences.getBoolean(
getString(R.string.prioritize_enqueue),
false
)
);

/* Listener for toggling advanced options view. */
dialogView.findViewById(R.id.layout_toggle_adv)
.setOnClickListener(v -> setVisibilityOfAdvancedOptions(
dialogView,
layoutAdvancedOptionsContent.getVisibility() != View.VISIBLE,
true
)
);

/* Save linked preference when changed. */
prioritizeEnqueue.setOnCheckedChangeListener((v, checked) ->
preferences.edit()
.putBoolean(getString(R.string.prioritize_enqueue), checked)
.apply()
);
}

private void setVisibilityOfAdvancedOptions(
final View dialogView,
final boolean visible,
final boolean doAnimation
) {
dialogView.findViewById(R.id.advanced_options_content)
.setVisibility(visible ? View.VISIBLE : View.GONE);

animateRotation(
dialogView.findViewById(R.id.toggle_adv_icon),
doAnimation ? 300 : 0,
visible ? 0 : -90
);
}

private List<AdapterChoiceItem> getChoicesForService(final StreamingService service,
final LinkType linkType) {
final Context context = getThemeWrapperContext();
Expand Down Expand Up @@ -796,12 +864,37 @@ 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);

// If prioritize_enqueue is enabled, then enqueue this stream.
// Otherwise, open preferred player instead
if (prioritizeEnqueue) {
if (choice.playerChoice.equals(videoPlayerKey)) {
NavigationHelper.enqueueOnPlayer(
this,
playQueue,
MainPlayer.PlayerType.VIDEO);
} else if (choice.playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.enqueueOnPlayer(
this,
playQueue,
MainPlayer.PlayerType.AUDIO);
} else if (choice.playerChoice.equals(popupPlayerKey)) {
NavigationHelper.enqueueOnPlayer(
this,
playQueue,
MainPlayer.PlayerType.POPUP);
}
litetex marked this conversation as resolved.
Show resolved Hide resolved
} 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
78 changes: 78 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,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to use a ConstraintLayout to prevent view nesting?

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"
android:orientation="vertical">

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

</RadioGroup>
litetex marked this conversation as resolved.
Show resolved Hide resolved

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:orientation="vertical">

<LinearLayout
android:id="@+id/layout_toggle_adv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:minHeight="30dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/toggle_adv_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
app:srcCompat="@drawable/ic_expand_more" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:text="@string/advanced_options"
android:textSize="16sp"
android:textStyle="bold" />

<View
android:id="@+id/horizontal_line"
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>

<LinearLayout
android:id="@+id/advanced_options_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp"
android:orientation="vertical">

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/prioritize_enqueue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="40dp"
android:text="@string/prioritize_enqueue_title" />

</LinearLayout>

</LinearLayout>

</LinearLayout>
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
Stypox marked this conversation as resolved.
Show resolved Hide resolved
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