From edb440a5a9a05e24c344a71b272b9238217e9c55 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 31 Mar 2024 18:40:15 +0200 Subject: Restructure related UI classes together (#7044) --- .../java/de/danoeh/antennapod/model/feed/Feed.java | 9 +- .../antennapod/model/playback/RemoteMedia.java | 16 +-- .../model/VolumeAdaptionSettingTest.java | 129 +++++++++++++++++++++ 3 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 model/src/test/java/de/danoeh/antennapod/model/VolumeAdaptionSettingTest.java (limited to 'model/src') diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java b/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java index 8d36d24a3..15d256c24 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/Feed.java @@ -1,12 +1,11 @@ package de.danoeh.antennapod.model.feed; -import android.text.TextUtils; - import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; /** * Data Object for a whole feed. @@ -205,9 +204,9 @@ public class Feed { } public String getHumanReadableIdentifier() { - if (!TextUtils.isEmpty(customTitle)) { + if (!StringUtils.isEmpty(customTitle)) { return customTitle; - } else if (!TextUtils.isEmpty(feedTitle)) { + } else if (!StringUtils.isEmpty(feedTitle)) { return feedTitle; } else { return downloadUrl; @@ -266,7 +265,7 @@ public class Feed { } public String getTitle() { - return !TextUtils.isEmpty(customTitle) ? customTitle : feedTitle; + return !StringUtils.isEmpty(customTitle) ? customTitle : feedTitle; } public void setTitle(String title) { diff --git a/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java b/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java index b963f3de1..c979488a6 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java +++ b/model/src/main/java/de/danoeh/antennapod/model/playback/RemoteMedia.java @@ -3,7 +3,6 @@ package de.danoeh.antennapod.model.playback; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; -import android.text.TextUtils; import androidx.annotation.Nullable; import de.danoeh.antennapod.model.feed.Chapter; import de.danoeh.antennapod.model.feed.Feed; @@ -13,6 +12,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.HashCodeBuilder; /** @@ -68,7 +68,7 @@ public class RemoteMedia implements Playable { this.episodeTitle = item.getTitle(); this.episodeLink = item.getLink(); this.feedAuthor = item.getFeed().getAuthor(); - if (!TextUtils.isEmpty(item.getImageUrl())) { + if (!StringUtils.isEmpty(item.getImageUrl())) { this.imageUrl = item.getImageUrl(); } else { this.imageUrl = item.getFeed().getImageUrl(); @@ -280,21 +280,21 @@ public class RemoteMedia implements Playable { public boolean equals(Object other) { if (other instanceof RemoteMedia) { RemoteMedia rm = (RemoteMedia) other; - return TextUtils.equals(downloadUrl, rm.downloadUrl) - && TextUtils.equals(feedUrl, rm.feedUrl) - && TextUtils.equals(itemIdentifier, rm.itemIdentifier); + return StringUtils.equals(downloadUrl, rm.downloadUrl) + && StringUtils.equals(feedUrl, rm.feedUrl) + && StringUtils.equals(itemIdentifier, rm.itemIdentifier); } if (other instanceof FeedMedia) { FeedMedia fm = (FeedMedia) other; - if (!TextUtils.equals(downloadUrl, fm.getStreamUrl())) { + if (!StringUtils.equals(downloadUrl, fm.getStreamUrl())) { return false; } FeedItem fi = fm.getItem(); - if (fi == null || !TextUtils.equals(itemIdentifier, fi.getItemIdentifier())) { + if (fi == null || !StringUtils.equals(itemIdentifier, fi.getItemIdentifier())) { return false; } Feed feed = fi.getFeed(); - return feed != null && TextUtils.equals(feedUrl, feed.getDownloadUrl()); + return feed != null && StringUtils.equals(feedUrl, feed.getDownloadUrl()); } return false; } diff --git a/model/src/test/java/de/danoeh/antennapod/model/VolumeAdaptionSettingTest.java b/model/src/test/java/de/danoeh/antennapod/model/VolumeAdaptionSettingTest.java new file mode 100644 index 000000000..265b425e8 --- /dev/null +++ b/model/src/test/java/de/danoeh/antennapod/model/VolumeAdaptionSettingTest.java @@ -0,0 +1,129 @@ +package de.danoeh.antennapod.model; + +import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +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; + assertThat(setting.toInteger(), is(equalTo(0))); + } + + @Test + public void mapLightReductionToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.LIGHT_REDUCTION; + + assertThat(setting.toInteger(), is(equalTo(1))); + } + + @Test + public void mapHeavyReductionToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.HEAVY_REDUCTION; + + assertThat(setting.toInteger(), is(equalTo(2))); + } + + @Test + public void mapLightBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.LIGHT_BOOST; + + assertThat(setting.toInteger(), is(equalTo(3))); + } + + @Test + public void mapMediumBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.MEDIUM_BOOST; + + assertThat(setting.toInteger(), is(equalTo(4))); + } + + @Test + public void mapHeavyBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.HEAVY_BOOST; + + assertThat(setting.toInteger(), is(equalTo(5))); + } + + @Test + public void mapIntegerToVolumeAdaptionSetting() { + assertThat(VolumeAdaptionSetting.fromInteger(0), is(equalTo(VolumeAdaptionSetting.OFF))); + assertThat(VolumeAdaptionSetting.fromInteger(1), is(equalTo(VolumeAdaptionSetting.LIGHT_REDUCTION))); + assertThat(VolumeAdaptionSetting.fromInteger(2), is(equalTo(VolumeAdaptionSetting.HEAVY_REDUCTION))); + assertThat(VolumeAdaptionSetting.fromInteger(3), is(equalTo(VolumeAdaptionSetting.LIGHT_BOOST))); + assertThat(VolumeAdaptionSetting.fromInteger(4), is(equalTo(VolumeAdaptionSetting.MEDIUM_BOOST))); + assertThat(VolumeAdaptionSetting.fromInteger(5), is(equalTo(VolumeAdaptionSetting.HEAVY_BOOST))); + } + + @Test(expected = IllegalArgumentException.class) + public void cannotMapNegativeValues() { + VolumeAdaptionSetting.fromInteger(-1); + } + + @Test(expected = IllegalArgumentException.class) + public void cannotMapValuesOutOfRange() { + VolumeAdaptionSetting.fromInteger(6); + } + + @Test + public void noAdaptionIfTurnedOff() { + float adaptionFactor = VolumeAdaptionSetting.OFF.getAdaptionFactor(); + assertEquals(1.0f, adaptionFactor, 0.01f); + } + + @Test + public void lightReductionYieldsHigherValueThanHeavyReduction() { + float lightReductionFactor = VolumeAdaptionSetting.LIGHT_REDUCTION.getAdaptionFactor(); + + float heavyReductionFactor = VolumeAdaptionSetting.HEAVY_REDUCTION.getAdaptionFactor(); + + assertTrue("Light reduction must have higher factor than heavy reduction", lightReductionFactor > heavyReductionFactor); + } + + @Test + public void lightBoostYieldsHigherValueThanLightReduction() { + float lightReductionFactor = VolumeAdaptionSetting.LIGHT_REDUCTION.getAdaptionFactor(); + + float lightBoostFactor = VolumeAdaptionSetting.LIGHT_BOOST.getAdaptionFactor(); + + assertTrue("Light boost must have higher factor than light reduction", lightBoostFactor > lightReductionFactor); + } + + @Test + public void mediumBoostYieldsHigherValueThanLightBoost() { + float lightBoostFactor = VolumeAdaptionSetting.LIGHT_BOOST.getAdaptionFactor(); + + float mediumBoostFactor = VolumeAdaptionSetting.MEDIUM_BOOST.getAdaptionFactor(); + + assertTrue("Medium boost must have higher factor than light boost", mediumBoostFactor > lightBoostFactor); + } + + @Test + public void heavyBoostYieldsHigherValueThanMediumBoost() { + float mediumBoostFactor = VolumeAdaptionSetting.MEDIUM_BOOST.getAdaptionFactor(); + + float heavyBoostFactor = VolumeAdaptionSetting.HEAVY_BOOST.getAdaptionFactor(); + + assertTrue("Heavy boost must have higher factor than medium boost", heavyBoostFactor > mediumBoostFactor); + } +} -- cgit v1.2.3