Show speed dialog on single click
This commit is contained in:
parent
ca9ad0d2d3
commit
508cfc24c2
|
@ -1,131 +0,0 @@
|
||||||
package de.test.antennapod.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.test.rule.ActivityTestRule;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
import de.danoeh.antennapod.R;
|
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
|
||||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
|
||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
|
||||||
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
|
||||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
|
||||||
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
|
|
||||||
import de.test.antennapod.EspressoTestUtils;
|
|
||||||
import de.test.antennapod.IgnoreOnCi;
|
|
||||||
import org.awaitility.Awaitility;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|
||||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
|
||||||
import static de.test.antennapod.EspressoTestUtils.waitForView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User interface tests for changing the playback speed.
|
|
||||||
*/
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@IgnoreOnCi
|
|
||||||
public class SpeedChangeTest {
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class, false, false);
|
|
||||||
private UITestUtils uiTestUtils;
|
|
||||||
private String[] availableSpeeds;
|
|
||||||
private PlaybackController controller;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
EspressoTestUtils.clearPreferences();
|
|
||||||
EspressoTestUtils.clearDatabase();
|
|
||||||
EspressoTestUtils.setLastNavFragment(QueueFragment.TAG);
|
|
||||||
|
|
||||||
Context context = getInstrumentation().getTargetContext();
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, true).commit();
|
|
||||||
|
|
||||||
uiTestUtils = new UITestUtils(context);
|
|
||||||
uiTestUtils.setup();
|
|
||||||
uiTestUtils.setMediaFileName("30sec.mp3");
|
|
||||||
uiTestUtils.addLocalFeedData(true);
|
|
||||||
|
|
||||||
List<FeedItem> queue = DBReader.getQueue();
|
|
||||||
PlaybackPreferences.writeMediaPlaying(queue.get(0).getMedia(), PlayerStatus.PAUSED, false);
|
|
||||||
availableSpeeds = new String[] {"1.00", "2.00", "3.00"};
|
|
||||||
UserPreferences.setPlaybackSpeedArray(Arrays.asList(1.0f, 2.0f, 3.0f));
|
|
||||||
|
|
||||||
EspressoTestUtils.tryKillPlaybackService();
|
|
||||||
activityRule.launchActivity(new Intent().putExtra(MainActivityStarter.EXTRA_OPEN_PLAYER, true));
|
|
||||||
controller = new PlaybackController(activityRule.getActivity()) {
|
|
||||||
@Override
|
|
||||||
public void loadMediaInfo() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
controller.init();
|
|
||||||
controller.getMedia(); // To load media
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
uiTestUtils.tearDown();
|
|
||||||
controller.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChangeSpeedServiceNotRunning() {
|
|
||||||
clickThroughSpeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChangeSpeedPlaying() {
|
|
||||||
onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000));
|
|
||||||
controller.playPause();
|
|
||||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(()
|
|
||||||
-> controller.getStatus() == PlayerStatus.PLAYING);
|
|
||||||
clickThroughSpeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChangeSpeedPaused() {
|
|
||||||
onView(isRoot()).perform(waitForView(withId(R.id.butPlay), 1000));
|
|
||||||
controller.playPause();
|
|
||||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(()
|
|
||||||
-> controller.getStatus() == PlayerStatus.PLAYING);
|
|
||||||
controller.playPause();
|
|
||||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(()
|
|
||||||
-> controller.getStatus() == PlayerStatus.PAUSED);
|
|
||||||
clickThroughSpeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clickThroughSpeeds() {
|
|
||||||
onView(isRoot()).perform(waitForView(withText(availableSpeeds[0]), 1000));
|
|
||||||
onView(withId(R.id.txtvPlaybackSpeed)).check(matches(withText(availableSpeeds[0])));
|
|
||||||
onView(withId(R.id.butPlaybackSpeed)).perform(click());
|
|
||||||
onView(isRoot()).perform(waitForView(withText(availableSpeeds[1]), 1000));
|
|
||||||
onView(withId(R.id.txtvPlaybackSpeed)).check(matches(withText(availableSpeeds[1])));
|
|
||||||
onView(withId(R.id.butPlaybackSpeed)).perform(click());
|
|
||||||
onView(isRoot()).perform(waitForView(withText(availableSpeeds[2]), 1000));
|
|
||||||
onView(withId(R.id.txtvPlaybackSpeed)).check(matches(withText(availableSpeeds[2])));
|
|
||||||
onView(withId(R.id.butPlaybackSpeed)).perform(click());
|
|
||||||
onView(isRoot()).perform(waitForView(withText(availableSpeeds[0]), 1000));
|
|
||||||
onView(withId(R.id.txtvPlaybackSpeed)).check(matches(withText(availableSpeeds[0])));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -131,8 +131,8 @@ public class VariableSpeedDialog extends DialogFragment {
|
||||||
});
|
});
|
||||||
holder.chip.setOnClickListener(v -> {
|
holder.chip.setOnClickListener(v -> {
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
dismiss();
|
||||||
controller.setPlaybackSpeed(speed);
|
controller.setPlaybackSpeed(speed);
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
public static final int POS_COVER = 0;
|
public static final int POS_COVER = 0;
|
||||||
public static final int POS_DESCRIPTION = 1;
|
public static final int POS_DESCRIPTION = 1;
|
||||||
private static final int NUM_CONTENT_FRAGMENTS = 2;
|
private static final int NUM_CONTENT_FRAGMENTS = 2;
|
||||||
private static final float EPSILON = 0.001f;
|
|
||||||
|
|
||||||
PlaybackSpeedIndicatorView butPlaybackSpeed;
|
PlaybackSpeedIndicatorView butPlaybackSpeed;
|
||||||
TextView txtvPlaybackSpeed;
|
TextView txtvPlaybackSpeed;
|
||||||
|
@ -136,7 +135,7 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
|
|
||||||
setupLengthTextView();
|
setupLengthTextView();
|
||||||
setupControlButtons();
|
setupControlButtons();
|
||||||
setupPlaybackSpeedButton();
|
butPlaybackSpeed.setOnClickListener(v -> new VariableSpeedDialog().show(getChildFragmentManager(), null));
|
||||||
sbPosition.setOnSeekBarChangeListener(this);
|
sbPosition.setOnSeekBarChangeListener(this);
|
||||||
|
|
||||||
pager = root.findViewById(R.id.pager);
|
pager = root.findViewById(R.id.pager);
|
||||||
|
@ -244,40 +243,6 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPlaybackSpeedButton() {
|
|
||||||
butPlaybackSpeed.setOnClickListener(v -> {
|
|
||||||
if (controller == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<Float> availableSpeeds = UserPreferences.getPlaybackSpeedArray();
|
|
||||||
float currentSpeed = controller.getCurrentPlaybackSpeedMultiplier();
|
|
||||||
|
|
||||||
int newSpeedIndex = 0;
|
|
||||||
while (newSpeedIndex < availableSpeeds.size()
|
|
||||||
&& availableSpeeds.get(newSpeedIndex) < currentSpeed + EPSILON) {
|
|
||||||
newSpeedIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
float newSpeed;
|
|
||||||
if (availableSpeeds.size() == 0) {
|
|
||||||
newSpeed = 1.0f;
|
|
||||||
} else if (newSpeedIndex == availableSpeeds.size()) {
|
|
||||||
newSpeed = availableSpeeds.get(0);
|
|
||||||
} else {
|
|
||||||
newSpeed = availableSpeeds.get(newSpeedIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
controller.setPlaybackSpeed(newSpeed);
|
|
||||||
loadMediaInfo();
|
|
||||||
});
|
|
||||||
butPlaybackSpeed.setOnLongClickListener(v -> {
|
|
||||||
new VariableSpeedDialog().show(getChildFragmentManager(), null);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
butPlaybackSpeed.setVisibility(View.VISIBLE);
|
|
||||||
txtvPlaybackSpeed.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updatePlaybackSpeedButton(Playable media) {
|
protected void updatePlaybackSpeedButton(Playable media) {
|
||||||
if (butPlaybackSpeed == null || controller == null) {
|
if (butPlaybackSpeed == null || controller == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -286,8 +251,6 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
String speedStr = new DecimalFormat("0.00").format(speed);
|
String speedStr = new DecimalFormat("0.00").format(speed);
|
||||||
txtvPlaybackSpeed.setText(speedStr);
|
txtvPlaybackSpeed.setText(speedStr);
|
||||||
butPlaybackSpeed.setSpeed(speed);
|
butPlaybackSpeed.setSpeed(speed);
|
||||||
butPlaybackSpeed.setVisibility(View.VISIBLE);
|
|
||||||
txtvPlaybackSpeed.setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMediaInfo() {
|
private void loadMediaInfo() {
|
||||||
|
|
Loading…
Reference in New Issue