TubeLab-App-Android/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayVideosFragment.java

546 lines
22 KiB
Java
Raw Normal View History

2020-06-26 14:34:39 +02:00
package app.fedilab.fedilabtube.fragment;
2020-07-01 16:36:08 +02:00
/* 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 <http://www.gnu.org/licenses>. */
2020-06-26 14:34:39 +02:00
import android.content.Context;
import android.content.SharedPreferences;
2020-07-09 17:57:01 +02:00
import android.graphics.Rect;
2020-06-26 14:34:39 +02:00
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
2020-06-26 14:34:39 +02:00
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
2020-06-27 11:21:25 +02:00
2020-06-26 14:34:39 +02:00
import androidx.annotation.NonNull;
2020-10-10 10:28:45 +02:00
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
2020-06-26 14:34:39 +02:00
import androidx.fragment.app.Fragment;
2020-10-10 10:28:45 +02:00
import androidx.fragment.app.FragmentManager;
2020-09-07 11:15:43 +02:00
import androidx.lifecycle.ViewModelProvider;
2020-07-09 17:57:01 +02:00
import androidx.recyclerview.widget.GridLayoutManager;
2020-06-26 14:34:39 +02:00
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
2020-06-27 11:21:25 +02:00
2020-06-26 14:34:39 +02:00
import org.jetbrains.annotations.NotNull;
2020-06-27 11:21:25 +02:00
2020-06-26 14:34:39 +02:00
import java.util.ArrayList;
2020-10-07 17:46:15 +02:00
import java.util.HashMap;
2020-06-26 14:34:39 +02:00
import java.util.List;
2020-10-07 17:46:15 +02:00
import java.util.Map;
2020-06-26 14:34:39 +02:00
2020-10-10 10:28:45 +02:00
import app.fedilab.fedilabtube.MainActivity;
2020-06-26 14:34:39 +02:00
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.APIResponse;
2020-09-25 18:58:04 +02:00
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
2020-10-10 09:25:00 +02:00
import app.fedilab.fedilabtube.client.data.ChannelData;
2020-09-25 18:58:04 +02:00
import app.fedilab.fedilabtube.client.data.VideoData;
2020-10-08 16:21:14 +02:00
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
2020-10-07 17:46:15 +02:00
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
2020-09-03 18:56:48 +02:00
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
2020-06-26 14:34:39 +02:00
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper;
2020-09-07 14:14:36 +02:00
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
2020-10-07 17:46:15 +02:00
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
2020-09-07 14:14:36 +02:00
import app.fedilab.fedilabtube.viewmodel.SearchVM;
2020-09-27 16:33:43 +02:00
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
2020-06-26 14:34:39 +02:00
import es.dmoral.toasty.Toasty;
2020-10-08 17:16:42 +02:00
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener {
2020-06-26 14:34:39 +02:00
private LinearLayoutManager mLayoutManager;
2020-07-09 17:57:01 +02:00
private GridLayoutManager gLayoutManager;
2020-06-26 14:34:39 +02:00
private boolean flag_loading;
private Context context;
private PeertubeAdapter peertubeAdapater;
2020-09-03 18:56:48 +02:00
private AccountsHorizontalListAdapter accountsHorizontalListAdapter;
private String max_id, max_id_accounts;
2020-09-25 18:58:04 +02:00
private List<VideoData.Video> peertubes;
2020-10-10 09:25:00 +02:00
private List<ChannelData.Channel> channels;
2020-09-26 16:52:41 +02:00
private TimelineVM.TimelineType type;
2020-06-26 14:34:39 +02:00
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private SharedPreferences sharedpreferences;
private String search_peertube;
private TextView textviewNoActionText;
private View rootView;
private RecyclerView lv_status;
2020-09-03 18:56:48 +02:00
private boolean check_ScrollingUp;
private String forAccount;
private ConstraintLayout top_account_container;
2020-09-25 18:58:04 +02:00
private TimelineVM viewModelFeeds;
2020-09-10 15:56:33 +02:00
private SearchVM viewModelSearch;
private AccountsVM viewModelAccounts;
2020-09-26 16:46:51 +02:00
private String channelId;
2020-10-07 17:46:15 +02:00
private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> playlists;
2020-10-08 16:21:14 +02:00
private String playlistId;
2020-06-26 14:34:39 +02:00
2020-09-25 18:58:04 +02:00
public DisplayVideosFragment() {
2020-06-26 14:34:39 +02:00
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_video, container, false);
2020-06-26 18:17:17 +02:00
2020-06-26 14:34:39 +02:00
peertubes = new ArrayList<>();
2020-10-10 09:25:00 +02:00
channels = new ArrayList<>();
2020-06-26 14:34:39 +02:00
context = getContext();
Bundle bundle = this.getArguments();
if (bundle != null) {
search_peertube = bundle.getString("search_peertube", null);
2020-09-26 16:46:51 +02:00
channelId = bundle.getString("channelId", null);
2020-10-08 16:21:14 +02:00
type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE);
playlistId = bundle.getString("playlistId", null);
2020-06-26 14:34:39 +02:00
}
2020-09-27 14:12:06 +02:00
max_id = "0";
forAccount = null;
2020-06-26 14:34:39 +02:00
lv_status = rootView.findViewById(R.id.lv_status);
RecyclerView lv_accounts = rootView.findViewById(R.id.lv_accounts);
Button display_all = rootView.findViewById(R.id.display_all);
top_account_container = rootView.findViewById(R.id.top_account_container);
2020-09-03 18:56:48 +02:00
max_id_accounts = null;
2020-06-26 14:34:39 +02:00
flag_loading = true;
firstLoad = true;
2020-09-03 18:56:48 +02:00
check_ScrollingUp = false;
2020-06-26 14:34:39 +02:00
assert context != null;
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
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);
2020-10-06 17:11:25 +02:00
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
2020-10-07 17:46:15 +02:00
peertubeAdapater.playlistListener = this;
peertubeAdapater.relationShipListener = this;
2020-06-26 14:34:39 +02:00
lv_status.setAdapter(peertubeAdapater);
2020-10-10 09:25:00 +02:00
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.channels, this);
2020-09-03 18:56:48 +02:00
LinearLayoutManager layoutManager
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lv_accounts.setLayoutManager(layoutManager);
lv_accounts.setAdapter(accountsHorizontalListAdapter);
2020-07-09 17:57:01 +02:00
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);
}
2020-09-25 18:58:04 +02:00
viewModelAccounts = new ViewModelProvider(DisplayVideosFragment.this).get(AccountsVM.class);
viewModelFeeds = new ViewModelProvider(DisplayVideosFragment.this).get(TimelineVM.class);
viewModelSearch = new ViewModelProvider(DisplayVideosFragment.this).get(SearchVM.class);
2020-10-10 10:28:45 +02:00
swipeRefreshLayout.setOnRefreshListener(() -> pullToRefresh(true));
2020-06-26 14:34:39 +02:00
2020-09-25 18:58:04 +02:00
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
2020-10-02 19:29:00 +02:00
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
2020-09-25 18:58:04 +02:00
if (dy > 0) {
2020-10-02 19:29:00 +02:00
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
2020-09-25 18:58:04 +02:00
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
viewModelAccounts.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id_accounts).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageViewAccounts(apiResponse));
2020-09-24 07:27:41 +02:00
}
}
2020-09-25 18:58:04 +02:00
}
});
2020-09-03 18:56:48 +02:00
2020-09-27 11:11:39 +02:00
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);
2020-09-03 18:56:48 +02:00
2020-09-27 11:11:39 +02:00
}
} else {
if (!check_ScrollingUp) {
top_account_container.setVisibility(View.VISIBLE);
final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = true, 300);
2020-09-03 18:56:48 +02:00
}
}
2020-09-27 11:11:39 +02:00
}
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);
2020-07-09 17:57:01 +02:00
}
2020-09-27 11:11:39 +02:00
} else {
nextElementLoader.setVisibility(View.GONE);
2020-07-09 17:57:01 +02:00
}
2020-09-27 11:11:39 +02:00
}
} 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);
2020-06-26 14:34:39 +02:00
}
2020-09-27 11:11:39 +02:00
} else {
nextElementLoader.setVisibility(View.GONE);
2020-06-26 14:34:39 +02:00
}
}
}
2020-09-27 11:11:39 +02:00
}
});
2020-09-26 16:52:41 +02:00
if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
2020-09-08 15:54:07 +02:00
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
2020-09-25 18:58:04 +02:00
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
2020-09-03 18:56:48 +02:00
}
2020-09-27 14:12:06 +02:00
loadTimeline(max_id);
display_all.setOnClickListener(v -> {
forAccount = null;
2020-10-10 10:28:45 +02:00
pullToRefresh(false);
});
2020-06-26 14:34:39 +02:00
return rootView;
}
2020-10-07 17:46:15 +02:00
2020-06-26 14:34:39 +02:00
@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();
}
2020-09-03 18:56:48 +02:00
2020-09-07 14:14:36 +02:00
private void manageViewAccounts(APIResponse apiResponse) {
2020-10-10 09:25:00 +02:00
if (apiResponse != null && apiResponse.getChannels() != null && apiResponse.getChannels().size() > 0) {
if (top_account_container.getVisibility() == View.GONE) {
top_account_container.setVisibility(View.VISIBLE);
2020-09-03 18:56:48 +02:00
}
2020-10-10 09:25:00 +02:00
int previousPosition = channels.size();
channels.addAll(apiResponse.getChannels());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getChannels().size());
if (max_id_accounts == null) {
2020-09-03 18:56:48 +02:00
max_id_accounts = "0";
}
//max_id_accounts needs to work like an offset
2020-09-03 18:56:48 +02:00
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage);
}
}
2020-09-07 11:15:43 +02:00
2020-09-07 14:14:36 +02:00
private void manageVIewVideos(APIResponse apiResponse) {
2020-06-26 14:34:39 +02:00
//hide loaders
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
2020-09-29 17:42:15 +02:00
//handle other API error
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) {
2020-06-26 14:34:39 +02:00
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;
}
int previousPosition = this.peertubes.size();
if (max_id == null)
max_id = "0";
//max_id needs to work like an offset
2020-10-08 18:13:04 +02:00
int videoPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage);
2020-10-08 16:21:14 +02:00
if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) {
2020-06-26 14:34:39 +02:00
return;
}
2020-10-08 16:21:14 +02:00
if (apiResponse.getVideoPlaylist() != null) {
apiResponse.setPeertubes(new ArrayList<>());
for (VideoPlaylistData.VideoPlaylist v : apiResponse.getVideoPlaylist()) {
apiResponse.getPeertubes().add(v.getVideo());
}
}
2020-06-26 14:34:39 +02:00
this.peertubes.addAll(apiResponse.getPeertubes());
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
2020-10-06 17:11:25 +02:00
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
2020-10-07 17:46:15 +02:00
peertubeAdapater.playlistListener = DisplayVideosFragment.this;
peertubeAdapater.relationShipListener = DisplayVideosFragment.this;
2020-06-26 14:34:39 +02:00
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;
2020-10-07 17:46:15 +02:00
if (Helper.isLoggedIn(context)) {
List<String> uids = new ArrayList<>();
for (VideoData.Video video : apiResponse.getPeertubes()) {
2020-10-10 11:49:18 +02:00
if( video != null) {
uids.add(video.getChannel().getName() + "@" + video.getChannel().getHost());
}
2020-10-07 17:46:15 +02:00
}
2020-10-08 16:21:14 +02:00
if (uids.size() > 0 && !DisplayVideosFragment.this.isDetached()) {
try {
RelationshipVM viewModel = new ViewModelProvider(this).get(RelationshipVM.class);
viewModel.get(uids).observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewRelationship);
} catch (Exception ignored) {
}
2020-10-07 17:46:15 +02:00
}
List<String> videoIds = new ArrayList<>();
for (VideoData.Video video : apiResponse.getPeertubes()) {
2020-10-10 11:49:18 +02:00
if( video != null) {
videoIds.add(video.getId());
}
2020-10-07 17:46:15 +02:00
}
2020-10-08 16:21:14 +02:00
if (videoIds.size() > 0 && !DisplayVideosFragment.this.isDetached()) {
try {
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
viewModel.videoExists(videoIds).observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewPlaylist);
} catch (Exception ignored) {
}
2020-10-07 17:46:15 +02:00
}
}
2020-06-26 14:34:39 +02:00
}
2020-10-07 17:46:15 +02:00
public void manageVIewPlaylist(APIResponse apiResponse) {
2020-10-08 16:21:14 +02:00
if (apiResponse.getError() != null || apiResponse.getVideoExistPlaylist() == null) {
2020-10-07 17:46:15 +02:00
return;
}
if (playlists == null) {
playlists = new HashMap<>();
}
playlists.putAll(apiResponse.getVideoExistPlaylist());
2020-10-08 16:21:14 +02:00
for (VideoData.Video video : peertubes) {
2020-10-10 11:49:18 +02:00
if( video != null) {
video.setPlaylistExists(playlists.get(video.getId()));
}
2020-10-08 16:21:14 +02:00
}
2020-10-07 17:46:15 +02:00
}
public void manageVIewRelationship(APIResponse apiResponse) {
if (apiResponse.getError() != null) {
return;
}
if (relationship == null) {
relationship = new HashMap<>();
}
relationship.putAll(apiResponse.getRelationships());
}
2020-06-26 14:34:39 +02:00
@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);
2020-07-09 17:57:01 +02:00
} else if (gLayoutManager != null) {
gLayoutManager.scrollToPositionWithOffset(0, 0);
2020-06-26 14:34:39 +02:00
}
}
2020-10-10 10:28:45 +02:00
public void pullToRefresh(boolean reload) {
if( type == TimelineVM.TimelineType.SUBSCRIBTIONS && reload) {
Fragment fragment = ((AppCompatActivity)context).getSupportFragmentManager().findFragmentByTag("2");
if(fragment != null) {
if( context instanceof MainActivity) {
FragmentManager fm = ((MainActivity) context).getSupportFragmentManager();
fm.beginTransaction().remove(fragment).commit();
DisplayVideosFragment subscriptionFragment = new DisplayVideosFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.SUBSCRIBTIONS);
subscriptionFragment.setArguments(bundle);
((MainActivity) context).setActive(subscriptionFragment);
((MainActivity) context).setSubscriptionFragment(subscriptionFragment);
fm.beginTransaction().add(R.id.nav_host_fragment, subscriptionFragment, "2").commit();
}
}
}else {
int size = peertubes.size();
peertubes.clear();
peertubes = new ArrayList<>();
max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) {
for (ChannelData.Channel channel : channels) {
channel.setSelected(false);
}
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, channels.size());
}
2020-10-10 10:28:45 +02:00
loadTimeline("0");
}
2020-10-10 10:28:45 +02:00
2020-06-26 14:34:39 +02:00
}
@Override
public void click(String forAccount) {
this.forAccount = forAccount;
2020-10-10 10:28:45 +02:00
pullToRefresh(false);
}
2020-07-09 17:57:01 +02:00
2020-09-27 16:33:43 +02:00
/**
* 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);
2020-10-08 16:21:14 +02:00
} else if (type == TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) {
2020-10-08 18:13:04 +02:00
viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
2020-09-27 16:33:43 +02:00
} else {
2020-10-10 09:25:00 +02:00
viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
2020-09-27 16:33:43 +02:00
}
} else {
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
}
}
2020-10-06 15:30:15 +02:00
2020-10-07 17:46:15 +02:00
@Override
public Map<String, Boolean> getRelationShip() {
return relationship;
}
@Override
public Map<String, List<PlaylistExist>> getPlaylist() {
return playlists;
}
2020-07-09 17:57:01 +02:00
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;
}
}
}
}
2020-06-26 14:34:39 +02:00
}