From f5fa9944add1a22dd3fd4be39ffe79cc7d5f8b82 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 27 Sep 2020 11:11:39 +0200 Subject: [PATCH] Change overview management --- .../fedilabtube/client/PeertubeService.java | 2 +- .../client/RetrofitPeertubeAPI.java | 8 +- .../fedilabtube/client/data/VideoData.java | 37 ++ .../fedilabtube/drawer/PeertubeAdapter.java | 32 +- .../fragment/DisplayOverviewFragment.java | 364 ++++++++++++++++++ .../fragment/DisplayVideosFragment.java | 140 +++---- .../fedilabtube/viewmodel/TimelineVM.java | 29 +- app/src/main/res/layout/fragment_overview.xml | 96 +++++ .../main/res/navigation/mobile_navigation.xml | 6 +- .../mobile_navigation_connected.xml | 6 +- 10 files changed, 607 insertions(+), 113 deletions(-) create mode 100644 app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayOverviewFragment.java create mode 100644 app/src/main/res/layout/fragment_overview.xml diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java index 8b2e74e..efcbbe2 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -99,7 +99,7 @@ public interface PeertubeService { //Overview videos @GET("overviews/videos") - Call getOverviewVideos(@Query("start") String maxId, @Query("languageOneOf") List languageOneOf); + Call getOverviewVideos(@Query("page") String page, @Query("languageOneOf") List languageOneOf); //Most liked videos @GET("videos?sort=-likes") diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index df74319..b7fed18 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -299,16 +299,16 @@ public class RetrofitPeertubeAPI { } /** - * Retrieves overview videos videos *synchronously* + * Retrieves overview videos *synchronously* * - * @param max_id String id max + * @param page String id pagination * @return APIResponse */ - public APIResponse getOverviewVideo(String max_id) { + public APIResponse getOverviewVideo(String page) { APIResponse apiResponse = new APIResponse(); PeertubeService peertubeService = init(); ArrayList filter = selection!=null?new ArrayList<>(selection):null; - Call overviewVideoCall = peertubeService.getOverviewVideos(max_id, filter); + Call overviewVideoCall = peertubeService.getOverviewVideos(page, filter); try { Response response = overviewVideoCall.execute(); if (response.isSuccessful() && response.body() != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java b/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java index f2fd87a..5a1a3f7 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/data/VideoData.java @@ -116,6 +116,17 @@ public class VideoData { private String myRating; + //Dedicated to overview videos to reuse the logic of videos + private boolean hasTitle = false; + private String title; + private titleType titleType; + + + public enum titleType{ + TAG, + CATEGORY, + CHANNEL + } public Video() { } @@ -459,6 +470,29 @@ public class VideoData { this.myRating = myRating; } + public boolean isHasTitle() { + return hasTitle; + } + + public void setHasTitle(boolean hasTitle) { + this.hasTitle = hasTitle; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Video.titleType getTitleType() { + return titleType; + } + + public void setTitleType(Video.titleType titleType) { + this.titleType = titleType; + } @Override public int describeContents() { @@ -614,5 +648,8 @@ public class VideoData { public void setTargetUri(String targetUri) { this.targetUri = targetUri; } + + + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index c80e7ea..3f67460 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -85,32 +85,32 @@ public class PeertubeAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ShowChannelActivity.class); Bundle b = new Bundle(); - if (peertube.getChannel() == null) { - b.putParcelable("channel", peertube.getAccount()); - } else { - b.putParcelable("channel", peertube.getChannel()); - } + b.putParcelable("channel", peertube.getAccount()); intent.putExtras(b); context.startActivity(intent); }); } - if (peertube.getTags() != null) { - List type = peertube.getTags(); - if (type.size() > 0) { - holder.header_title.setText(String.format("#%s", peertube.getTags().get(0))); - holder.header_title.setVisibility(View.VISIBLE); - } else { - holder.header_title.setVisibility(View.GONE); - } - } else { - holder.header_title.setVisibility(View.GONE); - } if (!ownVideos) { holder.bottom_container.setOnClickListener(v -> { diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayOverviewFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayOverviewFragment.java new file mode 100644 index 0000000..2b2f770 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayOverviewFragment.java @@ -0,0 +1,364 @@ +package app.fedilab.fedilabtube.fragment; +/* Copyright 2020 Thomas Schneider + * + * This file is a part of TubeLab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with TubeLab; if not, + * see . */ + +import android.content.Context; +import android.graphics.Rect; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +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.data.VideoData; +import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter; +import app.fedilab.fedilabtube.drawer.PeertubeAdapter; +import app.fedilab.fedilabtube.helper.Helper; +import app.fedilab.fedilabtube.viewmodel.TimelineVM; +import es.dmoral.toasty.Toasty; + +import static app.fedilab.fedilabtube.client.data.VideoData.Video.titleType.CATEGORY; +import static app.fedilab.fedilabtube.client.data.VideoData.Video.titleType.CHANNEL; +import static app.fedilab.fedilabtube.client.data.VideoData.Video.titleType.TAG; + + +public class DisplayOverviewFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener { + + + private LinearLayoutManager mLayoutManager; + private GridLayoutManager gLayoutManager; + private boolean flag_loading; + private Context context; + private PeertubeAdapter peertubeAdapater; + private int page; + private List peertubes; + private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; + private boolean firstLoad; + private SwipeRefreshLayout swipeRefreshLayout; + private TextView textviewNoActionText; + private View rootView; + private RecyclerView lv_status; + private String forAccount; + private TimelineVM viewModelFeeds; + + public DisplayOverviewFragment() { + } + + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + rootView = inflater.inflate(R.layout.fragment_overview, container, false); + + + peertubes = new ArrayList<>(); + context = getContext(); + + forAccount = null; + lv_status = rootView.findViewById(R.id.lv_status); + page = 0; + flag_loading = true; + firstLoad = true; + + swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); + mainLoader = rootView.findViewById(R.id.loader); + nextElementLoader = rootView.findViewById(R.id.loading_next_status); + textviewNoAction = rootView.findViewById(R.id.no_action); + textviewNoActionText = rootView.findViewById(R.id.no_action_text); + mainLoader.setVisibility(View.VISIBLE); + nextElementLoader.setVisibility(View.GONE); + + peertubeAdapater = new PeertubeAdapter(this.peertubes); + lv_status.setAdapter(peertubeAdapater); + + + if (!Helper.isTablet(context)) { + mLayoutManager = new LinearLayoutManager(context); + lv_status.setLayoutManager(mLayoutManager); + } else { + gLayoutManager = new GridLayoutManager(context, 2); + int spanCount = (int) Helper.convertDpToPixel(2, context); + int spacing = (int) Helper.convertDpToPixel(5, context); + lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true)); + lv_status.setLayoutManager(gLayoutManager); + } + + viewModelFeeds = new ViewModelProvider(DisplayOverviewFragment.this).get(TimelineVM.class); + swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh); + loadTimeline(page); + lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (mLayoutManager != null) { + int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); + if (dy > 0) { + int visibleItemCount = mLayoutManager.getChildCount(); + int totalItemCount = mLayoutManager.getItemCount(); + if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { + if (!flag_loading) { + flag_loading = true; + loadTimeline(page); + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } else if (gLayoutManager != null) { + int firstVisibleItem = gLayoutManager.findFirstVisibleItemPosition(); + if (dy > 0) { + int visibleItemCount = gLayoutManager.getChildCount(); + int totalItemCount = gLayoutManager.getItemCount(); + if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { + if (!flag_loading) { + flag_loading = true; + loadTimeline(page); + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } + } + }); + return rootView; + } + + @Override + public void onPause() { + super.onPause(); + if (swipeRefreshLayout != null) { + swipeRefreshLayout.setEnabled(false); + swipeRefreshLayout.setRefreshing(false); + swipeRefreshLayout.clearAnimation(); + } + if (getActivity() != null) { + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null && getView() != null) { + imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); + } + } + } + + + @Override + public void onCreate(Bundle saveInstance) { + super.onCreate(saveInstance); + } + + + @Override + public void onAttach(@NotNull Context context) { + super.onAttach(context); + this.context = context; + } + + + @Override + public void onStop() { + super.onStop(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + + + private void manageVIewVideos(APIResponse apiResponse) { + //hide loaders + 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) + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + else { + Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); + } + swipeRefreshLayout.setRefreshing(false); + flag_loading = false; + return; + } + OverviewVideoData.OverviewVideo overviewVideos = apiResponse.getOverviewVideo(); + String categoryTitle = overviewVideos.getCategories().getCategory().getLabel(); + List videoCategories = overviewVideos.getCategories().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); + } + String tagTitle = overviewVideos.getTags().getTag(); + List videoTags = overviewVideos.getTags().getVideos(); + i = 0; + for(VideoData.Video video: videoTags) { + if( i == 0) { + video.setTitle(tagTitle); + video.setHasTitle(true); + video.setTitleType(TAG); + } + i++; + peertubes.add(video); + } + String channelTitle = overviewVideos.getChannels().getChannels().getAcct(); + List videoChannels = overviewVideos.getChannels().getVideos(); + i = 0; + for(VideoData.Video video: videoChannels) { + if( i == 0) { + video.setTitle(channelTitle); + video.setHasTitle(true); + video.setTitleType(CHANNEL); + } + 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()); + //remove handlers + swipeRefreshLayout.setRefreshing(false); + textviewNoAction.setVisibility(View.GONE); + if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) { + textviewNoActionText.setText(R.string.no_video_to_display); + textviewNoAction.setVisibility(View.VISIBLE); + } + flag_loading = false; + firstLoad = false; + } + + + @Override + public void onDestroyView() { + if (lv_status != null) { + try { + lv_status.setAdapter(null); + } catch (Exception ignored) { + } + } + super.onDestroyView(); + rootView = null; + } + + @Override + public void onResume() { + super.onResume(); + swipeRefreshLayout.setEnabled(true); + } + + + public void scrollToTop() { + if (mLayoutManager != null) { + mLayoutManager.scrollToPositionWithOffset(0, 0); + } else if (gLayoutManager != null) { + gLayoutManager.scrollToPositionWithOffset(0, 0); + } + } + + + public void pullToRefresh() { + int size = peertubes.size(); + peertubes.clear(); + peertubes = new ArrayList<>(); + page = 0; + peertubeAdapater.notifyItemRangeRemoved(0, size); + loadTimeline(page); + } + + @Override + public void click(String forAccount) { + this.forAccount = forAccount; + pullToRefresh(); + } + + static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration { + + private int spanCount; + private int spacing; + private boolean includeEdge; + + public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) { + this.spanCount = spanCount; + this.spacing = spacing; + this.includeEdge = includeEdge; + } + + @Override + public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, RecyclerView parent, @NotNull RecyclerView.State state) { + int position = parent.getChildAdapterPosition(view); + int column = position % spanCount; + + if (includeEdge) { + outRect.left = spacing - column * spacing / spanCount; + outRect.right = (column + 1) * spacing / spanCount; + + if (position < spanCount) { + outRect.top = spacing; + } + outRect.bottom = spacing; + } else { + outRect.left = column * spacing / spanCount; + outRect.right = spacing - (column + 1) * spacing / spanCount; + if (position >= spanCount) { + outRect.top = spacing; + } + } + } + } + + + /** + * Manage timeline load + * @param page String pagination + */ + private void loadTimeline(int page) { + viewModelFeeds.getOverviewVideos(String.valueOf(page)).observe(DisplayOverviewFragment.this.requireActivity(), this::manageVIewVideos); + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java index 2f4313e..4e47a5c 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java @@ -175,76 +175,57 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta }); - if (type != TimelineVM.TimelineType.OVERVIEW) { - lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) { - if (dy > 0) { - if (check_ScrollingUp) { - top_account_container.setVisibility(View.GONE); - final Handler handler = new Handler(); - handler.postDelayed(() -> check_ScrollingUp = false, 300); + lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) { + if (dy > 0) { + if (check_ScrollingUp) { + top_account_container.setVisibility(View.GONE); + final Handler handler = new Handler(); + handler.postDelayed(() -> check_ScrollingUp = false, 300); - } - } else { - if (!check_ScrollingUp) { - top_account_container.setVisibility(View.VISIBLE); - final Handler handler = new Handler(); - handler.postDelayed(() -> check_ScrollingUp = true, 300); - } } - } - if (mLayoutManager != null) { - int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); - if (dy > 0) { - int visibleItemCount = mLayoutManager.getChildCount(); - int totalItemCount = mLayoutManager.getItemCount(); - if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { - if (!flag_loading) { - flag_loading = true; - if (search_peertube == null) { //Not a Peertube search - if( type == TimelineVM.TimelineType.USER_VIDEOS){ - viewModelFeeds.getVideosInChannel(channelId, max_id).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - }else { - viewModelFeeds.getVideos(type, max_id).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - } - } else { - viewModelSearch.getVideos(max_id, search_peertube).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - } - nextElementLoader.setVisibility(View.VISIBLE); - } - } else { - nextElementLoader.setVisibility(View.GONE); - } - } - } else if (gLayoutManager != null) { - int firstVisibleItem = gLayoutManager.findFirstVisibleItemPosition(); - if (dy > 0) { - int visibleItemCount = gLayoutManager.getChildCount(); - int totalItemCount = gLayoutManager.getItemCount(); - if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { - if (!flag_loading) { - flag_loading = true; - if (search_peertube == null) { //Not a Peertube search - if( type == TimelineVM.TimelineType.USER_VIDEOS){ - viewModelFeeds.getVideosInChannel(channelId, max_id).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - }else { - viewModelFeeds.getVideos(type, max_id).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - } - } else { - viewModelSearch.getVideos(max_id, search_peertube).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse)); - } - - nextElementLoader.setVisibility(View.VISIBLE); - } - } else { - nextElementLoader.setVisibility(View.GONE); - } + } else { + if (!check_ScrollingUp) { + top_account_container.setVisibility(View.VISIBLE); + final Handler handler = new Handler(); + handler.postDelayed(() -> check_ScrollingUp = true, 300); } } } - }); - } + if (mLayoutManager != null) { + int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); + if (dy > 0) { + int visibleItemCount = mLayoutManager.getChildCount(); + int totalItemCount = mLayoutManager.getItemCount(); + if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { + if (!flag_loading) { + flag_loading = true; + loadTimeline(max_id); + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } else if (gLayoutManager != null) { + int firstVisibleItem = gLayoutManager.findFirstVisibleItemPosition(); + if (dy > 0) { + int visibleItemCount = gLayoutManager.getChildCount(); + int totalItemCount = gLayoutManager.getItemCount(); + if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) { + if (!flag_loading) { + flag_loading = true; + loadTimeline(max_id); + nextElementLoader.setVisibility(View.VISIBLE); + } + } else { + nextElementLoader.setVisibility(View.GONE); + } + } + } + } + }); if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) { AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class); viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts); @@ -399,19 +380,9 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta } accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size()); } - if (search_peertube == null) { //Not a Peertube search - - if( type == TimelineVM.TimelineType.USER_VIDEOS){ - viewModelFeeds.getVideosInChannel(channelId, "0").observe(this.requireActivity(), this::manageVIewVideos); - }else { - viewModelFeeds.getVideos(type, "0").observe(this.requireActivity(), this::manageVIewVideos); - } - } else { - viewModelSearch.getVideos("0", search_peertube).observe(this.requireActivity(), this::manageVIewVideos); - } + loadTimeline("0"); } - @Override public void click(String forAccount) { this.forAccount = forAccount; @@ -452,4 +423,21 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta } } } + + + /** + * Manage timeline load + * @param max_id String pagination + */ + private void loadTimeline(String max_id) { + if (search_peertube == null) { //Not a Peertube search + if( type == TimelineVM.TimelineType.USER_VIDEOS){ + viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos); + }else { + viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos); + } + } else { + viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos); + } + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java index 789d7a5..e45e0a4 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java @@ -41,6 +41,12 @@ public class TimelineVM extends AndroidViewModel { return apiResponseMutableLiveData; } + public LiveData getOverviewVideos(String page) { + apiResponseMutableLiveData = new MutableLiveData<>(); + loadOverviewVideos(page); + return apiResponseMutableLiveData; + } + public LiveData getVideo(String videoId) { apiResponseMutableLiveData = new MutableLiveData<>(); @@ -97,11 +103,23 @@ public class TimelineVM extends AndroidViewModel { if (timeline == null) return; APIResponse apiResponse; - if( timeline == TimelineType.OVERVIEW) { - apiResponse = retrofitPeertubeAPI.getOverviewVideo(max_id); - }else{ - apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id); - } + apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id); + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); + mainHandler.post(myRunnable); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + + + private void loadOverviewVideos(String page) { + Context _mContext = getApplication().getApplicationContext(); + new Thread(() -> { + try { + RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + APIResponse apiResponse = retrofitPeertubeAPI.getOverviewVideo(page); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); mainHandler.post(myRunnable); @@ -117,7 +135,6 @@ public class TimelineVM extends AndroidViewModel { SUBSCRIBTIONS, MY_VIDEOS, LOCAL, - OVERVIEW, TRENDING, MOST_LIKED, HISTORY, diff --git a/app/src/main/res/layout/fragment_overview.xml b/app/src/main/res/layout/fragment_overview.xml new file mode 100644 index 0000000..1438a45 --- /dev/null +++ b/app/src/main/res/layout/fragment_overview.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index a1a4368..7a56458 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -7,13 +7,9 @@ - diff --git a/app/src/main/res/navigation/mobile_navigation_connected.xml b/app/src/main/res/navigation/mobile_navigation_connected.xml index b9d3fc3..56e81f4 100644 --- a/app/src/main/res/navigation/mobile_navigation_connected.xml +++ b/app/src/main/res/navigation/mobile_navigation_connected.xml @@ -7,13 +7,9 @@ -