1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-05-11 23:29:09 +02:00

Fix issue #115 - Filter with remote accounts does not work

This commit is contained in:
Thomas 2020-11-28 09:20:44 +01:00
parent 7d9e299940
commit b59d97279d
8 changed files with 100 additions and 108 deletions

View File

@ -11,8 +11,8 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 27 versionCode 28
versionName "1.8.0" versionName "1.9.0-beta-1"
multiDexEnabled true multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -294,7 +294,7 @@ public class ShowAccountActivity extends AppCompatActivity {
} }
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment(); DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.ACCOUNT_VIDEOS); bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.ACCOUNT_VIDEOS);
bundle.putString("channelId", account.getAcct()); bundle.putParcelable("account", account);
bundle.putString("peertube_instance", account.getHost()); bundle.putString("peertube_instance", account.getHost());
displayVideosFragment.setArguments(bundle); displayVideosFragment.setArguments(bundle);
return displayVideosFragment; return displayVideosFragment;

View File

@ -493,7 +493,7 @@ public class ShowChannelActivity extends AppCompatActivity {
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment(); DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.CHANNEL_VIDEOS); bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.CHANNEL_VIDEOS);
bundle.putString("channelId", channel.getAcct()); bundle.putParcelable("channel", channel);
bundle.putString("peertube_instance", channel.getHost()); bundle.putString("peertube_instance", channel.getHost());
bundle.putBoolean("sepia_search", sepiaSearch); bundle.putBoolean("sepia_search", sepiaSearch);
displayVideosFragment.setArguments(bundle); displayVideosFragment.setArguments(bundle);

View File

@ -19,19 +19,13 @@ import android.graphics.Color;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.List; import java.util.List;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.ChannelData; import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.databinding.DrawerHorizontalAccountBinding;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
@ -50,8 +44,8 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
context = parent.getContext(); context = parent.getContext();
LayoutInflater layoutInflater = LayoutInflater.from(context); DrawerHorizontalAccountBinding itemBinding = DrawerHorizontalAccountBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_horizontal_account, parent, false)); return new ViewHolder(itemBinding);
} }
@Override @Override
@ -60,17 +54,17 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
final ChannelData.Channel channel = channels.get(position); final ChannelData.Channel channel = channels.get(position);
if (channel.getDisplayName() != null && !channel.getDisplayName().trim().equals("")) if (channel.getDisplayName() != null && !channel.getDisplayName().trim().equals(""))
holder.account_dn.setText(channel.getDisplayName()); holder.binding.accountDn.setText(channel.getDisplayName());
else else
holder.account_dn.setText(channel.getName().replace("@", "")); holder.binding.accountDn.setText(channel.getName().replace("@", ""));
//Profile picture //Profile picture
Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp, 270); Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.binding.accountPp, 270);
if (channel.isSelected()) { if (channel.isSelected()) {
holder.main_container.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50)); holder.binding.mainContainer.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50));
} else { } else {
holder.main_container.setBackgroundColor(Color.TRANSPARENT); holder.binding.mainContainer.setBackgroundColor(Color.TRANSPARENT);
} }
} }
@ -87,27 +81,24 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
public interface EventListener { public interface EventListener {
void click(String forAccount); void click(ChannelData.Channel channel);
} }
private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView account_pp; DrawerHorizontalAccountBinding binding;
TextView account_dn;
LinearLayout main_container; ViewHolder(DrawerHorizontalAccountBinding itemView) {
super(itemView.getRoot());
binding = itemView;
itemView.getRoot().setOnClickListener(this);
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
account_pp = itemView.findViewById(R.id.account_pp);
account_dn = itemView.findViewById(R.id.account_dn);
main_container = itemView.findViewById(R.id.main_container);
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
ChannelData.Channel channel = channels.get(getAdapterPosition()); ChannelData.Channel channel = channels.get(getAdapterPosition());
listener.click(channel.getAcct()); listener.click(channel);
for (ChannelData.Channel acc : channels) { for (ChannelData.Channel acc : channels) {
acc.setSelected(acc.getId().compareTo(channel.getId()) == 0); acc.setSelected(acc.getId().compareTo(channel.getId()) == 0);
} }

View File

@ -41,6 +41,7 @@ import java.util.List;
import app.fedilab.fedilabtube.BuildConfig; import app.fedilab.fedilabtube.BuildConfig;
import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.SepiaSearch; import app.fedilab.fedilabtube.client.entities.SepiaSearch;
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter; import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
@ -279,7 +280,7 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
} }
@Override @Override
public void click(String forAccount) { public void click(ChannelData.Channel forChannel) {
pullToRefresh(); pullToRefresh();
} }

View File

@ -23,20 +23,16 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -50,10 +46,12 @@ import app.fedilab.fedilabtube.MainActivity;
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.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData;
import app.fedilab.fedilabtube.client.data.ChannelData; import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData; import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
import app.fedilab.fedilabtube.client.entities.PlaylistExist; import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.databinding.FragmentVideoBinding;
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter; import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter; import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
@ -80,27 +78,23 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private List<VideoData.Video> peertubes; private List<VideoData.Video> peertubes;
private List<ChannelData.Channel> channels; private List<ChannelData.Channel> channels;
private TimelineVM.TimelineType type; private TimelineVM.TimelineType type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad; private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private SharedPreferences sharedpreferences;
private String search_peertube; private String search_peertube;
private TextView textviewNoActionText;
private View rootView;
private RecyclerView lv_status;
private boolean check_ScrollingUp; private boolean check_ScrollingUp;
private String forAccount; private ChannelData.Channel forChannel;
private ConstraintLayout top_account_container;
private TimelineVM viewModelFeeds; private TimelineVM viewModelFeeds;
private SearchVM viewModelSearch; private SearchVM viewModelSearch;
private AccountsVM viewModelAccounts; private AccountsVM viewModelAccounts;
private String channelId; private ChannelData.Channel channel;
private AccountData.Account account;
private Map<String, Boolean> relationship; private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> playlists; private Map<String, List<PlaylistExist>> playlists;
private String playlistId; private String playlistId;
private String remoteInstance; private String remoteInstance;
private boolean sepiaSearch; private boolean sepiaSearch;
private String startDate, endDate; private String startDate, endDate;
private FragmentVideoBinding binding;
private String channelId;
public DisplayVideosFragment() { public DisplayVideosFragment() {
} }
@ -108,9 +102,14 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_video, container, false); binding = FragmentVideoBinding.inflate(inflater, container, false);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
peertubes = new ArrayList<>(); peertubes = new ArrayList<>();
channels = new ArrayList<>(); channels = new ArrayList<>();
context = getContext(); context = getContext();
@ -119,7 +118,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
Bundle bundle = this.getArguments(); Bundle bundle = this.getArguments();
if (bundle != null) { if (bundle != null) {
search_peertube = bundle.getString("search_peertube", null); search_peertube = bundle.getString("search_peertube", null);
channelId = bundle.getString("channelId", null); channel = bundle.getParcelable("channel");
account = bundle.getParcelable("account");
remoteInstance = bundle.getString("peertube_instance", null); remoteInstance = bundle.getString("peertube_instance", null);
sepiaSearch = bundle.getBoolean("sepia_search", false); sepiaSearch = bundle.getBoolean("sepia_search", false);
type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE); type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE);
@ -127,54 +127,48 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
startDate = bundle.getString("startDate", null); startDate = bundle.getString("startDate", null);
endDate = bundle.getString("endDate", null); endDate = bundle.getString("endDate", null);
} }
if (channel != null) {
channelId = channel.getAcct();
} else if (account != null) {
channelId = account.getAcct();
}
max_id = "0"; max_id = "0";
forAccount = type == TimelineVM.TimelineType.ACCOUNT_VIDEOS ? channelId : null; // forChannel = type == TimelineVM.TimelineType.ACCOUNT_VIDEOS ? channelId : null;
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);
max_id_accounts = null; max_id_accounts = null;
flag_loading = true; flag_loading = true;
firstLoad = true; firstLoad = true;
check_ScrollingUp = false; check_ScrollingUp = false;
assert context != null; binding.loader.setVisibility(View.VISIBLE);
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); binding.loadingNextVideos.setVisibility(View.GONE);
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, type, sepiaSearch); peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch);
peertubeAdapater.playlistListener = this; peertubeAdapater.playlistListener = this;
peertubeAdapater.relationShipListener = this; peertubeAdapater.relationShipListener = this;
lv_status.setAdapter(peertubeAdapater); binding.lvVideos.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.channels, this); accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.channels, this);
LinearLayoutManager layoutManager LinearLayoutManager layoutManager
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false); = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lv_accounts.setLayoutManager(layoutManager); binding.lvAccounts.setLayoutManager(layoutManager);
lv_accounts.setAdapter(accountsHorizontalListAdapter); binding.lvAccounts.setAdapter(accountsHorizontalListAdapter);
if (!Helper.isTablet(context)) { if (!Helper.isTablet(context)) {
mLayoutManager = new LinearLayoutManager(context); mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager); binding.lvVideos.setLayoutManager(mLayoutManager);
} else { } else {
gLayoutManager = new GridLayoutManager(context, 2); gLayoutManager = new GridLayoutManager(context, 2);
int spanCount = (int) Helper.convertDpToPixel(2, context); int spanCount = (int) Helper.convertDpToPixel(2, context);
int spacing = (int) Helper.convertDpToPixel(5, context); int spacing = (int) Helper.convertDpToPixel(5, context);
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true)); binding.lvVideos.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
lv_status.setLayoutManager(gLayoutManager); binding.lvVideos.setLayoutManager(gLayoutManager);
} }
viewModelAccounts = new ViewModelProvider(DisplayVideosFragment.this).get(AccountsVM.class); viewModelAccounts = new ViewModelProvider(DisplayVideosFragment.this).get(AccountsVM.class);
viewModelFeeds = new ViewModelProvider(DisplayVideosFragment.this).get(TimelineVM.class); viewModelFeeds = new ViewModelProvider(DisplayVideosFragment.this).get(TimelineVM.class);
viewModelSearch = new ViewModelProvider(DisplayVideosFragment.this).get(SearchVM.class); viewModelSearch = new ViewModelProvider(DisplayVideosFragment.this).get(SearchVM.class);
swipeRefreshLayout.setOnRefreshListener(() -> pullToRefresh(true)); binding.swipeContainer.setOnRefreshListener(() -> pullToRefresh(true));
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.lvAccounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
if (dy > 0) { if (dy > 0) {
@ -189,19 +183,19 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (type != VIDEOS_IN_LOCAL_PLAYLIST) { if (type != VIDEOS_IN_LOCAL_PLAYLIST) {
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.lvVideos.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); binding.topAccountContainer.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 { } else {
if (!check_ScrollingUp) { if (!check_ScrollingUp) {
top_account_container.setVisibility(View.VISIBLE); binding.topAccountContainer.setVisibility(View.VISIBLE);
final Handler handler = new Handler(); final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = true, 300); handler.postDelayed(() -> check_ScrollingUp = true, 300);
} }
@ -216,10 +210,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
loadTimeline(max_id); loadTimeline(max_id);
nextElementLoader.setVisibility(View.VISIBLE); binding.loadingNextVideos.setVisibility(View.VISIBLE);
} }
} else { } else {
nextElementLoader.setVisibility(View.GONE); binding.loadingNextVideos.setVisibility(View.GONE);
} }
} }
} else if (gLayoutManager != null) { } else if (gLayoutManager != null) {
@ -231,10 +225,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
loadTimeline(max_id); loadTimeline(max_id);
nextElementLoader.setVisibility(View.VISIBLE); binding.loadingNextVideos.setVisibility(View.VISIBLE);
} }
} else { } else {
nextElementLoader.setVisibility(View.GONE); binding.loadingNextVideos.setVisibility(View.GONE);
} }
} }
} }
@ -246,27 +240,26 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
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);
} }
loadTimeline(max_id); loadTimeline(max_id);
display_all.setOnClickListener(v -> { binding.displayAll.setOnClickListener(v -> {
forAccount = null; forChannel = null;
pullToRefresh(false); pullToRefresh(false);
}); });
return rootView;
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
swipeRefreshLayout.setEnabled(true); binding.swipeContainer.setEnabled(true);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (swipeRefreshLayout != null) { if (binding.swipeContainer != null) {
swipeRefreshLayout.setEnabled(false); binding.swipeContainer.setEnabled(false);
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
swipeRefreshLayout.clearAnimation(); binding.swipeContainer.clearAnimation();
} }
if (getActivity() != null) { if (getActivity() != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
@ -303,8 +296,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private void manageViewAccounts(APIResponse apiResponse) { private void manageViewAccounts(APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getChannels() != null && apiResponse.getChannels().size() > 0) { if (apiResponse != null && apiResponse.getChannels() != null && apiResponse.getChannels().size() > 0) {
if (top_account_container.getVisibility() == View.GONE) { if (binding.topAccountContainer.getVisibility() == View.GONE) {
top_account_container.setVisibility(View.VISIBLE); binding.topAccountContainer.setVisibility(View.VISIBLE);
} }
int previousPosition = channels.size(); int previousPosition = channels.size();
channels.addAll(apiResponse.getChannels()); channels.addAll(apiResponse.getChannels());
@ -312,6 +305,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (max_id_accounts == null) { if (max_id_accounts == null) {
max_id_accounts = "0"; max_id_accounts = "0";
} }
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//max_id_accounts needs to work like an offset //max_id_accounts needs to work like an offset
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage); max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage);
@ -321,8 +315,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private void manageVIewVideos(APIResponse apiResponse) { private void manageVIewVideos(APIResponse apiResponse) {
//hide loaders //hide loaders
mainLoader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); binding.loadingNextVideos.setVisibility(View.GONE);
//handle other API error //handle other API error
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) { if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) {
if (apiResponse == null) if (apiResponse == null)
@ -330,7 +324,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
else { else {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
} }
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
flag_loading = false; flag_loading = false;
return; return;
} }
@ -338,6 +332,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (max_id == null) if (max_id == null)
max_id = "0"; max_id = "0";
//max_id needs to work like an offset //max_id needs to work like an offset
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int videoPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); int videoPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage); max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage);
if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) { if (apiResponse.getPeertubes() == null && apiResponse.getVideoPlaylist() == null) {
@ -365,15 +360,15 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch); peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch);
peertubeAdapater.playlistListener = DisplayVideosFragment.this; peertubeAdapater.playlistListener = DisplayVideosFragment.this;
peertubeAdapater.relationShipListener = DisplayVideosFragment.this; peertubeAdapater.relationShipListener = DisplayVideosFragment.this;
lv_status.setAdapter(peertubeAdapater); binding.lvVideos.setAdapter(peertubeAdapater);
} else } else
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size()); peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
//remove handlers //remove handlers
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
textviewNoAction.setVisibility(View.GONE); binding.noAction.setVisibility(View.GONE);
if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) { if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) {
textviewNoActionText.setText(R.string.no_video_to_display); binding.noActionText.setText(R.string.no_video_to_display);
textviewNoAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
} }
flag_loading = false; flag_loading = false;
firstLoad = false; firstLoad = false;
@ -438,14 +433,13 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
@Override @Override
public void onDestroyView() { public void onDestroyView() {
if (lv_status != null) { if (binding.lvVideos != null) {
try { try {
lv_status.setAdapter(null); binding.lvVideos.setAdapter(null);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
super.onDestroyView(); super.onDestroyView();
rootView = null;
} }
@ -471,7 +465,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubes = new ArrayList<>(); peertubes = new ArrayList<>();
max_id = "0"; max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size); peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) { if (forChannel == null) {
for (ChannelData.Channel channel : channels) { for (ChannelData.Channel channel : channels) {
channel.setSelected(false); channel.setSelected(false);
} }
@ -483,8 +477,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
} }
@Override @Override
public void click(String forAccount) { public void click(ChannelData.Channel forChannel) {
this.forAccount = forAccount; this.forChannel = forChannel;
pullToRefresh(false); pullToRefresh(false);
} }
@ -504,7 +498,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
} else if (type == TimelineVM.TimelineType.HISTORY) { } else if (type == TimelineVM.TimelineType.HISTORY) {
viewModelFeeds.getVideoHistory(max_id, startDate, endDate).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.getVideoHistory(max_id, startDate, endDate).observe(this.requireActivity(), this::manageVIewVideos);
} else { } else {
viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.getVideos(type, max_id, forChannel).observe(this.requireActivity(), this::manageVIewVideos);
} }
} else { } else {
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos); viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);

