resolve review remarks w.r.t naming: volume reduction -> volume adaption

This commit is contained in:
Max Bechtold 2019-12-21 12:21:05 +01:00
parent 9ca5cab246
commit 12be60f1ba
17 changed files with 175 additions and 180 deletions

View File

@ -3,8 +3,8 @@ package de.test.antennapod.service.playback;
import android.content.Context;
import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.test.antennapod.EspressoTestUtils;
import junit.framework.AssertionFailedError;
@ -126,7 +126,7 @@ public class PlaybackServiceMediaPlayerTest {
private Playable writeTestPlayable(String downloadUrl, String fileUrl) {
final Context c = getInstrumentation().getTargetContext();
Feed f = new Feed(0, null, "f", "l", "d", null, null, null, null, "i", null, null, "l", false);
FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, VolumeReductionSetting.OFF, null, null);
FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, VolumeAdaptionSetting.OFF, null, null);
f.setPreferences(prefs);
f.setItems(new ArrayList<>());
FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);

View File

@ -14,7 +14,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
@ -48,7 +47,7 @@ import de.danoeh.antennapod.core.event.DownloadEvent;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.glide.FastBlurTransformation;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -227,7 +226,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
url = URLChecker.prepareURL(url);
feed = new Feed(url, null);
if (username != null && password != null) {
feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeReductionSetting.OFF, username, password));
feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeAdaptionSetting.OFF, username, password));
}
String fileUrl = new File(getExternalCacheDir(),
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();

View File

@ -14,7 +14,7 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedFilter;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader;
@ -216,42 +216,42 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> {
switch ((String) newValue) {
case "off":
feedPreferences.setVolumeReductionSetting(VolumeReductionSetting.OFF);
feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.OFF);
break;
case "light":
feedPreferences.setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
break;
case "heavy":
feedPreferences.setVolumeReductionSetting(VolumeReductionSetting.HEAVY);
feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION);
break;
}
feed.savePreferences();
updateVolumeReductionValue();
sendVolumeReductionChangedIntent();
sendVolumeAdaptionChangedIntent();
return false;
});
}
private void sendVolumeReductionChangedIntent() {
private void sendVolumeAdaptionChangedIntent() {
Context context = getContext();
Intent intent = new Intent(PlaybackService.ACTION_VOLUME_REDUCTION_CHANGED).setPackage(context.getPackageName());
intent.putExtra(PlaybackService.EXTRA_VOLUME_REDUCTION_AFFECTED_FEED, feed.getIdentifyingValue());
intent.putExtra(PlaybackService.EXTRA_VOLUME_REDUCTION_SETTING, feedPreferences.getVolumeReductionSetting());
Intent intent = new Intent(PlaybackService.ACTION_VOLUME_ADAPTION_CHANGED).setPackage(context.getPackageName());
intent.putExtra(PlaybackService.EXTRA_VOLUME_ADAPTION_AFFECTED_FEED, feed.getIdentifyingValue());
intent.putExtra(PlaybackService.EXTRA_VOLUME_ADAPTION_SETTING, feedPreferences.getVolumeAdaptionSetting());
context.sendBroadcast(intent);
}
private void updateVolumeReductionValue() {
ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
switch (feedPreferences.getVolumeReductionSetting()) {
switch (feedPreferences.getVolumeAdaptionSetting()) {
case OFF:
volumeReductionPreference.setValue("off");
break;
case LIGHT:
case LIGHT_REDUCTION:
volumeReductionPreference.setValue("light");
break;
case HEAVY:
case HEAVY_REDUCTION:
volumeReductionPreference.setValue("heavy");
break;
}

View File

@ -171,7 +171,7 @@ public class Feed extends FeedFile implements ImageResource {
*/
public Feed(String url, String lastUpdate, String title, String username, String password) {
this(url, lastUpdate, title);
preferences = new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeReductionSetting.OFF, username, password);
preferences = new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeAdaptionSetting.OFF, username, password);
}
public static Feed fromCursor(Cursor cursor) {

View File

@ -29,22 +29,22 @@ public class FeedPreferences {
}
private AutoDeleteAction auto_delete_action;
private VolumeReductionSetting volumeReductionSetting;
private VolumeAdaptionSetting volumeAdaptionSetting;
private String username;
private String password;
private float feedPlaybackSpeed;
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, VolumeReductionSetting volumeReductionSetting, String username, String password) {
this(feedID, autoDownload, true, auto_delete_action, volumeReductionSetting, username, password, new FeedFilter(), SPEED_USE_GLOBAL);
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, VolumeAdaptionSetting volumeAdaptionSetting, String username, String password) {
this(feedID, autoDownload, true, auto_delete_action, volumeAdaptionSetting, username, password, new FeedFilter(), SPEED_USE_GLOBAL);
}
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, VolumeReductionSetting volumeReductionSetting, String username, String password, @NonNull FeedFilter filter, float feedPlaybackSpeed) {
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, VolumeAdaptionSetting volumeAdaptionSetting, String username, String password, @NonNull FeedFilter filter, float feedPlaybackSpeed) {
this.feedID = feedID;
this.autoDownload = autoDownload;
this.keepUpdated = keepUpdated;
this.auto_delete_action = auto_delete_action;
this.volumeReductionSetting = volumeReductionSetting;
this.volumeAdaptionSetting = volumeAdaptionSetting;
this.username = username;
this.password = password;
this.filter = filter;
@ -56,7 +56,7 @@ public class FeedPreferences {
int indexAutoDownload = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DOWNLOAD);
int indexAutoRefresh = cursor.getColumnIndex(PodDBAdapter.KEY_KEEP_UPDATED);
int indexAutoDeleteAction = cursor.getColumnIndex(PodDBAdapter.KEY_AUTO_DELETE_ACTION);
int indexVolumeReduction = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_VOLUME_REDUCTION);
int indexVolumeAdaption = cursor.getColumnIndex(PodDBAdapter.KEY_FEED_VOLUME_ADAPTION);
int indexUsername = cursor.getColumnIndex(PodDBAdapter.KEY_USERNAME);
int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD);
int indexIncludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_INCLUDE_FILTER);
@ -68,14 +68,14 @@ public class FeedPreferences {
boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0;
int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction);
AutoDeleteAction autoDeleteAction = AutoDeleteAction.values()[autoDeleteActionIndex];
int volumeReductionValue = cursor.getInt(indexVolumeReduction);
VolumeReductionSetting volumeReductionSetting = VolumeReductionSetting.fromInteger(volumeReductionValue);
int volumeAdaptionValue = cursor.getInt(indexVolumeAdaption);
VolumeAdaptionSetting volumeAdaptionSetting = VolumeAdaptionSetting.fromInteger(volumeAdaptionValue);
String username = cursor.getString(indexUsername);
String password = cursor.getString(indexPassword);
String includeFilter = cursor.getString(indexIncludeFilter);
String excludeFilter = cursor.getString(indexExcludeFilter);
float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed);
return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, volumeReductionSetting, username, password, new FeedFilter(includeFilter, excludeFilter), feedPlaybackSpeed);
return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, volumeAdaptionSetting, username, password, new FeedFilter(includeFilter, excludeFilter), feedPlaybackSpeed);
}
/**
@ -151,16 +151,16 @@ public class FeedPreferences {
return auto_delete_action;
}
public VolumeReductionSetting getVolumeReductionSetting() {
return volumeReductionSetting;
public VolumeAdaptionSetting getVolumeAdaptionSetting() {
return volumeAdaptionSetting;
}
public void setAutoDeleteAction(AutoDeleteAction auto_delete_action) {
this.auto_delete_action = auto_delete_action;
}
public void setVolumeReductionSetting(VolumeReductionSetting volumeReductionSetting) {
this.volumeReductionSetting = volumeReductionSetting;
public void setVolumeAdaptionSetting(VolumeAdaptionSetting volumeAdaptionSetting) {
this.volumeAdaptionSetting = volumeAdaptionSetting;
}
public boolean getCurrentAutoDelete() {

View File

@ -0,0 +1,32 @@
package de.danoeh.antennapod.core.feed;
public enum VolumeAdaptionSetting {
OFF(0, 1.0f),
LIGHT_REDUCTION(1, 0.5f),
HEAVY_REDUCTION(2, 0.2f);
private final int value;
private float adaptionFactor;
VolumeAdaptionSetting(int value, float adaptionFactor) {
this.value = value;
this.adaptionFactor = adaptionFactor;
}
public static VolumeAdaptionSetting fromInteger(int value) {
for (VolumeAdaptionSetting setting : values()) {
if (setting.value == value) {
return setting;
}
}
throw new IllegalArgumentException("Cannot map value to VolumeAdaptionSetting: " + value);
}
public int toInteger() {
return value;
}
public float getAdaptionFactor() {
return adaptionFactor;
}
}

View File

@ -1,32 +0,0 @@
package de.danoeh.antennapod.core.feed;
public enum VolumeReductionSetting {
OFF(0, 1.0f),
LIGHT(1, 0.5f),
HEAVY(2, 0.2f);
private final int value;
private float reductionFactor;
VolumeReductionSetting(int value, float reductionFactor) {
this.value = value;
this.reductionFactor = reductionFactor;
}
public static VolumeReductionSetting fromInteger(int value) {
for (VolumeReductionSetting setting : values()) {
if (setting.value == value) {
return setting;
}
}
throw new IllegalArgumentException("Cannot map value to VolumeReductionSetting: " + value);
}
public int toInteger() {
return value;
}
public float getReductionFactor() {
return reductionFactor;
}
}

View File

@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import org.apache.commons.io.FileUtils;
import org.greenrobot.eventbus.EventBus;

View File

@ -4,7 +4,7 @@ import android.util.Log;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.service.download.DownloadRequest;
import de.danoeh.antennapod.core.service.download.DownloadStatus;
import de.danoeh.antennapod.core.storage.DownloadRequester;
@ -38,7 +38,7 @@ public class FeedParserTask implements Callable<FeedHandlerResult> {
feed.setId(request.getFeedfileId());
feed.setDownloaded(true);
feed.setPreferences(new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL,
VolumeReductionSetting.OFF, request.getUsername(), request.getPassword()));
VolumeAdaptionSetting.OFF, request.getUsername(), request.getPassword()));
feed.setPageNr(request.getArguments().getInt(DownloadRequester.REQUEST_ARG_PAGE_NR, 0));
DownloadError reason = null;

View File

@ -29,8 +29,8 @@ import java.util.concurrent.locks.ReentrantLock;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.RewindAfterPauseUtils;
import de.danoeh.antennapod.core.util.playback.AudioPlayer;
@ -673,10 +673,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
if (playable instanceof FeedMedia) {
FeedMedia feedMedia = (FeedMedia) playable;
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
VolumeReductionSetting volumeReductionSetting = preferences.getVolumeReductionSetting();
float reductionFactor = volumeReductionSetting.getReductionFactor();
volumeLeft *= reductionFactor;
volumeRight *= reductionFactor;
VolumeAdaptionSetting volumeAdaptionSetting = preferences.getVolumeAdaptionSetting();
float adaptionFactor = volumeAdaptionSetting.getAdaptionFactor();
volumeLeft *= adaptionFactor;
volumeRight *= adaptionFactor;
}
mediaPlayer.setVolume(volumeLeft, volumeRight);
Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);

View File

@ -1,6 +1,5 @@
package de.danoeh.antennapod.core.service.playback;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
@ -58,7 +57,7 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.feed.SearchResult;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
@ -72,7 +71,6 @@ import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import de.danoeh.antennapod.core.util.playback.ExternalMedia;
import de.danoeh.antennapod.core.util.playback.Playable;
@ -139,11 +137,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public static final String ACTION_PAUSE_PLAY_CURRENT_EPISODE = "action.de.danoeh.antennapod.core.service.pausePlayCurrentEpisode";
/**
* If the PlaybackService receives this action, it will try to apply the supplied volume reduction setting.
* If the PlaybackService receives this action, it will try to apply the supplied volume adaption setting.
*/
public static final String ACTION_VOLUME_REDUCTION_CHANGED = "action.de.danoeh.antennapod.core.service.volumedReductionChanged";
public static final String EXTRA_VOLUME_REDUCTION_SETTING = "PlaybackService.VolumeReductionSettingExtra";
public static final String EXTRA_VOLUME_REDUCTION_AFFECTED_FEED = "PlaybackService.VolumeReductionSettingAffectedFeed";
public static final String ACTION_VOLUME_ADAPTION_CHANGED = "action.de.danoeh.antennapod.core.service.volumedAdaptionChanged";
public static final String EXTRA_VOLUME_ADAPTION_SETTING = "PlaybackService.VolumeAdaptionSettingExtra";
public static final String EXTRA_VOLUME_ADAPTION_AFFECTED_FEED = "PlaybackService.VolumeAdaptionSettingAffectedFeed";
/**
* Custom action used by Android Wear
@ -286,7 +284,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
registerReceiver(audioBecomingNoisy, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(ACTION_SKIP_CURRENT_EPISODE));
registerReceiver(pausePlayCurrentEpisodeReceiver, new IntentFilter(ACTION_PAUSE_PLAY_CURRENT_EPISODE));
registerReceiver(volumeReductionChangedReceiver, new IntentFilter(ACTION_VOLUME_REDUCTION_CHANGED));
registerReceiver(volumeAdaptionChangedReceiver, new IntentFilter(ACTION_VOLUME_ADAPTION_CHANGED));
taskManager = new PlaybackServiceTaskManager(this, taskManagerCallback);
flavorHelper = new PlaybackServiceFlavorHelper(PlaybackService.this, flavorHelperCallback);
@ -1446,18 +1444,18 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
};
private final BroadcastReceiver volumeReductionChangedReceiver = new BroadcastReceiver() {
private final BroadcastReceiver volumeAdaptionChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(intent.getAction(), ACTION_VOLUME_REDUCTION_CHANGED)) {
Log.d(TAG, "Received ACTION_VOLUME_REDUCTION_CHANGED intent");
if (TextUtils.equals(intent.getAction(), ACTION_VOLUME_ADAPTION_CHANGED)) {
Log.d(TAG, "Received ACTION_VOLUME_ADAPTION_CHANGED intent");
String affectedFeed = intent.getStringExtra(EXTRA_VOLUME_REDUCTION_AFFECTED_FEED);
Serializable volumeReductionExtra = intent.getSerializableExtra(EXTRA_VOLUME_REDUCTION_SETTING);
VolumeReductionSetting volumeReductionSetting = (VolumeReductionSetting) volumeReductionExtra;
String affectedFeed = intent.getStringExtra(EXTRA_VOLUME_ADAPTION_AFFECTED_FEED);
Serializable volumeAdaptionExtra = intent.getSerializableExtra(EXTRA_VOLUME_ADAPTION_SETTING);
VolumeAdaptionSetting volumeAdaptionSetting = (VolumeAdaptionSetting) volumeAdaptionExtra;
PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, affectedFeed, volumeReductionSetting);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, affectedFeed, volumeAdaptionSetting);
}
}
};

View File

@ -2,25 +2,25 @@ package de.danoeh.antennapod.core.service.playback;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.util.playback.Playable;
class PlaybackVolumeUpdater {
public void updateVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting) {
public void updateVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeAdaptionSetting volumeAdaptionSetting) {
Playable playable = mediaPlayer.getPlayable();
boolean isFeedMedia = playable instanceof FeedMedia;
boolean isPlayableLoaded = isPlayableLoaded(mediaPlayer.getPlayerStatus());
if (isFeedMedia && isPlayableLoaded) {
updateFeedMediaVolumeIfNecessary(mediaPlayer, affectedFeedIdentifier, volumeReductionSetting, (FeedMedia) playable);
updateFeedMediaVolumeIfNecessary(mediaPlayer, affectedFeedIdentifier, volumeAdaptionSetting, (FeedMedia) playable);
}
}
private void updateFeedMediaVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeReductionSetting volumeReductionSetting, FeedMedia feedMedia) {
private void updateFeedMediaVolumeIfNecessary(PlaybackServiceMediaPlayer mediaPlayer, String affectedFeedIdentifier, VolumeAdaptionSetting volumeAdaptionSetting, FeedMedia feedMedia) {
if (mediaBelongsToAffectedFeed(feedMedia, affectedFeedIdentifier)) {
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
preferences.setVolumeReductionSetting(volumeReductionSetting);
preferences.setVolumeAdaptionSetting(volumeAdaptionSetting);
if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
forceUpdateVolume(mediaPlayer);

View File

@ -300,7 +300,7 @@ class DBUpgrader {
+ " ADD COLUMN " + PodDBAdapter.KEY_SORT_ORDER + " TEXT");
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_VOLUME_REDUCTION + " INTEGER DEFAULT 0");
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_VOLUME_ADAPTION + " INTEGER DEFAULT 0");
}
}

View File

@ -12,7 +12,6 @@ import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@ -97,7 +96,7 @@ public class PodDBAdapter {
public static final String KEY_AUTO_DOWNLOAD = "auto_download";
public static final String KEY_KEEP_UPDATED = "keep_updated";
public static final String KEY_AUTO_DELETE_ACTION = "auto_delete_action";
public static final String KEY_FEED_VOLUME_REDUCTION = "feed_volume_reduction";
public static final String KEY_FEED_VOLUME_ADAPTION = "feed_volume_adaption";
public static final String KEY_PLAYED_DURATION = "played_duration";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";
@ -146,7 +145,7 @@ public class PodDBAdapter {
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0,"
+ KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0,"
+ KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL + ","
+ KEY_FEED_VOLUME_REDUCTION + " INTEGER DEFAULT 0)";
+ KEY_FEED_VOLUME_ADAPTION + " INTEGER DEFAULT 0)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
@ -243,7 +242,7 @@ public class PodDBAdapter {
TABLE_NAME_FEEDS + "." + KEY_SORT_ORDER,
TABLE_NAME_FEEDS + "." + KEY_LAST_UPDATE_FAILED,
TABLE_NAME_FEEDS + "." + KEY_AUTO_DELETE_ACTION,
TABLE_NAME_FEEDS + "." + KEY_FEED_VOLUME_REDUCTION,
TABLE_NAME_FEEDS + "." + KEY_FEED_VOLUME_ADAPTION,
TABLE_NAME_FEEDS + "." + KEY_INCLUDE_FILTER,
TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER,
TABLE_NAME_FEEDS + "." + KEY_FEED_PLAYBACK_SPEED
@ -406,7 +405,7 @@ public class PodDBAdapter {
values.put(KEY_AUTO_DOWNLOAD, prefs.getAutoDownload());
values.put(KEY_KEEP_UPDATED, prefs.getKeepUpdated());
values.put(KEY_AUTO_DELETE_ACTION, prefs.getAutoDeleteAction().ordinal());
values.put(KEY_FEED_VOLUME_REDUCTION, prefs.getVolumeReductionSetting().toInteger());
values.put(KEY_FEED_VOLUME_ADAPTION, prefs.getVolumeAdaptionSetting().toInteger());
values.put(KEY_USERNAME, prefs.getUsername());
values.put(KEY_PASSWORD, prefs.getPassword());
values.put(KEY_INCLUDE_FILTER, prefs.getFilter().getIncludeFilter());

View File

@ -0,0 +1,64 @@
package de.danoeh.antennapod.core.feed;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class VolumeAdaptionSettingTest {
@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 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)));
}
@Test(expected = IllegalArgumentException.class)
public void cannotMapNegativeValues() {
VolumeAdaptionSetting.fromInteger(-1);
}
@Test(expected = IllegalArgumentException.class)
public void cannotMapValuesOutOfRange() {
VolumeAdaptionSetting.fromInteger(3);
}
@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);
}
}

View File

@ -1,64 +0,0 @@
package de.danoeh.antennapod.core.feed;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class VolumeReductionSettingTest {
@Test
public void mapOffToInteger() {
VolumeReductionSetting setting = VolumeReductionSetting.OFF;
assertThat(setting.toInteger(), is(equalTo(0)));
}
@Test
public void mapLightToInteger() {
VolumeReductionSetting setting = VolumeReductionSetting.LIGHT;
assertThat(setting.toInteger(), is(equalTo(1)));
}
@Test
public void mapHeavyToInteger() {
VolumeReductionSetting setting = VolumeReductionSetting.HEAVY;
assertThat(setting.toInteger(), is(equalTo(2)));
}
@Test
public void mapIntegerToVolumeReductionSetting() {
assertThat(VolumeReductionSetting.fromInteger(0), is(equalTo(VolumeReductionSetting.OFF)));
assertThat(VolumeReductionSetting.fromInteger(1), is(equalTo(VolumeReductionSetting.LIGHT)));
assertThat(VolumeReductionSetting.fromInteger(2), is(equalTo(VolumeReductionSetting.HEAVY)));
}
@Test(expected = IllegalArgumentException.class)
public void cannotMapNegativeValues() {
VolumeReductionSetting.fromInteger(-1);
}
@Test(expected = IllegalArgumentException.class)
public void cannotMapValuesOutOfRange() {
VolumeReductionSetting.fromInteger(3);
}
@Test
public void noReductionIfTurnedOff() {
float reductionFactor = VolumeReductionSetting.OFF.getReductionFactor();
assertEquals(1.0f, reductionFactor, 0.01f);
}
@Test
public void lightReductionYieldsHigherValueThanHeavyReduction() {
float lightReductionFactor = VolumeReductionSetting.LIGHT.getReductionFactor();
float heavyReductionFactor = VolumeReductionSetting.HEAVY.getReductionFactor();
assertTrue("Light reduction must have higher factor than heavy reduction", lightReductionFactor > heavyReductionFactor);
}
}

View File

@ -4,7 +4,7 @@ import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
import de.danoeh.antennapod.core.util.playback.Playable;
import org.junit.Before;
import org.junit.Test;
@ -36,7 +36,7 @@ public class PlaybackVolumeUpdaterTest {
Playable noFeedMedia = mock(Playable.class);
when(mediaPlayer.getPlayable()).thenReturn(noFeedMedia);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -51,7 +51,7 @@ public class PlaybackVolumeUpdaterTest {
FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -66,7 +66,7 @@ public class PlaybackVolumeUpdaterTest {
FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -81,7 +81,7 @@ public class PlaybackVolumeUpdaterTest {
FeedMedia feedMedia = mock(FeedMedia.class);
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -98,7 +98,7 @@ public class PlaybackVolumeUpdaterTest {
Feed feed = mockFeed(feedMedia, FEED_ID);
when(feed.getIdentifyingValue()).thenReturn("wrongFeedId");
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.OFF);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -114,9 +114,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -132,9 +132,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -150,9 +150,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -168,9 +168,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -186,9 +186,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.LIGHT);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.LIGHT);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
verify(mediaPlayer, never()).resume();
@ -204,9 +204,9 @@ public class PlaybackVolumeUpdaterTest {
when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
FeedPreferences feedPreferences = mockFeedPreferences(feedMedia, FEED_ID);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeReductionSetting.HEAVY);
playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.HEAVY_REDUCTION);
verify(feedPreferences, times(1)).setVolumeReductionSetting(VolumeReductionSetting.HEAVY);
verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION);
verify(mediaPlayer, times(1)).pause(false, false);
verify(mediaPlayer, times(1)).resume();