Change overview management
This commit is contained in:
parent
3697917d2b
commit
f5fa9944ad
|
@ -99,7 +99,7 @@ public interface PeertubeService {
|
||||||
|
|
||||||
//Overview videos
|
//Overview videos
|
||||||
@GET("overviews/videos")
|
@GET("overviews/videos")
|
||||||
Call<OverviewVideoData> getOverviewVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf);
|
Call<OverviewVideoData> getOverviewVideos(@Query("page") String page, @Query("languageOneOf") List<String> languageOneOf);
|
||||||
|
|
||||||
//Most liked videos
|
//Most liked videos
|
||||||
@GET("videos?sort=-likes")
|
@GET("videos?sort=-likes")
|
||||||
|
|
|
@ -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
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getOverviewVideo(String max_id) {
|
public APIResponse getOverviewVideo(String page) {
|
||||||
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(max_id, filter);
|
Call<OverviewVideoData> overviewVideoCall = peertubeService.getOverviewVideos(page, filter);
|
||||||
try {
|
try {
|
||||||
Response<OverviewVideoData> response = overviewVideoCall.execute();
|
Response<OverviewVideoData> response = overviewVideoCall.execute();
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
|
|
@ -116,6 +116,17 @@ public class VideoData {
|
||||||
|
|
||||||
private String myRating;
|
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() {
|
public Video() {
|
||||||
}
|
}
|
||||||
|
@ -459,6 +470,29 @@ public class VideoData {
|
||||||
this.myRating = myRating;
|
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
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
|
@ -614,5 +648,8 @@ public class VideoData {
|
||||||
public void setTargetUri(String targetUri) {
|
public void setTargetUri(String targetUri) {
|
||||||
this.targetUri = targetUri;
|
this.targetUri = targetUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,32 +85,32 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
|
|
||||||
Helper.loadGiF(context, peertube.getThumbnailPath(), holder.peertube_video_image);
|
Helper.loadGiF(context, peertube.getThumbnailPath(), holder.peertube_video_image);
|
||||||
|
|
||||||
|
//For Overview Videos: boolean values for displaying title is managed in the fragment
|
||||||
|
if( peertube.isHasTitle()) {
|
||||||
|
holder.header_title.setVisibility(View.VISIBLE);
|
||||||
|
switch (peertube.getTitleType()){
|
||||||
|
case TAG:
|
||||||
|
holder.header_title.setText(String.format("#%s", peertube.getTitle()));
|
||||||
|
break;
|
||||||
|
case CHANNEL:
|
||||||
|
case CATEGORY:
|
||||||
|
holder.header_title.setText(String.format("%s", peertube.getTitle()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
holder.header_title.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ownVideos) {
|
if (!ownVideos) {
|
||||||
holder.peertube_profile.setOnClickListener(v -> {
|
holder.peertube_profile.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
if (peertube.getChannel() == null) {
|
b.putParcelable("channel", peertube.getAccount());
|
||||||
b.putParcelable("channel", peertube.getAccount());
|
|
||||||
} else {
|
|
||||||
b.putParcelable("channel", peertube.getChannel());
|
|
||||||
}
|
|
||||||
intent.putExtras(b);
|
intent.putExtras(b);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peertube.getTags() != null) {
|
|
||||||
List<String> 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) {
|
if (!ownVideos) {
|
||||||
holder.bottom_container.setOnClickListener(v -> {
|
holder.bottom_container.setOnClickListener(v -> {
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
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<VideoData.Video> 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<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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -175,76 +175,57 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (type != TimelineVM.TimelineType.OVERVIEW) {
|
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
|
||||||
if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
|
if (dy > 0) {
|
||||||
if (dy > 0) {
|
if (check_ScrollingUp) {
|
||||||
if (check_ScrollingUp) {
|
top_account_container.setVisibility(View.GONE);
|
||||||
top_account_container.setVisibility(View.GONE);
|
final Handler handler = new Handler();
|
||||||
final Handler handler = new Handler();
|
handler.postDelayed(() -> check_ScrollingUp = false, 300);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (mLayoutManager != null) {
|
if (!check_ScrollingUp) {
|
||||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
top_account_container.setVisibility(View.VISIBLE);
|
||||||
if (dy > 0) {
|
final Handler handler = new Handler();
|
||||||
int visibleItemCount = mLayoutManager.getChildCount();
|
handler.postDelayed(() -> check_ScrollingUp = true, 300);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
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) {
|
if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
|
||||||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||||
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
|
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());
|
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
|
||||||
}
|
}
|
||||||
if (search_peertube == null) { //Not a Peertube search
|
loadTimeline("0");
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(String forAccount) {
|
public void click(String forAccount) {
|
||||||
this.forAccount = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,12 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
return apiResponseMutableLiveData;
|
return apiResponseMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<APIResponse> getOverviewVideos(String page) {
|
||||||
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
|
loadOverviewVideos(page);
|
||||||
|
return apiResponseMutableLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public LiveData<APIResponse> getVideo(String videoId) {
|
public LiveData<APIResponse> getVideo(String videoId) {
|
||||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
|
@ -97,11 +103,23 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
if (timeline == null)
|
if (timeline == null)
|
||||||
return;
|
return;
|
||||||
APIResponse apiResponse;
|
APIResponse apiResponse;
|
||||||
if( timeline == TimelineType.OVERVIEW) {
|
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id);
|
||||||
apiResponse = retrofitPeertubeAPI.getOverviewVideo(max_id);
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
}else{
|
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||||
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id);
|
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());
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
|
@ -117,7 +135,6 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
SUBSCRIBTIONS,
|
SUBSCRIBTIONS,
|
||||||
MY_VIDEOS,
|
MY_VIDEOS,
|
||||||
LOCAL,
|
LOCAL,
|
||||||
OVERVIEW,
|
|
||||||
TRENDING,
|
TRENDING,
|
||||||
MOST_LIKED,
|
MOST_LIKED,
|
||||||
HISTORY,
|
HISTORY,
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
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>.
|
||||||
|
-->
|
||||||
|
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipeContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/lv_status"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbars="none" />
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_action"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_action_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:text="@string/no_videos"
|
||||||
|
android:textSize="25sp" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<!-- Main Loader -->
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<!-- Loader for next videos -->
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loading_next_status"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
|
android:gravity="bottom|center_horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:indeterminate="true" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
|
@ -7,13 +7,9 @@
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_discover"
|
android:id="@+id/navigation_discover"
|
||||||
android:name="app.fedilab.fedilabtube.fragment.DisplayVideosFragment"
|
android:name="app.fedilab.fedilabtube.fragment.DisplayOverviewFragment"
|
||||||
android:label="@string/title_discover"
|
android:label="@string/title_discover"
|
||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
|
||||||
android:name="type"
|
|
||||||
android:defaultValue="OVERVIEW"
|
|
||||||
app:argType="app.fedilab.fedilabtube.viewmodel.TimelineVM$TimelineType" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,9 @@
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_discover"
|
android:id="@+id/navigation_discover"
|
||||||
android:name="app.fedilab.fedilabtube.fragment.DisplayVideosFragment"
|
android:name="app.fedilab.fedilabtube.fragment.DisplayOverviewFragment"
|
||||||
android:label="@string/title_discover"
|
android:label="@string/title_discover"
|
||||||
tools:layout="@layout/fragment_video">
|
tools:layout="@layout/fragment_video">
|
||||||
<argument
|
|
||||||
android:name="type"
|
|
||||||
android:defaultValue="OVERVIEW"
|
|
||||||
app:argType="app.fedilab.fedilabtube.viewmodel.TimelineVM$TimelineType" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue