Last fixes

This commit is contained in:
Thomas 2020-10-10 15:05:39 +02:00
parent bf119a5808
commit 8dddfc5497
7 changed files with 70 additions and 40 deletions

View File

@ -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<String> 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;
}

View File

@ -1004,7 +1004,6 @@ public class RetrofitPeertubeAPI {
try {
Response<ChannelData> response = channelDataCall.execute();
if (response.isSuccessful() && response.body() != null) {
apiResponse.setChannels(response.body().data);
} else {
setError(apiResponse, response.code(), response.errorBody());

View File

@ -68,13 +68,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private List<VideoData.Video> videos;
private Context context;
private TimelineVM.TimelineType timelineType;
private boolean sepiaSearch;
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType) {
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType, boolean sepiaSearch) {
this.videos = videos;
this.timelineType = timelineType;
this.sepiaSearch = sepiaSearch || timelineType == SEPIA_SEARCH;
}
public PeertubeAdapter(List<VideoData.Video> videos) {
this.videos = videos;
}
@ -111,7 +115,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
String instance = null;
if( timelineType == SEPIA_SEARCH) {
if( sepiaSearch) {
instance = video.getAccount().getHost();
}
@ -146,7 +150,10 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Intent intent = new Intent(context, ShowChannelActivity.class);
Bundle b = new Bundle();
b.putParcelable("channel", video.getChannel());
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
b.putBoolean("sepia_search", sepiaSearch);
if( sepiaSearch) {
b.putString("peertube_instance", video.getAccount().getHost());
}
intent.putExtras(b);
context.startActivity(intent);
});
@ -254,8 +261,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
if( timelineType == SEPIA_SEARCH) {
b.putBoolean("sepia_search", sepiaSearch);
if( sepiaSearch) {
b.putString("peertube_instance", video.getAccount().getHost());
}
intent.putExtras(b);
@ -267,8 +274,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
if( timelineType == SEPIA_SEARCH) {
b.putBoolean("sepia_search", sepiaSearch);
if( sepiaSearch) {
b.putString("peertube_instance", video.getAccount().getHost());
}
intent.putExtras(b);

View File

@ -100,7 +100,7 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH, true);
lv_status.setAdapter(peertubeAdapater);
@ -218,7 +218,7 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
this.peertubes.addAll(videoData.data);
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH, true);
lv_status.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, videoData.data.size());

View File

@ -96,7 +96,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> 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);

View File

@ -43,13 +43,19 @@ public class ChannelsVM extends AndroidViewModel {
super(application);
}
public LiveData<APIResponse> get(RetrofitPeertubeAPI.DataType type, String element) {
public LiveData<APIResponse> 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<APIResponse> 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);

View File

@ -71,15 +71,27 @@ public class TimelineVM extends AndroidViewModel {
public LiveData<APIResponse> 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<APIResponse> 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);