Fix issue #115 - Filter with remote accounts does not work
This commit is contained in:
parent
7d9e299940
commit
b59d97279d
|
@ -11,8 +11,8 @@ android {
|
|||
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 27
|
||||
versionName "1.8.0"
|
||||
versionCode 28
|
||||
versionName "1.9.0-beta-1"
|
||||
multiDexEnabled true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ public class ShowAccountActivity extends AppCompatActivity {
|
|||
}
|
||||
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
||||
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.ACCOUNT_VIDEOS);
|
||||
bundle.putString("channelId", account.getAcct());
|
||||
bundle.putParcelable("account", account);
|
||||
bundle.putString("peertube_instance", account.getHost());
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
return displayVideosFragment;
|
||||
|
|
|
@ -493,7 +493,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
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.putBoolean("sepia_search", sepiaSearch);
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
|
|
|
@ -19,19 +19,13 @@ import android.graphics.Color;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.databinding.DrawerHorizontalAccountBinding;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
|
@ -50,8 +44,8 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
|
|||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
context = parent.getContext();
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_horizontal_account, parent, false));
|
||||
DrawerHorizontalAccountBinding itemBinding = DrawerHorizontalAccountBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||
return new ViewHolder(itemBinding);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,17 +54,17 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
|
|||
final ChannelData.Channel channel = channels.get(position);
|
||||
|
||||
if (channel.getDisplayName() != null && !channel.getDisplayName().trim().equals(""))
|
||||
holder.account_dn.setText(channel.getDisplayName());
|
||||
holder.binding.accountDn.setText(channel.getDisplayName());
|
||||
else
|
||||
holder.account_dn.setText(channel.getName().replace("@", ""));
|
||||
holder.binding.accountDn.setText(channel.getName().replace("@", ""));
|
||||
|
||||
//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()) {
|
||||
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 {
|
||||
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 {
|
||||
void click(String forAccount);
|
||||
void click(ChannelData.Channel channel);
|
||||
}
|
||||
|
||||
|
||||
private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
ImageView account_pp;
|
||||
TextView account_dn;
|
||||
LinearLayout main_container;
|
||||
DrawerHorizontalAccountBinding binding;
|
||||
|
||||
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
|
||||
public void onClick(View v) {
|
||||
ChannelData.Channel channel = channels.get(getAdapterPosition());
|
||||
listener.click(channel.getAcct());
|
||||
listener.click(channel);
|
||||
for (ChannelData.Channel acc : channels) {
|
||||
acc.setSelected(acc.getId().compareTo(channel.getId()) == 0);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.fedilabtube.BuildConfig;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.SepiaSearch;
|
||||
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||
|
@ -279,7 +280,7 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
|
|||
}
|
||||
|
||||
@Override
|
||||
public void click(String forAccount) {
|
||||
public void click(ChannelData.Channel forChannel) {
|
||||
pullToRefresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,20 +23,16 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
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;
|
||||
|
||||
|
@ -50,10 +46,12 @@ import app.fedilab.fedilabtube.MainActivity;
|
|||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
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.VideoData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
||||
import app.fedilab.fedilabtube.databinding.FragmentVideoBinding;
|
||||
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
@ -80,27 +78,23 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
private List<VideoData.Video> peertubes;
|
||||
private List<ChannelData.Channel> channels;
|
||||
private TimelineVM.TimelineType type;
|
||||
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;
|
||||
private boolean check_ScrollingUp;
|
||||
private String forAccount;
|
||||
private ConstraintLayout top_account_container;
|
||||
private ChannelData.Channel forChannel;
|
||||
private TimelineVM viewModelFeeds;
|
||||
private SearchVM viewModelSearch;
|
||||
private AccountsVM viewModelAccounts;
|
||||
private String channelId;
|
||||
private ChannelData.Channel channel;
|
||||
private AccountData.Account account;
|
||||
private Map<String, Boolean> relationship;
|
||||
private Map<String, List<PlaylistExist>> playlists;
|
||||
private String playlistId;
|
||||
private String remoteInstance;
|
||||
private boolean sepiaSearch;
|
||||
private String startDate, endDate;
|
||||
private FragmentVideoBinding binding;
|
||||
private String channelId;
|
||||
|
||||
public DisplayVideosFragment() {
|
||||
}
|
||||
|
@ -108,9 +102,14 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
|
||||
@Override
|
||||
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<>();
|
||||
channels = new ArrayList<>();
|
||||
context = getContext();
|
||||
|
@ -119,7 +118,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
Bundle bundle = this.getArguments();
|
||||
if (bundle != 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);
|
||||
sepiaSearch = bundle.getBoolean("sepia_search", false);
|
||||
type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE);
|
||||
|
@ -127,54 +127,48 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
startDate = bundle.getString("startDate", null);
|
||||
endDate = bundle.getString("endDate", null);
|
||||
}
|
||||
if (channel != null) {
|
||||
channelId = channel.getAcct();
|
||||
} else if (account != null) {
|
||||
channelId = account.getAcct();
|
||||
}
|
||||
|
||||
max_id = "0";
|
||||
forAccount = 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);
|
||||
// forChannel = type == TimelineVM.TimelineType.ACCOUNT_VIDEOS ? channelId : null;
|
||||
max_id_accounts = null;
|
||||
flag_loading = true;
|
||||
firstLoad = true;
|
||||
check_ScrollingUp = false;
|
||||
|
||||
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);
|
||||
binding.loader.setVisibility(View.VISIBLE);
|
||||
binding.loadingNextVideos.setVisibility(View.GONE);
|
||||
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch);
|
||||
peertubeAdapater.playlistListener = this;
|
||||
peertubeAdapater.relationShipListener = this;
|
||||
lv_status.setAdapter(peertubeAdapater);
|
||||
binding.lvVideos.setAdapter(peertubeAdapater);
|
||||
|
||||
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.channels, this);
|
||||
LinearLayoutManager layoutManager
|
||||
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
|
||||
lv_accounts.setLayoutManager(layoutManager);
|
||||
lv_accounts.setAdapter(accountsHorizontalListAdapter);
|
||||
binding.lvAccounts.setLayoutManager(layoutManager);
|
||||
binding.lvAccounts.setAdapter(accountsHorizontalListAdapter);
|
||||
if (!Helper.isTablet(context)) {
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_status.setLayoutManager(mLayoutManager);
|
||||
binding.lvVideos.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);
|
||||
binding.lvVideos.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
|
||||
binding.lvVideos.setLayoutManager(gLayoutManager);
|
||||
}
|
||||
viewModelAccounts = new ViewModelProvider(DisplayVideosFragment.this).get(AccountsVM.class);
|
||||
viewModelFeeds = new ViewModelProvider(DisplayVideosFragment.this).get(TimelineVM.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) {
|
||||
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
||||
if (dy > 0) {
|
||||
|
@ -189,19 +183,19 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
|
||||
|
||||
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) {
|
||||
if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
|
||||
if (dy > 0) {
|
||||
if (check_ScrollingUp) {
|
||||
top_account_container.setVisibility(View.GONE);
|
||||
binding.topAccountContainer.setVisibility(View.GONE);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(() -> check_ScrollingUp = false, 300);
|
||||
|
||||
}
|
||||
} else {
|
||||
if (!check_ScrollingUp) {
|
||||
top_account_container.setVisibility(View.VISIBLE);
|
||||
binding.topAccountContainer.setVisibility(View.VISIBLE);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(() -> check_ScrollingUp = true, 300);
|
||||
}
|
||||
|
@ -216,10 +210,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
loadTimeline(max_id);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
binding.loadingNextVideos.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
binding.loadingNextVideos.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
} else if (gLayoutManager != null) {
|
||||
|
@ -231,10 +225,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
loadTimeline(max_id);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
binding.loadingNextVideos.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
loadTimeline(max_id);
|
||||
display_all.setOnClickListener(v -> {
|
||||
forAccount = null;
|
||||
binding.displayAll.setOnClickListener(v -> {
|
||||
forChannel = null;
|
||||
pullToRefresh(false);
|
||||
});
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
swipeRefreshLayout.setEnabled(true);
|
||||
binding.swipeContainer.setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setEnabled(false);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
swipeRefreshLayout.clearAnimation();
|
||||
if (binding.swipeContainer != null) {
|
||||
binding.swipeContainer.setEnabled(false);
|
||||
binding.swipeContainer.setRefreshing(false);
|
||||
binding.swipeContainer.clearAnimation();
|
||||
}
|
||||
if (getActivity() != null) {
|
||||
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) {
|
||||
if (apiResponse != null && apiResponse.getChannels() != null && apiResponse.getChannels().size() > 0) {
|
||||
if (top_account_container.getVisibility() == View.GONE) {
|
||||
top_account_container.setVisibility(View.VISIBLE);
|
||||
if (binding.topAccountContainer.getVisibility() == View.GONE) {
|
||||
binding.topAccountContainer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
int previousPosition = channels.size();
|
||||
channels.addAll(apiResponse.getChannels());
|
||||
|
@ -312,6 +305,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
if (max_id_accounts == null) {
|
||||
max_id_accounts = "0";
|
||||
}
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//max_id_accounts needs to work like an offset
|
||||
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
|
||||
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) {
|
||||
//hide loaders
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
binding.loadingNextVideos.setVisibility(View.GONE);
|
||||
//handle other API error
|
||||
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) {
|
||||
if (apiResponse == null)
|
||||
|
@ -330,7 +324,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
else {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
binding.swipeContainer.setRefreshing(false);
|
||||
flag_loading = false;
|
||||
return;
|
||||
}
|
||||
|
@ -338,6 +332,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
if (max_id == null)
|
||||
max_id = "0";
|
||||
//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);
|
||||
max_id = String.valueOf(Integer.parseInt(max_id) + videoPerPage);
|
||||
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.playlistListener = DisplayVideosFragment.this;
|
||||
peertubeAdapater.relationShipListener = DisplayVideosFragment.this;
|
||||
lv_status.setAdapter(peertubeAdapater);
|
||||
binding.lvVideos.setAdapter(peertubeAdapater);
|
||||
} else
|
||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
|
||||
//remove handlers
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
binding.swipeContainer.setRefreshing(false);
|
||||
binding.noAction.setVisibility(View.GONE);
|
||||
if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) {
|
||||
textviewNoActionText.setText(R.string.no_video_to_display);
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
binding.noActionText.setText(R.string.no_video_to_display);
|
||||
binding.noAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
flag_loading = false;
|
||||
firstLoad = false;
|
||||
|
@ -438,14 +433,13 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (lv_status != null) {
|
||||
if (binding.lvVideos != null) {
|
||||
try {
|
||||
lv_status.setAdapter(null);
|
||||
binding.lvVideos.setAdapter(null);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
super.onDestroyView();
|
||||
rootView = null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -471,7 +465,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
peertubes = new ArrayList<>();
|
||||
max_id = "0";
|
||||
peertubeAdapater.notifyItemRangeRemoved(0, size);
|
||||
if (forAccount == null) {
|
||||
if (forChannel == null) {
|
||||
for (ChannelData.Channel channel : channels) {
|
||||
channel.setSelected(false);
|
||||
}
|
||||
|
@ -483,8 +477,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
}
|
||||
|
||||
@Override
|
||||
public void click(String forAccount) {
|
||||
this.forAccount = forAccount;
|
||||
public void click(ChannelData.Channel forChannel) {
|
||||
this.forChannel = forChannel;
|
||||
pullToRefresh(false);
|
||||
}
|
||||
|
||||
|
@ -504,7 +498,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
} else if (type == TimelineVM.TimelineType.HISTORY) {
|
||||
viewModelFeeds.getVideoHistory(max_id, startDate, endDate).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
viewModelFeeds.getVideos(type, max_id, forChannel).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
} else {
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.ManagePlaylistsDAO;
|
||||
|
@ -45,9 +46,9 @@ public class TimelineVM extends AndroidViewModel {
|
|||
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<>();
|
||||
loadVideos(action, max_id, forAccount);
|
||||
loadVideos(action, max_id, forChannel);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
@ -189,15 +190,20 @@ public class TimelineVM extends AndroidViewModel {
|
|||
}).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();
|
||||
new Thread(() -> {
|
||||
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)
|
||||
return;
|
||||
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());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_status"
|
||||
android:id="@+id/lv_videos"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none" />
|
||||
|
@ -109,7 +109,7 @@
|
|||
</RelativeLayout>
|
||||
<!-- Loader for next videos -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_next_status"
|
||||
android:id="@+id/loading_next_videos"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
|
|
Loading…
Reference in New Issue