Merge pull request #7989 from litetex/refactor-playback-parameter-dialog

Rewrote ``PlaybackParameterDialog``
This commit is contained in:
Stypox 2022-04-30 17:53:26 +02:00 committed by GitHub
commit 7646c683b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 715 additions and 728 deletions

View File

@ -25,7 +25,6 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import android.os.Parcelable
@ -37,7 +36,6 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.annotation.AttrRes
import androidx.annotation.Nullable
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
@ -80,6 +78,7 @@ import org.schabi.newpipe.util.DeviceUtils
import org.schabi.newpipe.util.Localization
import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountStreams
import org.schabi.newpipe.util.ThemeHelper.resolveDrawable
import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout
import java.time.OffsetDateTime
import java.util.function.Consumer
@ -579,19 +578,6 @@ class FeedFragment : BaseStateFragment<FeedState>() {
lastNewItemsCount = highlightCount
}
private fun resolveDrawable(context: Context, @AttrRes attrResId: Int): Drawable? {
return androidx.core.content.ContextCompat.getDrawable(
context,
android.util.TypedValue().apply {
context.theme.resolveAttribute(
attrResId,
this,
true
)
}.resourceId
)
}
private fun showNewItemsLoaded() {
tryGetNewItemsLoadedButton()?.clearAnimation()
tryGetNewItemsLoadedButton()

View File

@ -0,0 +1,38 @@
package org.schabi.newpipe.player.helper;
/**
* Converts between percent and 12-tone equal temperament semitones.
* <br/>
* @see
* <a href="https://en.wikipedia.org/wiki/Equal_temperament#Twelve-tone_equal_temperament">
* Wikipedia: Equal temperament#Twelve-tone equal temperament
* </a>
*/
public final class PlayerSemitoneHelper {
public static final int SEMITONE_COUNT = 12;
private PlayerSemitoneHelper() {
// No impl
}
public static String formatPitchSemitones(final double percent) {
return formatPitchSemitones(percentToSemitones(percent));
}
public static String formatPitchSemitones(final int semitones) {
return semitones > 0 ? "+" + semitones : "" + semitones;
}
public static double semitonesToPercent(final int semitones) {
return Math.pow(2, ensureSemitonesInRange(semitones) / (double) SEMITONE_COUNT);
}
public static int percentToSemitones(final double percent) {
return ensureSemitonesInRange(
(int) Math.round(SEMITONE_COUNT * Math.log(percent) / Math.log(2)));
}
private static int ensureSemitonesInRange(final int semitones) {
return Math.max(-SEMITONE_COUNT, Math.min(SEMITONE_COUNT, semitones));
}
}

View File

@ -23,9 +23,11 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.ActionBar;
@ -227,6 +229,22 @@ public final class ThemeHelper {
return value.data;
}
/**
* Resolves a {@link Drawable} by it's id.
*
* @param context Context
* @param attrResId Resource id
* @return the {@link Drawable}
*/
public static Drawable resolveDrawable(
@NonNull final Context context,
@AttrRes final int attrResId
) {
final TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(attrResId, typedValue, true);
return ContextCompat.getDrawable(context, typedValue.resourceId);
}
private static String getSelectedThemeKey(final Context context) {
final String themeKey = context.getString(R.string.theme_key);
final String defaultTheme = context.getResources().getString(R.string.default_theme_value);

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
@ -29,9 +30,9 @@
<RelativeLayout
android:id="@+id/tempoControl"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_below="@id/tempoControlText"
android:layout_marginTop="3dp"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<org.schabi.newpipe.views.NewPipeTextView
@ -39,7 +40,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackground"
android:clickable="true"
@ -57,9 +57,7 @@
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_toStartOf="@id/tempoStepUp"
android:layout_toLeftOf="@id/tempoStepUp"
android:layout_toEndOf="@id/tempoStepDown"
android:layout_toRightOf="@id/tempoStepDown"
android:orientation="horizontal">
<org.schabi.newpipe.views.NewPipeTextView
@ -67,9 +65,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="center"
android:text="-.--x"
android:textColor="?attr/colorAccent"
@ -93,9 +89,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:text="---%"
android:textColor="?attr/colorAccent"
@ -108,7 +102,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tempoCurrentText"
android:paddingBottom="4dp"
android:paddingBottom="2dp"
tools:progress="50" />
</RelativeLayout>
@ -117,10 +111,8 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
@ -138,9 +130,9 @@
android:layout_height="1dp"
android:layout_below="@id/tempoControl"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="6dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="5dp"
android:background="?attr/separator_color" />
<org.schabi.newpipe.views.NewPipeTextView
@ -154,20 +146,72 @@
android:textColor="?attr/colorAccent"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/pitchControl"
<ImageView
android:id="@+id/pitchToogleControlModes"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_below="@id/separatorPitch"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true"
app:srcCompat="@drawable/ic_expand_more"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/pitchControlModeTabs"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="22dp"
android:layout_below="@id/pitchControlText"
android:layout_marginTop="3dp"
android:layout_marginStart="22dp"
android:layout_marginEnd="22dp"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchControlModePercent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/percent"
android:textColor="?attr/colorAccent" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchControlModeSemitone"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/semitone"
android:textColor="?attr/colorAccent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/pitchControlContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pitchControlModeTabs"
android:layout_marginTop="1dp">
<RelativeLayout
android:id="@+id/pitchPercentControl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchStepDown"
android:id="@+id/pitchPercentStepDown"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackground"
android:clickable="true"
@ -180,25 +224,21 @@
tools:text="-5%" />
<RelativeLayout
android:id="@+id/pitchDisplay"
android:id="@+id/pitchPercentDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_toStartOf="@+id/pitchStepUp"
android:layout_toLeftOf="@+id/pitchStepUp"
android:layout_toEndOf="@+id/pitchStepDown"
android:layout_toRightOf="@+id/pitchStepDown"
android:layout_toStartOf="@+id/pitchPercentStepUp"
android:layout_toEndOf="@+id/pitchPercentStepDown"
android:orientation="horizontal">
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchMinimumText"
android:id="@+id/pitchPercentMinimumText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="center"
android:text="---%"
android:textColor="?attr/colorAccent"
@ -206,7 +246,7 @@
tools:text="25%" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchCurrentText"
android:id="@+id/pitchPercentCurrentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
@ -218,13 +258,11 @@
tools:text="100%" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchMaximumText"
android:id="@+id/pitchPercentMaximumText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:text="---%"
android:textColor="?attr/colorAccent"
@ -232,24 +270,22 @@
tools:text="300%" />
<androidx.appcompat.widget.AppCompatSeekBar
android:id="@+id/pitchSeekbar"
android:id="@+id/pitchPercentSeekbar"
style="@style/Widget.AppCompat.SeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pitchCurrentText"
android:paddingBottom="4dp"
android:layout_below="@+id/pitchPercentCurrentText"
android:paddingBottom="2dp"
tools:progress="50" />
</RelativeLayout>
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/pitchStepUp"
android:id="@+id/pitchPercentStepUp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
@ -262,19 +298,17 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/semitoneControl"
android:id="@+id/pitchSemitoneControl"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/pitchControlText"
android:layout_marginTop="4dp"
android:orientation="horizontal">
android:layout_height="match_parent"
android:orientation="horizontal"
tools:visibility="gone">
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/semitoneStepDown"
android:id="@+id/pitchSemitoneStepDown"
android:layout_width="24dp"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackground"
android:clickable="true"
@ -287,73 +321,66 @@
tools:ignore="HardcodedText" />
<RelativeLayout
android:id="@+id/semitoneDisplay"
android:id="@+id/pitchSemitoneDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_toStartOf="@+id/semitoneStepUp"
android:layout_toLeftOf="@+id/semitoneStepUp"
android:layout_toEndOf="@+id/semitoneStepDown"
android:layout_toRightOf="@+id/semitoneStepDown"
android:layout_toStartOf="@+id/pitchSemitoneStepUp"
android:layout_toEndOf="@+id/pitchSemitoneStepDown"
android:orientation="horizontal">
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/semitoneMinimumText"
android:id="@+id/pitchSemitoneMinimumText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="center"
android:text="-12"
android:textColor="?attr/colorAccent"
tools:ignore="HardcodedText"/>
tools:ignore="HardcodedText" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/semitoneCurrentText"
android:id="@+id/pitchSemitoneCurrentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="?attr/colorAccent"
android:textStyle="bold"
tools:text="0" />
tools:text="0"
tools:ignore="RelativeOverlap" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/semitoneMaximumText"
android:id="@+id/pitchSemitoneMaximumText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:text="+12"
android:textColor="?attr/colorAccent"
tools:ignore="HardcodedText" />
<androidx.appcompat.widget.AppCompatSeekBar
android:id="@+id/semitoneSeekbar"
android:id="@+id/pitchSemitoneSeekbar"
style="@style/Widget.AppCompat.SeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/semitoneCurrentText"
android:layout_below="@+id/pitchSemitoneCurrentText"
android:max="24"
android:paddingBottom="4dp"
android:paddingBottom="2dp"
android:progress="12" />
</RelativeLayout>
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/semitoneStepUp"
android:id="@+id/pitchSemitoneStepUp"
android:layout_width="24dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
@ -364,22 +391,23 @@
android:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout>
</RelativeLayout>
<View
android:id="@+id/separatorStepSizeSelector"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/semitoneControl"
android:layout_below="@+id/pitchControlContainer"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="6dp"
android:layout_marginBottom="5dp"
android:background="?attr/separator_color" />
<LinearLayout
android:id="@+id/stepSizeSelector"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_height="30dp"
android:layout_below="@id/separatorStepSizeSelector"
android:orientation="horizontal">
@ -403,7 +431,8 @@
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="?attr/colorAccent" />
android:textColor="?attr/colorAccent"
tools:text="1%" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/stepSizeFivePercent"
@ -414,7 +443,8 @@
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="?attr/colorAccent" />
android:textColor="?attr/colorAccent"
tools:text="5%" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/stepSizeTenPercent"
@ -425,7 +455,8 @@
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="?attr/colorAccent" />
android:textColor="?attr/colorAccent"
tools:text="10%" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/stepSizeTwentyFivePercent"
@ -436,9 +467,10 @@
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="?attr/colorAccent" />
android:textColor="?attr/colorAccent"
tools:text="25%" />
<TextView
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/stepSizeOneHundredPercent"
android:layout_width="0dp"
android:layout_height="match_parent"
@ -447,7 +479,8 @@
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="?attr/colorAccent" />
android:textColor="?attr/colorAccent"
tools:text="100%" />
</LinearLayout>
<View
@ -456,9 +489,9 @@
android:layout_height="1dp"
android:layout_below="@+id/stepSizeSelector"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="6dp"
android:layout_marginBottom="5dp"
android:background="?attr/separator_color" />
<LinearLayout
@ -486,17 +519,6 @@
android:focusable="true"
android:text="@string/skip_silence_checkbox" />
<CheckBox
android:id="@+id/adjustBySemitonesCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/skipSilenceCheckbox"
android:layout_centerHorizontal="true"
android:checked="false"
android:clickable="true"
android:focusable="true"
android:maxLines="1"
android:text="@string/adjust_by_semitones_checkbox" />
</LinearLayout>
<!-- END HERE -->

View File

@ -497,10 +497,10 @@
<string name="playback_pitch">Pitch</string>
<string name="unhook_checkbox">Unhook (may cause distortion)</string>
<string name="skip_silence_checkbox">Fast-forward during silence</string>
<string name="adjust_by_semitones_checkbox">Adjust pitch by musical semitones</string>
<string name="playback_step">Step</string>
<string name="playback_tempo_step">Tempo step</string>
<string name="playback_reset">Reset</string>
<string name="percent">Percent</string>
<string name="semitone">Semitone</string>
<!-- GDPR dialog -->
<string name="start_accept_privacy_policy">In order to comply with the European General Data Protection Regulation (GDPR), we hereby draw your attention to NewPipe\'s privacy policy. Please read it carefully.
\nYou must accept it to send us the bug report.</string>