Merge branch 'mchelen-notifymore2' into develop
This commit is contained in:
commit
441165ff3f
|
@ -90,6 +90,7 @@
|
|||
<string name="download_label">Download</string>
|
||||
<string name="play_label">Play</string>
|
||||
<string name="pause_label">Pause</string>
|
||||
<string name="stop_label">Stop</string>
|
||||
<string name="stream_label">Stream</string>
|
||||
<string name="remove_label">Remove</string>
|
||||
<string name="remove_episode_lable">Remove episode</string>
|
||||
|
@ -250,6 +251,11 @@
|
|||
<string name="pref_seek_delta_sum">Seek this many seconds when rewinding or fast-forwarding</string>
|
||||
<string name="pref_gpodnet_sethostname_title">Set hostname</string>
|
||||
<string name="pref_gpodnet_sethostname_use_default_host">Use default host</string>
|
||||
<string name="pref_expandNotify_title">Expand Notification</string>
|
||||
<string name="pref_expandNotify_sum">Always expand the notification to show playback buttons.</string>
|
||||
<string name="pref_persistNotify_title">Persistent playback controls</string>
|
||||
<string name="pref_persistNotify_sum">Keep notification and lockscreen controls when playback is paused.</string>
|
||||
<string name="pref_expand_notify_unsupport_toast">Android versions before 4.1 do not support expanded notifications.</string>
|
||||
|
||||
<!-- Auto-Flattr dialog -->
|
||||
<string name="auto_flattr_enable">Enable automatic flattring</string>
|
||||
|
|
|
@ -9,6 +9,18 @@
|
|||
android:key="prefTheme"
|
||||
android:summary="@string/pref_set_theme_sum"
|
||||
android:defaultValue="0"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefExpandNotify"
|
||||
android:summary="@string/pref_expandNotify_sum"
|
||||
android:title="@string/pref_expandNotify_title"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefPersistNotify"
|
||||
android:summary="@string/pref_persistNotify_sum"
|
||||
android:title="@string/pref_persistNotify_title"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/playback_pref">
|
||||
<CheckBoxPreference
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.res.Resources.Theme;
|
|||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
|
@ -60,6 +61,9 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
private static final String PREF_GPODNET_LOGOUT = "pref_gpodnet_logout";
|
||||
private static final String PREF_GPODNET_HOSTNAME = "pref_gpodnet_hostname";
|
||||
|
||||
private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
|
||||
private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
|
||||
|
||||
private CheckBoxPreference[] selectedNetworks;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
|
@ -77,6 +81,23 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
}
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// disable expanded notification option on unsupported android versions
|
||||
findPreference(PREF_EXPANDED_NOTIFICATION).setEnabled(false);
|
||||
findPreference(PREF_EXPANDED_NOTIFICATION).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Toast toast = Toast.makeText(PreferenceActivity.this, R.string.pref_expand_notify_unsupport_toast, Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
|
||||
|
@ -272,8 +293,6 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
buildAutodownloadSelectedNetworsPreference();
|
||||
setSelectedNetworksEnabled(UserPreferences
|
||||
.isEnableAutodownloadWifiFilter());
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void updateGpodnetPreferenceScreen() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -53,6 +54,8 @@ public class UserPreferences implements
|
|||
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
|
||||
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
|
||||
private static final String PREF_SEEK_DELTA_SECS = "prefSeekDeltaSecs";
|
||||
private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
|
||||
private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
|
||||
|
||||
// TODO: Make this value configurable
|
||||
private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f;
|
||||
|
@ -82,6 +85,8 @@ public class UserPreferences implements
|
|||
private boolean pauseForFocusLoss;
|
||||
private int seekDeltaSecs;
|
||||
private boolean isFreshInstall;
|
||||
private int notifyPriority;
|
||||
private boolean persistNotify;
|
||||
|
||||
private UserPreferences(Context context) {
|
||||
this.context = context;
|
||||
|
@ -138,6 +143,13 @@ public class UserPreferences implements
|
|||
PREF_PLAYBACK_SPEED_ARRAY, null));
|
||||
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
|
||||
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
|
||||
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
|
||||
notifyPriority = NotificationCompat.PRIORITY_MAX;
|
||||
}
|
||||
else {
|
||||
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
|
||||
}
|
||||
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
|
||||
}
|
||||
|
||||
private int readThemeValue(String valueFromPrefs) {
|
||||
|
@ -243,6 +255,17 @@ public class UserPreferences implements
|
|||
return instance.autoFlattr;
|
||||
}
|
||||
|
||||
public static int getNotifyPriority() {
|
||||
instanceAvailable();
|
||||
return instance.notifyPriority;
|
||||
}
|
||||
|
||||
public static boolean isPersistNotify() {
|
||||
instanceAvailable();
|
||||
return instance.persistNotify;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the time after which an episode should be auto-flattr'd in percent of the episode's
|
||||
* duration.
|
||||
|
@ -366,6 +389,15 @@ public class UserPreferences implements
|
|||
} else if (key.equals(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD)) {
|
||||
autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
|
||||
PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
|
||||
} else if (key.equals(PREF_EXPANDED_NOTIFICATION)) {
|
||||
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
|
||||
notifyPriority = NotificationCompat.PRIORITY_MAX;
|
||||
}
|
||||
else {
|
||||
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
|
||||
}
|
||||
} else if (key.equals(PREF_PERSISTENT_NOTIFICATION)) {
|
||||
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -297,7 +297,12 @@ public class PlaybackService extends Service {
|
|||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
if (UserPreferences.isPersistNotify()) {
|
||||
mediaPlayer.pause(false, true);
|
||||
}
|
||||
else {
|
||||
mediaPlayer.pause(true, true);
|
||||
}
|
||||
} else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) {
|
||||
mediaPlayer.resume();
|
||||
} else if (status == PlayerStatus.PREPARING) {
|
||||
|
@ -317,8 +322,13 @@ public class PlaybackService extends Service {
|
|||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
if (UserPreferences.isPersistNotify()) {
|
||||
mediaPlayer.pause(false, true);
|
||||
}
|
||||
else {
|
||||
mediaPlayer.pause(true, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
|
||||
|
@ -328,6 +338,12 @@ public class PlaybackService extends Service {
|
|||
case KeyEvent.KEYCODE_MEDIA_REWIND:
|
||||
mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs());
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_STOP:
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
mediaPlayer.pause(true, true);
|
||||
}
|
||||
stopForeground(true); // gets rid of persistent notification
|
||||
break;
|
||||
default:
|
||||
if (info.playable != null && info.playerStatus == PlayerStatus.PLAYING) { // only notify the user about an unknown key event if it is actually doing something
|
||||
String message = String.format(getResources().getString(R.string.unknown_media_key), keycode);
|
||||
|
@ -401,7 +417,13 @@ public class PlaybackService extends Service {
|
|||
taskManager.cancelPositionSaver();
|
||||
saveCurrentPosition(false, 0);
|
||||
taskManager.cancelWidgetUpdater();
|
||||
if (UserPreferences.isPersistNotify()) {
|
||||
// do not remove notification on pause
|
||||
}
|
||||
else {
|
||||
// remove notifcation on pause
|
||||
stopForeground(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case STOPPED:
|
||||
|
@ -713,7 +735,7 @@ public class PlaybackService extends Service {
|
|||
String contentTitle = info.playable.getEpisodeTitle();
|
||||
Notification notification = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
Intent pauseButtonIntent = new Intent(
|
||||
Intent pauseButtonIntent = new Intent( // pause button intent
|
||||
PlaybackService.this, PlaybackService.class);
|
||||
pauseButtonIntent.putExtra(
|
||||
MediaButtonReceiver.EXTRA_KEYCODE,
|
||||
|
@ -722,6 +744,24 @@ public class PlaybackService extends Service {
|
|||
.getService(PlaybackService.this, 0,
|
||||
pauseButtonIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Intent playButtonIntent = new Intent( // play button intent
|
||||
PlaybackService.this, PlaybackService.class);
|
||||
playButtonIntent.putExtra(
|
||||
MediaButtonReceiver.EXTRA_KEYCODE,
|
||||
KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||
PendingIntent playButtonPendingIntent = PendingIntent
|
||||
.getService(PlaybackService.this, 1,
|
||||
playButtonIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Intent stopButtonIntent = new Intent( // stop button intent
|
||||
PlaybackService.this, PlaybackService.class);
|
||||
stopButtonIntent.putExtra(
|
||||
MediaButtonReceiver.EXTRA_KEYCODE,
|
||||
KeyEvent.KEYCODE_MEDIA_STOP);
|
||||
PendingIntent stopButtonPendingIntent = PendingIntent
|
||||
.getService(PlaybackService.this, 2,
|
||||
stopButtonIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification.Builder notificationBuilder = new Notification.Builder(
|
||||
PlaybackService.this)
|
||||
.setContentTitle(contentTitle)
|
||||
|
@ -730,9 +770,16 @@ public class PlaybackService extends Service {
|
|||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna)
|
||||
.addAction(android.R.drawable.ic_media_pause,
|
||||
.setPriority(UserPreferences.getNotifyPriority()) // set notification priority
|
||||
.addAction(android.R.drawable.ic_media_play, //play action
|
||||
getString(R.string.play_label),
|
||||
playButtonPendingIntent)
|
||||
.addAction(android.R.drawable.ic_media_pause, //pause action
|
||||
getString(R.string.pause_label),
|
||||
pauseButtonPendingIntent);
|
||||
pauseButtonPendingIntent)
|
||||
.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action
|
||||
getString(R.string.stop_label),
|
||||
stopButtonPendingIntent);
|
||||
notification = notificationBuilder.build();
|
||||
} else {
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
|
||||
|
@ -949,9 +996,14 @@ public class PlaybackService extends Service {
|
|||
*/
|
||||
private void pauseIfPauseOnDisconnect() {
|
||||
if (UserPreferences.isPauseOnHeadsetDisconnect()) {
|
||||
if (UserPreferences.isPersistNotify()) {
|
||||
mediaPlayer.pause(false, true);
|
||||
}
|
||||
else {
|
||||
mediaPlayer.pause(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue