some changes

This commit is contained in:
Thomas 2020-09-26 10:22:11 +02:00
parent 618384cccb
commit 55179c6955
14 changed files with 313 additions and 205 deletions

View File

@ -164,7 +164,7 @@ public class MainActivity extends AppCompatActivity {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance); Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance);
if (account != null) { if (account != null) {
new Thread(() -> new RetrofitPeertubeAPI(MainActivity.this).refreshToken(account.getToken(), account.getHost())).start(); new Thread(() -> new RetrofitPeertubeAPI(MainActivity.this).refreshToken(account.getClient_id(), account.getClient_secret(),account.getToken())).start();
} }
} else { } else {
instanceItem.setVisible(true); instanceItem.setVisible(true);
@ -205,14 +205,14 @@ public class MainActivity extends AppCompatActivity {
} else if (item.getItemId() == R.id.action_myvideos) { } else if (item.getItemId() == R.id.action_myvideos) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class); Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable("type", TimelineVM.Type.MYVIDEOS); bundle.putSerializable("type", TimelineVM.TimelineType.MY_VIDEOS);
intent.putExtras(bundle); intent.putExtras(bundle);
startActivity(intent); startActivity(intent);
return true; return true;
} else if (item.getItemId() == R.id.action_history) { } else if (item.getItemId() == R.id.action_history) {
Intent intent = new Intent(MainActivity.this, MyVideosActivity.class); Intent intent = new Intent(MainActivity.this, MyVideosActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable("type", TimelineVM.Type.PEERTUBE_HISTORY); bundle.putSerializable("type", TimelineVM.TimelineType.HISTORY);
intent.putExtras(bundle); intent.putExtras(bundle);
startActivity(intent); startActivity(intent);
return true; return true;

View File

@ -26,7 +26,7 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM;
public class MyVideosActivity extends AppCompatActivity { public class MyVideosActivity extends AppCompatActivity {
private TimelineVM.Type type; private TimelineVM.TimelineType type;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -39,13 +39,13 @@ public class MyVideosActivity extends AppCompatActivity {
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
if (b != null) if (b != null)
type = (TimelineVM.Type) b.get("type"); type = (TimelineVM.TimelineType) b.get("type");
if (type == TimelineVM.Type.MYVIDEOS) { if (type == TimelineVM.TimelineType.MY_VIDEOS) {
setTitle(R.string.my_videos); setTitle(R.string.my_videos);
} else if (type == TimelineVM.Type.PSUBSCRIPTIONS) { } else if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) {
setTitle(R.string.subscriptions); setTitle(R.string.subscriptions);
} else if (type == TimelineVM.Type.PEERTUBE_HISTORY) { } else if (type == TimelineVM.TimelineType.HISTORY) {
setTitle(R.string.my_history); setTitle(R.string.my_history);
} }

View File

@ -82,27 +82,23 @@ import com.google.android.exoplayer2.util.Util;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import javax.net.ssl.HttpsURLConnection;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.TLSSocketFactory; import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.data.AccountData; import app.fedilab.fedilabtube.client.data.CaptionData.Caption;
import app.fedilab.fedilabtube.client.data.CommentData; import app.fedilab.fedilabtube.client.data.CommentData.Comment;
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.Caption;
import app.fedilab.fedilabtube.client.entities.File; import app.fedilab.fedilabtube.client.entities.File;
import app.fedilab.fedilabtube.client.entities.Playlist; import app.fedilab.fedilabtube.client.entities.PlaylistParams;
import app.fedilab.fedilabtube.client.entities.PlaylistElement; import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.drawer.CommentListAdapter; import app.fedilab.fedilabtube.drawer.CommentListAdapter;
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory; import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
import app.fedilab.fedilabtube.helper.FullScreenMediaController; import app.fedilab.fedilabtube.helper.FullScreenMediaController;
@ -122,7 +118,7 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.helper.Helper.getAttColor; import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance; import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST; import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS;
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST_FOR_VIDEO; import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST_FOR_VIDEO;
@ -146,7 +142,7 @@ public class PeertubeActivity extends AppCompatActivity {
private ImageView send; private ImageView send;
private TextView add_comment_read; private TextView add_comment_read;
private EditText add_comment_write; private EditText add_comment_write;
private List<PlaylistElement> playlistForVideo; private List<PlaylistParams> playlistForVideo;
private List<Playlist> playlists; private List<Playlist> playlists;
private PlaylistsVM playlistsViewModel; private PlaylistsVM playlistsViewModel;
private boolean playInMinimized; private boolean playInMinimized;
@ -190,7 +186,7 @@ public class PeertubeActivity extends AppCompatActivity {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(PeertubeActivity.this); String instance = Helper.getLiveInstance(PeertubeActivity.this);
AccountData.Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance); Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance);
Helper.loadGiF(PeertubeActivity.this, account.getAvatar().getPath(), my_pp); Helper.loadGiF(PeertubeActivity.this, account.getAvatar().getPath(), my_pp);
@ -212,7 +208,7 @@ public class PeertubeActivity extends AppCompatActivity {
playlistForVideo = new ArrayList<>(); playlistForVideo = new ArrayList<>();
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
if (Helper.isLoggedIn(PeertubeActivity.this)) { if (Helper.isLoggedIn(PeertubeActivity.this)) {
playlistsViewModel.manage(GET_PLAYLIST, null, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLIST, apiResponse)); playlistsViewModel.manage(GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLISTS, apiResponse));
} }
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
if (b != null) { if (b != null) {
@ -308,7 +304,7 @@ public class PeertubeActivity extends AppCompatActivity {
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewVideo); feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class); CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
captionsViewModel.getCaptions(videoId).observe(PeertubeActivity.this, this::manageCaptions); captionsViewModel.getCaptions(videoId).observe(PeertubeActivity.this, this::manageCaptions);
@ -375,14 +371,14 @@ public class PeertubeActivity extends AppCompatActivity {
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create(); androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show(); alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.VIDEO, alertDialog)); report_video.setOnClickListener(v -> reportAlert(RetrofitPeertubeAPI.reportType.VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.ACCOUNT, alertDialog)); report_account.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.ACCOUNT, alertDialog));
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void reportAlert(PeertubeAPI.reportType type, androidx.appcompat.app.AlertDialog alertDialog) { private void reportAlert(RetrofitPeertubeAPI.ActionType type, androidx.appcompat.app.AlertDialog alertDialog) {
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this); androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater(); LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(PeertubeActivity.this), false); View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(PeertubeActivity.this), false);
@ -393,14 +389,23 @@ public class PeertubeActivity extends AppCompatActivity {
if (report_content.getText().toString().trim().length() == 0) { if (report_content.getText().toString().trim().length() == 0) {
Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show(); Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
} else { } else {
if (type == PeertubeAPI.reportType.VIDEO) { PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); if (type == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
viewModel.post(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_VIDEO, apiResponse)); Report report = new Report();
Report.VideoReport videoReport = new Report.VideoReport();
videoReport.setId(peertube.getId());
report.setVideo(videoReport);
report.setReason(report_content.getText().toString());
viewModel.report(report).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, apiResponse));
alertDialog.dismiss(); alertDialog.dismiss();
dialog.dismiss(); dialog.dismiss();
} else if (type == PeertubeAPI.reportType.ACCOUNT) { } else if (type == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); Report report = new Report();
viewModel.post(RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse)); Report.AccountReport accountReport = new Report.AccountReport();
accountReport.setId(peertube.getAccount().getId());
report.setAccount(accountReport);
report.setReason(report_content.getText().toString());
viewModel.report(report).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT, apiResponse));
alertDialog.dismiss(); alertDialog.dismiss();
dialog.dismiss(); dialog.dismiss();
} }
@ -443,7 +448,7 @@ public class PeertubeActivity extends AppCompatActivity {
peertube = apiResponse.getPeertubes().get(0); peertube = apiResponse.getPeertubes().get(0);
//TODO: currently streaming service gives the wrong values for duration //TODO: currently streaming service gives the wrong values for duration
playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2)); playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId()).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2));
add_comment_read.setOnClickListener(v -> { add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
@ -483,8 +488,8 @@ public class PeertubeActivity extends AppCompatActivity {
String title = null; String title = null;
boolean isPresent = false; boolean isPresent = false;
String elementId = null; String elementId = null;
PlaylistElement playlistElementFinal = null; PlaylistParams playlistElementFinal = null;
for (PlaylistElement playlistElement : playlistForVideo) { for (PlaylistParams playlistElement : playlistForVideo) {
if (playlist.getId().equals(playlistElement.getPlaylistId())) { if (playlist.getId().equals(playlistElement.getPlaylistId())) {
title = "" + playlist.getDisplayName(); title = "" + playlist.getDisplayName();
isPresent = true; isPresent = true;
@ -499,7 +504,7 @@ public class PeertubeActivity extends AppCompatActivity {
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title); MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
boolean finalIsPresent = isPresent; boolean finalIsPresent = isPresent;
String finalElementId = elementId; String finalElementId = elementId;
PlaylistElement finalPlaylistElementFinal = playlistElementFinal; PlaylistParams finalPlaylistElementFinal = playlistElementFinal;
item.setOnMenuItemClickListener(item1 -> { item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this)); item1.setActionView(new View(PeertubeActivity.this));
@ -516,12 +521,12 @@ public class PeertubeActivity extends AppCompatActivity {
}); });
if (finalIsPresent) { if (finalIsPresent) {
item1.setTitle(playlist.getDisplayName()); item1.setTitle(playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId, null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3)); playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
playlistForVideo.remove(finalPlaylistElementFinal); playlistForVideo.remove(finalPlaylistElementFinal);
} else { } else {
item1.setTitle("" + playlist.getDisplayName()); item1.setTitle("" + playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3)); playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId()).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
PlaylistElement playlistElement = new PlaylistElement(); PlaylistParams playlistElement = new PlaylistParams();
playlistElement.setPlaylistElementId(null); playlistElement.setPlaylistElementId(null);
playlistElement.setPlaylistId(playlist.getId()); playlistElement.setPlaylistId(playlist.getId());
playlistForVideo.add(playlistElement); playlistForVideo.add(playlistElement);
@ -583,7 +588,7 @@ public class PeertubeActivity extends AppCompatActivity {
if (isLoggedIn(PeertubeActivity.this)) { if (isLoggedIn(PeertubeActivity.this)) {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
viewModel.post(RetrofitPeertubeAPI.ActionType.RATEVIDEO, peertube.getId(), newState, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1)); viewModel.post(RetrofitPeertubeAPI.ActionType.RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1));
peertube.setMyRating(newState); peertube.setMyRating(newState);
int count = Integer.parseInt(peertube_dislike_count.getText().toString()); int count = Integer.parseInt(peertube_dislike_count.getText().toString());
if (newState.compareTo("none") == 0) { if (newState.compareTo("none") == 0) {
@ -601,11 +606,7 @@ public class PeertubeActivity extends AppCompatActivity {
} }
}); });
try {
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
} catch (KeyManagementException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
if (mode == Helper.VIDEO_MODE_NORMAL) { if (mode == Helper.VIDEO_MODE_NORMAL) {
@ -797,8 +798,8 @@ public class PeertubeActivity extends AppCompatActivity {
Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return; return;
} }
List<CommentData.Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
for (CommentData.Comment comment : apiResponse.getComments()) { for (Comment comment : apiResponse.getComments()) {
if (comment.getDescription() != null && comment.getDescription().trim().length() > 0) { if (comment.getDescription() != null && comment.getDescription().trim().length() > 0) {
comments.add(comment); comments.add(comment);
} }
@ -941,15 +942,15 @@ public class PeertubeActivity extends AppCompatActivity {
} }
@SuppressWarnings({"unused", "RedundantSuppression"}) @SuppressWarnings({"unused", "RedundantSuppression"})
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) { public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) { if (peertube.isCommentsEnabled() && statusAction == RetrofitPeertubeAPI.ActionType.PEERTUBECOMMENT) {
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getComment(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewComment); commentViewModel.getComment(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewComment);
} else if (statusAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) { } else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show(); Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
} else if (statusAction == PeertubeAPI.StatusAction.REPORT_VIDEO) { } else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show(); Toasty.success(PeertubeActivity.this, getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show();
} }
} }
@ -1000,7 +1001,7 @@ public class PeertubeActivity extends AppCompatActivity {
private void initResolution() { private void initResolution() {
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution); resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp", peertube.getResolution().get(0))); resolution.setText(String.format("%sp", peertube.getFiles().get(0).getResolutions().getLabel()));
resolution.setOnClickListener(v -> displayResolution()); resolution.setOnClickListener(v -> displayResolution());
} }
@ -1037,7 +1038,7 @@ public class PeertubeActivity extends AppCompatActivity {
if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) { if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
playlistForVideo = apiResponse.getPlaylistForVideos(); playlistForVideo = apiResponse.getPlaylistForVideos();
} else if (actionType == GET_PLAYLIST && apiResponse != null) { } else if (actionType == GET_PLAYLISTS && apiResponse != null) {
playlists = apiResponse.getPlaylists(); playlists = apiResponse.getPlaylists();
} }
} }

View File

@ -49,7 +49,6 @@ import net.gotev.uploadservice.UploadStatusDelegate;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -57,17 +56,23 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData.Account; import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.entities.Peertube; import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
import app.fedilab.fedilabtube.client.data.VideoData.Video;
import app.fedilab.fedilabtube.client.entities.Item;
import app.fedilab.fedilabtube.client.entities.VideoParams;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import app.fedilab.fedilabtube.viewmodel.MyVideoVM;
import app.fedilab.fedilabtube.viewmodel.TimelineVM; import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
import mabbas007.tagsedittext.TagsEditText; import mabbas007.tagsedittext.TagsEditText;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.PEERTUBEDELETEVIDEO;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS;
public class PeertubeEditUploadActivity extends AppCompatActivity { public class PeertubeEditUploadActivity extends AppCompatActivity {
@ -75,11 +80,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
private final int PICK_IMAGE = 50378; private final int PICK_IMAGE = 50378;
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724; private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
HashMap<Integer, String> categoryToSend;
HashMap<Integer, String> licenseToSend;
HashMap<Integer, String> privacyToSend;
HashMap<String, String> languageToSend;
HashMap<String, String> channelToSend;
private Button set_upload_submit; private Button set_upload_submit;
private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel; private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel;
private EditText p_video_title, p_video_description; private EditText p_video_title, p_video_description;
@ -87,10 +87,13 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
private CheckBox set_upload_nsfw, set_upload_enable_comments; private CheckBox set_upload_nsfw, set_upload_enable_comments;
private LinkedHashMap<String, String> channels; private LinkedHashMap<String, String> channels;
private String videoId; private String videoId;
private Account channel; private Channel channel;
private ImageView p_video_preview; private ImageView p_video_preview;
private Button set_preview; private Button set_preview;
private Peertube peertube; private VideoParams videoParams;
private Video video;
private String channelToSendId;
Item languageToSend, licenseToSend, privacyToSend, categoryToSend;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -131,7 +134,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
PostActionsVM viewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(PostActionsVM.class); PostActionsVM viewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(PostActionsVM.class);
viewModel.post(PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, null, null).observe(PeertubeEditUploadActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, apiResponse)); viewModel.post(PEERTUBEDELETEVIDEO, videoId, null).observe(PeertubeEditUploadActivity.this, apiResponse -> manageVIewPostActions(PEERTUBEDELETEVIDEO, apiResponse));
dialog.dismiss(); dialog.dismiss();
}); });
builderInner.show(); builderInner.show();
@ -218,9 +221,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
set_upload_privacy.setAdapter(adapterPrivacies); set_upload_privacy.setAdapter(adapterPrivacies);
String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this);
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); feedsViewModel.getVideo(videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
channels = new LinkedHashMap<>(); channels = new LinkedHashMap<>();
setTitle(R.string.edit_video); setTitle(R.string.edit_video);
@ -238,25 +240,18 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
} }
//Peertube video //Peertube video
peertube = apiResponse.getPeertubes().get(0); video = apiResponse.getPeertubes().get(0);
if (peertube.isUpdate()) { ChannelsVM viewModelC = new ViewModelProvider(PeertubeEditUploadActivity.this).get(ChannelsVM.class);
Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show(); viewModelC.get(MY_CHANNELS, null).observe(PeertubeEditUploadActivity.this, this::manageVIewChannels);
peertube.setUpdate(false);
set_upload_submit.setEnabled(true);
} else {
ChannelsVM viewModelC = new ViewModelProvider(PeertubeEditUploadActivity.this).get(ChannelsVM.class);
viewModelC.get().observe(PeertubeEditUploadActivity.this, this::manageVIewChannels);
}
languageToSend = peertube.getLanguage(); languageToSend = video.getLanguage();
licenseToSend = peertube.getLicense(); licenseToSend = video.getLicence();
privacyToSend = peertube.getPrivacy(); privacyToSend = video.getPrivacy();
categoryToSend = peertube.getCategory(); categoryToSend = video.getCategory();
Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(),p_video_preview);
Glide.with(PeertubeEditUploadActivity.this)
.load("https://" + peertube.getInstance() + peertube.getThumbnailPath())
.into(p_video_preview);
set_preview.setOnClickListener(v -> { set_preview.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
@ -276,64 +271,51 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
}); });
if (languageToSend == null) { if (languageToSend == null) {
languageToSend = new Item();
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
Map.Entry<String, String> entryString = languages.entrySet().iterator().next(); Map.Entry<String, String> entryString = languages.entrySet().iterator().next();
languageToSend = new HashMap<>(); languageToSend.setId(Long.parseLong(entryString.getKey()));
languageToSend.put(entryString.getKey(), entryString.getValue()); languageToSend.setLabel(entryString.getValue());
} }
if (licenseToSend == null) { if (licenseToSend == null) {
licenseToSend = new Item();
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences()); LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next(); Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next();
licenseToSend = new HashMap<>(); licenseToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
licenseToSend.put(entryInt.getKey(), entryInt.getValue()); licenseToSend.setLabel(entryInt.getValue());
} }
if (categoryToSend == null) { if (categoryToSend == null) {
categoryToSend = new Item();
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next(); Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next();
categoryToSend = new HashMap<>(); categoryToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
categoryToSend.put(entryInt.getKey(), entryInt.getValue()); categoryToSend.setLabel(entryInt.getValue());
} }
if (privacyToSend == null) { if (privacyToSend == null) {
privacyToSend = new Item();
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies()); LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next(); Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next();
privacyToSend = new HashMap<>(); privacyToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
privacyToSend.put(entryInt.getKey(), entryInt.getValue()); privacyToSend.setLabel(entryInt.getValue());
} }
String language = null; String language = languageToSend.getLabel();
if (languageToSend != null) { String license = licenseToSend.getLabel();
Map.Entry<String, String> entryString = languageToSend.entrySet().iterator().next(); String privacy = privacyToSend.getLabel();
language = entryString.getValue(); String category = categoryToSend.getLabel();
}
String license = null; channel = video.getChannel();
if (licenseToSend != null) { String title = video.getName();
Map.Entry<Integer, String> entryInt = licenseToSend.entrySet().iterator().next(); boolean commentEnabled = video.isCommentsEnabled();
license = entryInt.getValue(); boolean isNSFW = video.isNsfw();
}
String privacy = null;
if (privacyToSend != null) {
Map.Entry<Integer, String> entryInt = privacyToSend.entrySet().iterator().next();
privacy = entryInt.getValue();
}
String category = null;
if (categoryToSend != null && categoryToSend.entrySet().iterator().hasNext()) {
Map.Entry<Integer, String> entryInt = categoryToSend.entrySet().iterator().next();
category = entryInt.getValue();
}
channel = peertube.getChannel();
String title = peertube.getName();
boolean commentEnabled = peertube.isCommentsEnabled();
boolean isNSFW = peertube.isSensitive();
set_upload_enable_comments.setChecked(commentEnabled); set_upload_enable_comments.setChecked(commentEnabled);
set_upload_nsfw.setChecked(isNSFW); set_upload_nsfw.setChecked(isNSFW);
p_video_title.setText(title); p_video_title.setText(title);
p_video_description.setText(peertube.getDescription()); p_video_description.setText(video.getDescription());
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences()); LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
@ -395,8 +377,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<Integer, String> pair = it.next(); Map.Entry<Integer, String> pair = it.next();
if (i == position) { if (i == position) {
privacyToSend = new HashMap<>(); privacyToSend.setId(pair.getKey());
privacyToSend.put(pair.getKey(), pair.getValue()); privacyToSend.setLabel(pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -418,8 +400,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<Integer, String> pair = it.next(); Map.Entry<Integer, String> pair = it.next();
if (i == position) { if (i == position) {
licenseToSend = new HashMap<>(); licenseToSend.setId(pair.getKey());
licenseToSend.put(pair.getKey(), pair.getValue()); licenseToSend.setLabel(pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -442,8 +424,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<Integer, String> pair = it.next(); Map.Entry<Integer, String> pair = it.next();
if (i == position) { if (i == position) {
categoryToSend = new HashMap<>(); categoryToSend.setId(pair.getKey());
categoryToSend.put(pair.getKey(), pair.getValue()); categoryToSend.setLabel(pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -467,8 +449,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, String> pair = it.next(); Map.Entry<String, String> pair = it.next();
if (i == position) { if (i == position) {
languageToSend = new HashMap<>(); languageToSend.setId(Long.parseLong(pair.getKey()));
languageToSend.put(pair.getKey(), pair.getValue()); languageToSend.setLabel(pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -491,9 +473,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, String> pair = it.next(); Map.Entry<String, String> pair = it.next();
if (i == position) { if (i == position) {
channelToSend = new HashMap<>(); channelToSendId = pair.getKey();
channelToSend.put(pair.getKey(), pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -508,25 +488,30 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
}); });
Item finalCategoryToSend = categoryToSend;
Item finalLicenseToSend = licenseToSend;
Item finalLanguageToSend = languageToSend;
Item finalPrivacyToSend = privacyToSend;
set_upload_submit.setOnClickListener(v -> { set_upload_submit.setOnClickListener(v -> {
String title1 = p_video_title.getText().toString().trim(); String title1 = p_video_title.getText().toString().trim();
String description = p_video_description.getText().toString().trim(); String description = p_video_description.getText().toString().trim();
boolean isNSFW1 = set_upload_nsfw.isChecked(); boolean isNSFW1 = set_upload_nsfw.isChecked();
boolean commentEnabled1 = set_upload_enable_comments.isChecked(); boolean commentEnabled1 = set_upload_enable_comments.isChecked();
peertube.setName(title1); videoParams = new VideoParams();
peertube.setDescription(description); videoParams.setName(title1);
peertube.setSensitive(isNSFW1); videoParams.setDescription(description);
peertube.setCommentsEnabled(commentEnabled1); videoParams.setNsfw(isNSFW1);
peertube.setCategory(categoryToSend); videoParams.setCommentsEnabled(commentEnabled1);
peertube.setLicense(licenseToSend); videoParams.setCategory((int)finalCategoryToSend.getId());
peertube.setLanguage(languageToSend); videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
peertube.setChannelForUpdate(channelToSend); videoParams.setLanguage((int) finalLanguageToSend.getId());
peertube.setPrivacy(privacyToSend); videoParams.setChannelId(channelToSendId);
videoParams.setPrivacy((int) finalPrivacyToSend.getId());
List<String> tags = p_video_tags.getTags(); List<String> tags = p_video_tags.getTags();
peertube.setTags(tags); videoParams.setTags(tags);
set_upload_submit.setEnabled(false); set_upload_submit.setEnabled(false);
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class); MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class);
feedsViewModel.updateVideo(peertube).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
}); });
set_upload_privacy.setSelection(privacyPosition); set_upload_privacy.setSelection(privacyPosition);
@ -534,10 +519,9 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
set_upload_licenses.setSelection(licensePosition); set_upload_licenses.setSelection(licensePosition);
set_upload_categories.setSelection(categoryPosition); set_upload_categories.setSelection(categoryPosition);
List<String> tags = peertube.getTags(); String[] tags = video.getTags();
if (tags != null && tags.size() > 0) { if (tags != null && tags.length > 0) {
String[] tagsA = tags.toArray(new String[0]); p_video_tags.setTags(tags);
p_video_tags.setTags(tagsA);
} }
} }
@ -559,7 +543,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
Uri uri = data.getData(); Uri uri = data.getData();
try { try {
String uploadId = UUID.randomUUID().toString(); String uploadId = UUID.randomUUID().toString();
new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", peertube.getId())) new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", video.getId()))
.addFileToUpload(uri.toString().replace("file://", ""), "previewfile") .addFileToUpload(uri.toString().replace("file://", ""), "previewfile")
.setMethod("PUT") .setMethod("PUT")
.addHeader("Authorization", "Bearer " + token) .addHeader("Authorization", "Bearer " + token)
@ -624,22 +608,21 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
String[] channelName = new String[accounts.size()]; String[] channelName = new String[accounts.size()];
int i = 0; int i = 0;
for (Account account : accounts) { for (Account account : accounts) {
channels.put(account.getUsername(), account.getId()); channels.put(account.getName(), account.getId());
channelName[i] = account.getUsername(); channelName[i] = account.getName();
i++; i++;
} }
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this, ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
android.R.layout.simple_spinner_dropdown_item, channelName); android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel); set_upload_channel.setAdapter(adapterChannel);
int channelPosition = 0; int channelPosition = 0;
if (channels.containsKey(channel.getUsername())) { if (channels.containsKey(channel.getName())) {
LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels); LinkedHashMap<String, String> channelsIterator = new LinkedHashMap<>(channels);
Iterator<Map.Entry<String, String>> it = channelsIterator.entrySet().iterator(); Iterator<Map.Entry<String, String>> it = channelsIterator.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<String, String> pair = it.next(); Map.Entry<String, String> pair = it.next();
if (pair.getKey().equals(channel.getUsername())) { if (pair.getKey().equals(channel.getName())) {
channelToSend = new HashMap<>(); channelToSendId = pair.getKey();
channelToSend.put(pair.getKey(), pair.getValue());
break; break;
} }
it.remove(); it.remove();
@ -651,7 +634,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) { public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class); Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class);
intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS); intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS);
startActivity(intent); startActivity(intent);

View File

@ -41,7 +41,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.AccountCreation; import app.fedilab.fedilabtube.client.entities.AccountCreation;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -185,7 +185,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
new Thread(() -> { new Thread(() -> {
try { try {
APIResponse apiResponse = new PeertubeAPI(PeertubeRegisterActivity.this, instance, null).createAccount(accountCreation); APIResponse apiResponse = new RetrofitPeertubeAPI(PeertubeRegisterActivity.this, instance, null).createAccount(accountCreation);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
if (apiResponse.getError() != null) { if (apiResponse.getError() != null) {

View File

@ -60,6 +60,7 @@ import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS;
public class PeertubeUploadActivity extends AppCompatActivity { public class PeertubeUploadActivity extends AppCompatActivity {
@ -95,7 +96,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
video_title = findViewById(R.id.video_title); video_title = findViewById(R.id.video_title);
ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class); ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class);
viewModelC.get().observe(PeertubeUploadActivity.this, this::manageVIewChannels); viewModelC.get(MY_CHANNELS, null).observe(PeertubeUploadActivity.this, this::manageVIewChannels);
channels = new HashMap<>(); channels = new HashMap<>();
setTitle(R.string.upload_video); setTitle(R.string.upload_video);
} }
@ -168,8 +169,8 @@ public class PeertubeUploadActivity extends AppCompatActivity {
String[] channelId = new String[accounts.size()]; String[] channelId = new String[accounts.size()];
int i = 0; int i = 0;
for (Account account : accounts) { for (Account account : accounts) {
channels.put(account.getUsername(), account.getId()); channels.put(account.getName(), account.getId());
channelName[i] = account.getUsername(); channelName[i] = account.getName();
channelId[i] = account.getId(); channelId[i] = account.getId();
i++; i++;
} }

View File

@ -31,8 +31,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Peertube; import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.entities.Playlist; import app.fedilab.fedilabtube.client.data.VideoData.Video;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter; import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -47,7 +47,7 @@ public class PlaylistsActivity extends AppCompatActivity {
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
private boolean swiped; private boolean swiped;
private List<Peertube> peertubes; private List<Video> peertubes;
private String max_id; private String max_id;
private Playlist playlist; private Playlist playlist;
private boolean firstLoad; private boolean firstLoad;
@ -111,7 +111,7 @@ public class PlaylistsActivity extends AppCompatActivity {
if (firstVisibleItem + visibleItemCount == totalItemCount) { if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
viewModel.manage(GET_LIST_VIDEOS, playlist, null, max_id).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse)); viewModel.manage(GET_LIST_VIDEOS, playlist, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
nextElementLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.VISIBLE);
} }
} else { } else {
@ -127,10 +127,10 @@ public class PlaylistsActivity extends AppCompatActivity {
firstLoad = true; firstLoad = true;
flag_loading = true; flag_loading = true;
swiped = true; swiped = true;
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse)); viewModel.manage(GET_LIST_VIDEOS, playlist, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
}); });
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse)); viewModel.manage(GET_LIST_VIDEOS, playlist, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
} }
@ -159,7 +159,7 @@ public class PlaylistsActivity extends AppCompatActivity {
if (actionType == GET_LIST_VIDEOS) { if (actionType == GET_LIST_VIDEOS) {
int previousPosition = this.peertubes.size(); int previousPosition = this.peertubes.size();
List<Peertube> videos = apiResponse.getPeertubes(); List<Video> videos = apiResponse.getPeertubes();
max_id = apiResponse.getMax_id(); max_id = apiResponse.getMax_id();
flag_loading = (max_id == null); flag_loading = (max_id == null);
if (!swiped && firstLoad && (videos == null || videos.size() == 0)) if (!swiped && firstLoad && (videos == null || videos.size() == 0))

View File

@ -124,14 +124,12 @@ public interface PeertubeService {
//Get my video //Get my video
@GET("users/me/videos?sort=-publishedAt") @GET("users/me/videos?sort=-publishedAt")
Call<VideoData.Video> getMyVideo(@Header("Authorization") String credentials, @Query("start") String maxId); Call<List<VideoData.Video>> getMyVideo(@Header("Authorization") String credentials, @Query("start") String maxId);
//Get my video //Get my video
@GET("accounts/{name}/videos?sort=-publishedAt") @GET("accounts/{name}/videos?sort=-publishedAt")
Call<VideoData.Video> getVideosForAccount(@Query("start") String maxId); Call<VideoData.Video> getVideosForAccount(@Query("start") String maxId);
@POST("videos/upload")
Call<String> addVideo(@Header("Authorization") String credentials, @Body VideoParams videoParams, @Part MultipartBody.Part videofile, @Part MultipartBody.Part thumbnailfile, @Part MultipartBody.Part previewfile);
@PUT("videos/{id}") @PUT("videos/{id}")
Call<String> updateVideo(@Header("Authorization") String credentials, @Path("id") String videoId, @Body VideoParams videoParams, @Part MultipartBody.Part thumbnailfile, @Part MultipartBody.Part previewfile); Call<String> updateVideo(@Header("Authorization") String credentials, @Path("id") String videoId, @Body VideoParams videoParams, @Part MultipartBody.Part thumbnailfile, @Part MultipartBody.Part previewfile);
@ -143,12 +141,15 @@ public interface PeertubeService {
//Post/Update/Delete channel //Post/Update/Delete channel
//Channels for account //Channels for account
@GET("accounts/{accountId}/video-channels") @GET("accounts/{accountId}/video-channels")
Call<ChannelData> getChannelsForAccount(@Path("accountId") String accountId); Call<List<ChannelData.Channel>> getChannelsForAccount(@Path("accountId") String accountId);
//Get a channel //Get a channel
@GET("video-channels/{name}") @GET("video-channels/{name}")
Call<ChannelData.Channel> getChannel(@Path("name") String name); Call<ChannelData.Channel> getChannel(@Path("name") String name);
@GET("video-channels")
Call<List<ChannelData.Channel>> getMyChannels(@Header("Authorization") String credentials);
@GET("video-channels/{channelHandle}/videos") @GET("video-channels/{channelHandle}/videos")
Call<List<VideoData.Video>> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId); Call<List<VideoData.Video>> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId);

View File

@ -45,10 +45,12 @@ import app.fedilab.fedilabtube.client.entities.PlaylistParams;
import app.fedilab.fedilabtube.client.entities.Rating; import app.fedilab.fedilabtube.client.entities.Rating;
import app.fedilab.fedilabtube.client.entities.RefreshToken; import app.fedilab.fedilabtube.client.entities.RefreshToken;
import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.client.entities.VideoParams;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import app.fedilab.fedilabtube.viewmodel.CommentVM; import app.fedilab.fedilabtube.viewmodel.CommentVM;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.RequestBody; import okhttp3.RequestBody;
@ -102,7 +104,7 @@ public class RetrofitPeertubeAPI {
* Verifiy credential of the authenticated user *synchronously* * Verifiy credential of the authenticated user *synchronously*
* @return Account * @return Account
*/ */
private RefreshToken refreshToken(String client_id, String client_secret, String refresh_token) { public RefreshToken refreshToken(String client_id, String client_secret, String refresh_token) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<RefreshToken> refreshTokenCall = peertubeService.refreshToken("refresh_token", client_id, client_secret, refresh_token); Call<RefreshToken> refreshTokenCall = peertubeService.refreshToken("refresh_token", client_id, client_secret, refresh_token);
try { try {
@ -158,11 +160,14 @@ public class RetrofitPeertubeAPI {
return apiResponse; return apiResponse;
} }
public APIResponse getTL(TimelineType timelineType, String max_id) { public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id) {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<List<VideoData.Video>> videoCall = null; Call<List<VideoData.Video>> videoCall = null;
switch (timelineType) { switch (timelineType) {
case MY_VIDEOS:
videoCall = peertubeService.getMyVideo(token, max_id);
break;
case SUBSCRIBTIONS: case SUBSCRIBTIONS:
videoCall = peertubeService.getSubscriptionVideos(max_id, new ArrayList<>(selection)); videoCall = peertubeService.getSubscriptionVideos(max_id, new ArrayList<>(selection));
break; break;
@ -549,6 +554,51 @@ public class RetrofitPeertubeAPI {
return apiResponse; return apiResponse;
} }
/***
* Update a video
* @param videoId String id of the video
* @param videoParams VideoParams params for the video
* @param thumbnail File thumbnail
* @param previewfile File preview
* @return APIResponse
*/
public APIResponse updateVideo(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
PeertubeService peertubeService = init();
MultipartBody.Part bodyThumbnail = null;
MultipartBody.Part bodyPreviewfile= null;
if (thumbnail != null) {
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), thumbnail);
bodyThumbnail = MultipartBody.Part.createFormData("image", thumbnail.getName(), requestFile);
}
if (previewfile != null) {
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), previewfile);
bodyPreviewfile = MultipartBody.Part.createFormData("image", previewfile.getName(), requestFile);
}
Call<String> upload = peertubeService.updateVideo(token, videoId, videoParams, bodyThumbnail, bodyPreviewfile);
APIResponse apiResponse = new APIResponse();
try {
Response<String> response = upload.execute();
if (response.isSuccessful()) {
apiResponse.setActionReturn(response.body());
} else {
Error error = new Error();
error.setStatusCode(response.code());
if (response.errorBody() != null) {
error.setError(response.message());
} else {
error.setError(_context.getString(R.string.toast_error));
}
apiResponse.setError(error);
}
} catch (IOException e) {
Error error = new Error();
error.setError(_context.getString(R.string.toast_error));
apiResponse.setError(error);
e.printStackTrace();
}
return apiResponse;
}
public APIResponse createAccount(AccountCreation accountCreation) { public APIResponse createAccount(AccountCreation accountCreation) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
Call<String> report1 = peertubeService.register(accountCreation.getEmail(), accountCreation.getPassword(), accountCreation.getUsername(), accountCreation.getDisplayName()); Call<String> report1 = peertubeService.register(accountCreation.getEmail(), accountCreation.getPassword(), accountCreation.getUsername(), accountCreation.getDisplayName());
@ -722,6 +772,7 @@ public class RetrofitPeertubeAPI {
return apiResponse; return apiResponse;
} }
/** /**
* Get channel data * Get channel data
* *
@ -734,10 +785,16 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
switch (accountDataType) { switch (accountDataType) {
case MY_CHANNELS:
case CHANNELS_FOR_ACCOUNT: case CHANNELS_FOR_ACCOUNT:
Call<ChannelData> channelDataCall = peertubeService.getChannelsForAccount(element); Call<List<ChannelData.Channel>> channelDataCall;
if( accountDataType == DataType.MY_CHANNELS) {
channelDataCall = peertubeService.getMyChannels(token);
} else {
channelDataCall = peertubeService.getChannelsForAccount(element);
}
try { try {
Response<ChannelData> response = channelDataCall.execute(); Response<List<ChannelData.Channel>> response = channelDataCall.execute();
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
Error error = new Error(); Error error = new Error();
error.setStatusCode(response.code()); error.setStatusCode(response.code());
@ -748,10 +805,7 @@ public class RetrofitPeertubeAPI {
} }
apiResponse.setError(error); apiResponse.setError(error);
} else { } else {
ChannelData channelData = response.body(); apiResponse.setChannels( response.body());
if (channelData != null) {
apiResponse.setChannels(channelData.data);
}
} }
} catch (IOException e) { } catch (IOException e) {
Error error = new Error(); Error error = new Error();
@ -1104,21 +1158,13 @@ public class RetrofitPeertubeAPI {
} }
public enum TimelineType {
SUBSCRIBTIONS,
LOCAL,
OVERVIEW,
TRENDING,
MOST_LIKED,
HISTORY,
RECENT
}
public enum DataType { public enum DataType {
SUBSCRIBER, SUBSCRIBER,
MUTED, MUTED,
CHANNELS_FOR_ACCOUNT, CHANNELS_FOR_ACCOUNT,
CHANNEL CHANNEL,
MY_CHANNELS
} }
@ -1131,6 +1177,7 @@ public class RetrofitPeertubeAPI {
PEERTUBEDELETECOMMENT, PEERTUBEDELETECOMMENT,
PEERTUBEDELETEVIDEO, PEERTUBEDELETEVIDEO,
REPORT_VIDEO, REPORT_VIDEO,
REPORT_ACCOUNT,
DELETE_CHANNEL DELETE_CHANNEL
} }

View File

@ -59,7 +59,7 @@ public class VideoData {
@SerializedName("blacklistedReason") @SerializedName("blacklistedReason")
private String blacklistedReason; private String blacklistedReason;
@SerializedName("category") @SerializedName("category")
private Item item; private Item category;
@SerializedName("channel") @SerializedName("channel")
private ChannelData.Channel channel; private ChannelData.Channel channel;
@SerializedName("commentsEnabled") @SerializedName("commentsEnabled")
@ -132,7 +132,7 @@ public class VideoData {
this.account = in.readParcelable(Account.class.getClassLoader()); this.account = in.readParcelable(Account.class.getClassLoader());
this.blacklisted = in.readByte() != 0; this.blacklisted = in.readByte() != 0;
this.blacklistedReason = in.readString(); this.blacklistedReason = in.readString();
this.item = in.readParcelable(Item.class.getClassLoader()); this.category = in.readParcelable(Item.class.getClassLoader());
this.channel = in.readParcelable(ChannelData.Channel.class.getClassLoader()); this.channel = in.readParcelable(ChannelData.Channel.class.getClassLoader());
this.commentsEnabled = in.readByte() != 0; this.commentsEnabled = in.readByte() != 0;
long tmpCreatedAt = in.readLong(); long tmpCreatedAt = in.readLong();
@ -245,12 +245,12 @@ public class VideoData {
this.blacklistedReason = blacklistedReason; this.blacklistedReason = blacklistedReason;
} }
public Item getItem() { public Item getCategory() {
return item; return category;
} }
public void setItem(Item item) { public void setCategory(Item item) {
this.item = item; this.category = item;
} }
public ChannelData.Channel getChannel() { public ChannelData.Channel getChannel() {
@ -519,7 +519,7 @@ public class VideoData {
dest.writeParcelable(this.account, flags); dest.writeParcelable(this.account, flags);
dest.writeByte(this.blacklisted ? (byte) 1 : (byte) 0); dest.writeByte(this.blacklisted ? (byte) 1 : (byte) 0);
dest.writeString(this.blacklistedReason); dest.writeString(this.blacklistedReason);
dest.writeParcelable(this.item, flags); dest.writeParcelable(this.category, flags);
dest.writeParcelable(this.channel, flags); dest.writeParcelable(this.channel, flags);
dest.writeByte(this.commentsEnabled ? (byte) 1 : (byte) 0); dest.writeByte(this.commentsEnabled ? (byte) 1 : (byte) 0);
dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1); dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1);

View File

@ -1,5 +1,7 @@
package app.fedilab.fedilabtube.client.entities; package app.fedilab.fedilabtube.client.entities;
import com.google.gson.annotations.SerializedName;
import java.util.List; import java.util.List;
/* Copyright 2020 Thomas Schneider /* Copyright 2020 Thomas Schneider
@ -16,10 +18,20 @@ import java.util.List;
* *
* You should have received a copy of the GNU General Public License along with TubeLab; if not, * You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
@SuppressWarnings("unused")
public class Report { public class Report {
@SerializedName("reason")
private String reason; private String reason;
@SerializedName("predefinedReasons")
private List<String> predefinedReasons; private List<String> predefinedReasons;
@SerializedName("video")
private VideoReport video;
@SerializedName("comment")
private CommentReport comment;
@SerializedName("account")
private AccountReport account;
public String getReason() { public String getReason() {
return reason; return reason;
@ -37,9 +49,36 @@ public class Report {
this.predefinedReasons = predefinedReasons; this.predefinedReasons = predefinedReasons;
} }
public static class videoReport { public VideoReport getVideo() {
return video;
}
public void setVideo(VideoReport video) {
this.video = video;
}
public CommentReport getComment() {
return comment;
}
public void setComment(CommentReport comment) {
this.comment = comment;
}
public AccountReport getAccount() {
return account;
}
public void setAccount(AccountReport account) {
this.account = account;
}
public static class VideoReport {
@SerializedName("id")
private String id; private String id;
@SerializedName("startAt")
private long startAt; private long startAt;
@SerializedName("endAt")
private long endAt; private long endAt;
public String getId() { public String getId() {
@ -67,7 +106,8 @@ public class Report {
} }
} }
public static class commentReport { public static class CommentReport {
@SerializedName("id")
private String id; private String id;
public String getId() { public String getId() {
@ -79,7 +119,8 @@ public class Report {
} }
} }
public static class accountReport { public static class AccountReport {
@SerializedName("id")
private String id; private String id;
public String getId() { public String getId() {

View File

@ -24,9 +24,11 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import java.io.File;
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.VideoData; import app.fedilab.fedilabtube.client.entities.VideoParams;
public class MyVideoVM extends AndroidViewModel { public class MyVideoVM extends AndroidViewModel {
@ -37,23 +39,21 @@ public class MyVideoVM extends AndroidViewModel {
} }
public LiveData<APIResponse> updateVideo(VideoData.Video peertube) { public LiveData<APIResponse> updateVideo(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
update(peertube); update(videoId, videoParams, thumbnail, previewfile);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
private void update(VideoData.Video peertube) { private void update(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(_mContext); RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(_mContext);
/* APIResponse apiResponse = peertubeAPI.u(peertube); APIResponse apiResponse = peertubeAPI.updateVideo(videoId, videoParams, thumbnail, previewfile);
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
apiResponse.getPeertubes().get(0).setUpdate(true);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> apiResponseMutableLiveData.postValue(apiResponse); Runnable myRunnable = () -> apiResponseMutableLiveData.postValue(apiResponse);
mainHandler.post(myRunnable);*/ mainHandler.post(myRunnable);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -26,6 +26,7 @@ import androidx.lifecycle.MutableLiveData;
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.entities.Report;
public class PostActionsVM extends AndroidViewModel { public class PostActionsVM extends AndroidViewModel {
@ -41,6 +42,12 @@ public class PostActionsVM extends AndroidViewModel {
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
} }
public LiveData<APIResponse> report(Report report) {
apiResponseMutableLiveData = new MutableLiveData<>();
sendReport(report);
return apiResponseMutableLiveData;
}
private void makeAction(RetrofitPeertubeAPI.ActionType apiAction, String id, String element) { private void makeAction(RetrofitPeertubeAPI.ActionType apiAction, String id, String element) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
@ -56,4 +63,19 @@ public class PostActionsVM extends AndroidViewModel {
}).start(); }).start();
} }
private void sendReport(Report report) {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
try {
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(_mContext);
APIResponse apiResponse = peertubeAPI.report(report);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
mainHandler.post(myRunnable);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
} }

View File

@ -35,7 +35,7 @@ public class TimelineVM extends AndroidViewModel {
super(application); super(application);
} }
public LiveData<APIResponse> getVideos(RetrofitPeertubeAPI.TimelineType action, String max_id) { public LiveData<APIResponse> getVideos(TimelineType action, String max_id) {
apiResponseMutableLiveData = new MutableLiveData<>(); apiResponseMutableLiveData = new MutableLiveData<>();
loadVideos(action, max_id); loadVideos(action, max_id);
return apiResponseMutableLiveData; return apiResponseMutableLiveData;
@ -69,7 +69,7 @@ public class TimelineVM extends AndroidViewModel {
}).start(); }).start();
} }
private void loadVideos(RetrofitPeertubeAPI.TimelineType timeline, String max_id) { private void loadVideos(TimelineType timeline, String max_id) {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
@ -77,7 +77,7 @@ public class TimelineVM extends AndroidViewModel {
if (timeline == null) if (timeline == null)
return; return;
APIResponse apiResponse; APIResponse apiResponse;
if( timeline != RetrofitPeertubeAPI.TimelineType.OVERVIEW) { if( timeline != TimelineType.OVERVIEW) {
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id); apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id);
}else{ }else{
apiResponse = retrofitPeertubeAPI.getOverviewVideo(max_id); apiResponse = retrofitPeertubeAPI.getOverviewVideo(max_id);
@ -90,4 +90,16 @@ public class TimelineVM extends AndroidViewModel {
} }
}).start(); }).start();
} }
public enum TimelineType {
SUBSCRIBTIONS,
MY_VIDEOS,
LOCAL,
OVERVIEW,
TRENDING,
MOST_LIKED,
HISTORY,
RECENT
}
} }