diff --git a/app/src/main/java/app/fedilab/fedilabtube/ShowChannelActivity.java b/app/src/main/java/app/fedilab/fedilabtube/ShowChannelActivity.java index b2433e0..3463a00 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/ShowChannelActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/ShowChannelActivity.java @@ -72,6 +72,7 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFO import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNEL; import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; +import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.SEPIA_SEARCH; public class ShowChannelActivity extends AppCompatActivity { @@ -87,6 +88,8 @@ public class ShowChannelActivity extends AppCompatActivity { private Channel channel; private action doAction; private String channelAcct; + private boolean sepiaSearch; + private String peertubeInstance; @Override protected void onCreate(Bundle savedInstanceState) { @@ -103,6 +106,9 @@ public class ShowChannelActivity extends AppCompatActivity { if (b != null) { channel = b.getParcelable("channel"); channelAcct = b.getString("channelId"); + sepiaSearch = b.getBoolean("sepia_search", false); + peertubeInstance = b.getString("peertube_instance", null); + } else { Toasty.error(ShowChannelActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show(); } @@ -116,14 +122,14 @@ public class ShowChannelActivity extends AppCompatActivity { ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class); - viewModel.get(CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts); + viewModel.get(sepiaSearch?peertubeInstance:null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts); manageChannel(); } @Override public boolean onCreateOptionsMenu(@NotNull Menu menu) { getMenuInflater().inflate(R.menu.main_account, menu); - if (!Helper.isLoggedIn(ShowChannelActivity.this)) { + if (!Helper.isLoggedIn(ShowChannelActivity.this) || sepiaSearch) { menu.findItem(R.id.action_mute).setVisible(false); } return true; @@ -163,7 +169,7 @@ public class ShowChannelActivity extends AppCompatActivity { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); String accountIdRelation = channel.getAcct(); - if (isLoggedIn(ShowChannelActivity.this)) { + if (isLoggedIn(ShowChannelActivity.this) && !sepiaSearch) { RelationshipVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(RelationshipVM.class); List uids = new ArrayList<>(); uids.add(accountIdRelation); @@ -239,7 +245,7 @@ public class ShowChannelActivity extends AppCompatActivity { manageNotes(channel); - Helper.loadGiF(ShowChannelActivity.this, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp); + Helper.loadGiF(ShowChannelActivity.this, sepiaSearch?peertubeInstance:null, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp); //Follow button String target = channel.getAcct(); @@ -412,21 +418,14 @@ public class ShowChannelActivity extends AppCompatActivity { @NotNull @Override public Fragment getItem(int position) { + DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment(); Bundle bundle = new Bundle(); - if (position == 0) { - DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment(); - bundle = new Bundle(); - bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.USER_VIDEOS); - bundle.putString("channelId", channel.getAcct()); - displayVideosFragment.setArguments(bundle); - return displayVideosFragment; - } - DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment(); - bundle.putString("targetedid", channel.getId()); - bundle.putString("instance", getLiveInstance(ShowChannelActivity.this)); - bundle.putString("name", channel.getAcct()); - displayAccountsFragment.setArguments(bundle); - return displayAccountsFragment; + bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.USER_VIDEOS); + bundle.putString("channelId", channel.getAcct()); + bundle.putString("peertube_instance", channel.getHost()); + bundle.putBoolean("sepia_search", sepiaSearch); + displayVideosFragment.setArguments(bundle); + return displayVideosFragment; } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index 4bc0e7e..afa1d30 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -1004,7 +1004,6 @@ public class RetrofitPeertubeAPI { try { Response response = channelDataCall.execute(); if (response.isSuccessful() && response.body() != null) { - apiResponse.setChannels(response.body().data); } else { setError(apiResponse, response.code(), response.errorBody()); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index 033ed51..da4c4ac 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -68,13 +68,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter videos; private Context context; private TimelineVM.TimelineType timelineType; + private boolean sepiaSearch; - public PeertubeAdapter(List videos, TimelineVM.TimelineType timelineType) { + + public PeertubeAdapter(List videos, TimelineVM.TimelineType timelineType, boolean sepiaSearch) { this.videos = videos; this.timelineType = timelineType; + this.sepiaSearch = sepiaSearch || timelineType == SEPIA_SEARCH; } + public PeertubeAdapter(List videos) { this.videos = videos; } @@ -111,7 +115,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter relationship; private Map> playlists; private String playlistId; - + private String remoteInstance; + private boolean sepiaSearch; public DisplayVideosFragment() { } @@ -113,6 +114,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta if (bundle != null) { search_peertube = bundle.getString("search_peertube", null); channelId = bundle.getString("channelId", null); + remoteInstance = bundle.getString("peertube_instance", null); + sepiaSearch = bundle.getBoolean("sepia_search", false); type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE); playlistId = bundle.getString("playlistId", null); } @@ -138,7 +141,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); - peertubeAdapater = new PeertubeAdapter(this.peertubes, type); + peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch); peertubeAdapater.playlistListener = this; peertubeAdapater.relationShipListener = this; lv_status.setAdapter(peertubeAdapater); @@ -334,7 +337,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta this.peertubes.addAll(apiResponse.getPeertubes()); //If no item were inserted previously the adapter is created if (previousPosition == 0) { - peertubeAdapater = new PeertubeAdapter(this.peertubes, type); + peertubeAdapater = new PeertubeAdapter(this.peertubes, type, sepiaSearch); peertubeAdapater.playlistListener = DisplayVideosFragment.this; peertubeAdapater.relationShipListener = DisplayVideosFragment.this; lv_status.setAdapter(peertubeAdapater); @@ -484,9 +487,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta 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); + viewModelFeeds.getVideosInChannel(sepiaSearch?remoteInstance:null, channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos); } else if (type == TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) { - viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos); } else { viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos); diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java index f950534..24d21d5 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java @@ -43,13 +43,19 @@ public class ChannelsVM extends AndroidViewModel { super(application); } - public LiveData get(RetrofitPeertubeAPI.DataType type, String element) { + public LiveData get(String instance, RetrofitPeertubeAPI.DataType type, String element) { apiResponseMutableLiveData = new MutableLiveData<>(); - getChannels(type, element); + getChannels(instance, type, element); return apiResponseMutableLiveData; } - private void getChannels(RetrofitPeertubeAPI.DataType type, String element) { + public LiveData get(RetrofitPeertubeAPI.DataType type, String element) { + apiResponseMutableLiveData = new MutableLiveData<>(); + getChannels(null, type, element); + return apiResponseMutableLiveData; + } + + private void getChannels(String instance, RetrofitPeertubeAPI.DataType type, String element) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { String finalElement = element; @@ -61,7 +67,12 @@ public class ChannelsVM extends AndroidViewModel { AccountData.Account account = new AccountDAO(_mContext, db).getAccountByToken(token); finalElement = account.getUsername() + "@" + account.getHost(); } - RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if( instance == null ) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + } else { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } APIResponse apiResponse = retrofitPeertubeAPI.getChannelData(type, finalElement); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java index 153d7e4..3ee0792 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java @@ -71,15 +71,27 @@ public class TimelineVM extends AndroidViewModel { public LiveData getVideosInChannel(String channelId, String max_id) { apiResponseMutableLiveData = new MutableLiveData<>(); - loadVideosForChannel(channelId, max_id); + loadVideosForChannel(null, channelId, max_id); return apiResponseMutableLiveData; } - private void loadVideosForChannel(String channelId, String max_id) { + + public LiveData getVideosInChannel(String instance, String channelId, String max_id) { + apiResponseMutableLiveData = new MutableLiveData<>(); + loadVideosForChannel(instance, channelId, max_id); + return apiResponseMutableLiveData; + } + + private void loadVideosForChannel(String instance, String channelId, String max_id) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if( instance == null) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + }else { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } APIResponse apiResponse = retrofitPeertubeAPI.getVideosForChannel(channelId, max_id); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);