View File

@ -30,6 +30,7 @@ import java.util.List;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.ManagePlaylistsDAO; import app.fedilab.fedilabtube.sqlite.ManagePlaylistsDAO;
@ -45,9 +46,9 @@ public class TimelineVM extends AndroidViewModel {
super(application); super(application);
} }
public LiveData<APIResponse> getVideos(TimelineType action, String max_id, String forAccount) { public LiveData<APIResponse> getVideos(TimelineType action, String max_id, ChannelData.Channel forChannel) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
loadVideos(action, max_id, forAccount); loadVideos(action, max_id, forChannel);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
@ -189,15 +190,20 @@ public class TimelineVM extends AndroidViewModel {
}).start(); }).start();
} }
private void loadVideos(TimelineType timeline, String max_id, String forAccount) { private void loadVideos(TimelineType timeline, String max_id, ChannelData.Channel forChannel) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); RetrofitPeertubeAPI retrofitPeertubeAPI;
if (forChannel != null) {
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, forChannel.getHost(), null);
} else {
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
}
if (timeline == null) if (timeline == null)
return; return;
APIResponse apiResponse; APIResponse apiResponse;
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id, forAccount); apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id, forChannel != null ? forChannel.getAcct() : null);
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);

View File

@ -68,7 +68,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_status" android:id="@+id/lv_videos"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="none" /> android:scrollbars="none" />
@ -109,7 +109,7 @@
</RelativeLayout> </RelativeLayout>
<!-- Loader for next videos --> <!-- Loader for next videos -->
<RelativeLayout <RelativeLayout
android:id="@+id/loading_next_status" android:id="@+id/loading_next_videos"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"