Merge branch 'master' into develop

This commit is contained in:
ByteHamster 2024-02-18 19:05:13 +01:00
commit 0d29e44de5
8 changed files with 94 additions and 11 deletions

View File

@ -491,7 +491,7 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte
}
info += "";
info += getString(R.string.time_left_label);
info += Converter.getDurationStringLocalized(getActivity(), timeLeft);
info += Converter.getDurationStringLocalized(getResources(), timeLeft, false);
}
infoBar.setText(info);
}

View File

@ -0,0 +1,27 @@
package de.danoeh.antennapod.preferences;
import android.content.Context;
import android.util.AttributeSet;
import java.util.Arrays;
import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
public class VolumeAdaptationPreference extends MaterialListPreference {
public VolumeAdaptationPreference(Context context) {
super(context);
}
public VolumeAdaptationPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public CharSequence[] getEntries() {
if (VolumeAdaptionSetting.isBoostSupported()) {
return super.getEntries();
} else {
return Arrays.copyOfRange(super.getEntries(), 0, 3);
}
}
}

View File

@ -48,7 +48,7 @@
android:summary="@string/global_default"
android:title="@string/auto_delete_label" />
<de.danoeh.antennapod.preferences.MaterialListPreference
<de.danoeh.antennapod.preferences.VolumeAdaptationPreference
android:defaultValue="off"
android:entries="@array/spnVolumeAdaptationItems"
android:entryValues="@array/spnVolumeAdaptationValues"

View File

@ -7,6 +7,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
@ -37,6 +38,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.service.download.HttpCredentialEncoder;
@ -69,7 +71,8 @@ public class ExoPlayerWrapper {
private PlaybackParameters playbackParameters;
private DefaultTrackSelector trackSelector;
private LoudnessEnhancer loudnessEnhancer;
@Nullable
private LoudnessEnhancer loudnessEnhancer = null;
ExoPlayerWrapper(Context context) {
this.context = context;
@ -247,11 +250,15 @@ public class ExoPlayerWrapper {
public void setVolume(float v, float v1) {
if (v > 1) {
exoPlayer.setVolume(1f);
loudnessEnhancer.setEnabled(true);
loudnessEnhancer.setTargetGain((int) (1000 * (v - 1)));
if (loudnessEnhancer != null) {
loudnessEnhancer.setEnabled(true);
loudnessEnhancer.setTargetGain((int) (1000 * (v - 1)));
}
} else {
exoPlayer.setVolume(v);
loudnessEnhancer.setEnabled(false);
if (loudnessEnhancer != null) {
loudnessEnhancer.setEnabled(false);
}
}
}
@ -354,6 +361,10 @@ public class ExoPlayerWrapper {
}
private void initLoudnessEnhancer(int audioStreamId) {
if (!VolumeAdaptionSetting.isBoostSupported()) {
return;
}
LoudnessEnhancer newEnhancer = new LoudnessEnhancer(audioStreamId);
LoudnessEnhancer oldEnhancer = this.loudnessEnhancer;
if (oldEnhancer != null) {

View File

@ -83,14 +83,16 @@ public final class Converter {
* Converts milliseconds to a localized string containing hours and minutes.
*/
public static String getDurationStringLocalized(Context context, long duration) {
return getDurationStringLocalized(context.getResources(), duration);
return getDurationStringLocalized(context.getResources(), duration, false);
}
public static String getDurationStringLocalized(Resources resources, long duration) {
public static String getDurationStringLocalized(Resources resources, long duration, boolean includeDays) {
String result = "";
int h = (int) (duration / HOURS_MIL);
int d = h / 24;
if (d > 0) {
if (!includeDays) {
d = 0;
} else if (d > 0) {
String days = resources.getQuantityString(R.plurals.time_days_quantified, d, d);
result += days.replace(" ", "\u00A0") + " ";
h -= d * 24;

View File

@ -1,6 +1,9 @@
package de.danoeh.antennapod.core.feed;
import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
@ -11,6 +14,16 @@ import static org.junit.Assert.assertTrue;
public class VolumeAdaptionSettingTest {
@Before
public void setUp() throws Exception {
VolumeAdaptionSetting.setBoostSupported(false);
}
@After
public void tearDown() throws Exception {
VolumeAdaptionSetting.setBoostSupported(null);
}
@Test
public void mapOffToInteger() {
VolumeAdaptionSetting setting = VolumeAdaptionSetting.OFF;

View File

@ -1,5 +1,10 @@
package de.danoeh.antennapod.model.feed;
import android.media.audiofx.AudioEffect;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
public enum VolumeAdaptionSetting {
OFF(0, 1.0f),
LIGHT_REDUCTION(1, 0.5f),
@ -32,4 +37,29 @@ public enum VolumeAdaptionSetting {
public float getAdaptionFactor() {
return adaptionFactor;
}
@Nullable
private static Boolean boostSupported = null;
public static boolean isBoostSupported() {
if (boostSupported != null) {
return boostSupported;
}
final AudioEffect.Descriptor[] audioEffects = AudioEffect.queryEffects();
if (audioEffects != null) {
for (AudioEffect.Descriptor effect : audioEffects) {
if (effect.type.equals(AudioEffect.EFFECT_TYPE_LOUDNESS_ENHANCER)) {
boostSupported = true;
return boostSupported;
}
}
}
boostSupported = false;
return boostSupported;
}
@VisibleForTesting
public static void setBoostSupported(@Nullable Boolean boostSupported) {
VolumeAdaptionSetting.boostSupported = boostSupported;
}
}

View File

@ -221,7 +221,7 @@ public class EchoActivity extends AppCompatActivity {
dec31.get(Calendar.DAY_OF_YEAR) - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1);
long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
String timePerDay = Converter.getDurationStringLocalized(
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000);
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000, true);
double hoursPerDay = (double) (secondsPerDay / 3600);
int nextYear = RELEASE_YEAR + 1;
if (hoursPerDay < 1.5) {
@ -249,7 +249,7 @@ public class EchoActivity extends AppCompatActivity {
}
viewBinding.smallLabel.setText(getString(R.string.echo_listened_after_time,
Converter.getDurationStringLocalized(
getLocalizedResources(this, getEchoLanguage()), timeBetweenReleaseAndPlay)));
getLocalizedResources(this, getEchoLanguage()), timeBetweenReleaseAndPlay, true)));
currentDrawable = new RotatingSquaresScreen(this);
break;
case 4: