Draft volume reduction settings per feed
This commit is contained in:
parent
0bd3b72652
commit
c628fdfcfd
|
@ -129,7 +129,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, null, null);
|
||||
FeedPreferences prefs = new FeedPreferences(f.getId(), false, FeedPreferences.AutoDeleteAction.NO, FeedPreferences.VolumeReductionSetting.OFF, null, null);
|
||||
f.setPreferences(prefs);
|
||||
f.setItems(new ArrayList<>());
|
||||
FeedItem i = new FeedItem(0, "t", "i", "l", new Date(), FeedItem.UNPLAYED, f);
|
||||
|
|
|
@ -270,7 +270,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, username, password));
|
||||
feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, FeedPreferences.VolumeReductionSetting.OFF, username, password));
|
||||
}
|
||||
String fileUrl = new File(getExternalCacheDir(),
|
||||
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();
|
||||
|
|
|
@ -38,10 +38,12 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
|||
setupAutoDownloadPreference();
|
||||
setupKeepUpdatedPreference();
|
||||
setupAutoDeletePreference();
|
||||
setupVolumeReductionPreferences();
|
||||
setupAuthentificationPreference();
|
||||
setupEpisodeFilterPreference();
|
||||
|
||||
updateAutoDeleteSummary();
|
||||
updateVolumeReductionSummary();
|
||||
updateAutoDownloadEnabled();
|
||||
}).dispose();
|
||||
}
|
||||
|
@ -114,6 +116,46 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
}
|
||||
|
||||
private void setupVolumeReductionPreferences() {
|
||||
ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
|
||||
volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
switch ((String) newValue) {
|
||||
case "off":
|
||||
feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.OFF);
|
||||
break;
|
||||
case "light":
|
||||
feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.LIGHT);
|
||||
break;
|
||||
case "heavy":
|
||||
feedPreferences.setVolumeReductionSetting(FeedPreferences.VolumeReductionSetting.HEAVY);
|
||||
break;
|
||||
}
|
||||
feed.savePreferences();
|
||||
updateVolumeReductionSummary();
|
||||
// TODO maxbechtold Check if we can call setVolume for the PlaybackService, if running
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateVolumeReductionSummary() {
|
||||
ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction");
|
||||
|
||||
switch (feedPreferences.getVolumeReductionSetting()) {
|
||||
case OFF:
|
||||
volumeReductionPreference.setSummary(R.string.feed_volume_reduction_off);
|
||||
volumeReductionPreference.setValue("off");
|
||||
break;
|
||||
case LIGHT:
|
||||
volumeReductionPreference.setSummary(R.string.feed_volume_reduction_light);
|
||||
volumeReductionPreference.setValue("light");
|
||||
break;
|
||||
case HEAVY:
|
||||
volumeReductionPreference.setSummary(R.string.feed_volume_reduction_heavy);
|
||||
volumeReductionPreference.setValue("heavy");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setupKeepUpdatedPreference() {
|
||||
SwitchPreference pref = (SwitchPreference) findPreference("keepUpdated");
|
||||
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
android:title="@string/auto_delete_label"
|
||||
android:key="autoDelete"/>
|
||||
|
||||
<ListPreference
|
||||
android:entries="@array/spnVolumeReductionItems"
|
||||
android:entryValues="@array/spnVolumeReductionValues"
|
||||
android:summary="Reduce volume when playing episodes of this feed"
|
||||
android:title="@string/feed_volume_reduction"
|
||||
|
||||
android:key="volumeReduction"/>
|
||||
|
||||
<PreferenceCategory android:title="@string/auto_download_settings_label">
|
||||
<SwitchPreference
|
||||
android:key="autoDownload"
|
||||
|
|
|
@ -160,7 +160,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, username, password);
|
||||
preferences = new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, FeedPreferences.VolumeReductionSetting.OFF, username, password);
|
||||
}
|
||||
|
||||
public static Feed fromCursor(Cursor cursor) {
|
||||
|
|
|
@ -26,18 +26,27 @@ public class FeedPreferences {
|
|||
NO
|
||||
}
|
||||
private AutoDeleteAction auto_delete_action;
|
||||
|
||||
public enum VolumeReductionSetting {
|
||||
OFF,
|
||||
LIGHT,
|
||||
HEAVY
|
||||
}
|
||||
private VolumeReductionSetting volumeReductionSetting;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password) {
|
||||
this(feedID, autoDownload, true, auto_delete_action, username, password, new FeedFilter());
|
||||
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());
|
||||
}
|
||||
|
||||
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, String username, String password, @NonNull FeedFilter filter) {
|
||||
private FeedPreferences(long feedID, boolean autoDownload, boolean keepUpdated, AutoDeleteAction auto_delete_action, VolumeReductionSetting volumeReductionSetting, String username, String password, @NonNull FeedFilter filter) {
|
||||
this.feedID = feedID;
|
||||
this.autoDownload = autoDownload;
|
||||
this.keepUpdated = keepUpdated;
|
||||
this.auto_delete_action = auto_delete_action;
|
||||
this.volumeReductionSetting = volumeReductionSetting;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.filter = filter;
|
||||
|
@ -48,6 +57,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 indexUsername = cursor.getColumnIndex(PodDBAdapter.KEY_USERNAME);
|
||||
int indexPassword = cursor.getColumnIndex(PodDBAdapter.KEY_PASSWORD);
|
||||
int indexIncludeFilter = cursor.getColumnIndex(PodDBAdapter.KEY_INCLUDE_FILTER);
|
||||
|
@ -58,11 +68,13 @@ public class FeedPreferences {
|
|||
boolean autoRefresh = cursor.getInt(indexAutoRefresh) > 0;
|
||||
int autoDeleteActionIndex = cursor.getInt(indexAutoDeleteAction);
|
||||
AutoDeleteAction autoDeleteAction = AutoDeleteAction.values()[autoDeleteActionIndex];
|
||||
int volumeReductionIndex = cursor.getInt(indexVolumeReduction);
|
||||
VolumeReductionSetting volumeReductionSetting = VolumeReductionSetting.values()[volumeReductionIndex];
|
||||
String username = cursor.getString(indexUsername);
|
||||
String password = cursor.getString(indexPassword);
|
||||
String includeFilter = cursor.getString(indexIncludeFilter);
|
||||
String excludeFilter = cursor.getString(indexExcludeFilter);
|
||||
return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, username, password, new FeedFilter(includeFilter, excludeFilter));
|
||||
return new FeedPreferences(feedId, autoDownload, autoRefresh, autoDeleteAction, volumeReductionSetting, username, password, new FeedFilter(includeFilter, excludeFilter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,10 +150,18 @@ public class FeedPreferences {
|
|||
return auto_delete_action;
|
||||
}
|
||||
|
||||
public VolumeReductionSetting getVolumeReductionSetting() {
|
||||
return volumeReductionSetting;
|
||||
}
|
||||
|
||||
public void setAutoDeleteAction(AutoDeleteAction auto_delete_action) {
|
||||
this.auto_delete_action = auto_delete_action;
|
||||
}
|
||||
|
||||
public void setVolumeReductionSetting(VolumeReductionSetting volumeReductionSetting) {
|
||||
this.volumeReductionSetting = volumeReductionSetting;
|
||||
}
|
||||
|
||||
public boolean getCurrentAutoDelete() {
|
||||
switch (auto_delete_action) {
|
||||
case GLOBAL:
|
||||
|
|
|
@ -764,7 +764,7 @@ public class DownloadService extends Service {
|
|||
feed.setId(request.getFeedfileId());
|
||||
feed.setDownloaded(true);
|
||||
feed.setPreferences(new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL,
|
||||
request.getUsername(), request.getPassword()));
|
||||
FeedPreferences.VolumeReductionSetting.OFF, request.getUsername(), request.getPassword()));
|
||||
feed.setPageNr(request.getArguments().getInt(DownloadRequester.REQUEST_ARG_PAGE_NR, 0));
|
||||
|
||||
DownloadError reason = null;
|
||||
|
|
|
@ -313,18 +313,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
UserPreferences.setPlaybackSpeed(String.valueOf(speed));
|
||||
}
|
||||
setPlaybackParams(speed, UserPreferences.isSkipSilence());
|
||||
// TODO MAX Here and everywhere else volume is adapted
|
||||
Playable playable = getPlayable();
|
||||
if (playable instanceof FeedMedia) {
|
||||
FeedMedia feedMedia = (FeedMedia) playable;
|
||||
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
|
||||
|
||||
// TODO MAX Check if this feed should have volume adjusted (e.g. louder than others)
|
||||
|
||||
|
||||
}
|
||||
|
||||
setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
|
||||
float leftVolume = UserPreferences.getLeftVolume();
|
||||
float rightVolume = UserPreferences.getRightVolume();
|
||||
setVolume(leftVolume, rightVolume);
|
||||
|
||||
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
|
||||
int newPosition = RewindAfterPauseUtils.calculatePositionWithRewind(
|
||||
|
@ -344,8 +336,25 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
private float getVolumeReductionFactor() {
|
||||
Playable playable = getPlayable();
|
||||
if (playable instanceof FeedMedia) {
|
||||
FeedMedia feedMedia = (FeedMedia) playable;
|
||||
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
|
||||
FeedPreferences.VolumeReductionSetting volumeReductionSetting = preferences.getVolumeReductionSetting();
|
||||
|
||||
/**
|
||||
// TODO maxbechtold These numbers should be tested
|
||||
if (volumeReductionSetting == FeedPreferences.VolumeReductionSetting.LIGHT) {
|
||||
return 0.4f;
|
||||
} else if (volumeReductionSetting == FeedPreferences.VolumeReductionSetting.HEAVY) {
|
||||
return 0.2f;
|
||||
}
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the current position and pauses playback. Note that, if audiofocus
|
||||
* is abandoned, the lockscreen controls will also disapear.
|
||||
* <p/>
|
||||
|
@ -681,6 +690,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
private void setVolumeSync(float volumeLeft, float volumeRight) {
|
||||
playerLock.lock();
|
||||
if (media != null && media.getMediaType() == MediaType.AUDIO) {
|
||||
// TODO maxbechtold does not apply to currently playing episode
|
||||
float reductionFactor = getVolumeReductionFactor();
|
||||
volumeLeft *= reductionFactor;
|
||||
volumeRight *= reductionFactor;
|
||||
mediaPlayer.setVolume(volumeLeft, volumeRight);
|
||||
Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);
|
||||
}
|
||||
|
|
|
@ -193,6 +193,7 @@ class DBUpgrader {
|
|||
db.execSQL(sql);
|
||||
}
|
||||
if (oldVersion <= 17) {
|
||||
// TODO maxbechtold Something like this for volume reduction
|
||||
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
|
||||
+ " ADD COLUMN " + PodDBAdapter.KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0");
|
||||
}
|
||||
|
|
|
@ -103,6 +103,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_PLAYED_DURATION = "played_duration";
|
||||
public static final String KEY_USERNAME = "username";
|
||||
public static final String KEY_PASSWORD = "password";
|
||||
|
@ -146,7 +147,8 @@ public class PodDBAdapter {
|
|||
+ KEY_NEXT_PAGE_LINK + " TEXT,"
|
||||
+ KEY_HIDE + " TEXT,"
|
||||
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0,"
|
||||
+ KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0)";
|
||||
+ KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0,"
|
||||
+ KEY_FEED_VOLUME_REDUCTION + " INTEGER DEFAULT 0)";
|
||||
|
||||
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
|
||||
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
||||
|
@ -242,6 +244,7 @@ public class PodDBAdapter {
|
|||
TABLE_NAME_FEEDS + "." + KEY_HIDE,
|
||||
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_INCLUDE_FILTER,
|
||||
TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER
|
||||
};
|
||||
|
@ -404,6 +407,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().ordinal());
|
||||
values.put(KEY_USERNAME, prefs.getUsername());
|
||||
values.put(KEY_PASSWORD, prefs.getPassword());
|
||||
values.put(KEY_INCLUDE_FILTER, prefs.getFilter().getIncludeFilter());
|
||||
|
|
|
@ -13,6 +13,18 @@
|
|||
<item>never</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="spnVolumeReductionItems">
|
||||
<item>@string/feed_volume_reduction_off</item>
|
||||
<item>@string/feed_volume_reduction_light</item>
|
||||
<item>@string/feed_volume_reduction_heavy</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="spnVolumeReductionValues">
|
||||
<item>off</item>
|
||||
<item>light</item>
|
||||
<item>heavy</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="smart_mark_as_played_values">
|
||||
<item>0</item>
|
||||
<item>15</item>
|
||||
|
|
|
@ -97,6 +97,10 @@
|
|||
<string name="auto_download_apply_to_items_title">Apply to Previous Episodes</string>
|
||||
<string name="auto_download_apply_to_items_message">The new <i>Auto Download</i> setting will automatically be applied to new episodes.\nDo you also want to apply it to previously published episodes?</string>
|
||||
<string name="auto_delete_label">Auto Delete Episode</string>
|
||||
<string name="feed_volume_reduction">Volume Reduction</string>
|
||||
<string name="feed_volume_reduction_off">Off</string>
|
||||
<string name="feed_volume_reduction_light">Light</string>
|
||||
<string name="feed_volume_reduction_heavy">Heavy</string>
|
||||
<string name="parallel_downloads_suffix">\u0020parallel downloads</string>
|
||||
<string name="feed_auto_download_global">Global default</string>
|
||||
<string name="feed_auto_download_always">Always</string>
|
||||
|
|
Loading…
Reference in New Issue