This commit is contained in:
Thomas 2020-11-22 10:59:30 +01:00
parent 14efbdd08f
commit 5540c8cacc
4 changed files with 38 additions and 6 deletions

View File

@ -727,7 +727,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@SuppressLint("ClickableViewAccessibility")
public void manageVIewVideo(APIResponse apiResponse) {
if (!isRemote && apiResponse != null && apiResponse.getPeertubes().get(0).getErrorCode() == 1 && apiResponse.getPeertubes().get(0).getOriginUrl() != null) {
if (!isRemote && apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().get(0).getErrorCode() == 1 && apiResponse.getPeertubes().get(0).getOriginUrl() != null) {
String url = apiResponse.getPeertubes().get(0).getOriginUrl();
Pattern link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})(\\?start=(\\d+[hH])?(\\d+[mM])?(\\d+[sS])?)?$");
Matcher matcherLink = link.matcher(url);
@ -771,6 +771,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
return;
}
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0).getErrorMessage() != null) {
Toasty.error(PeertubeActivity.this, apiResponse.getPeertubes().get(0).getErrorMessage(), Toast.LENGTH_LONG).show();
binding.loader.setVisibility(View.GONE);
return;
}
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();
binding.loader.setVisibility(View.GONE);
@ -782,11 +787,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
return;
}
long position = -1;
peertube = apiResponse.getPeertubes().get(0);
if (peertube.getUserHistory() != null) {
position = peertube.getUserHistory().getCurrentTime() * 1000;
}
peertube = apiResponse.getPeertubes().get(0);
if (peertube.getTags() != null && peertube.getTags().size() > 0) {
SearchVM searchViewModel = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
searchViewModel.searchNextVideos(peertube.getTags()).observe(PeertubeActivity.this, this::manageNextVideos);

View File

@ -1664,10 +1664,10 @@ public class RetrofitPeertubeAPI {
* @param id String id
* @return APIResponse
*/
public APIResponse getVideos(String id, boolean myVideo) {
public APIResponse getVideos(String id, boolean myVideo, boolean canUseToken) {
PeertubeService peertubeService = init();
Call<VideoData.Video> video;
if (myVideo) {
if (myVideo || canUseToken) {
video = peertubeService.getMyVideo(getToken(), id);
} else {
video = peertubeService.getVideo(id);
@ -1682,6 +1682,7 @@ public class RetrofitPeertubeAPI {
} else {
if (response.errorBody() != null) {
String error = response.errorBody().string();
if (error.contains("originUrl")) {
try {
@ -1695,6 +1696,17 @@ public class RetrofitPeertubeAPI {
} catch (JSONException e) {
e.printStackTrace();
}
} else if (error.contains("error")) {
try {
JSONObject jsonObject = new JSONObject(error);
List<VideoData.Video> videos = new ArrayList<>();
VideoData.Video videoErrorMessage = new VideoData.Video();
videoErrorMessage.setErrorMessage(jsonObject.getString("error"));
videos.add(videoErrorMessage);
apiResponse.setPeertubes(videos);
} catch (JSONException e) {
e.printStackTrace();
}
}
} else {
Error error = new Error();

View File

@ -133,6 +133,7 @@ public class VideoData {
private String myRating;
private String originUrl;
private int errorCode;
private String errorMessage;
//Dedicated to overview videos to reuse the logic of videos
private boolean hasTitle = false;
private String title;
@ -600,6 +601,14 @@ public class VideoData {
this.playlistExists = playlistExists;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public UserHistory getUserHistory() {
return userHistory;
}

View File

@ -122,6 +122,11 @@ public class TimelineVM extends AndroidViewModel {
private void getSingle(String instance, String videoId, boolean myVideo) {
Context _mContext = getApplication().getApplicationContext();
boolean canUseToken = false;
if (instance == null || instance.compareTo(Helper.getLiveInstance(_mContext)) == 0) {
canUseToken = true;
}
boolean finalCanUseToken = canUseToken;
new Thread(() -> {
try {
RetrofitPeertubeAPI retrofitPeertubeAPI;
@ -130,7 +135,7 @@ public class TimelineVM extends AndroidViewModel {
} else {
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null);
}
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId, myVideo);
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId, myVideo, finalCanUseToken);
if (Helper.isLoggedIn(_mContext) && instance == null) {
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);