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