Fix marking as played when there is no media (#7192)

This commit is contained in:
ByteHamster 2024-05-24 10:00:28 +02:00 committed by GitHub
parent baeb0d8ced
commit 155d769fca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import java.util.concurrent.TimeoutException;
import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
@ -44,6 +45,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText; import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;
public class EspressoTestUtils { public class EspressoTestUtils {
/** /**
@ -143,6 +145,21 @@ public class EspressoTestUtils {
}; };
} }
public static void waitForViewToDisappear(Matcher<? super View> matcher, long maxWaitingTimeMs) {
long endTime = System.currentTimeMillis() + maxWaitingTimeMs;
while (System.currentTimeMillis() <= endTime) {
try {
onView(allOf(matcher, isDisplayed())).check(matches(not(doesNotExist())));
Thread.sleep(100);
} catch (NoMatchingViewException ex) {
return; // view has disappeared
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
throw new RuntimeException("timeout exceeded"); // or whatever exception you want
}
/** /**
* Clear all app databases. * Clear all app databases.
*/ */

View File

@ -27,7 +27,6 @@ import static de.test.antennapod.EspressoTestUtils.onDrawerItem;
import static de.test.antennapod.EspressoTestUtils.openNavDrawer; import static de.test.antennapod.EspressoTestUtils.openNavDrawer;
import static de.test.antennapod.EspressoTestUtils.waitForView; import static de.test.antennapod.EspressoTestUtils.waitForView;
import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.not;
/** /**
* Test UI for feeds that do not have media files * Test UI for feeds that do not have media files
@ -67,7 +66,7 @@ public class TextOnlyFeedsTest {
onView(withText(feed.getItemAtIndex(0).getTitle())).perform(click()); onView(withText(feed.getItemAtIndex(0).getTitle())).perform(click());
onView(isRoot()).perform(waitForView(withText(R.string.mark_read_no_media_label), 3000)); onView(isRoot()).perform(waitForView(withText(R.string.mark_read_no_media_label), 3000));
onView(allOf(withText(R.string.mark_read_no_media_label), isDisplayed())).perform(click()); onView(allOf(withText(R.string.mark_read_no_media_label), isDisplayed())).perform(click());
onView(isRoot()).perform(waitForView(allOf(withText(R.string.mark_read_no_media_label), not(isDisplayed())), 3000)); EspressoTestUtils.waitForViewToDisappear(withText(R.string.mark_read_no_media_label), 3000);
} }
} }

View File

@ -693,7 +693,7 @@ public class PodDBAdapter {
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?", new String[]{String.valueOf(item.getId())}); db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?", new String[]{String.valueOf(item.getId())});
item.setPlayed(played == FeedItem.PLAYED); item.setPlayed(played == FeedItem.PLAYED);
if (resetMediaPosition) { if (resetMediaPosition && item.hasMedia()) {
values.clear(); values.clear();
values.put(KEY_POSITION, 0); values.put(KEY_POSITION, 0);
db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",