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

Fix "Add to playlist" not working and cleanup "RouterActivity" choice handling #8340

Merged
merged 6 commits into from
Jun 5, 2022
Merged
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
284 changes: 164 additions & 120 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ protected void initListeners() {
binding.detailControlsCrashThePlayer.setOnClickListener(
v -> VideoDetailPlayerCrasher.onCrashThePlayer(
this.getContext(),
this.player,
getLayoutInflater())
this.player)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.schabi.newpipe.fragments.detail;

import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW;
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED;
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED;

import android.content.Context;
import android.util.Log;
import android.view.ContextThemeWrapper;
Expand Down Expand Up @@ -29,10 +33,6 @@
import java.util.Map;
import java.util.function.Supplier;

import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW;
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_DECODING_FAILED;
import static com.google.android.exoplayer2.PlaybackException.ERROR_CODE_UNSPECIFIED;

/**
* Outsourced logic for crashing the player in the {@link VideoDetailFragment}.
*/
Expand Down Expand Up @@ -97,8 +97,7 @@ private static Context getThemeWrapperContext(final Context context) {

public static void onCrashThePlayer(
@NonNull final Context context,
@Nullable final Player player,
@NonNull final LayoutInflater layoutInflater
@Nullable final Player player
) {
if (player == null) {
Log.d(TAG, "Player is not available");
Expand All @@ -109,16 +108,15 @@ public static void onCrashThePlayer(
}

// -- Build the dialog/UI --

final Context themeWrapperContext = getThemeWrapperContext(context);

final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext);
final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(layoutInflater)
.list;

final AlertDialog alertDialog = new AlertDialog.Builder(getThemeWrapperContext(context))
final SingleChoiceDialogViewBinding binding =
SingleChoiceDialogViewBinding.inflate(inflater);

final AlertDialog alertDialog = new AlertDialog.Builder(themeWrapperContext)
.setTitle("Choose an exception")
.setView(radioGroup)
.setView(binding.getRoot())
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.create();
Expand All @@ -136,11 +134,9 @@ public static void onCrashThePlayer(
);
radioButton.setOnClickListener(v -> {
tryCrashPlayerWith(player, entry.getValue().get());
if (alertDialog != null) {
alertDialog.cancel();
}
alertDialog.cancel();
});
radioGroup.addView(radioButton);
binding.list.addView(radioButton);
}

alertDialog.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
Expand All @@ -25,6 +24,8 @@
import androidx.preference.PreferenceViewHolder;

import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
import org.schabi.newpipe.player.MainPlayer;
import org.schabi.newpipe.player.NotificationConstants;
import org.schabi.newpipe.util.DeviceUtils;
Expand Down Expand Up @@ -189,13 +190,12 @@ void updateInfo() {

void openActionChooserDialog() {
final LayoutInflater inflater = LayoutInflater.from(getContext());
final LinearLayout rootLayout = (LinearLayout) inflater.inflate(
R.layout.single_choice_dialog_view, null, false);
final RadioGroup radioGroup = rootLayout.findViewById(android.R.id.list);
final SingleChoiceDialogViewBinding binding =
SingleChoiceDialogViewBinding.inflate(inflater);

final AlertDialog alertDialog = new AlertDialog.Builder(getContext())
.setTitle(SLOT_TITLES[i])
.setView(radioGroup)
.setView(binding.getRoot())
.setCancelable(true)
.create();

Expand All @@ -207,8 +207,8 @@ void openActionChooserDialog() {

for (int id = 0; id < NotificationConstants.SLOT_ALLOWED_ACTIONS[i].length; ++id) {
final int action = NotificationConstants.SLOT_ALLOWED_ACTIONS[i][id];
final RadioButton radioButton
= (RadioButton) inflater.inflate(R.layout.list_radio_icon_item, null);
final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater)
.getRoot();

// if present set action icon with correct color
if (NotificationConstants.ACTION_ICONS[action] != 0) {
Expand All @@ -230,7 +230,7 @@ void openActionChooserDialog() {
radioButton.setLayoutParams(new RadioGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
radioButton.setOnClickListener(radioButtonsClickListener);
radioGroup.addView(radioButton);
binding.list.addView(radioButton);
}
alertDialog.show();

Expand Down
18 changes: 13 additions & 5 deletions app/src/main/res/layout/single_choice_dialog_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
<?xml version="1.0" encoding="utf-8"?><!-- -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="?attr/listPreferredItemPaddingLeft" />
android:layout_height="match_parent"
android:fadeScrollbars="false">

<RadioGroup
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="?attr/listPreferredItemPaddingLeft" />
</ScrollView>


22 changes: 16 additions & 6 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@
<style name="Base" parent="Base.V21"/>

<!-- Light Theme -->
<style name="Base.V21.LightTheme" parent="Base.V19.LightTheme">
<style name="Base.V21.LightTheme" parent="Base.V19.LightTheme" />

</style>
<style name="Base.LightTheme" parent="Base.V21.LightTheme" />

<!-- Dark Theme -->
<style name="Base.V21.DarkTheme" parent="Base.V19.DarkTheme">
<style name="Base.V21.DarkTheme" parent="Base.V19.DarkTheme" />

</style>
<style name="Base.DarkTheme" parent="Base.V21.DarkTheme" />

<!-- Black Theme -->
<style name="Base.V21.BlackTheme" parent="Base.V19.BlackTheme">
<style name="Base.V21.BlackTheme" parent="Base.V19.BlackTheme" />

</style>
<style name="Base.BlackTheme" parent="Base.V21.BlackTheme" />

<!-- Router Activity -->
<style name="Base.V21.RouterActivityThemeLight" parent="Base.RouterActivityThemeLight">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

<style name="RouterActivityThemeLight" parent="Base.V21.RouterActivityThemeLight" />

<style name="Base.V21.RouterActivityThemeDark" parent="Base.RouterActivityThemeDark">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

<style name="RouterActivityThemeDark" parent="Base.V21.RouterActivityThemeDark" />

</resources>
9 changes: 7 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,25 @@
<item name="colorAccent">@color/black_settings_accent_color</item>
</style>

<style name="RouterActivityThemeLight" parent="LightTheme">
<!-- Router Activity -->
<style name="Base.RouterActivityThemeLight" parent="LightTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@null</item>
</style>

<style name="RouterActivityThemeDark" parent="DarkTheme">
<style name="RouterActivityThemeLight" parent="Base.RouterActivityThemeLight" />

<style name="Base.RouterActivityThemeDark" parent="DarkTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@null</item>
</style>

<style name="RouterActivityThemeDark" parent="Base.RouterActivityThemeDark" />

</resources>