55import androidx .room .Entity ;
66import androidx .room .ForeignKey ;
77
8+ import java .util .Objects ;
9+
810import static androidx .room .ForeignKey .CASCADE ;
911import static org .schabi .newpipe .database .stream .model .StreamStateEntity .JOIN_STREAM_ID ;
1012import static org .schabi .newpipe .database .stream .model .StreamStateEntity .STREAM_STATE_TABLE ;
@@ -26,15 +28,18 @@ public class StreamStateEntity {
2628 public static final String STREAM_PROGRESS_MILLIS = "progress_time" ;
2729
2830 /**
29- * Playback state will not be saved, if playback time is less than this threshold.
31+ * Playback state will not be saved, if playback time is less than this threshold (5000ms = 5s) .
3032 */
31- private static final long PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS = 5000 ; // 5000ms = 5s
33+ private static final long PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS = 5000 ;
3234
3335 /**
36+ * Stream will be considered finished if the playback time left exceeds this threshold
37+ * (60000ms = 60s).
3438 * @see #isFinished(long)
3539 * @see org.schabi.newpipe.database.feed.dao.FeedDAO#getLiveOrNotPlayedStreams()
40+ * @see org.schabi.newpipe.database.feed.dao.FeedDAO#getLiveOrNotPlayedStreamsForGroup(long)
3641 */
37- public static final long PLAYBACK_FINISHED_END_MILLISECONDS = 60000 ; // 60000ms = 60s
42+ public static final long PLAYBACK_FINISHED_END_MILLISECONDS = 60000 ;
3843
3944 @ ColumnInfo (name = JOIN_STREAM_ID )
4045 private long streamUid ;
@@ -65,11 +70,13 @@ public void setProgressMillis(final long progressMillis) {
6570
6671 /**
6772 * The state will be considered valid, and thus be saved, if the progress is more than {@link
68- * #PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS}.
73+ * #PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS} or at least 1/4 of the video length.
74+ * @param durationInSeconds the duration of the stream connected with this state, in seconds
6975 * @return whether this stream state entity should be saved or not
7076 */
71- public boolean isValid () {
72- return progressMillis > PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS ;
77+ public boolean isValid (final long durationInSeconds ) {
78+ return progressMillis > PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS
79+ || progressMillis > durationInSeconds * 1000 / 4 ;
7380 }
7481
7582 /**
@@ -78,6 +85,8 @@ public boolean isValid() {
7885 * The state will be saved anyway, so that it can be shown under stream info items, but the
7986 * player will not resume if a state is considered as finished. Finished streams are also the
8087 * ones that can be filtered out in the feed fragment.
88+ * @see org.schabi.newpipe.database.feed.dao.FeedDAO#getLiveOrNotPlayedStreams()
89+ * @see org.schabi.newpipe.database.feed.dao.FeedDAO#getLiveOrNotPlayedStreamsForGroup(long)
8190 * @param durationInSeconds the duration of the stream connected with this state, in seconds
8291 * @return whether the stream is finished or not
8392 */
@@ -95,4 +104,9 @@ public boolean equals(@Nullable final Object obj) {
95104 return false ;
96105 }
97106 }
107+
108+ @ Override
109+ public int hashCode () {
110+ return Objects .hash (streamUid , progressMillis );
111+ }
98112}
0 commit comments