Fix issue #47 - Seek to last known position

This commit is contained in:
Thomas 2020-11-07 15:51:38 +01:00
parent ffa5d0883a
commit 8ab237a957
2 changed files with 75 additions and 18 deletions

View File

@ -174,7 +174,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private List<Comment> commentsThread; private List<Comment> commentsThread;
private BroadcastReceiver mPowerKeyReceiver = null; private BroadcastReceiver mPowerKeyReceiver = null;
private boolean isPlayInMinimized; private boolean isPlayInMinimized;
private Intent urlIntent;
public static List<String> playedVideos = new ArrayList<>(); public static List<String> playedVideos = new ArrayList<>();
private VideoData.Video nextVideo; private VideoData.Video nextVideo;
private TorrentStream torrentStream; private TorrentStream torrentStream;
@ -241,7 +240,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
setContentView(view); setContentView(view);
videoOrientationType = videoOrientation.LANDSCAPE; videoOrientationType = videoOrientation.LANDSCAPE;
max_id = "0"; max_id = "0";
urlIntent = null;
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
@ -430,6 +428,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
return; return;
} }
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
if( peertube.getUserHistory() != null) {
player.seekTo(peertube.getUserHistory().getCurrentTime()*1000);
}
sepiaSearch = false; sepiaSearch = false;
playVideo(); playVideo();
} }
@ -524,7 +525,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube = new VideoData.Video(); peertube = new VideoData.Video();
peertube.setUuid(uuid); peertube.setUuid(uuid);
peertube.setEmbedUrl(url); peertube.setEmbedUrl(url);
urlIntent = intent;
SearchVM viewModelSearch = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class); SearchVM viewModelSearch = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
viewModelSearch.getVideos("0", peertube.getEmbedUrl()).observe(PeertubeActivity.this, this::manageVIewVideos); viewModelSearch.getVideos("0", peertube.getEmbedUrl()).observe(PeertubeActivity.this, this::manageVIewVideos);
}else { }else {
@ -565,7 +565,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
setFullscreen(FullScreenMediaController.fullscreen.OFF); setFullscreen(FullScreenMediaController.fullscreen.OFF);
fullScreenMode = false; fullScreenMode = false;
} }
updateHistory(0);
binding.peertubePlaylist.setVisibility(View.VISIBLE); binding.peertubePlaylist.setVisibility(View.VISIBLE);
binding.peertubeBookmark.setVisibility(View.GONE); binding.peertubeBookmark.setVisibility(View.GONE);
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
@ -582,12 +581,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.peertubeDescriptionMore.setVisibility(View.GONE); binding.peertubeDescriptionMore.setVisibility(View.GONE);
show_more_content = null; show_more_content = null;
}else{ }else{
if( peertube != null && peertube.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0) { if( !PeertubeActivity.this.isFinishing()) {
binding.peertubeDescriptionMore.setVisibility(View.VISIBLE); if (peertube != null && peertube.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0) {
show_more_content = description.getDescription(); binding.peertubeDescriptionMore.setVisibility(View.VISIBLE);
}else{ show_more_content = description.getDescription();
binding.peertubeDescriptionMore.setVisibility(View.GONE); } else {
show_more_content = null; binding.peertubeDescriptionMore.setVisibility(View.GONE);
show_more_content = null;
}
} }
} }
@ -619,9 +620,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
if (playInMinimized && player != null) { if (playInMinimized && player != null) {
finishAndRemoveTask(); finishAndRemoveTask();
Intent intent = new Intent(PeertubeActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
} }
finish(); finish();
return true; return true;
@ -714,7 +712,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
public void manageVIewVideo(APIResponse apiResponse) { public void manageVIewVideo(APIResponse apiResponse) {
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) { if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
@ -725,7 +722,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.loader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
return; return;
} }
long position = -1;
if( peertube.getUserHistory() != null) {
position = peertube.getUserHistory().getCurrentTime() * 1000;
}
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
if( peertube.getTags() != null && peertube.getTags().size() > 0) { if( peertube.getTags() != null && peertube.getTags().size() > 0) {
@ -873,7 +873,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
startStream( startStream(
apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this), apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this),
apiResponse.getPeertubes().get(0).getStreamingPlaylists().size()>0?apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl():null, apiResponse.getPeertubes().get(0).getStreamingPlaylists().size()>0?apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl():null,
autoPlay,-1, null, null); autoPlay,position, null, null);
player.prepare(); player.prepare();
player.setPlayWhenReady(autoPlay); player.setPlayWhenReady(autoPlay);
} }
@ -966,7 +966,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath()); uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath());
} }
} }
long position = player.getCurrentPosition(); long newPosition = player.getCurrentPosition();
if (player != null) if (player != null)
player.release(); player.release();
@ -979,7 +979,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this), apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this),
null, null,
true, true,
position, newPosition,
uri, uri,
itemsKeyLanguage[which] itemsKeyLanguage[which]
); );

View File

@ -121,6 +121,8 @@ public class VideoData {
private List<String> trackerUrls; private List<String> trackerUrls;
@SerializedName("updatedAt") @SerializedName("updatedAt")
private Date updatedAt; private Date updatedAt;
@SerializedName("userHistory")
private UserHistory userHistory;
@SerializedName("uuid") @SerializedName("uuid")
private String uuid; private String uuid;
@SerializedName("views") @SerializedName("views")
@ -178,6 +180,7 @@ public class VideoData {
this.trackerUrls = in.createStringArrayList(); this.trackerUrls = in.createStringArrayList();
long tmpUpdatedAt = in.readLong(); long tmpUpdatedAt = in.readLong();
this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt); this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
this.userHistory = in.readParcelable(UserHistory.class.getClassLoader());
this.uuid = in.readString(); this.uuid = in.readString();
this.views = in.readInt(); this.views = in.readInt();
this.waitTranscoding = in.readByte() != 0; this.waitTranscoding = in.readByte() != 0;
@ -578,6 +581,14 @@ public class VideoData {
this.playlistExists = playlistExists; this.playlistExists = playlistExists;
} }
public UserHistory getUserHistory() {
return userHistory;
}
public void setUserHistory(UserHistory userHistory) {
this.userHistory = userHistory;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -618,6 +629,7 @@ public class VideoData {
dest.writeString(this.thumbnailPath); dest.writeString(this.thumbnailPath);
dest.writeStringList(this.trackerUrls); dest.writeStringList(this.trackerUrls);
dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1); dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1);
dest.writeParcelable(this.userHistory, flags);
dest.writeString(this.uuid); dest.writeString(this.uuid);
dest.writeInt(this.views); dest.writeInt(this.views);
dest.writeByte(this.waitTranscoding ? (byte) 1 : (byte) 0); dest.writeByte(this.waitTranscoding ? (byte) 1 : (byte) 0);
@ -686,6 +698,51 @@ public class VideoData {
} }
public static class UserHistory implements Parcelable{
public static final Creator<UserHistory> CREATOR = new Creator<UserHistory>() {
@Override
public UserHistory createFromParcel(Parcel in) {
return new UserHistory(in);
}
@Override
public UserHistory[] newArray(int size) {
return new UserHistory[size];
}
};
@SerializedName("currentTime")
long currentTime;
public UserHistory() {
}
protected UserHistory(Parcel in) {
this.currentTime = in.readLong();
}
public long getCurrentTime() {
return currentTime;
}
public void setCurrentTime(long currentTime) {
this.currentTime = currentTime;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(currentTime);
}
}
public static class Description{ public static class Description{
@SerializedName("description") @SerializedName("description")
private String description; private String description;