From 55179c69558110ff9d48880cdf837532b7e2e6f9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 26 Sep 2020 10:22:11 +0200 Subject: [PATCH] some changes --- .../app/fedilab/fedilabtube/MainActivity.java | 6 +- .../fedilab/fedilabtube/MyVideosActivity.java | 10 +- .../fedilab/fedilabtube/PeertubeActivity.java | 89 ++++----- .../PeertubeEditUploadActivity.java | 179 ++++++++---------- .../fedilabtube/PeertubeRegisterActivity.java | 4 +- .../fedilabtube/PeertubeUploadActivity.java | 7 +- .../fedilabtube/PlaylistsActivity.java | 14 +- .../fedilabtube/client/PeertubeService.java | 9 +- .../client/RetrofitPeertubeAPI.java | 83 ++++++-- .../fedilabtube/client/data/VideoData.java | 14 +- .../fedilabtube/client/entities/Report.java | 47 ++++- .../fedilabtube/viewmodel/MyVideoVM.java | 16 +- .../fedilabtube/viewmodel/PostActionsVM.java | 22 +++ .../fedilabtube/viewmodel/TimelineVM.java | 18 +- 14 files changed, 313 insertions(+), 205 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index a1dcc5a..52a01ce 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -164,7 +164,7 @@ public class MainActivity extends AppCompatActivity { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance); 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 { instanceItem.setVisible(true); @@ -205,14 +205,14 @@ public class MainActivity extends AppCompatActivity { } else if (item.getItemId() == R.id.action_myvideos) { Intent intent = new Intent(MainActivity.this, MyVideosActivity.class); Bundle bundle = new Bundle(); - bundle.putSerializable("type", TimelineVM.Type.MYVIDEOS); + 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); Bundle bundle = new Bundle(); - bundle.putSerializable("type", TimelineVM.Type.PEERTUBE_HISTORY); + bundle.putSerializable("type", TimelineVM.TimelineType.HISTORY); intent.putExtras(bundle); startActivity(intent); return true; diff --git a/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java index af1723f..bafb629 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java @@ -26,7 +26,7 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM; public class MyVideosActivity extends AppCompatActivity { - private TimelineVM.Type type; + private TimelineVM.TimelineType type; @Override protected void onCreate(Bundle savedInstanceState) { @@ -39,13 +39,13 @@ public class MyVideosActivity extends AppCompatActivity { Bundle b = getIntent().getExtras(); 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); - } else if (type == TimelineVM.Type.PSUBSCRIPTIONS) { + } else if (type == TimelineVM.TimelineType.SUBSCRIBTIONS) { setTitle(R.string.subscriptions); - } else if (type == TimelineVM.Type.PEERTUBE_HISTORY) { + } else if (type == TimelineVM.TimelineType.HISTORY) { setTitle(R.string.my_history); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 35ead4a..62d94e2 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -82,27 +82,23 @@ import com.google.android.exoplayer2.util.Util; import org.jetbrains.annotations.NotNull; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; -import javax.net.ssl.HttpsURLConnection; import app.fedilab.fedilabtube.client.APIResponse; -import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; -import app.fedilab.fedilabtube.client.TLSSocketFactory; -import app.fedilab.fedilabtube.client.data.AccountData; -import app.fedilab.fedilabtube.client.data.CommentData; +import app.fedilab.fedilabtube.client.data.AccountData.Account; +import app.fedilab.fedilabtube.client.data.CaptionData.Caption; +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.entities.Caption; import app.fedilab.fedilabtube.client.entities.File; -import app.fedilab.fedilabtube.client.entities.Playlist; -import app.fedilab.fedilabtube.client.entities.PlaylistElement; +import app.fedilab.fedilabtube.client.entities.PlaylistParams; +import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.drawer.CommentListAdapter; import app.fedilab.fedilabtube.helper.CacheDataSourceFactory; 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.getLiveInstance; 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; @@ -146,7 +142,7 @@ public class PeertubeActivity extends AppCompatActivity { private ImageView send; private TextView add_comment_read; private EditText add_comment_write; - private List playlistForVideo; + private List playlistForVideo; private List playlists; private PlaylistsVM playlistsViewModel; private boolean playInMinimized; @@ -190,7 +186,7 @@ public class PeertubeActivity extends AppCompatActivity { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); 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); @@ -212,7 +208,7 @@ public class PeertubeActivity extends AppCompatActivity { playlistForVideo = new ArrayList<>(); playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class); 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(); if (b != null) { @@ -308,7 +304,7 @@ public class PeertubeActivity extends AppCompatActivity { 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); 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()); androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create(); 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)); return true; } 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); LayoutInflater inflater1 = getLayoutInflater(); 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) { Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show(); } else { - if (type == PeertubeAPI.reportType.VIDEO) { - PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModel.post(RetrofitPeertubeAPI.ActionType.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_VIDEO, apiResponse)); + PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); + if (type == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) { + 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(); dialog.dismiss(); - } else if (type == PeertubeAPI.reportType.ACCOUNT) { - PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); - viewModel.post(RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse)); + } else if (type == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) { + Report report = new Report(); + 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(); dialog.dismiss(); } @@ -443,7 +448,7 @@ public class PeertubeActivity extends AppCompatActivity { peertube = apiResponse.getPeertubes().get(0); //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 -> { if (isLoggedIn(PeertubeActivity.this)) { @@ -483,8 +488,8 @@ public class PeertubeActivity extends AppCompatActivity { String title = null; boolean isPresent = false; String elementId = null; - PlaylistElement playlistElementFinal = null; - for (PlaylistElement playlistElement : playlistForVideo) { + PlaylistParams playlistElementFinal = null; + for (PlaylistParams playlistElement : playlistForVideo) { if (playlist.getId().equals(playlistElement.getPlaylistId())) { title = "✔ " + playlist.getDisplayName(); isPresent = true; @@ -499,7 +504,7 @@ public class PeertubeActivity extends AppCompatActivity { MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title); boolean finalIsPresent = isPresent; String finalElementId = elementId; - PlaylistElement finalPlaylistElementFinal = playlistElementFinal; + PlaylistParams finalPlaylistElementFinal = playlistElementFinal; item.setOnMenuItemClickListener(item1 -> { item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); item1.setActionView(new View(PeertubeActivity.this)); @@ -516,12 +521,12 @@ public class PeertubeActivity extends AppCompatActivity { }); if (finalIsPresent) { 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); } else { item1.setTitle("✔ " + playlist.getDisplayName()); - playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3)); - PlaylistElement playlistElement = new PlaylistElement(); + playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId()).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3)); + PlaylistParams playlistElement = new PlaylistParams(); playlistElement.setPlaylistElementId(null); playlistElement.setPlaylistId(playlist.getId()); playlistForVideo.add(playlistElement); @@ -583,7 +588,7 @@ public class PeertubeActivity extends AppCompatActivity { if (isLoggedIn(PeertubeActivity.this)) { String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; 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); int count = Integer.parseInt(peertube_dislike_count.getText().toString()); 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) { @@ -797,8 +798,8 @@ public class PeertubeActivity extends AppCompatActivity { Toasty.error(PeertubeActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); return; } - List comments = new ArrayList<>(); - for (CommentData.Comment comment : apiResponse.getComments()) { + List comments = new ArrayList<>(); + for (Comment comment : apiResponse.getComments()) { if (comment.getDescription() != null && comment.getDescription().trim().length() > 0) { comments.add(comment); } @@ -941,15 +942,15 @@ public class PeertubeActivity extends AppCompatActivity { } @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); 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(); - } 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(); } } @@ -1000,7 +1001,7 @@ public class PeertubeActivity extends AppCompatActivity { private void initResolution() { PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); 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()); } @@ -1037,7 +1038,7 @@ public class PeertubeActivity extends AppCompatActivity { if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) { playlistForVideo = apiResponse.getPlaylistForVideos(); - } else if (actionType == GET_PLAYLIST && apiResponse != null) { + } else if (actionType == GET_PLAYLISTS && apiResponse != null) { playlists = apiResponse.getPlaylists(); } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index ae80376..63c14b3 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -49,7 +49,6 @@ import net.gotev.uploadservice.UploadStatusDelegate; import java.io.FileNotFoundException; import java.net.MalformedURLException; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -57,17 +56,23 @@ import java.util.Map; import java.util.UUID; 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.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.viewmodel.ChannelsVM; +import app.fedilab.fedilabtube.viewmodel.MyVideoVM; import app.fedilab.fedilabtube.viewmodel.TimelineVM; import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; import mabbas007.tagsedittext.TagsEditText; 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 { @@ -75,11 +80,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { private final int PICK_IMAGE = 50378; private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724; - HashMap categoryToSend; - HashMap licenseToSend; - HashMap privacyToSend; - HashMap languageToSend; - HashMap channelToSend; private Button set_upload_submit; 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; @@ -87,10 +87,13 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { private CheckBox set_upload_nsfw, set_upload_enable_comments; private LinkedHashMap channels; private String videoId; - private Account channel; + private Channel channel; private ImageView p_video_preview; private Button set_preview; - private Peertube peertube; + private VideoParams videoParams; + private Video video; + private String channelToSendId; + Item languageToSend, licenseToSend, privacyToSend, categoryToSend; @Override protected void onCreate(Bundle savedInstanceState) { @@ -131,7 +134,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { 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(); }); builderInner.show(); @@ -218,9 +221,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { set_upload_privacy.setAdapter(adapterPrivacies); - String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this); 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<>(); setTitle(R.string.edit_video); @@ -238,25 +240,18 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } //Peertube video - peertube = apiResponse.getPeertubes().get(0); + video = apiResponse.getPeertubes().get(0); - if (peertube.isUpdate()) { - Toasty.success(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show(); - 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); - } + ChannelsVM viewModelC = new ViewModelProvider(PeertubeEditUploadActivity.this).get(ChannelsVM.class); + viewModelC.get(MY_CHANNELS, null).observe(PeertubeEditUploadActivity.this, this::manageVIewChannels); - languageToSend = peertube.getLanguage(); - licenseToSend = peertube.getLicense(); - privacyToSend = peertube.getPrivacy(); - categoryToSend = peertube.getCategory(); + languageToSend = video.getLanguage(); + licenseToSend = video.getLicence(); + privacyToSend = video.getPrivacy(); + 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 -> { if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != @@ -276,64 +271,51 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { }); if (languageToSend == null) { + languageToSend = new Item(); LinkedHashMap languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); Map.Entry entryString = languages.entrySet().iterator().next(); - languageToSend = new HashMap<>(); - languageToSend.put(entryString.getKey(), entryString.getValue()); + languageToSend.setId(Long.parseLong(entryString.getKey())); + languageToSend.setLabel(entryString.getValue()); } if (licenseToSend == null) { + licenseToSend = new Item(); LinkedHashMap licences = new LinkedHashMap<>(peertubeInformation.getLicences()); Map.Entry entryInt = licences.entrySet().iterator().next(); - licenseToSend = new HashMap<>(); - licenseToSend.put(entryInt.getKey(), entryInt.getValue()); + licenseToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey()))); + licenseToSend.setLabel(entryInt.getValue()); } if (categoryToSend == null) { + categoryToSend = new Item(); LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); Map.Entry entryInt = categories.entrySet().iterator().next(); - categoryToSend = new HashMap<>(); - categoryToSend.put(entryInt.getKey(), entryInt.getValue()); + categoryToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey()))); + categoryToSend.setLabel(entryInt.getValue()); } if (privacyToSend == null) { + privacyToSend = new Item(); LinkedHashMap privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies()); Map.Entry entryInt = privacies.entrySet().iterator().next(); - privacyToSend = new HashMap<>(); - privacyToSend.put(entryInt.getKey(), entryInt.getValue()); + privacyToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey()))); + privacyToSend.setLabel(entryInt.getValue()); } - String language = null; - if (languageToSend != null) { - Map.Entry entryString = languageToSend.entrySet().iterator().next(); - language = entryString.getValue(); - } + String language = languageToSend.getLabel(); + String license = licenseToSend.getLabel(); + String privacy = privacyToSend.getLabel(); + String category = categoryToSend.getLabel(); - String license = null; - if (licenseToSend != null) { - Map.Entry entryInt = licenseToSend.entrySet().iterator().next(); - license = entryInt.getValue(); - } - - String privacy = null; - if (privacyToSend != null) { - Map.Entry entryInt = privacyToSend.entrySet().iterator().next(); - privacy = entryInt.getValue(); - } - String category = null; - if (categoryToSend != null && categoryToSend.entrySet().iterator().hasNext()) { - Map.Entry entryInt = categoryToSend.entrySet().iterator().next(); - category = entryInt.getValue(); - } - channel = peertube.getChannel(); - String title = peertube.getName(); - boolean commentEnabled = peertube.isCommentsEnabled(); - boolean isNSFW = peertube.isSensitive(); + channel = video.getChannel(); + String title = video.getName(); + boolean commentEnabled = video.isCommentsEnabled(); + boolean isNSFW = video.isNsfw(); set_upload_enable_comments.setChecked(commentEnabled); set_upload_nsfw.setChecked(isNSFW); p_video_title.setText(title); - p_video_description.setText(peertube.getDescription()); + p_video_description.setText(video.getDescription()); LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap licences = new LinkedHashMap<>(peertubeInformation.getLicences()); @@ -395,8 +377,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { while (it.hasNext()) { Map.Entry pair = it.next(); if (i == position) { - privacyToSend = new HashMap<>(); - privacyToSend.put(pair.getKey(), pair.getValue()); + privacyToSend.setId(pair.getKey()); + privacyToSend.setLabel(pair.getValue()); break; } it.remove(); @@ -418,8 +400,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { while (it.hasNext()) { Map.Entry pair = it.next(); if (i == position) { - licenseToSend = new HashMap<>(); - licenseToSend.put(pair.getKey(), pair.getValue()); + licenseToSend.setId(pair.getKey()); + licenseToSend.setLabel(pair.getValue()); break; } it.remove(); @@ -442,8 +424,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { while (it.hasNext()) { Map.Entry pair = it.next(); if (i == position) { - categoryToSend = new HashMap<>(); - categoryToSend.put(pair.getKey(), pair.getValue()); + categoryToSend.setId(pair.getKey()); + categoryToSend.setLabel(pair.getValue()); break; } it.remove(); @@ -467,8 +449,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { while (it.hasNext()) { Map.Entry pair = it.next(); if (i == position) { - languageToSend = new HashMap<>(); - languageToSend.put(pair.getKey(), pair.getValue()); + languageToSend.setId(Long.parseLong(pair.getKey())); + languageToSend.setLabel(pair.getValue()); break; } it.remove(); @@ -491,9 +473,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { while (it.hasNext()) { Map.Entry pair = it.next(); if (i == position) { - channelToSend = new HashMap<>(); - channelToSend.put(pair.getKey(), pair.getValue()); - + channelToSendId = pair.getKey(); break; } 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 -> { String title1 = p_video_title.getText().toString().trim(); String description = p_video_description.getText().toString().trim(); boolean isNSFW1 = set_upload_nsfw.isChecked(); boolean commentEnabled1 = set_upload_enable_comments.isChecked(); - peertube.setName(title1); - peertube.setDescription(description); - peertube.setSensitive(isNSFW1); - peertube.setCommentsEnabled(commentEnabled1); - peertube.setCategory(categoryToSend); - peertube.setLicense(licenseToSend); - peertube.setLanguage(languageToSend); - peertube.setChannelForUpdate(channelToSend); - peertube.setPrivacy(privacyToSend); + videoParams = new VideoParams(); + videoParams.setName(title1); + videoParams.setDescription(description); + videoParams.setNsfw(isNSFW1); + videoParams.setCommentsEnabled(commentEnabled1); + videoParams.setCategory((int)finalCategoryToSend.getId()); + videoParams.setLicence(String.valueOf(finalLicenseToSend.getId())); + videoParams.setLanguage((int) finalLanguageToSend.getId()); + videoParams.setChannelId(channelToSendId); + videoParams.setPrivacy((int) finalPrivacyToSend.getId()); List tags = p_video_tags.getTags(); - peertube.setTags(tags); + videoParams.setTags(tags); set_upload_submit.setEnabled(false); - TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class); - feedsViewModel.updateVideo(peertube).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); + MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class); + myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); }); set_upload_privacy.setSelection(privacyPosition); @@ -534,10 +519,9 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { set_upload_licenses.setSelection(licensePosition); set_upload_categories.setSelection(categoryPosition); - List tags = peertube.getTags(); - if (tags != null && tags.size() > 0) { - String[] tagsA = tags.toArray(new String[0]); - p_video_tags.setTags(tagsA); + String[] tags = video.getTags(); + if (tags != null && tags.length > 0) { + p_video_tags.setTags(tags); } } @@ -559,7 +543,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { Uri uri = data.getData(); try { 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") .setMethod("PUT") .addHeader("Authorization", "Bearer " + token) @@ -624,22 +608,21 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { String[] channelName = new String[accounts.size()]; int i = 0; for (Account account : accounts) { - channels.put(account.getUsername(), account.getId()); - channelName[i] = account.getUsername(); + channels.put(account.getName(), account.getId()); + channelName[i] = account.getName(); i++; } ArrayAdapter adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, channelName); set_upload_channel.setAdapter(adapterChannel); int channelPosition = 0; - if (channels.containsKey(channel.getUsername())) { + if (channels.containsKey(channel.getName())) { LinkedHashMap channelsIterator = new LinkedHashMap<>(channels); Iterator> it = channelsIterator.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = it.next(); - if (pair.getKey().equals(channel.getUsername())) { - channelToSend = new HashMap<>(); - channelToSend.put(pair.getKey(), pair.getValue()); + if (pair.getKey().equals(channel.getName())) { + channelToSendId = pair.getKey(); break; } it.remove(); @@ -651,7 +634,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } @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.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS); startActivity(intent); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java index 640da36..2aa7873 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java @@ -41,7 +41,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; 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.helper.Helper; import es.dmoral.toasty.Toasty; @@ -185,7 +185,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity { new Thread(() -> { 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()); Runnable myRunnable = () -> { if (apiResponse.getError() != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java index 45f8ec8..f65984f 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java @@ -60,6 +60,7 @@ import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import es.dmoral.toasty.Toasty; import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; +import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS; public class PeertubeUploadActivity extends AppCompatActivity { @@ -95,7 +96,7 @@ public class PeertubeUploadActivity extends AppCompatActivity { video_title = findViewById(R.id.video_title); 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<>(); setTitle(R.string.upload_video); } @@ -168,8 +169,8 @@ public class PeertubeUploadActivity extends AppCompatActivity { String[] channelId = new String[accounts.size()]; int i = 0; for (Account account : accounts) { - channels.put(account.getUsername(), account.getId()); - channelName[i] = account.getUsername(); + channels.put(account.getName(), account.getId()); + channelName[i] = account.getName(); channelId[i] = account.getId(); i++; } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java index 63f68b8..72e7e8f 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java @@ -31,8 +31,8 @@ import java.util.ArrayList; import java.util.List; import app.fedilab.fedilabtube.client.APIResponse; -import app.fedilab.fedilabtube.client.entities.Peertube; -import app.fedilab.fedilabtube.client.entities.Playlist; +import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist; +import app.fedilab.fedilabtube.client.data.VideoData.Video; import app.fedilab.fedilabtube.drawer.PeertubeAdapter; import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import es.dmoral.toasty.Toasty; @@ -47,7 +47,7 @@ public class PlaylistsActivity extends AppCompatActivity { private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; private SwipeRefreshLayout swipeRefreshLayout; private boolean swiped; - private List peertubes; + private List