Fix OverviewVideo
This commit is contained in:
parent
f5fa9944ad
commit
a8a5028852
|
@ -26,7 +26,7 @@ import app.fedilab.fedilabtube.client.data.NotificationData;
|
|||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.data.OverviewVideoData.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.Rating;
|
||||
|
||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||
|
|
|
@ -23,13 +23,13 @@ import app.fedilab.fedilabtube.client.data.ChannelData;
|
|||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
import app.fedilab.fedilabtube.client.data.InstanceData;
|
||||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.data.OverviewVideoData;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.CaptionsParams;
|
||||
import app.fedilab.fedilabtube.client.entities.ChannelParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Oauth;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Rating;
|
||||
|
@ -99,7 +99,7 @@ public interface PeertubeService {
|
|||
|
||||
//Overview videos
|
||||
@GET("overviews/videos")
|
||||
Call<OverviewVideoData> getOverviewVideos(@Query("page") String page, @Query("languageOneOf") List<String> languageOneOf);
|
||||
Call<OverviewVideo> getOverviewVideos(@Query("page") String page, @Query("languageOneOf") List<String> languageOneOf);
|
||||
|
||||
//Most liked videos
|
||||
@GET("videos?sort=-likes")
|
||||
|
|
|
@ -41,7 +41,7 @@ import app.fedilab.fedilabtube.client.data.ChannelData;
|
|||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
import app.fedilab.fedilabtube.client.data.InstanceData;
|
||||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.data.OverviewVideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
|
@ -308,11 +308,11 @@ public class RetrofitPeertubeAPI {
|
|||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
ArrayList<String> filter = selection!=null?new ArrayList<>(selection):null;
|
||||
Call<OverviewVideoData> overviewVideoCall = peertubeService.getOverviewVideos(page, filter);
|
||||
Call<OverviewVideo> overviewVideoCall = peertubeService.getOverviewVideos(page, filter);
|
||||
try {
|
||||
Response<OverviewVideoData> response = overviewVideoCall.execute();
|
||||
Response<OverviewVideo> response = overviewVideoCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setOverviewVideo(response.body().data);
|
||||
apiResponse.setOverviewVideo(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.fedilabtube.client.data;
|
||||
package app.fedilab.fedilabtube.client.entities;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
|
@ -18,55 +18,49 @@ import com.google.gson.annotations.SerializedName;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.entities.Item;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData.Video;
|
||||
|
||||
public class OverviewVideoData {
|
||||
@SuppressWarnings({"unused"})
|
||||
public class OverviewVideo {
|
||||
|
||||
@SerializedName("total")
|
||||
public int total;
|
||||
@SerializedName("data")
|
||||
public OverviewVideo data;
|
||||
|
||||
public static class OverviewVideo {
|
||||
@SerializedName("categories")
|
||||
private Categories categories;
|
||||
@SerializedName("channels")
|
||||
private Channels channels;
|
||||
@SerializedName("tags")
|
||||
private Tags tags;
|
||||
|
||||
public Categories getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(Categories categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public Channels getChannels() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setChannels(Channels channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Tags tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
@SerializedName("categories")
|
||||
private List<Categories> categories;
|
||||
@SerializedName("channels")
|
||||
private List<Channels> channels;
|
||||
@SerializedName("tags")
|
||||
private List<Tags> tags;
|
||||
|
||||
|
||||
public List<Categories> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<Categories> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public List<Channels> getChannels() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setChannels(List<Channels> channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public List<Tags> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tags> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public static class Categories {
|
||||
@SerializedName("category")
|
||||
private Item category;
|
||||
@SerializedName("videos")
|
||||
private List<VideoData.Video> videos;
|
||||
private List<Video> videos;
|
||||
|
||||
public Item getCategory() {
|
||||
return category;
|
||||
|
@ -76,34 +70,34 @@ public class OverviewVideoData {
|
|||
this.category = category;
|
||||
}
|
||||
|
||||
public List<VideoData.Video> getVideos() {
|
||||
public List<Video> getVideos() {
|
||||
return videos;
|
||||
}
|
||||
|
||||
public void setVideos(List<VideoData.Video> videos) {
|
||||
public void setVideos(List<Video> videos) {
|
||||
this.videos = videos;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Channels {
|
||||
@SerializedName("channels")
|
||||
private ChannelData.Channel channels;
|
||||
private Channel channels;
|
||||
@SerializedName("videos")
|
||||
private List<VideoData.Video> videos;
|
||||
private List<Video> videos;
|
||||
|
||||
public ChannelData.Channel getChannels() {
|
||||
public Channel getChannels() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setChannels(ChannelData.Channel channels) {
|
||||
public void setChannels(Channel channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public List<VideoData.Video> getVideos() {
|
||||
public List<Video> getVideos() {
|
||||
return videos;
|
||||
}
|
||||
|
||||
public void setVideos(List<VideoData.Video> videos) {
|
||||
public void setVideos(List<Video> videos) {
|
||||
this.videos = videos;
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +106,7 @@ public class OverviewVideoData {
|
|||
@SerializedName("tag")
|
||||
private String tag;
|
||||
@SerializedName("videos")
|
||||
private List<VideoData.Video> videos;
|
||||
private List<Video> videos;
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
|
@ -122,11 +116,11 @@ public class OverviewVideoData {
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
public List<VideoData.Video> getVideos() {
|
||||
public List<Video> getVideos() {
|
||||
return videos;
|
||||
}
|
||||
|
||||
public void setVideos(List<VideoData.Video> videos) {
|
||||
public void setVideos(List<Video> videos) {
|
||||
this.videos = videos;
|
||||
}
|
||||
}
|
|
@ -40,8 +40,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.data.OverviewVideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
|
@ -70,7 +69,6 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
private TextView textviewNoActionText;
|
||||
private View rootView;
|
||||
private RecyclerView lv_status;
|
||||
private String forAccount;
|
||||
private TimelineVM viewModelFeeds;
|
||||
|
||||
public DisplayOverviewFragment() {
|
||||
|
@ -84,10 +82,8 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
|
||||
peertubes = new ArrayList<>();
|
||||
context = getContext();
|
||||
|
||||
forAccount = null;
|
||||
lv_status = rootView.findViewById(R.id.lv_status);
|
||||
page = 0;
|
||||
page = 1;
|
||||
flag_loading = true;
|
||||
firstLoad = true;
|
||||
|
||||
|
@ -202,8 +198,8 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//handle other API error but discards 404 - error which can often happen due to toots which have been deleted
|
||||
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) {
|
||||
if (apiResponse == null)
|
||||
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) {
|
||||
if (apiResponse == null || apiResponse.getError() == null)
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
else {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
@ -212,61 +208,68 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
flag_loading = false;
|
||||
return;
|
||||
}
|
||||
OverviewVideoData.OverviewVideo overviewVideos = apiResponse.getOverviewVideo();
|
||||
String categoryTitle = overviewVideos.getCategories().getCategory().getLabel();
|
||||
List<VideoData.Video> videoCategories = overviewVideos.getCategories().getVideos();
|
||||
int i = 0;
|
||||
for(VideoData.Video video: videoCategories) {
|
||||
if( i == 0) {
|
||||
video.setTitle(categoryTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(CATEGORY);
|
||||
OverviewVideo overviewVideos = apiResponse.getOverviewVideo();
|
||||
int totalAdded = 0;
|
||||
int previousPosition = this.peertubes.size();
|
||||
if( overviewVideos.getCategories() != null) {
|
||||
String categoryTitle = overviewVideos.getCategories().get(0).getCategory().getLabel();
|
||||
List<VideoData.Video> videoCategories = overviewVideos.getCategories().get(0).getVideos();
|
||||
int i = 0;
|
||||
for (VideoData.Video video : videoCategories) {
|
||||
if (i == 0) {
|
||||
video.setTitle(categoryTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(CATEGORY);
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
totalAdded++;
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
}
|
||||
String tagTitle = overviewVideos.getTags().getTag();
|
||||
List<VideoData.Video> videoTags = overviewVideos.getTags().getVideos();
|
||||
i = 0;
|
||||
for(VideoData.Video video: videoTags) {
|
||||
if( i == 0) {
|
||||
video.setTitle(tagTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(TAG);
|
||||
if( overviewVideos.getTags().get(0) != null) {
|
||||
String tagTitle = overviewVideos.getTags().get(0).getTag();
|
||||
List<VideoData.Video> videoTags = overviewVideos.getTags().get(0).getVideos();
|
||||
int i = 0;
|
||||
for (VideoData.Video video : videoTags) {
|
||||
if (i == 0) {
|
||||
video.setTitle(tagTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(TAG);
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
totalAdded++;
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
}
|
||||
String channelTitle = overviewVideos.getChannels().getChannels().getAcct();
|
||||
List<VideoData.Video> videoChannels = overviewVideos.getChannels().getVideos();
|
||||
i = 0;
|
||||
for(VideoData.Video video: videoChannels) {
|
||||
if( i == 0) {
|
||||
video.setTitle(channelTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(CHANNEL);
|
||||
if( overviewVideos.getChannels().get(0).getChannels() != null) {
|
||||
String channelTitle = overviewVideos.getChannels().get(0).getChannels().getAcct();
|
||||
List<VideoData.Video> videoChannels = overviewVideos.getChannels().get(0).getVideos();
|
||||
int i = 0;
|
||||
for (VideoData.Video video : videoChannels) {
|
||||
if (i == 0) {
|
||||
video.setTitle(channelTitle);
|
||||
video.setHasTitle(true);
|
||||
video.setTitleType(CHANNEL);
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
totalAdded++;
|
||||
}
|
||||
i++;
|
||||
peertubes.add(video);
|
||||
}
|
||||
|
||||
int previousPosition = this.peertubes.size();
|
||||
|
||||
//max_id needs to work like an offset
|
||||
page++;
|
||||
if (apiResponse.getPeertubes() == null) {
|
||||
return;
|
||||
}
|
||||
this.peertubes.addAll(apiResponse.getPeertubes());
|
||||
//If no item were inserted previously the adapter is created
|
||||
if (previousPosition == 0) {
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes);
|
||||
lv_status.setAdapter(peertubeAdapater);
|
||||
} else
|
||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
|
||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
|
||||
//remove handlers
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) {
|
||||
if (firstLoad && (this.peertubes == null || this.peertubes.size() == 0)) {
|
||||
textviewNoActionText.setText(R.string.no_video_to_display);
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -307,14 +310,13 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
int size = peertubes.size();
|
||||
peertubes.clear();
|
||||
peertubes = new ArrayList<>();
|
||||
page = 0;
|
||||
page = 1;
|
||||
peertubeAdapater.notifyItemRangeRemoved(0, size);
|
||||
loadTimeline(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(String forAccount) {
|
||||
this.forAccount = forAccount;
|
||||
pullToRefresh();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue