Fix issue #109
This commit is contained in:
parent
14efbdd08f
commit
5540c8cacc
|
@ -727,7 +727,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
public void manageVIewVideo(APIResponse apiResponse) {
|
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();
|
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])?)?$");
|
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);
|
Matcher matcherLink = link.matcher(url);
|
||||||
|
@ -771,6 +771,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
}
|
}
|
||||||
return;
|
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) {
|
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);
|
||||||
|
@ -782,11 +787,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long position = -1;
|
long position = -1;
|
||||||
|
|
||||||
|
peertube = apiResponse.getPeertubes().get(0);
|
||||||
|
|
||||||
if (peertube.getUserHistory() != null) {
|
if (peertube.getUserHistory() != null) {
|
||||||
position = peertube.getUserHistory().getCurrentTime() * 1000;
|
position = peertube.getUserHistory().getCurrentTime() * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
peertube = apiResponse.getPeertubes().get(0);
|
|
||||||
if (peertube.getTags() != null && peertube.getTags().size() > 0) {
|
if (peertube.getTags() != null && peertube.getTags().size() > 0) {
|
||||||
SearchVM searchViewModel = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
|
SearchVM searchViewModel = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
|
||||||
searchViewModel.searchNextVideos(peertube.getTags()).observe(PeertubeActivity.this, this::manageNextVideos);
|
searchViewModel.searchNextVideos(peertube.getTags()).observe(PeertubeActivity.this, this::manageNextVideos);
|
||||||
|
|
|
@ -1664,10 +1664,10 @@ public class RetrofitPeertubeAPI {
|
||||||
* @param id String id
|
* @param id String id
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getVideos(String id, boolean myVideo) {
|
public APIResponse getVideos(String id, boolean myVideo, boolean canUseToken) {
|
||||||
PeertubeService peertubeService = init();
|
PeertubeService peertubeService = init();
|
||||||
Call<VideoData.Video> video;
|
Call<VideoData.Video> video;
|
||||||
if (myVideo) {
|
if (myVideo || canUseToken) {
|
||||||
video = peertubeService.getMyVideo(getToken(), id);
|
video = peertubeService.getMyVideo(getToken(), id);
|
||||||
} else {
|
} else {
|
||||||
video = peertubeService.getVideo(id);
|
video = peertubeService.getVideo(id);
|
||||||
|
@ -1682,6 +1682,7 @@ public class RetrofitPeertubeAPI {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (response.errorBody() != null) {
|
if (response.errorBody() != null) {
|
||||||
|
|
||||||
String error = response.errorBody().string();
|
String error = response.errorBody().string();
|
||||||
if (error.contains("originUrl")) {
|
if (error.contains("originUrl")) {
|
||||||
try {
|
try {
|
||||||
|
@ -1695,6 +1696,17 @@ public class RetrofitPeertubeAPI {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
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 {
|
} else {
|
||||||
Error error = new Error();
|
Error error = new Error();
|
||||||
|
|
|
@ -133,6 +133,7 @@ public class VideoData {
|
||||||
private String myRating;
|
private String myRating;
|
||||||
private String originUrl;
|
private String originUrl;
|
||||||
private int errorCode;
|
private int errorCode;
|
||||||
|
private String errorMessage;
|
||||||
//Dedicated to overview videos to reuse the logic of videos
|
//Dedicated to overview videos to reuse the logic of videos
|
||||||
private boolean hasTitle = false;
|
private boolean hasTitle = false;
|
||||||
private String title;
|
private String title;
|
||||||
|
@ -600,6 +601,14 @@ public class VideoData {
|
||||||
this.playlistExists = playlistExists;
|
this.playlistExists = playlistExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public UserHistory getUserHistory() {
|
public UserHistory getUserHistory() {
|
||||||
return userHistory;
|
return userHistory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,11 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
|
|
||||||
private void getSingle(String instance, String videoId, boolean myVideo) {
|
private void getSingle(String instance, String videoId, boolean myVideo) {
|
||||||
Context _mContext = getApplication().getApplicationContext();
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
boolean canUseToken = false;
|
||||||
|
if (instance == null || instance.compareTo(Helper.getLiveInstance(_mContext)) == 0) {
|
||||||
|
canUseToken = true;
|
||||||
|
}
|
||||||
|
boolean finalCanUseToken = canUseToken;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
RetrofitPeertubeAPI retrofitPeertubeAPI;
|
RetrofitPeertubeAPI retrofitPeertubeAPI;
|
||||||
|
@ -130,7 +135,7 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
} else {
|
} else {
|
||||||
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null);
|
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 (Helper.isLoggedIn(_mContext) && instance == null) {
|
||||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||||
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
||||||
|
|
Loading…
Reference in New Issue