Merge pull request #7989 from litetex/refactor-playback-parameter-dialog
Rewrote ``PlaybackParameterDialog``
This commit is contained in:
commit
7646c683b5
@ -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()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user