Skip to content

Commit 0113ad5

Browse files
committed
Correctly save stream progress at the end of a video
1 parent e58fead commit 0113ad5

13 files changed

Lines changed: 74 additions & 92 deletions

File tree

app/src/main/java/org/schabi/newpipe/database/history/dao/StreamHistoryDAO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_ID;
2222
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_TABLE;
2323
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_STREAM_ID_ALIAS;
24-
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_TIME;
24+
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS;
2525
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
2626

2727
@Dao
@@ -80,7 +80,7 @@ public Flowable<List<StreamHistoryEntity>> listByService(final int serviceId) {
8080

8181
+ " LEFT JOIN "
8282
+ "(SELECT " + JOIN_STREAM_ID + " AS " + JOIN_STREAM_ID_ALIAS + ", "
83-
+ STREAM_PROGRESS_TIME
83+
+ STREAM_PROGRESS_MILLIS
8484
+ " FROM " + STREAM_STATE_TABLE + " )"
8585
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID_ALIAS)
8686
public abstract Flowable<List<StreamStatisticsEntry>> getStatistics();

app/src/main/java/org/schabi/newpipe/database/playlist/PlaylistStreamEntry.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ data class PlaylistStreamEntry(
1212
@Embedded
1313
val streamEntity: StreamEntity,
1414

15-
@ColumnInfo(name = StreamStateEntity.STREAM_PROGRESS_TIME, defaultValue = "0")
16-
val progressTime: Long,
15+
@ColumnInfo(name = StreamStateEntity.STREAM_PROGRESS_MILLIS, defaultValue = "0")
16+
val progressMillis: Long,
1717

1818
@ColumnInfo(name = PlaylistStreamEntity.JOIN_STREAM_ID)
1919
val streamId: Long,

app/src/main/java/org/schabi/newpipe/database/playlist/dao/PlaylistStreamDAO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_ID;
2626
import static org.schabi.newpipe.database.stream.model.StreamEntity.STREAM_TABLE;
2727
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.JOIN_STREAM_ID_ALIAS;
28-
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_TIME;
28+
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS;
2929
import static org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_STATE_TABLE;
3030

3131
@Dao
@@ -64,7 +64,7 @@ default Flowable<List<PlaylistStreamEntity>> listByService(final int serviceId)
6464

6565
+ " LEFT JOIN "
6666
+ "(SELECT " + JOIN_STREAM_ID + " AS " + JOIN_STREAM_ID_ALIAS + ", "
67-
+ STREAM_PROGRESS_TIME
67+
+ STREAM_PROGRESS_MILLIS
6868
+ " FROM " + STREAM_STATE_TABLE + " )"
6969
+ " ON " + STREAM_ID + " = " + JOIN_STREAM_ID_ALIAS
7070

app/src/main/java/org/schabi/newpipe/database/stream/StreamStatisticsEntry.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import androidx.room.Embedded
55
import org.schabi.newpipe.database.LocalItem
66
import org.schabi.newpipe.database.history.model.StreamHistoryEntity
77
import org.schabi.newpipe.database.stream.model.StreamEntity
8-
import org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_TIME
8+
import org.schabi.newpipe.database.stream.model.StreamStateEntity.STREAM_PROGRESS_MILLIS
99
import org.schabi.newpipe.extractor.stream.StreamInfoItem
1010
import java.time.OffsetDateTime
1111

1212
class StreamStatisticsEntry(
1313
@Embedded
1414
val streamEntity: StreamEntity,
1515

16-
@ColumnInfo(name = STREAM_PROGRESS_TIME, defaultValue = "0")
17-
val progressTime: Long,
16+
@ColumnInfo(name = STREAM_PROGRESS_MILLIS, defaultValue = "0")
17+
val progressMillis: Long,
1818

1919
@ColumnInfo(name = StreamHistoryEntity.JOIN_STREAM_ID)
2020
val streamId: Long,

app/src/main/java/org/schabi/newpipe/database/stream/StreamWithState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ data class StreamWithState(
99
@Embedded
1010
val stream: StreamEntity,
1111

12-
@ColumnInfo(name = StreamStateEntity.STREAM_PROGRESS_TIME)
13-
val stateProgressTime: Long?
12+
@ColumnInfo(name = StreamStateEntity.STREAM_PROGRESS_MILLIS)
13+
val stateProgressMillis: Long?
1414
)

app/src/main/java/org/schabi/newpipe/database/stream/model/StreamStateEntity.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class StreamStateEntity {
2323
// This additional field is required for the SQL query because 'stream_id' is used
2424
// for some other joins already
2525
public static final String JOIN_STREAM_ID_ALIAS = "stream_id_alias";
26-
public static final String STREAM_PROGRESS_TIME = "progress_time";
26+
public static final String STREAM_PROGRESS_MILLIS = "progress_time";
2727

2828
/**
2929
* Playback state will not be saved, if playback time is less than this threshold.
@@ -39,12 +39,12 @@ public class StreamStateEntity {
3939
@ColumnInfo(name = JOIN_STREAM_ID)
4040
private long streamUid;
4141

42-
@ColumnInfo(name = STREAM_PROGRESS_TIME)
43-
private long progressTime;
42+
@ColumnInfo(name = STREAM_PROGRESS_MILLIS)
43+
private long progressMillis;
4444

45-
public StreamStateEntity(final long streamUid, final long progressTime) {
45+
public StreamStateEntity(final long streamUid, final long progressMillis) {
4646
this.streamUid = streamUid;
47-
this.progressTime = progressTime;
47+
this.progressMillis = progressMillis;
4848
}
4949

5050
public long getStreamUid() {
@@ -55,12 +55,12 @@ public void setStreamUid(final long streamUid) {
5555
this.streamUid = streamUid;
5656
}
5757

58-
public long getProgressTime() {
59-
return progressTime;
58+
public long getProgressMillis() {
59+
return progressMillis;
6060
}
6161

62-
public void setProgressTime(final long progressTime) {
63-
this.progressTime = progressTime;
62+
public void setProgressMillis(final long progressMillis) {
63+
this.progressMillis = progressMillis;
6464
}
6565

6666
/**
@@ -69,7 +69,7 @@ public void setProgressTime(final long progressTime) {
6969
* @return whether this stream state entity should be saved or not
7070
*/
7171
public boolean isValid() {
72-
return progressTime > PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS;
72+
return progressMillis > PLAYBACK_SAVE_THRESHOLD_START_MILLISECONDS;
7373
}
7474

7575
/**
@@ -82,15 +82,15 @@ public boolean isValid() {
8282
* @return whether the stream is finished or not
8383
*/
8484
public boolean isFinished(final long durationInSeconds) {
85-
return progressTime >= durationInSeconds * 1000 - PLAYBACK_FINISHED_END_MILLISECONDS
86-
&& progressTime >= durationInSeconds * 1000 * 3 / 4;
85+
return progressMillis >= durationInSeconds * 1000 - PLAYBACK_FINISHED_END_MILLISECONDS
86+
&& progressMillis >= durationInSeconds * 1000 * 3 / 4;
8787
}
8888

8989
@Override
9090
public boolean equals(@Nullable final Object obj) {
9191
if (obj instanceof StreamStateEntity) {
9292
return ((StreamStateEntity) obj).streamUid == streamUid
93-
&& ((StreamStateEntity) obj).progressTime == progressTime;
93+
&& ((StreamStateEntity) obj).progressMillis == progressMillis;
9494
} else {
9595
return false;
9696
}

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ private void updateProgressInfo(@NonNull final StreamInfo info) {
16691669
.onErrorComplete()
16701670
.observeOn(AndroidSchedulers.mainThread())
16711671
.subscribe(state -> {
1672-
showPlaybackProgress(state.getProgressTime(), info.getDuration() * 1000);
1672+
showPlaybackProgress(state.getProgressMillis(), info.getDuration() * 1000);
16731673
animate(binding.positionView, true, 500);
16741674
animate(binding.detailPositionView, true, 500);
16751675
}, e -> {

app/src/main/java/org/schabi/newpipe/info_list/holder/StreamMiniInfoItemHolder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void updateFromItem(final InfoItem infoItem,
6666
itemProgressView.setVisibility(View.VISIBLE);
6767
itemProgressView.setMax((int) item.getDuration());
6868
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS
69-
.toSeconds(state2.getProgressTime()));
69+
.toSeconds(state2.getProgressMillis()));
7070
} else {
7171
itemProgressView.setVisibility(View.GONE);
7272
}
@@ -121,10 +121,10 @@ public void updateState(final InfoItem infoItem,
121121
itemProgressView.setMax((int) item.getDuration());
122122
if (itemProgressView.getVisibility() == View.VISIBLE) {
123123
itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS
124-
.toSeconds(state.getProgressTime()));
124+
.toSeconds(state.getProgressMillis()));
125125
} else {
126126
itemProgressView.setProgress((int) TimeUnit.MILLISECONDS
127-
.toSeconds(state.getProgressTime()));
127+
.toSeconds(state.getProgressMillis()));
128128
ViewUtils.animate(itemProgressView, true, 500);
129129
}
130130
} else if (itemProgressView.getVisibility() == View.VISIBLE) {

app/src/main/java/org/schabi/newpipe/local/feed/item/StreamItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ data class StreamItem(
2929
}
3030

3131
private val stream: StreamEntity = streamWithState.stream
32-
private val stateProgressTime: Long? = streamWithState.stateProgressTime
32+
private val stateProgressTime: Long? = streamWithState.stateProgressMillis
3333

3434
override fun getId(): Long = stream.uid
3535

app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,12 @@ public Maybe<StreamStateEntity> loadStreamState(final StreamInfo info) {
228228
.subscribeOn(Schedulers.io());
229229
}
230230

231-
public Completable saveStreamState(@NonNull final StreamInfo info, final long progressTime) {
231+
public Completable saveStreamState(@NonNull final StreamInfo info, final long progressMillis) {
232232
return Completable.fromAction(() -> database.runInTransaction(() -> {
233233
final long streamId = streamTable.upsert(new StreamEntity(info));
234-
final StreamStateEntity state = new StreamStateEntity(streamId, progressTime);
234+
final StreamStateEntity state = new StreamStateEntity(streamId, progressMillis);
235235
if (state.isValid()) {
236236
streamStateTable.upsert(state);
237-
} else {
238-
streamStateTable.deleteState(streamId);
239237
}
240238
})).subscribeOn(Schedulers.io());
241239
}

0 commit comments

Comments
 (0)