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

View File

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

View File

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

View File

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

View File

@ -31,18 +31,18 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
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;
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
EventListener listener;
private List<Account> accounts;
private List<ChannelData.Channel> channels;
private Context context;
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) {
this.accounts = accounts;
public AccountsHorizontalListAdapter(List<ChannelData.Channel> channels, EventListener listener) {
this.channels = channels;
this.listener = listener;
}
@ -57,17 +57,17 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
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(""))
holder.account_dn.setText(account.getDisplayName());
if (channel.getDisplayName() != null && !channel.getDisplayName().trim().equals(""))
holder.account_dn.setText(channel.getDisplayName());
else
holder.account_dn.setText(account.getUsername().replace("@", ""));
holder.account_dn.setText(channel.getName().replace("@", ""));
//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));
} else {
holder.main_container.setBackgroundColor(Color.TRANSPARENT);
@ -82,7 +82,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override
public int getItemCount() {
return accounts.size();
return channels.size();
}
@ -106,16 +106,16 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
@Override
public void onClick(View v) {
Account account = accounts.get(getAdapterPosition());
listener.click(account.getId());
for (Account acc : accounts) {
if (acc.getId().compareTo(account.getId()) == 0) {
ChannelData.Channel channel = channels.get(getAdapterPosition());
listener.click(channel.getAcct());
for (ChannelData.Channel acc : channels) {
if (acc.getId().compareTo(channel.getId()) == 0) {
acc.setSelected(true);
} else {
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.client.APIResponse;
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.VideoPlaylistData;
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
@ -73,7 +73,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private AccountsHorizontalListAdapter accountsHorizontalListAdapter;
private String max_id, max_id_accounts;
private List<VideoData.Video> peertubes;
private List<Account> accounts;
private List<ChannelData.Channel> channels;
private TimelineVM.TimelineType type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
@ -104,7 +104,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubes = new ArrayList<>();
accounts = new ArrayList<>();
channels = new ArrayList<>();
context = getContext();
Bundle bundle = this.getArguments();
if (bundle != null) {
@ -140,7 +140,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubeAdapater.relationShipListener = this;
lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.channels, this);
LinearLayoutManager layoutManager
= new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lv_accounts.setLayoutManager(layoutManager);
@ -281,13 +281,13 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
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) {
top_account_container.setVisibility(View.VISIBLE);
}
int previousPosition = accounts.size();
accounts.addAll(apiResponse.getAccounts());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size());
int previousPosition = channels.size();
channels.addAll(apiResponse.getChannels());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getChannels().size());
if (max_id_accounts == null) {
max_id_accounts = "0";
}
@ -434,10 +434,10 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) {
for (Account account : accounts) {
account.setSelected(false);
for (ChannelData.Channel channel : channels) {
channel.setSelected(false);
}
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, channels.size());
}
loadTimeline("0");
}
@ -461,7 +461,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
} else {
viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos);
viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
}
} else {
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);

View File

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