Some changes

This commit is contained in:
Thomas 2020-10-08 17:16:42 +02:00
parent e96b9f7f02
commit e771153f35
8 changed files with 75 additions and 119 deletions

View File

@ -86,7 +86,7 @@
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".MyVideosActivity"
android:name=".VideosTimelineActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" />

View File

@ -148,8 +148,8 @@ public class MainActivity extends AppCompatActivity {
if (!Helper.isLoggedIn(MainActivity.this)) {
fm.beginTransaction().add(R.id.nav_host_fragment, recentFragment, "4").hide(recentFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, mostLikedFragment, "3").hide(trendingFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "2").hide(subscriptionFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, mostLikedFragment, "3").hide(mostLikedFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "2").hide(trendingFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, overviewFragment, "1").commit();
}
@ -304,21 +304,21 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
return true;
} else if (item.getItemId() == R.id.action_myvideos) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Intent intent = new Intent(MainActivity.this, VideosTimelineActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("type", TimelineVM.TimelineType.MY_VIDEOS);
intent.putExtras(bundle);
startActivity(intent);
return true;
} else if (item.getItemId() == R.id.action_history) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Intent intent = new Intent(MainActivity.this, VideosTimelineActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("type", TimelineVM.TimelineType.HISTORY);
intent.putExtras(bundle);
startActivity(intent);
return true;
} else if (item.getItemId() == R.id.action_most_liked) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Intent intent = new Intent(MainActivity.this, VideosTimelineActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("type", TimelineVM.TimelineType.MOST_LIKED);
intent.putExtras(bundle);

View File

@ -160,7 +160,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private String max_id;
private RecyclerView lv_comments;
private boolean flag_loading;
private boolean isMyVideo;
private List<Comment> comments;
private CommentListAdapter commentListAdapter;
@ -232,6 +232,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
videoId = b.getString("video_id", null);
videoUuid = b.getString("video_uuid", null);
isMyVideo = b.getBoolean("isMyVideo", false);
}
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
@ -368,7 +369,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(videoUuid).observe(PeertubeActivity.this, this::manageVIewVideo);
feedsViewModel.getVideo(videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
captionsViewModel.getCaptions(videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
}

View File

@ -21,10 +21,11 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
public class MyVideosActivity extends AppCompatActivity {
public class VideosTimelineActivity extends AppCompatActivity {
private TimelineVM.TimelineType type;
@ -43,8 +44,6 @@ public class MyVideosActivity extends AppCompatActivity {
if (type == TimelineVM.TimelineType.MY_VIDEOS) {
setTitle(R.string.my_videos);
} else if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
setTitle(R.string.subscriptions);
} else if (type == TimelineVM.TimelineType.HISTORY) {
setTitle(R.string.my_history);
} else if (type == TimelineVM.TimelineType.MOST_LIKED) {
@ -54,7 +53,7 @@ public class MyVideosActivity extends AppCompatActivity {
if (savedInstanceState == null) {
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("type", type);
bundle.putSerializable(Helper.TIMELINE_TYPE, type);
displayVideosFragment.setArguments(bundle);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.container, displayVideosFragment).commit();

View File

@ -64,7 +64,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
public RelationShipListener relationShipListener;
public PlaylistListener playlistListener;
public OwnerPlaylistsListener ownerPlaylistsListener;
private List<VideoData.Video> videos;
private Context context;
private TimelineVM.TimelineType timelineType;
@ -201,53 +200,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
break;
case R.id.action_playlist:
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(context);
builder.setTitle(R.string.modify_playlists);
List<PlaylistData.Playlist> ownerPlaylists = ownerPlaylistsListener.getOwnerPlaylists();
if( ownerPlaylists == null){
return false;
}
String[] label = new String[ownerPlaylists.size()];
boolean[] checked = new boolean[ownerPlaylists.size()];
int i = 0;
List<PlaylistExist> playlistsForVideo = playlistListener.getPlaylist().get(video.getId());
for (PlaylistData.Playlist playlist : ownerPlaylists) {
checked[i] = false;
if (playlistsForVideo != null) {
for (PlaylistExist playlistExist : playlistsForVideo) {
if (playlistExist != null && playlistExist.getPlaylistId().compareTo(playlist.getId()) == 0) {
checked[i] = true;
break;
}
}
}
label[i] = playlist.getDisplayName();
i++;
}
builder.setMultiChoiceItems(label, checked, (dialog, which, isChecked) -> {
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
if (isChecked) { //Add to playlist
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, ownerPlaylistsListener.getOwnerPlaylists().get(which), video.getUuid()).observe((LifecycleOwner) context, apiResponse3 -> addElement(ownerPlaylistsListener.getOwnerPlaylists().get(which).getId(), video.getId(), apiResponse3));
} else { //Remove from playlist
String elementInPlaylistId = null;
for (PlaylistExist playlistExist : video.getPlaylistExists()) {
if (playlistExist.getPlaylistId().compareTo(ownerPlaylistsListener.getOwnerPlaylists().get(which).getId()) == 0) {
elementInPlaylistId = playlistExist.getPlaylistElementId();
}
}
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, ownerPlaylistsListener.getOwnerPlaylists().get(which), elementInPlaylistId);
playlistListener.getPlaylist().remove(video.getId());
}
});
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog dialog = builder.create();
dialog.show();
PlaylistsVM viewModelOwnerPlaylist = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
viewModelOwnerPlaylist.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPlaylists(video, apiResponse));
break;
case R.id.action_edit:
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
@ -290,6 +244,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Bundle b = new Bundle();
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
intent.putExtras(b);
context.startActivity(intent);
});
@ -298,12 +253,67 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Bundle b = new Bundle();
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
intent.putExtras(b);
context.startActivity(intent);
});
}
public void manageVIewPlaylists(VideoData.Video video, APIResponse apiResponse) {
if (apiResponse.getError() != null) {
return;
}
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(context);
builder.setTitle(R.string.modify_playlists);
List<PlaylistData.Playlist> ownerPlaylists = apiResponse.getPlaylists();
if( ownerPlaylists == null){
return;
}
String[] label = new String[ownerPlaylists.size()];
boolean[] checked = new boolean[ownerPlaylists.size()];
int i = 0;
List<PlaylistExist> playlistsForVideo = playlistListener.getPlaylist().get(video.getId());
for (PlaylistData.Playlist playlist : ownerPlaylists) {
checked[i] = false;
if (playlistsForVideo != null) {
for (PlaylistExist playlistExist : playlistsForVideo) {
if (playlistExist != null && playlistExist.getPlaylistId().compareTo(playlist.getId()) == 0) {
checked[i] = true;
break;
}
}
}
label[i] = playlist.getDisplayName();
i++;
}
builder.setMultiChoiceItems(label, checked, (dialog, which, isChecked) -> {
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
if (isChecked) { //Add to playlist
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, ownerPlaylists.get(which), video.getUuid()).observe((LifecycleOwner) context, apiResponse3 -> addElement(ownerPlaylists.get(which).getId(), video.getId(), apiResponse3));
} else { //Remove from playlist
String elementInPlaylistId = null;
for (PlaylistExist playlistExist : video.getPlaylistExists()) {
if (playlistExist.getPlaylistId().compareTo(ownerPlaylists.get(which).getId()) == 0) {
elementInPlaylistId = playlistExist.getPlaylistElementId();
}
}
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, ownerPlaylists.get(which), elementInPlaylistId);
playlistListener.getPlaylist().remove(video.getId());
}
});
builder.setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog dialog = builder.create();
dialog.show();
}
}
public void addElement(String playlistId, String videoId, APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getActionReturn() != null) {
@ -348,9 +358,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Map<String, List<PlaylistExist>> getPlaylist();
}
public interface OwnerPlaylistsListener {
List<PlaylistData.Playlist> getOwnerPlaylists();
}
static class ViewHolder extends RecyclerView.ViewHolder {

View File

@ -42,7 +42,6 @@ import java.util.Map;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.data.PlaylistData;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
@ -58,7 +57,7 @@ import static app.fedilab.fedilabtube.client.data.VideoData.Video.titleType.CHAN
import static app.fedilab.fedilabtube.client.data.VideoData.Video.titleType.TAG;
public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener, PeertubeAdapter.OwnerPlaylistsListener {
public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener {
private LinearLayoutManager mLayoutManager;
@ -77,7 +76,7 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
private TimelineVM viewModelFeeds;
private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> playlists;
private List<PlaylistData.Playlist> ownerPlaylists;
public DisplayOverviewFragment() {
}
@ -107,7 +106,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
peertubeAdapater.playlistListener = this;
peertubeAdapater.relationShipListener = this;
peertubeAdapater.ownerPlaylistsListener = this;
lv_status.setAdapter(peertubeAdapater);
@ -162,10 +160,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
}
});
if (Helper.isLoggedIn(context)) {
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(DisplayOverviewFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse));
}
return rootView;
}
@ -315,7 +309,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
peertubeAdapater = new PeertubeAdapter(this.peertubes);
peertubeAdapater.playlistListener = DisplayOverviewFragment.this;
peertubeAdapater.relationShipListener = DisplayOverviewFragment.this;
peertubeAdapater.ownerPlaylistsListener = DisplayOverviewFragment.this;
lv_status.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
@ -438,20 +431,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
relationship.putAll(apiResponse.getRelationships());
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
if (apiResponse.getError() != null) {
return;
}
if (actionType == PlaylistsVM.action.GET_PLAYLISTS) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
if (this.ownerPlaylists == null) {
this.ownerPlaylists = new ArrayList<>();
}
this.ownerPlaylists.addAll(apiResponse.getPlaylists());
}
}
}
@Override
public Map<String, Boolean> getRelationShip() {
return relationship;
@ -462,8 +441,4 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
return playlists;
}
@Override
public List<PlaylistData.Playlist> getOwnerPlaylists() {
return ownerPlaylists;
}
}

