Fix channel filter for subscriptions

This commit is contained in:
Thomas 2020-10-10 09:25:00 +02:00
parent 3f1883fbbc
commit 23875a2ceb
8 changed files with 59 additions and 49 deletions

View File

@ -28,6 +28,7 @@ import android.widget.Spinner;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import com.mancj.materialsearchbar.MaterialSearchBar; import com.mancj.materialsearchbar.MaterialSearchBar;
@ -328,6 +329,10 @@ public class SepiaSearchActivity extends AppCompatActivity {
}else{ }else{
sepiaSearchVideo.setTagsAllOf(null); sepiaSearchVideo.setTagsAllOf(null);
} }
Fragment fragment = getSupportFragmentManager().findFragmentByTag("SEPIA_SEARCH");
if(fragment != null)
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
filter_elements.setVisibility(View.GONE); filter_elements.setVisibility(View.GONE);
sepiaSearchVideo.setSearch(searchBar.getText()); sepiaSearchVideo.setSearch(searchBar.getText());
DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment(); DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment();
@ -335,7 +340,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo); bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo);
displaySepiaSearchFragment.setArguments(bundle); displaySepiaSearchFragment.setArguments(bundle);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.container, displaySepiaSearchFragment).commit(); ft.add(R.id.container, displaySepiaSearchFragment,"SEPIA_SEARCH").commit();
} }
@Override @Override

View File

@ -288,7 +288,7 @@ public interface PeertubeService {
//Subscribe/Unsubscribe //Subscribe/Unsubscribe
//subscribers //subscribers
@GET("users/me/subscriptions") @GET("users/me/subscriptions")
Call<AccountData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count); Call<ChannelData> getSubscription(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
@GET("users/me/subscriptions/exist") @GET("users/me/subscriptions/exist")
Call<Map<String, Boolean>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris); Call<Map<String, Boolean>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris);

View File

@ -311,7 +311,7 @@ public class RetrofitPeertubeAPI {
return apiResponse; return apiResponse;
} }
public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id) { public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id, String forAccount) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<VideoData> videoCall = null; Call<VideoData> videoCall = null;
@ -321,7 +321,11 @@ public class RetrofitPeertubeAPI {
videoCall = peertubeService.getMyVideos(getToken(), max_id, count); videoCall = peertubeService.getMyVideos(getToken(), max_id, count);
break; break;
case SUBSCRIBTIONS: case SUBSCRIBTIONS:
videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, filter); if (forAccount == null) {
videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, count, filter);
} else {
videoCall = peertubeService.getChannelVideos(forAccount, max_id, count);
}
break; break;
case MOST_LIKED: case MOST_LIKED:
videoCall = peertubeService.getMostLikedVideos(max_id, count, filter); videoCall = peertubeService.getMostLikedVideos(max_id, count, filter);
@ -870,13 +874,13 @@ public class RetrofitPeertubeAPI {
*/ */
public APIResponse getSubscribtions(String maxId) { public APIResponse getSubscribtions(String maxId) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<AccountData> accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId, count); Call<ChannelData> channelDataCall = peertubeService.getSubscription("Bearer " + token, maxId, count);
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
if (accountDataCall != null) { if (channelDataCall != null) {
try { try {
Response<AccountData> response = accountDataCall.execute(); Response<ChannelData> response = channelDataCall.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setAccounts(response.body().data); apiResponse.setChannels(response.body().data);
} else { } else {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }

View File

@ -77,7 +77,7 @@ public class AccountData {
private String client_id; private String client_id;
private String client_secret; private String client_secret;
private String refresh_token; private String refresh_token;
private boolean selected;
public Account() { public Account() {
} }
@ -197,14 +197,6 @@ public class AccountData {
this.url = url; this.url = url;
} }
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public String getAcct() { public String getAcct() {
return name + "@" + host; return name + "@" + host;
} }

View File

@ -80,6 +80,7 @@ public class ChannelData {
@SerializedName("viewsPerDay") @SerializedName("viewsPerDay")
private List<ViewsPerDay> viewsPerDays; private List<ViewsPerDay> viewsPerDays;
private String acct; private String acct;
private boolean selected;
public Channel() { public Channel() {
} }
@ -243,6 +244,14 @@ public class ChannelData {
this.viewsPerDays = viewsPerDays; this.viewsPerDays = viewsPerDays;
} }
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -31,18 +31,18 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List; import java.util.List;
import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.AccountData.Account; import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
EventListener listener; EventListener listener;
private List<Account> accounts; private List<ChannelData.Channel> channels;
private Context context; private Context context;
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) { public AccountsHorizontalListAdapter(List<ChannelData.Channel> channels, EventListener listener) {
this.accounts = accounts; this.channels = channels;
this.listener = listener; this.listener = listener;
} }
@ -57,17 +57,17 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
final AccountsHorizontalListAdapter.ViewHolder holder = (AccountsHorizontalListAdapter.ViewHolder) viewHolder; final AccountsHorizontalListAdapter.ViewHolder holder = (AccountsHorizontalListAdapter.ViewHolder) viewHolder;
final Account account = accounts.get(position); final ChannelData.Channel channel = channels.get(position);
if (account.getDisplayName() != null && !account.getDisplayName().trim().equals("")) if (channel.getDisplayName() != null && !channel.getDisplayName().trim().equals(""))
holder.account_dn.setText(account.getDisplayName()); holder.account_dn.setText(channel.getDisplayName());
else else
holder.account_dn.setText(account.getUsername().replace("@", "")); holder.account_dn.setText(channel.getName().replace("@", ""));
//Profile picture //Profile picture
Helper.loadGiF(context, account.getAvatar() != null ? account.getAvatar().getPath() : null, holder.account_pp, 270); Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp, 270);
if (account.isSelected()) { if (channel.isSelected()) {
holder.main_container.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50)); holder.main_container.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50));
} else { } else {
holder.main_container.setBackgroundColor(Color.TRANSPARENT); holder.main_container.setBackgroundColor(Color.TRANSPARENT);
@ -82,7 +82,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override @Override
public int getItemCount() { public int getItemCount() {
return accounts.size(); return channels.size();
} }
@ -106,16 +106,16 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Account account = accounts.get(getAdapterPosition()); ChannelData.Channel channel = channels.get(getAdapterPosition());
listener.click(account.getId()); listener.click(channel.getAcct());
for (Account acc : accounts) { for (ChannelData.Channel acc : channels) {
if (acc.getId().compareTo(account.getId()) == 0) { if (acc.getId().compareTo(channel.getId()) == 0) {
acc.setSelected(true); acc.setSelected(true);
} else { } else {
acc.setSelected(false); acc.setSelected(false);
} }
} }
notifyItemRangeChanged(0, accounts.size()); notifyItemRangeChanged(0, channels.size());
} }
} }

View File

@ -47,7 +47,7 @@ import java.util.Map;
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.Account; 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;
@ -73,7 +73,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private AccountsHorizontalListAdapter accountsHorizontalListAdapter; private AccountsHorizontalListAdapter accountsHorizontalListAdapter;
private String max_id, max_id_accounts; private String max_id, max_id_accounts;
private List<VideoData.Video> peertubes; private List<VideoData.Video> peertubes;
private List<Account> accounts; private List<ChannelData.Channel> channels;
private TimelineVM.TimelineType type; private TimelineVM.TimelineType type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad; private boolean firstLoad;
@ -104,7 +104,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubes = new ArrayList<>(); peertubes = new ArrayList<>();
accounts = new ArrayList<>(); channels = new ArrayList<>();
context = getContext(); context = getContext();
Bundle bundle = this.getArguments(); Bundle bundle = this.getArguments();
if (bundle != null) { if (bundle != null) {
@ -140,7 +140,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubeAdapater.relationShipListener = this; peertubeAdapater.relationShipListener = this;
lv_status.setAdapter(peertubeAdapater); lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, 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); lv_accounts.setLayoutManager(layoutManager);
@ -281,13 +281,13 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private void manageViewAccounts(APIResponse apiResponse) { private void manageViewAccounts(APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) { if (apiResponse != null && apiResponse.getChannels() != null && apiResponse.getChannels().size() > 0) {
if (top_account_container.getVisibility() == View.GONE) { if (top_account_container.getVisibility() == View.GONE) {
top_account_container.setVisibility(View.VISIBLE); top_account_container.setVisibility(View.VISIBLE);
} }
int previousPosition = accounts.size(); int previousPosition = channels.size();
accounts.addAll(apiResponse.getAccounts()); channels.addAll(apiResponse.getChannels());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size()); accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getChannels().size());
if (max_id_accounts == null) { if (max_id_accounts == null) {
max_id_accounts = "0"; max_id_accounts = "0";
} }
@ -434,10 +434,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
max_id = "0"; max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size); peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) { if (forAccount == null) {
for (Account account : accounts) { for (ChannelData.Channel channel : channels) {
account.setSelected(false); channel.setSelected(false);
} }
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size()); accountsHorizontalListAdapter.notifyItemRangeRemoved(0, channels.size());
} }
loadTimeline("0"); loadTimeline("0");
} }
@ -461,7 +461,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
} else { } else {
viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos); viewModelFeeds.getVideos(type, max_id, forAccount).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

@ -38,9 +38,9 @@ public class TimelineVM extends AndroidViewModel {
super(application); super(application);
} }
public LiveData<APIResponse> getVideos(TimelineType action, String max_id) { public LiveData<APIResponse> getVideos(TimelineType action, String max_id, String forAccount) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
loadVideos(action, max_id); loadVideos(action, max_id, forAccount);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
@ -133,7 +133,7 @@ public class TimelineVM extends AndroidViewModel {
}).start(); }).start();
} }
private void loadVideos(TimelineType timeline, String max_id) { private void loadVideos(TimelineType timeline, String max_id, String forAccount) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
@ -141,7 +141,7 @@ public class TimelineVM extends AndroidViewModel {
if (timeline == null) if (timeline == null)
return; return;
APIResponse apiResponse; APIResponse apiResponse;
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id); apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id, forAccount);
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);