summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java13
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java30
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java55
-rw-r--r--app/src/main/res/layout/audioplayer_fragment.xml16
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java7
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java17
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java4
-rw-r--r--core/src/main/res/values/dimens.xml1
8 files changed, 58 insertions, 85 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java
index dbc86a228..fce78ea4f 100644
--- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java
@@ -5,6 +5,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.LargeTest;
+import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import org.awaitility.Awaitility;
import org.greenrobot.eventbus.EventBus;
import org.junit.After;
@@ -53,6 +54,8 @@ public class PlaybackServiceTaskManagerTest {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
+ SleepTimerPreferences.setShakeToReset(false);
+ SleepTimerPreferences.setVibrate(false);
}
@Test
@@ -304,7 +307,7 @@ public class PlaybackServiceTaskManagerTest {
PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
pstm.startWidgetUpdater();
pstm.startPositionSaver();
- pstm.setSleepTimer(100000, false, false);
+ pstm.setSleepTimer(100000);
pstm.cancelAllTasks();
assertFalse(pstm.isPositionSaverActive());
assertFalse(pstm.isWidgetUpdaterActive());
@@ -353,7 +356,7 @@ public class PlaybackServiceTaskManagerTest {
}
});
- pstm.setSleepTimer(TIME, false, false);
+ pstm.setSleepTimer(TIME);
countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
pstm.shutdown();
}
@@ -396,7 +399,7 @@ public class PlaybackServiceTaskManagerTest {
}
});
- pstm.setSleepTimer(TIME, false, false);
+ pstm.setSleepTimer(TIME);
pstm.disableSleepTimer();
assertFalse(countDownLatch.await(TIMEOUT, TimeUnit.MILLISECONDS));
pstm.shutdown();
@@ -407,7 +410,7 @@ public class PlaybackServiceTaskManagerTest {
public void testIsSleepTimerActivePositive() {
final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
- pstm.setSleepTimer(10000, false, false);
+ pstm.setSleepTimer(1000);
assertTrue(pstm.isSleepTimerActive());
pstm.shutdown();
}
@@ -417,7 +420,7 @@ public class PlaybackServiceTaskManagerTest {
public void testIsSleepTimerActiveNegative() {
final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext();
PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
- pstm.setSleepTimer(10000, false, false);
+ pstm.setSleepTimer(10000);
pstm.disableSleepTimer();
assertFalse(pstm.isSleepTimerActive());
pstm.shutdown();
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
index 9e647bcaa..655049b2c 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
@@ -409,13 +409,7 @@ public class MainActivity extends CastEnabledActivity {
public void onEventMainThread(MessageEvent event) {
Log.d(TAG, "onEvent(" + event + ")");
- Snackbar snackbar;
- if (getBottomSheet().getState() == BottomSheetBehavior.STATE_COLLAPSED) {
- snackbar = showSnackbarAbovePlayer(event.message, Snackbar.LENGTH_SHORT);
- } else {
- snackbar = Snackbar.make(findViewById(android.R.id.content), event.message, Snackbar.LENGTH_SHORT);
- snackbar.show();
- }
+ Snackbar snackbar = showSnackbarAbovePlayer(event.message, Snackbar.LENGTH_SHORT);
if (event.action != null) {
snackbar.setAction(getString(R.string.undo), v -> event.action.run());
}
@@ -453,21 +447,21 @@ public class MainActivity extends CastEnabledActivity {
setIntent(intent);
}
- public Snackbar showSnackbarAbovePlayer(int text, int duration) {
- Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration);
- if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) {
- s.setAnchorView(findViewById(R.id.audioplayerFragment));
+ public Snackbar showSnackbarAbovePlayer(CharSequence text, int duration) {
+ Snackbar s;
+ if (getBottomSheet().getState() == BottomSheetBehavior.STATE_COLLAPSED) {
+ s = Snackbar.make(findViewById(R.id.main_view), text, duration);
+ if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) {
+ s.setAnchorView(findViewById(R.id.audioplayerFragment));
+ }
+ } else {
+ s = Snackbar.make(findViewById(android.R.id.content), text, duration);
}
s.show();
return s;
}
- public Snackbar showSnackbarAbovePlayer(String text, int duration) {
- Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration);
- if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) {
- s.setAnchorView(findViewById(R.id.audioplayerFragment));
- }
- s.show();
- return s;
+ public Snackbar showSnackbarAbovePlayer(int text, int duration) {
+ return showSnackbarAbovePlayer(getResources().getText(text), duration);
}
}
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java
index fafe888ee..a9c54e879 100644
--- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java
@@ -2,9 +2,8 @@ package de.danoeh.antennapod.dialog;
import android.app.Dialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
@@ -14,7 +13,6 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
-import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
@@ -36,9 +34,6 @@ public class SleepTimerDialog extends DialogFragment {
private EditText etxtTime;
private Spinner spTimeUnit;
- private CheckBox cbShakeToReset;
- private CheckBox cbVibrate;
- private CheckBox chAutoEnable;
private LinearLayout timeSetup;
private LinearLayout timeDisplay;
private TextView time;
@@ -85,33 +80,15 @@ public class SleepTimerDialog extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.sleep_timer_label);
builder.setView(content);
- builder.setPositiveButton(android.R.string.ok, null);
+ builder.setPositiveButton(R.string.close_label, null);
etxtTime = content.findViewById(R.id.etxtTime);
spTimeUnit = content.findViewById(R.id.spTimeUnit);
- cbShakeToReset = content.findViewById(R.id.cbShakeToReset);
- cbVibrate = content.findViewById(R.id.cbVibrate);
- chAutoEnable = content.findViewById(R.id.chAutoEnable);
timeSetup = content.findViewById(R.id.timeSetup);
timeDisplay = content.findViewById(R.id.timeDisplay);
time = content.findViewById(R.id.time);
- AlertDialog dialog = builder.create();
etxtTime.setText(SleepTimerPreferences.lastTimerValue());
- etxtTime.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {
- dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- });
etxtTime.postDelayed(() -> {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT);
@@ -127,12 +104,21 @@ public class SleepTimerDialog extends DialogFragment {
spTimeUnit.setAdapter(spinnerAdapter);
spTimeUnit.setSelection(SleepTimerPreferences.lastTimerTimeUnit());
+ CheckBox cbShakeToReset = content.findViewById(R.id.cbShakeToReset);
+ CheckBox cbVibrate = content.findViewById(R.id.cbVibrate);
+ CheckBox chAutoEnable = content.findViewById(R.id.chAutoEnable);
+
cbShakeToReset.setChecked(SleepTimerPreferences.shakeToReset());
cbVibrate.setChecked(SleepTimerPreferences.vibrate());
chAutoEnable.setChecked(SleepTimerPreferences.autoEnable());
+ cbShakeToReset.setOnCheckedChangeListener((buttonView, isChecked)
+ -> SleepTimerPreferences.setShakeToReset(isChecked));
+ cbVibrate.setOnCheckedChangeListener((buttonView, isChecked)
+ -> SleepTimerPreferences.setVibrate(isChecked));
chAutoEnable.setOnCheckedChangeListener((compoundButton, isChecked)
- -> SleepTimerPreferences.setAutoEnable(isChecked));
+ -> SleepTimerPreferences.setAutoEnable(isChecked));
+
Button disableButton = content.findViewById(R.id.disableSleeptimerButton);
disableButton.setOnClickListener(v -> {
if (controller != null) {
@@ -143,27 +129,20 @@ public class SleepTimerDialog extends DialogFragment {
setButton.setOnClickListener(v -> {
if (!PlaybackService.isRunning) {
Snackbar.make(content, R.string.no_media_playing_label, Snackbar.LENGTH_LONG).show();
+ return;
}
try {
- savePreferences();
+ SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), spTimeUnit.getSelectedItemPosition());
long time = SleepTimerPreferences.timerMillis();
if (controller != null) {
- controller.setSleepTimer(time, cbShakeToReset.isChecked(), cbVibrate.isChecked());
+ controller.setSleepTimer(time);
}
} catch (NumberFormatException e) {
e.printStackTrace();
- Toast.makeText(getContext(), R.string.time_dialog_invalid_input, Toast.LENGTH_LONG).show();
+ Snackbar.make(content, R.string.time_dialog_invalid_input, Snackbar.LENGTH_LONG).show();
}
});
- return dialog;
- }
-
- private void savePreferences() {
- SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(),
- spTimeUnit.getSelectedItemPosition());
- SleepTimerPreferences.setShakeToReset(cbShakeToReset.isChecked());
- SleepTimerPreferences.setVibrate(cbVibrate.isChecked());
- SleepTimerPreferences.setAutoEnable(chAutoEnable.isChecked());
+ return builder.create();
}
private void updateTime() {
diff --git a/app/src/main/res/layout/audioplayer_fragment.xml b/app/src/main/res/layout/audioplayer_fragment.xml
index 1935ce36c..37c30b4dd 100644
--- a/app/src/main/res/layout/audioplayer_fragment.xml
+++ b/app/src/main/res/layout/audioplayer_fragment.xml
@@ -107,10 +107,10 @@
android:id="@+id/butPlay"
android:layout_width="@dimen/audioplayer_playercontrols_length_big"
android:layout_height="@dimen/audioplayer_playercontrols_length_big"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginRight="8dp"
- android:layout_marginEnd="8dp"
+ android:layout_marginLeft="@dimen/audioplayer_playercontrols_margin"
+ android:layout_marginStart="@dimen/audioplayer_playercontrols_margin"
+ android:layout_marginRight="@dimen/audioplayer_playercontrols_margin"
+ android:layout_marginEnd="@dimen/audioplayer_playercontrols_margin"
android:padding="8dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
@@ -145,8 +145,8 @@
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:layout_toLeftOf="@id/butPlay"
android:layout_toStartOf="@id/butPlay"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
+ android:layout_marginLeft="@dimen/audioplayer_playercontrols_margin"
+ android:layout_marginStart="@dimen/audioplayer_playercontrols_margin"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/rewind_label"
@@ -201,8 +201,8 @@
android:layout_height="@dimen/audioplayer_playercontrols_length"
android:layout_toRightOf="@id/butPlay"
android:layout_toEndOf="@id/butPlay"
- android:layout_marginRight="8dp"
- android:layout_marginEnd="8dp"
+ android:layout_marginRight="@dimen/audioplayer_playercontrols_margin"
+ android:layout_marginEnd="@dimen/audioplayer_playercontrols_margin"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/fast_forward_label"
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index 69253bc13..5f6e49e1c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -792,8 +792,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
// set sleep timer if auto-enabled
if (newInfo.oldPlayerStatus != null && newInfo.oldPlayerStatus != PlayerStatus.SEEKING
&& SleepTimerPreferences.autoEnable() && !sleepTimerActive()) {
- setSleepTimer(SleepTimerPreferences.timerMillis(), SleepTimerPreferences.shakeToReset(),
- SleepTimerPreferences.vibrate());
+ setSleepTimer(SleepTimerPreferences.timerMillis());
EventBus.getDefault().post(new MessageEvent(getString(R.string.sleep_timer_enabled_label),
PlaybackService.this::disableSleepTimer));
}
@@ -1067,9 +1066,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
}
- public void setSleepTimer(long waitingTime, boolean shakeToReset, boolean vibrate) {
+ public void setSleepTimer(long waitingTime) {
Log.d(TAG, "Setting sleep timer to " + waitingTime + " milliseconds");
- taskManager.setSleepTimer(waitingTime, shakeToReset, vibrate);
+ taskManager.setSleepTimer(waitingTime);
sendNotificationBroadcast(NOTIFICATION_TYPE_SLEEPTIMER_UPDATE, 0);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java
index 904c1508d..17cd1b24a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceTaskManager.java
@@ -7,6 +7,7 @@ import android.os.Vibrator;
import androidx.annotation.NonNull;
import android.util.Log;
+import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -215,7 +216,7 @@ public class PlaybackServiceTaskManager {
*
* @throws java.lang.IllegalArgumentException if waitingTime <= 0
*/
- public synchronized void setSleepTimer(long waitingTime, boolean shakeToReset, boolean vibrate) {
+ public synchronized void setSleepTimer(long waitingTime) {
if (waitingTime <= 0) {
throw new IllegalArgumentException("Waiting time <= 0");
}
@@ -224,7 +225,7 @@ public class PlaybackServiceTaskManager {
if (isSleepTimerActive()) {
sleepTimerFuture.cancel(true);
}
- sleepTimer = new SleepTimer(waitingTime, shakeToReset, vibrate);
+ sleepTimer = new SleepTimer(waitingTime);
sleepTimerFuture = schedExecutor.schedule(sleepTimer, 0, TimeUnit.MILLISECONDS);
}
@@ -361,17 +362,13 @@ public class PlaybackServiceTaskManager {
private static final long NOTIFICATION_THRESHOLD = 10000;
private final long waitingTime;
private long timeLeft;
- private final boolean shakeToReset;
- private final boolean vibrate;
private ShakeListener shakeListener;
private final Handler handler;
- public SleepTimer(long waitingTime, boolean shakeToReset, boolean vibrate) {
+ public SleepTimer(long waitingTime) {
super();
this.waitingTime = waitingTime;
this.timeLeft = waitingTime;
- this.shakeToReset = shakeToReset;
- this.vibrate = vibrate;
if (UserPreferences.useExoplayer() && Looper.myLooper() == Looper.getMainLooper()) {
// Run callbacks in main thread so they can call ExoPlayer methods themselves
@@ -409,13 +406,13 @@ public class PlaybackServiceTaskManager {
if (timeLeft < NOTIFICATION_THRESHOLD && !notifiedAlmostExpired) {
Log.d(TAG, "Sleep timer is about to expire");
- if (vibrate) {
+ if (SleepTimerPreferences.vibrate()) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(500);
}
}
- if (shakeListener == null && shakeToReset) {
+ if (shakeListener == null && SleepTimerPreferences.shakeToReset()) {
shakeListener = new ShakeListener(context, this);
}
postCallback(callback::onSleepTimerAlmostExpired);
@@ -442,7 +439,7 @@ public class PlaybackServiceTaskManager {
public void restart() {
postCallback(() -> {
- setSleepTimer(waitingTime, shakeToReset, vibrate);
+ setSleepTimer(waitingTime);
callback.onSleepTimerReset();
});
if (shakeListener != null) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
index 8f7e5dc33..0b849aa1f 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
@@ -556,9 +556,9 @@ public class PlaybackController {
}
}
- public void setSleepTimer(long time, boolean shakeToReset, boolean vibrate) {
+ public void setSleepTimer(long time) {
if (playbackService != null) {
- playbackService.setSleepTimer(time, shakeToReset, vibrate);
+ playbackService.setSleepTimer(time);
}
}
diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml
index cfb272ad9..41a24f6fa 100644
--- a/core/src/main/res/values/dimens.xml
+++ b/core/src/main/res/values/dimens.xml
@@ -31,6 +31,7 @@
<dimen name="audioplayer_playercontrols_length">48dp</dimen>
<dimen name="audioplayer_playercontrols_length_big">64dp</dimen>
+ <dimen name="audioplayer_playercontrols_margin">12dp</dimen>
<dimen name="media_router_controller_playback_control_vertical_padding">16dp</dimen>
<dimen name="media_router_controller_playback_control_horizontal_spacing">12dp</dimen>