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();
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;

View File

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

View File

@ -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<PlaylistElement> playlistForVideo;
private List<PlaylistParams> playlistForVideo;
private List<Playlist> 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<CommentData.Comment> comments = new ArrayList<>();
for (CommentData.Comment comment : apiResponse.getComments()) {
List<Comment> 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();
}
}

View File

@ -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<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 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<String, String> 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<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
Map.Entry<String, String> 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<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
Map.Entry<Integer, String> 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<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
Map.Entry<Integer, String> 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<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
Map.Entry<Integer, String> 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<String, String> 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<Integer, String> entryInt = licenseToSend.entrySet().iterator().next();
license = entryInt.getValue();
}
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();
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<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
@ -395,8 +377,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
while (it.hasNext()) {
Map.Entry<Integer, String> 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<Integer, String> 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<Integer, String> 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<String, String> 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<String, String> 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<String> 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<String> 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<String> 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<String, String> channelsIterator = new LinkedHashMap<>(channels);
Iterator<Map.Entry<String, String>> it = channelsIterator.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> 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);

View File

@ -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) {

View File

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

View File

@ -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<Peertube> peertubes;
private List<Video> peertubes;
private String max_id;
private Playlist playlist;
private boolean firstLoad;
@ -111,7 +111,7 @@ public class PlaylistsActivity extends AppCompatActivity {
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
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);
}
} else {
@ -127,10 +127,10 @@ public class PlaylistsActivity extends AppCompatActivity {
firstLoad = true;
flag_loading = 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) {
int previousPosition = this.peertubes.size();
List<Peertube> videos = apiResponse.getPeertubes();
List<Video> videos = apiResponse.getPeertubes();
max_id = apiResponse.getMax_id();
flag_loading = (max_id == null);
if (!swiped && firstLoad && (videos == null || videos.size() == 0))

View File

@ -124,14 +124,12 @@ public interface PeertubeService {
//Get my video
@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("accounts/{name}/videos?sort=-publishedAt")
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}")
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
//Channels for account
@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("video-channels/{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")
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.RefreshToken;
import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.client.entities.VideoParams;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import app.fedilab.fedilabtube.viewmodel.CommentVM;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
@ -102,7 +104,7 @@ public class RetrofitPeertubeAPI {
* Verifiy credential of the authenticated user *synchronously*
* @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();
Call<RefreshToken> refreshTokenCall = peertubeService.refreshToken("refresh_token", client_id, client_secret, refresh_token);
try {
@ -158,11 +160,14 @@ public class RetrofitPeertubeAPI {
return apiResponse;
}
public APIResponse getTL(TimelineType timelineType, String max_id) {
public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id) {
APIResponse apiResponse = new APIResponse();
PeertubeService peertubeService = init();
Call<List<VideoData.Video>> videoCall = null;
switch (timelineType) {
case MY_VIDEOS:
videoCall = peertubeService.getMyVideo(token, max_id);
break;
case SUBSCRIBTIONS:
videoCall = peertubeService.getSubscriptionVideos(max_id, new ArrayList<>(selection));
break;
@ -549,6 +554,51 @@ public class RetrofitPeertubeAPI {
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) {
PeertubeService peertubeService = init();
Call<String> report1 = peertubeService.register(accountCreation.getEmail(), accountCreation.getPassword(), accountCreation.getUsername(), accountCreation.getDisplayName());
@ -722,6 +772,7 @@ public class RetrofitPeertubeAPI {
return apiResponse;
}
/**
* Get channel data
*
@ -734,10 +785,16 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse();
switch (accountDataType) {
case MY_CHANNELS:
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 {
Response<ChannelData> response = channelDataCall.execute();
Response<List<ChannelData.Channel>> response = channelDataCall.execute();
if (!response.isSuccessful()) {
Error error = new Error();
error.setStatusCode(response.code());
@ -748,10 +805,7 @@ public class RetrofitPeertubeAPI {
}
apiResponse.setError(error);
} else {
ChannelData channelData = response.body();
if (channelData != null) {
apiResponse.setChannels(channelData.data);
}
apiResponse.setChannels( response.body());
}
} catch (IOException e) {
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 {
SUBSCRIBER,
MUTED,
CHANNELS_FOR_ACCOUNT,
CHANNEL
CHANNEL,
MY_CHANNELS
}
@ -1131,6 +1177,7 @@ public class RetrofitPeertubeAPI {
PEERTUBEDELETECOMMENT,
PEERTUBEDELETEVIDEO,
REPORT_VIDEO,
REPORT_ACCOUNT,
DELETE_CHANNEL
}

View File

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

View File

@ -1,5 +1,7 @@
package app.fedilab.fedilabtube.client.entities;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/* 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,
* see <http://www.gnu.org/licenses>. */
@SuppressWarnings("unused")
public class Report {
@SerializedName("reason")
private String reason;
@SerializedName("predefinedReasons")
private List<String> predefinedReasons;
@SerializedName("video")
private VideoReport video;
@SerializedName("comment")
private CommentReport comment;
@SerializedName("account")
private AccountReport account;
public String getReason() {
return reason;
@ -37,9 +49,36 @@ public class Report {
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;
@SerializedName("startAt")
private long startAt;
@SerializedName("endAt")
private long endAt;
public String getId() {
@ -67,7 +106,8 @@ public class Report {
}
}
public static class commentReport {
public static class CommentReport {
@SerializedName("id")
private String id;
public String getId() {
@ -79,7 +119,8 @@ public class Report {
}
}
public static class accountReport {
public static class AccountReport {
@SerializedName("id")
private String id;
public String getId() {

View File

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

View File

@ -26,6 +26,7 @@ import androidx.lifecycle.MutableLiveData;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Report;
public class PostActionsVM extends AndroidViewModel {
@ -41,6 +42,12 @@ public class PostActionsVM extends AndroidViewModel {
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) {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
@ -56,4 +63,19 @@ public class PostActionsVM extends AndroidViewModel {
}).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);
}
public LiveData<APIResponse> getVideos(RetrofitPeertubeAPI.TimelineType action, String max_id) {
public LiveData<APIResponse> getVideos(TimelineType action, String max_id) {
apiResponseMutableLiveData = new MutableLiveData<>();
loadVideos(action, max_id);
return apiResponseMutableLiveData;
@ -69,7 +69,7 @@ public class TimelineVM extends AndroidViewModel {
}).start();
}
private void loadVideos(RetrofitPeertubeAPI.TimelineType timeline, String max_id) {
private void loadVideos(TimelineType timeline, String max_id) {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
try {
@ -77,7 +77,7 @@ public class TimelineVM extends AndroidViewModel {
if (timeline == null)
return;
APIResponse apiResponse;
if( timeline != RetrofitPeertubeAPI.TimelineType.OVERVIEW) {
if( timeline != TimelineType.OVERVIEW) {
apiResponse = retrofitPeertubeAPI.getTL(timeline, max_id);
}else{
apiResponse = retrofitPeertubeAPI.getOverviewVideo(max_id);
@ -90,4 +90,16 @@ public class TimelineVM extends AndroidViewModel {
}
}).start();
}
public enum TimelineType {
SUBSCRIBTIONS,
MY_VIDEOS,
LOCAL,
OVERVIEW,
TRENDING,
MOST_LIKED,
HISTORY,
RECENT
}
}