View File

@ -48,7 +48,6 @@ 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.PlaylistData;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
@ -63,7 +62,7 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import es.dmoral.toasty.Toasty;
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener, PeertubeAdapter.OwnerPlaylistsListener {
public class DisplayVideosFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener, PeertubeAdapter.RelationShipListener, PeertubeAdapter.PlaylistListener {
private LinearLayoutManager mLayoutManager;
@ -93,7 +92,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
private String channelId;
private Map<String, Boolean> relationship;
private Map<String, List<PlaylistExist>> playlists;
private List<PlaylistData.Playlist> ownerPlaylists;
private String playlistId;
public DisplayVideosFragment() {
@ -141,7 +139,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
peertubeAdapater.playlistListener = this;
peertubeAdapater.relationShipListener = this;
peertubeAdapater.ownerPlaylistsListener = this;
lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
@ -233,10 +230,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
}
if (Helper.isLoggedIn(context)) {
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(DisplayVideosFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse));
}
loadTimeline(max_id);
display_all.setOnClickListener(v -> {
forAccount = null;
@ -246,20 +239,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
}
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
if (apiResponse.getError() != null) {
return;
}
if (actionType == PlaylistsVM.action.GET_PLAYLISTS) {
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
if (this.ownerPlaylists == null) {
this.ownerPlaylists = new ArrayList<>();
}
this.ownerPlaylists.addAll(apiResponse.getPlaylists());
}
}
}
@Override
public void onPause() {
@ -356,7 +335,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
peertubeAdapater.playlistListener = DisplayVideosFragment.this;
peertubeAdapater.relationShipListener = DisplayVideosFragment.this;
peertubeAdapater.ownerPlaylistsListener = DisplayVideosFragment.this;
lv_status.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
@ -501,10 +479,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
return playlists;
}
@Override
public List<PlaylistData.Playlist> getOwnerPlaylists() {
return ownerPlaylists;
}
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {

View File

@ -51,9 +51,9 @@ public class TimelineVM extends AndroidViewModel {
}
public LiveData<APIResponse> getVideo(String videoId) {
public LiveData<APIResponse> getVideo(String videoId, boolean isMyVideo) {
apiResponseMutableLiveData = new MutableLiveData<>();
getSingle(videoId, false);
getSingle(videoId, isMyVideo);
return apiResponseMutableLiveData;
}