VM-v4
This commit is contained in:
parent
f632aa4712
commit
014302c3a8
|
@ -36,6 +36,7 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
|
@ -47,7 +48,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
@ -56,13 +56,13 @@ import app.fedilab.fedilabtube.client.entities.Playlist;
|
|||
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
|
||||
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
|
||||
|
||||
public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
|
||||
public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface {
|
||||
|
||||
|
||||
PlaylistAdapter playlistAdapter;
|
||||
|
@ -121,7 +121,8 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
|||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
|
||||
new RetrievePeertubeChannelsAsyncTask(AllPlaylistsActivity.this, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(AllPlaylistsActivity.this, this::manageVIewChannels);
|
||||
|
||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
@ -235,18 +236,8 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
|
@ -55,6 +54,7 @@ import androidx.appcompat.widget.PopupMenu;
|
|||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -78,15 +78,10 @@ import java.util.Objects;
|
|||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleCommentsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.TLSSocketFactory;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
|
||||
|
@ -96,24 +91,26 @@ import app.fedilab.fedilabtube.drawer.StatusListAdapter;
|
|||
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
|
||||
import app.fedilab.fedilabtube.helper.FullScreenMediaController;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
import app.fedilab.fedilabtube.viewmodel.CommentVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST;
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_PLAYLIST_FOR_VIDEO;
|
||||
|
||||
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
|
||||
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_PLAYLIST_FOR_VIDEO;
|
||||
|
||||
|
||||
public class PeertubeActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface, OnPlaylistActionInterface {
|
||||
public class PeertubeActivity extends AppCompatActivity {
|
||||
|
||||
public static String video_id;
|
||||
private String peertubeInstance, videoId;
|
||||
|
@ -135,6 +132,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
private EditText add_comment_write;
|
||||
private List<PlaylistElement> playlistForVideo;
|
||||
private List<Playlist> playlists;
|
||||
private PlaylistsVM playlistsViewModel;
|
||||
|
||||
public static void hideKeyboard(Activity activity) {
|
||||
if (activity != null && activity.getWindow() != null) {
|
||||
|
@ -253,11 +251,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
initFullscreenDialog();
|
||||
initFullscreenButton();
|
||||
}
|
||||
playlistsViewModel = new ViewModelProvider(PeertubeActivity.this).get(PlaylistsVM.class);
|
||||
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST, null, null, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(GET_PLAYLIST, null, null, null).observe(PeertubeActivity.this, apiResponse -> manageVIewPlaylists(GET_PLAYLIST, apiResponse));
|
||||
}
|
||||
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
|
||||
}
|
||||
|
||||
public void change() {
|
||||
|
@ -336,11 +336,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
Toasty.info(PeertubeActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
||||
} else {
|
||||
if (type == PeertubeAPI.reportType.VIDEO) {
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_VIDEO, apiResponse));
|
||||
alertDialog.dismiss();
|
||||
dialog.dismiss();
|
||||
} else if (type == PeertubeAPI.reportType.ACCOUNT) {
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), null).observe(PeertubeActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse));
|
||||
alertDialog.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
@ -358,8 +360,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
public void manageVIewVideo(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
|
@ -374,8 +375,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
|
||||
peertube = apiResponse.getPeertubes().get(0);
|
||||
//TODO: currently streaming service gives the wrong values for duration
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2));
|
||||
|
||||
add_comment_read.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
|
@ -393,7 +393,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String comment = add_comment_write.getText().toString();
|
||||
if (comment.trim().length() > 0) {
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getId(), comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getAccount().getId(), comment, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBECOMMENT, apiResponse1));
|
||||
add_comment_write.setText("");
|
||||
add_comment_read.setVisibility(View.VISIBLE);
|
||||
add_comment_write.setVisibility(View.GONE);
|
||||
|
@ -447,11 +448,11 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
});
|
||||
if (finalIsPresent) {
|
||||
item1.setTitle(playlist.getDisplayName());
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, finalElementId, null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId, null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
|
||||
playlistForVideo.remove(finalPlaylistElementFinal);
|
||||
} else {
|
||||
item1.setTitle("✔ " + playlist.getDisplayName());
|
||||
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId(), null).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
|
||||
PlaylistElement playlistElement = new PlaylistElement();
|
||||
playlistElement.setPlaylistElementId(finalElementId);
|
||||
playlistElement.setPlaylistId(playlist.getId());
|
||||
|
@ -466,7 +467,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
|
||||
|
||||
if (peertube.isCommentsEnabled()) {
|
||||
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
||||
commentViewModel.getComment(peertubeInstance, videoId).observe(PeertubeActivity.this, this::manageVIewComment);
|
||||
write_comment_container.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
|
@ -491,7 +493,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
peertube_like_count.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1));
|
||||
peertube.setMyRating(newState);
|
||||
int count = Integer.parseInt(peertube_like_count.getText().toString());
|
||||
if (newState.compareTo("none") == 0) {
|
||||
|
@ -511,7 +514,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
peertube_dislike_count.setOnClickListener(v -> {
|
||||
if (isLoggedIn(PeertubeActivity.this)) {
|
||||
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
|
||||
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PostActionsVM viewModel = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, null).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) {
|
||||
|
@ -640,8 +644,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
public void manageVIewComment(APIResponse apiResponse) {
|
||||
if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 501)) {
|
||||
if (apiResponse == null)
|
||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
|
@ -667,10 +671,6 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
@ -741,11 +741,12 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
builderSingle.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
|
||||
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
|
||||
|
||||
|
||||
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) {
|
||||
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
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) {
|
||||
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
|
||||
} else if (statusAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
|
||||
|
@ -831,8 +832,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
|||
peertube_dislike_count.setCompoundDrawablesWithIntrinsicBounds(null, thumbDown, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
|
||||
if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
|
||||
playlistForVideo = apiResponse.getPlaylistForVideos();
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -38,6 +37,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
|
@ -57,9 +57,6 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.PostPeertubeAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
|
@ -67,7 +64,8 @@ import app.fedilab.fedilabtube.client.entities.Error;
|
|||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import mabbas007.tagsedittext.TagsEditText;
|
||||
|
||||
|
@ -75,7 +73,7 @@ import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
|
|||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
|
||||
|
||||
public class PeertubeEditUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface, OnPostActionInterface {
|
||||
public class PeertubeEditUploadActivity extends AppCompatActivity implements OnPostActionInterface {
|
||||
|
||||
|
||||
private final int PICK_IMAGE = 50378;
|
||||
|
@ -223,16 +221,15 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
|||
|
||||
|
||||
String peertubeInstance = Helper.getLiveInstance(PeertubeEditUploadActivity.this);
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeEditUploadActivity.this, peertubeInstance, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.getVideo(peertubeInstance, videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
channels = new LinkedHashMap<>();
|
||||
|
||||
setTitle(R.string.edit_video);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
public void manageVIewVideo(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
@ -250,7 +247,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
|||
peertube.setUpdate(false);
|
||||
set_upload_submit.setEnabled(true);
|
||||
} else {
|
||||
new RetrievePeertubeChannelsAsyncTask(PeertubeEditUploadActivity.this, PeertubeEditUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(PeertubeEditUploadActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(PeertubeEditUploadActivity.this, this::manageVIewChannels);
|
||||
}
|
||||
|
||||
languageToSend = peertube.getLanguage();
|
||||
|
@ -530,7 +528,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
|||
List<String> tags = p_video_tags.getTags();
|
||||
peertube.setTags(tags);
|
||||
set_upload_submit.setEnabled(false);
|
||||
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
|
||||
FeedsVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(FeedsVM.class);
|
||||
feedsViewModel.updateVideo(peertube).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
});
|
||||
|
||||
set_upload_privacy.setSelection(privacyPosition);
|
||||
|
@ -614,13 +613,9 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnR
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
|
|
@ -14,7 +14,6 @@ package app.fedilab.fedilabtube;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -23,6 +22,7 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
@ -30,18 +30,17 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask.action.GET_LIST_VIDEOS;
|
||||
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_LIST_VIDEOS;
|
||||
|
||||
|
||||
public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface {
|
||||
public class PlaylistsActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
LinearLayoutManager mLayoutManager;
|
||||
|
@ -111,7 +110,8 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
|||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, max_id, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, max_id).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
|
@ -127,10 +127,12 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
|||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
});
|
||||
|
||||
new ManagePlaylistsAsyncTask(PlaylistsActivity.this, GET_LIST_VIDEOS, playlist, null, null, PlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,8 +146,8 @@ public class PlaylistsActivity extends AppCompatActivity implements OnPlaylistAc
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package app.fedilab.fedilabtube.asynctasks;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class PostPeertubeAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private Peertube peertube;
|
||||
|
||||
|
||||
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.peertube = peertube;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = peertubeAPI.updateVideo(peertube);
|
||||
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
||||
apiResponse.getPeertubes().get(0).setUpdate(true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package app.fedilab.fedilabtube.asynctasks;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface;
|
||||
|
||||
|
||||
public class RetrieveAccountSubscriptionsAsyncTask extends AsyncTask<Void, Void, APIResponse> {
|
||||
|
||||
private OnRetrieveAccountsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String max_id;
|
||||
|
||||
public RetrieveAccountSubscriptionsAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveAccountsInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected APIResponse doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
return peertubeAPI.getSubscriptionUsers(max_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(APIResponse apiResponse) {
|
||||
listener.onRetrieveAccounts(apiResponse);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package app.fedilab.fedilabtube.asynctasks;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String query, max_id;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveFeedsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrievePeertubeSearchAsyncTask(Context context, String max_id, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.query = query;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.max_id = max_id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = api.searchPeertube(query, max_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(apiResponse);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package app.fedilab.fedilabtube.asynctasks;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, APIResponse> {
|
||||
|
||||
|
||||
private String videoId;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instanceName;
|
||||
|
||||
|
||||
public RetrievePeertubeSingleAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.videoId = videoId;
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected APIResponse doInBackground(Void... params) {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
APIResponse apiResponse = peertubeAPI.getSinglePeertube(this.instanceName, videoId, token);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
String rate = new PeertubeAPI(this.contextReference.get()).getRating(videoId);
|
||||
if (rate != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(APIResponse apiResponse) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package app.fedilab.fedilabtube.asynctasks;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
public class RetrievePeertubeSingleCommentsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private String videoId;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instanceName;
|
||||
|
||||
|
||||
public RetrievePeertubeSingleCommentsAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.videoId = videoId;
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
apiResponse = api.getSinglePeertubeComments(this.instanceName, videoId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertubeComments(apiResponse);
|
||||
}
|
||||
}
|
|
@ -40,6 +40,7 @@ public class APIResponse {
|
|||
private List<PlaylistElement> playlistForVideos;
|
||||
private Instance instance;
|
||||
private String stringData;
|
||||
private int statusCode;
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return accounts;
|
||||
|
@ -150,4 +151,12 @@ public class APIResponse {
|
|||
public void setStringData(String stringData) {
|
||||
this.stringData = stringData;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.fragment;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -40,6 +39,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
|
@ -54,8 +54,6 @@ import java.util.Map;
|
|||
|
||||
import app.fedilab.fedilabtube.PlaylistsActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
|
||||
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
@ -63,18 +61,17 @@ import app.fedilab.fedilabtube.client.entities.Account;
|
|||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
|
||||
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
|
||||
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
|
||||
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation;
|
||||
|
||||
|
||||
public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActionInterface, OnRetrievePeertubeInterface {
|
||||
public class DisplayPlaylistsFragment extends Fragment {
|
||||
|
||||
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private List<Playlist> playlists;
|
||||
private RelativeLayout mainLoader;
|
||||
private FloatingActionButton add_new;
|
||||
|
@ -105,7 +102,9 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
playlists = new ArrayList<>();
|
||||
playlistAdapter = new PlaylistAdapter(context, playlists, textviewNoAction);
|
||||
lv_playlist.setAdapter(playlistAdapter);
|
||||
asyncTask = new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
PlaylistsVM viewModel = new ViewModelProvider(DisplayPlaylistsFragment.this.requireActivity()).get(PlaylistsVM.class);
|
||||
viewModel.manage(PlaylistsVM.action.GET_PLAYLIST, null, null, null).observe(DisplayPlaylistsFragment.this.requireActivity(), apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLIST, apiResponse));
|
||||
|
||||
add_new = rootView.findViewById(R.id.add_new);
|
||||
|
||||
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
||||
|
@ -131,7 +130,8 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
|
||||
new RetrievePeertubeChannelsAsyncTask(context, DisplayPlaylistsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(DisplayPlaylistsFragment.this.requireActivity()).get(ChannelsVM.class);
|
||||
viewModelC.get().observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
||||
|
||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
@ -238,15 +238,13 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
add_new.setEnabled(true);
|
||||
if (apiResponse.getError() != null) {
|
||||
|
@ -254,7 +252,7 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
return;
|
||||
}
|
||||
|
||||
if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) {
|
||||
if (actionType == PlaylistsVM.action.GET_PLAYLIST) {
|
||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||
this.playlists.addAll(apiResponse.getPlaylists());
|
||||
playlistAdapter.notifyDataSetChanged();
|
||||
|
@ -262,7 +260,7 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
} else {
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (actionType == ManagePlaylistsAsyncTask.action.CREATE_PLAYLIST) {
|
||||
} else if (actionType == PlaylistsVM.action.CREATE_PLAYLIST) {
|
||||
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
|
||||
Intent intent = new Intent(context, PlaylistsActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
@ -275,25 +273,14 @@ public class DisplayPlaylistsFragment extends Fragment implements OnPlaylistActi
|
|||
} else {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else if (actionType == ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST) {
|
||||
} else if (actionType == PlaylistsVM.action.DELETE_PLAYLIST) {
|
||||
if (this.playlists.size() == 0)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeComments(APIResponse apiResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertubeChannels(APIResponse apiResponse) {
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
|
||||
public interface OnRetrieveAccountInterface {
|
||||
void onRetrieveAccount(Account account, Error error);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package app.fedilab.fedilabtube.interfaces;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
|
||||
public interface OnRetrievePeertubeNotificationsInterface {
|
||||
void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account);
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class ChannelsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public ChannelsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> get() {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getChannels();
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void getChannels() {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(_mContext);
|
||||
Account account = new AccountDAO(_mContext, db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(_mContext, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
APIResponse apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class CommentVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public CommentVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getComment(String instanceName, String videoId) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instanceName, videoId);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
private void getSingle(String instanceName, String videoId) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = api.getSinglePeertubeComments(instanceName, videoId);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.viewmodel;
|
|||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -30,6 +31,7 @@ import java.util.List;
|
|||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
@ -49,6 +51,59 @@ public class FeedsVM extends AndroidViewModel {
|
|||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
public LiveData<APIResponse> getVideo(String instanceName, String videoId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instanceName, videoId);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> updateVideo(Peertube peertube) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
update(peertube);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void update(Peertube peertube){
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = peertubeAPI.updateVideo(peertube);
|
||||
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
||||
apiResponse.getPeertubes().get(0).setUpdate(true);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void getSingle(String instanceName, String videoId){
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
APIResponse apiResponse = peertubeAPI.getSinglePeertube(instanceName, videoId, token);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
String rate = new PeertubeAPI(_mContext).getRating(videoId);
|
||||
if (rate != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(rate);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void loadVideos(Type action, String max_id, String target, String forAccount) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
|
||||
public class PlaylistsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public PlaylistsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> manage(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
managePlaylists(apiAction, playlist, videoId, max_id);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void managePlaylists(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(_mContext);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(_mContext, db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(_mContext, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
}
|
||||
int statusCode = -1;
|
||||
APIResponse apiResponse = null;
|
||||
if (account == null) {
|
||||
statusCode = 403;
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setPlaylists(new ArrayList<>());
|
||||
} else if (apiAction == action.GET_PLAYLIST) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlayists(account.getUsername());
|
||||
} else if (apiAction == action.GET_LIST_VIDEOS) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlaylistVideos(playlist.getId(), max_id, null);
|
||||
} else if (apiAction == action.DELETE_PLAYLIST) {
|
||||
statusCode = new PeertubeAPI(_mContext).deletePlaylist(playlist.getId());
|
||||
} else if (apiAction == action.ADD_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(_mContext).addVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.DELETE_VIDEOS) {
|
||||
statusCode = new PeertubeAPI(_mContext).deleteVideoPlaylist(playlist.getId(), videoId);
|
||||
} else if (apiAction == action.GET_PLAYLIST_FOR_VIDEO) {
|
||||
apiResponse = new PeertubeAPI(_mContext).getPlaylistForVideo(videoId);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
if( apiResponse != null) {
|
||||
apiResponse.setStatusCode(statusCode);
|
||||
}
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public enum action {
|
||||
GET_PLAYLIST,
|
||||
GET_LIST_VIDEOS,
|
||||
CREATE_PLAYLIST,
|
||||
DELETE_PLAYLIST,
|
||||
ADD_VIDEOS,
|
||||
DELETE_VIDEOS,
|
||||
GET_PLAYLIST_FOR_VIDEO,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package app.fedilab.fedilabtube.viewmodel;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
|
||||
|
||||
public class PostActionsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public PostActionsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> post(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
makeAction(apiAction, targetedId, comment, targetedComment);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void makeAction(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
int statusCode = -1;
|
||||
if (apiAction == PeertubeAPI.StatusAction.FOLLOW || apiAction == PeertubeAPI.StatusAction.UNFOLLOW
|
||||
|| apiAction == PeertubeAPI.StatusAction.MUTE || apiAction == PeertubeAPI.StatusAction.UNMUTE) {
|
||||
statusCode = peertubeAPI.postAction(apiAction, targetedId);
|
||||
} else if (apiAction == PeertubeAPI.StatusAction.RATEVIDEO)
|
||||
statusCode = peertubeAPI.postRating(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
|
||||
statusCode = peertubeAPI.postComment(targetedId, comment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEREPLY)
|
||||
statusCode = peertubeAPI.postReply(targetedId, comment, targetedComment);
|
||||
else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) {
|
||||
statusCode = peertubeAPI.deleteComment(targetedId, comment);
|
||||
} else if (apiAction == PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO) {
|
||||
statusCode = peertubeAPI.deleteVideo(targetedId);
|
||||
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) {
|
||||
statusCode = peertubeAPI.report(PeertubeAPI.reportType.ACCOUNT, targetedId, comment);
|
||||
} else if (apiAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
|
||||
statusCode = peertubeAPI.report(PeertubeAPI.reportType.VIDEO, targetedId, comment);
|
||||
}
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
apiResponse.setError(peertubeAPI.getError());
|
||||
apiResponse.setStatusCode(statusCode);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue