diff --git a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java index 88b727b..f7517ba 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java @@ -47,7 +47,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.HttpsConnection; import app.fedilab.fedilabtube.client.PeertubeAPI; @@ -55,14 +54,14 @@ 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.viewmodel.ChannelsVM; +import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import es.dmoral.toasty.Toasty; -import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; +import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; -public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylistActionInterface { +public class AllPlaylistsActivity extends AppCompatActivity { PlaylistAdapter playlistAdapter; @@ -93,7 +92,9 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis nextElementLoader.setVisibility(View.GONE); idChannel = null; - asyncTask = new ManagePlaylistsAsyncTask(AllPlaylistsActivity.this, ManagePlaylistsAsyncTask.action.GET_PLAYLIST, null, null, null, AllPlaylistsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PlaylistsVM viewModel = new ViewModelProvider(AllPlaylistsActivity.this).get(PlaylistsVM.class); + viewModel.manage(PlaylistsVM.action.GET_PLAYLIST, null, null, null).observe(AllPlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLIST, apiResponse)); + FloatingActionButton add_new = findViewById(R.id.add_new); @@ -216,15 +217,13 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis } - @Override - public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) { + public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { mainLoader.setVisibility(View.GONE); if (apiResponse.getError() != null) { Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); return; } - - if (actionType == ManagePlaylistsAsyncTask.action.GET_PLAYLIST) { + if (actionType == PlaylistsVM.action.GET_PLAYLIST) { if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) { playlists.addAll(apiResponse.getPlaylists()); playlistAdapter.notifyDataSetChanged(); @@ -236,7 +235,6 @@ public class AllPlaylistsActivity extends AppCompatActivity implements OnPlaylis } - public void manageVIewChannels(APIResponse apiResponse) { if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) { if (apiResponse.getError() != null && apiResponse.getError().getError() != null) diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index f58ede8..f66080a 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -19,7 +19,6 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; -import android.os.AsyncTask; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -41,7 +40,7 @@ import org.jetbrains.annotations.NotNull; import java.util.LinkedHashMap; -import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask; +import app.fedilab.fedilabtube.client.HttpsConnection; import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.Account; import app.fedilab.fedilabtube.client.entities.PeertubeInformation; @@ -50,11 +49,12 @@ import app.fedilab.fedilabtube.sqlite.AccountDAO; import app.fedilab.fedilabtube.sqlite.Sqlite; import app.fedilab.fedilabtube.viewmodel.FeedsVM; -import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; import static app.fedilab.fedilabtube.helper.Helper.academies; public class MainActivity extends AppCompatActivity { + public static PeertubeInformation peertubeInformation; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -67,17 +67,20 @@ public class MainActivity extends AppCompatActivity { navView.inflateMenu(R.menu.bottom_nav_menu); } - try { - peertubeInformation = new PeertubeInformation(); - peertubeInformation.setCategories(new LinkedHashMap<>()); - peertubeInformation.setLanguages(new LinkedHashMap<>()); - peertubeInformation.setLicences(new LinkedHashMap<>()); - peertubeInformation.setPrivacies(new LinkedHashMap<>()); - peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>()); - peertubeInformation.setTranslations(new LinkedHashMap<>()); - new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } catch (Exception ignored) { - } + peertubeInformation = new PeertubeInformation(); + peertubeInformation.setCategories(new LinkedHashMap<>()); + peertubeInformation.setLanguages(new LinkedHashMap<>()); + peertubeInformation.setLicences(new LinkedHashMap<>()); + peertubeInformation.setPrivacies(new LinkedHashMap<>()); + peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>()); + peertubeInformation.setTranslations(new LinkedHashMap<>()); + new Thread(() -> { + try { + peertubeInformation = new PeertubeAPI(MainActivity.this).getPeertubeInformation(); + } catch (HttpsConnection.HttpsConnectionException e) { + e.printStackTrace(); + } + }).start(); // Passing each menu ID as a set of Ids because each // menu should be considered as top level destinations. diff --git a/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java index f2196d8..0db01de 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MyVideosActivity.java @@ -20,13 +20,11 @@ import android.view.MenuItem; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; -import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.fragment.DisplayStatusFragment; -import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; import app.fedilab.fedilabtube.viewmodel.FeedsVM; -public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFeedsInterface { +public class MyVideosActivity extends AppCompatActivity { private FeedsVM.Type type; @@ -71,9 +69,4 @@ public class MyVideosActivity extends AppCompatActivity implements OnRetrieveFee return super.onOptionsItemSelected(item); } - - @Override - public void onRetrieveFeeds(APIResponse apiResponse) { - - } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 00bb64b..bec61f4 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -103,7 +103,6 @@ import app.fedilab.fedilabtube.webview.MastalabWebChromeClient; import app.fedilab.fedilabtube.webview.MastalabWebViewClient; import es.dmoral.toasty.Toasty; - 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; @@ -337,12 +336,12 @@ public class PeertubeActivity extends AppCompatActivity { } else { if (type == PeertubeAPI.reportType.VIDEO) { 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)); + 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) { 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)); + 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(); } @@ -375,7 +374,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(), null).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2)); add_comment_read.setOnClickListener(v -> { if (isLoggedIn(PeertubeActivity.this)) { @@ -394,7 +393,7 @@ public class PeertubeActivity extends AppCompatActivity { String comment = add_comment_write.getText().toString(); if (comment.trim().length() > 0) { 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)); + 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); @@ -448,11 +447,11 @@ 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, null).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)); + 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()); @@ -494,7 +493,7 @@ public class PeertubeActivity extends AppCompatActivity { if (isLoggedIn(PeertubeActivity.this)) { String newState = peertube.getMyRating().equals("like") ? "none" : "like"; 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)); + 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) { @@ -515,7 +514,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(PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), newState, null).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(PeertubeAPI.StatusAction.RATEVIDEO, apiResponse1)); + 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) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index c7a76ef..e739ce1 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -56,24 +56,21 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; 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.Error; import app.fedilab.fedilabtube.client.entities.Peertube; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.FeedsVM; +import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; import mabbas007.tagsedittext.TagsEditText; -import static android.os.AsyncTask.THREAD_POOL_EXECUTOR; -import static app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask.peertubeInformation; +import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; -public class PeertubeEditUploadActivity extends AppCompatActivity implements OnPostActionInterface { +public class PeertubeEditUploadActivity extends AppCompatActivity { private final int PICK_IMAGE = 50378; @@ -133,7 +130,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnP builderInner.setMessage(getString(R.string.delete_video_confirmation)); builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { - new PostActionAsyncTask(PeertubeEditUploadActivity.this, PeertubeAPI.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR); + 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)); dialog.dismiss(); }); builderInner.show(); @@ -614,7 +612,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnP } - public void manageVIewChannels(APIResponse apiResponse) { if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) { if (apiResponse.getError().getError() != null) @@ -654,8 +651,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity implements OnP set_upload_submit.setEnabled(true); } - @Override - public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) { + @SuppressWarnings("unused") + public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) { Intent intent = new Intent(PeertubeEditUploadActivity.this, MainActivity.class); intent.putExtra(Helper.INTENT_ACTION, Helper.RELOAD_MYVIDEOS); startActivity(intent); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java index 8cd5290..7bee622 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java @@ -15,6 +15,8 @@ package app.fedilab.fedilabtube; * see . */ import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.Patterns; @@ -33,16 +35,13 @@ import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; -import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; +import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.AccountCreation; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostStatusActionInterface; import es.dmoral.toasty.Toasty; -import static android.os.AsyncTask.THREAD_POOL_EXECUTOR; - -public class PeertubeRegisterActivity extends AppCompatActivity implements OnPostStatusActionInterface { +public class PeertubeRegisterActivity extends AppCompatActivity { private Button signup; @@ -143,7 +142,52 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim()); accountCreation.setUsername(username.getText().toString().trim()); accountCreation.setInstance(instance); - new CreatePeertubeAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, Helper.getPeertubeUrl(instance), PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR); + + new Thread(() -> { + try { + APIResponse apiResponse = new PeertubeAPI(PeertubeRegisterActivity.this, instance, null).createAccount(accountCreation); + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + if (apiResponse.getError() != null) { + String errorMessage; + if (apiResponse.getError().getError() != null) { + try { + String[] resp = apiResponse.getError().getError().split(":"); + if (resp.length == 2) + errorMessage = apiResponse.getError().getError().split(":")[1]; + else if (resp.length == 3) + errorMessage = apiResponse.getError().getError().split(":")[2]; + else + errorMessage = getString(R.string.toast_error); + } catch (Exception e) { + errorMessage = getString(R.string.toast_error); + } + } else { + errorMessage = getString(R.string.toast_error); + } + error_message.setText(errorMessage); + error_message.setVisibility(View.VISIBLE); + signup.setEnabled(true); + return; + } + + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeRegisterActivity.this); + dialogBuilder.setCancelable(false); + dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> { + dialog.dismiss(); + finish(); + }); + AlertDialog alertDialog = dialogBuilder.create(); + alertDialog.setTitle(getString(R.string.account_created)); + alertDialog.setMessage(getString(R.string.account_created_message, apiResponse.getStringData())); + alertDialog.show(); + }; + mainHandler.post(myRunnable); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + }); TextView agreement_text = findViewById(R.id.agreement_text); @@ -164,44 +208,6 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos } - @Override - public void onPostStatusAction(APIResponse apiResponse) { - if (apiResponse.getError() != null) { - String errorMessage; - if (apiResponse.getError().getError() != null) { - try { - String[] resp = apiResponse.getError().getError().split(":"); - if (resp.length == 2) - errorMessage = apiResponse.getError().getError().split(":")[1]; - else if (resp.length == 3) - errorMessage = apiResponse.getError().getError().split(":")[2]; - else - errorMessage = getString(R.string.toast_error); - } catch (Exception e) { - errorMessage = getString(R.string.toast_error); - } - } else { - errorMessage = getString(R.string.toast_error); - } - error_message.setText(errorMessage); - error_message.setVisibility(View.VISIBLE); - signup.setEnabled(true); - return; - } - - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeRegisterActivity.this); - dialogBuilder.setCancelable(false); - dialogBuilder.setPositiveButton(R.string.validate, (dialog, which) -> { - dialog.dismiss(); - finish(); - }); - AlertDialog alertDialog = dialogBuilder.create(); - alertDialog.setTitle(getString(R.string.account_created)); - alertDialog.setMessage(getString(R.string.account_created_message, apiResponse.getStringData())); - alertDialog.show(); - } - - @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java index 289da05..90ad2f0 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java @@ -23,7 +23,6 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; -import android.os.AsyncTask; import android.os.Bundle; import android.provider.OpenableColumns; import android.view.MenuItem; @@ -39,6 +38,7 @@ import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.lifecycle.ViewModelProvider; import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.UploadNotificationAction; @@ -53,17 +53,16 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeChannelsAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.entities.Account; import app.fedilab.fedilabtube.helper.Helper; -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; +import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; -public class PeertubeUploadActivity extends AppCompatActivity implements OnRetrievePeertubeInterface { +public class PeertubeUploadActivity extends AppCompatActivity { private final int PICK_IVDEO = 52378; @@ -95,7 +94,8 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri set_upload_submit = findViewById(R.id.set_upload_submit); video_title = findViewById(R.id.video_title); - new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class); + viewModelC.get().observe(PeertubeUploadActivity.this, this::manageVIewChannels); channels = new HashMap<>(); setTitle(R.string.upload_video); } @@ -143,10 +143,6 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri super.onDestroy(); } - @Override - public void onRetrievePeertube(APIResponse apiResponse) { - - } @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -157,14 +153,7 @@ public class PeertubeUploadActivity extends AppCompatActivity implements OnRetri 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() != null && apiResponse.getError().getError() != null) Toasty.error(PeertubeUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java index cb38ad2..cb82e1c 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PlaylistsActivity.java @@ -146,7 +146,6 @@ public class PlaylistsActivity extends AppCompatActivity { } - public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { mainLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE); diff --git a/app/src/main/java/app/fedilab/fedilabtube/SearchActivity.java b/app/src/main/java/app/fedilab/fedilabtube/SearchActivity.java index a7be386..05d64f5 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/SearchActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/SearchActivity.java @@ -21,13 +21,11 @@ import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; -import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.fragment.DisplayStatusFragment; -import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; import es.dmoral.toasty.Toasty; -public class SearchActivity extends AppCompatActivity implements OnRetrieveFeedsInterface { +public class SearchActivity extends AppCompatActivity { private String search; @@ -69,9 +67,4 @@ public class SearchActivity extends AppCompatActivity implements OnRetrieveFeeds return super.onOptionsItemSelected(item); } - - @Override - public void onRetrieveFeeds(APIResponse apiResponse) { - - } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/ShowAccountActivity.java b/app/src/main/java/app/fedilab/fedilabtube/ShowAccountActivity.java index b5b8780..da76471 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/ShowAccountActivity.java @@ -41,6 +41,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.lifecycle.ViewModelProvider; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -48,10 +49,8 @@ import com.google.android.material.tabs.TabLayout; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; -import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; import app.fedilab.fedilabtube.asynctasks.RetrieveRelationshipAsyncTask; import app.fedilab.fedilabtube.asynctasks.RetrieveSingleAccountAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; @@ -59,18 +58,13 @@ import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.Account; import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Relationship; -import app.fedilab.fedilabtube.client.entities.Status; -import app.fedilab.fedilabtube.client.entities.StatusDrawerParams; -import app.fedilab.fedilabtube.drawer.StatusListAdapter; import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment; import app.fedilab.fedilabtube.fragment.DisplayStatusFragment; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountsInterface; -import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsAccountInterface; -import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface; import app.fedilab.fedilabtube.viewmodel.FeedsVM; +import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY; @@ -78,11 +72,9 @@ import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; -public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface, OnRetrieveAccountsInterface { +public class ShowAccountActivity extends AppCompatActivity implements OnRetrieveRelationshipInterface, OnRetrieveAccountsInterface { - private List statuses; - private StatusListAdapter statusListAdapter; private Button account_follow; private ViewPager mPager; private TabLayout tabLayout; @@ -119,13 +111,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } else { Toasty.error(ShowAccountActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show(); } - statuses = new ArrayList<>(); - StatusDrawerParams statusDrawerParams = new StatusDrawerParams(); - statusDrawerParams.setType(FeedsVM.Type.USER); - statusDrawerParams.setTargetedId(accountId); - statusDrawerParams.setStatuses(statuses); - statusListAdapter = new StatusListAdapter(statusDrawerParams); - if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -158,7 +143,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi finish(); return true; } else if (item.getItemId() == R.id.action_mute) { - new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.MUTE, account.getchannelOwner() != null ? account.getchannelOwner().getAcct() : account.getAcct(), ShowAccountActivity.this).execute(); + PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.MUTE, account.getchannelOwner() != null ? account.getchannelOwner().getAcct() : account.getAcct(), null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.MUTE, apiResponse)); } else if (item.getItemId() == R.id.action_report) { androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(ShowAccountActivity.this); LayoutInflater inflater1 = getLayoutInflater(); @@ -170,7 +156,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi if (report_content.getText().toString().trim().length() == 0) { Toasty.info(ShowAccountActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show(); } else { - new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, account.getId(), report_content.getText().toString(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.REPORT_ACCOUNT, account.getId(), report_content.getText().toString(), null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.REPORT_ACCOUNT, apiResponse)); dialog.dismiss(); } }); @@ -274,7 +261,8 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi Toasty.info(ShowAccountActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show(); } else if (doAction == action.FOLLOW) { account_follow.setEnabled(false); - new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.FOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.FOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.FOLLOW, apiResponse)); } else if (doAction == action.UNFOLLOW) { boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true); if (confirm_unfollow) { @@ -284,33 +272,21 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> { account_follow.setEnabled(false); - new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.UNFOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.UNFOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNFOLLOW, apiResponse)); dialog.dismiss(); }); unfollowConfirm.show(); } else { account_follow.setEnabled(false); - new PostActionAsyncTask(ShowAccountActivity.this, PeertubeAPI.StatusAction.UNFOLLOW, target, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.UNFOLLOW, target, null, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNFOLLOW, apiResponse)); } } }); } - @Override - public void onRetrieveFeedsAccount(List statuses) { - if (statuses != null) { - this.statuses.addAll(statuses); - statusListAdapter.notifyDataSetChanged(); - } - } - - @Override - public void onRetrieveFeeds(APIResponse apiResponse) { - if (apiResponse.getError() != null) { - Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); - } - } @Override public void onRetrieveRelationship(List relationships, Error error) { @@ -387,18 +363,18 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } } - @Override - public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) { - if (error != null) { - Toasty.error(ShowAccountActivity.this, error.getError(), Toast.LENGTH_LONG).show(); + public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) { + + if (apiResponse.getError() != null) { + Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); return; } String target = account.getAcct(); //IF action is unfollow or mute, sends an intent to remove statuses if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) { Bundle b = new Bundle(); - b.putString("receive_action", targetedId); + b.putString("receive_action", apiResponse.getTargetedId()); Intent intentBC = new Intent(Helper.RECEIVE_ACTION); intentBC.putExtras(b); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/CreatePeertubeAccountAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/CreatePeertubeAccountAsyncTask.java deleted file mode 100644 index b7e8ad9..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/CreatePeertubeAccountAsyncTask.java +++ /dev/null @@ -1,55 +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 . */ - -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.AccountCreation; -import app.fedilab.fedilabtube.interfaces.OnPostStatusActionInterface; - - -public class CreatePeertubeAccountAsyncTask extends AsyncTask { - - private OnPostStatusActionInterface listener; - private APIResponse apiResponse; - private AccountCreation accountCreation; - private WeakReference contextReference; - private String instance; - - public CreatePeertubeAccountAsyncTask(Context context, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface) { - this.contextReference = new WeakReference<>(context); - this.listener = onPostStatusActionInterface; - this.accountCreation = accountCreation; - this.instance = instance; - } - - @Override - protected Void doInBackground(Void... params) { - apiResponse = new PeertubeAPI(contextReference.get(), instance, null).createAccount(accountCreation); - return null; - } - - @Override - protected void onPostExecute(Void result) { - listener.onPostStatusAction(apiResponse); - - } - -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/ManagePlaylistsAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/ManagePlaylistsAsyncTask.java deleted file mode 100644 index f9b4394..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/ManagePlaylistsAsyncTask.java +++ /dev/null @@ -1,100 +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 . */ - -import android.content.Context; -import android.content.SharedPreferences; -import android.database.sqlite.SQLiteDatabase; -import android.os.AsyncTask; - -import java.lang.ref.WeakReference; -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.interfaces.OnPlaylistActionInterface; -import app.fedilab.fedilabtube.sqlite.AccountDAO; -import app.fedilab.fedilabtube.sqlite.Sqlite; - - -public class ManagePlaylistsAsyncTask extends AsyncTask { - - private OnPlaylistActionInterface listener; - private APIResponse apiResponse; - private int statusCode; - private action apiAction; - private WeakReference contextReference; - private String max_id; - private Playlist playlist; - private String videoId; - - public ManagePlaylistsAsyncTask(Context context, action apiAction, Playlist playlist, String videoId, String max_id, OnPlaylistActionInterface onPlaylistActionInterface) { - contextReference = new WeakReference<>(context); - this.listener = onPlaylistActionInterface; - this.apiAction = apiAction; - this.max_id = max_id; - this.playlist = playlist; - this.videoId = videoId; - } - - @Override - protected Void doInBackground(Void... params) { - SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - String instance = Helper.getLiveInstance(contextReference.get()); - SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance); - if (account == null) { - account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance)); - } - if (account == null) { - statusCode = 403; - apiResponse = new APIResponse(); - apiResponse.setPlaylists(new ArrayList<>()); - } else if (apiAction == action.GET_PLAYLIST) { - apiResponse = new PeertubeAPI(contextReference.get()).getPlayists(account.getUsername()); - } else if (apiAction == action.GET_LIST_VIDEOS) { - apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistVideos(playlist.getId(), max_id, null); - } else if (apiAction == action.DELETE_PLAYLIST) { - statusCode = new PeertubeAPI(contextReference.get()).deletePlaylist(playlist.getId()); - } else if (apiAction == action.ADD_VIDEOS) { - statusCode = new PeertubeAPI(contextReference.get()).addVideoPlaylist(playlist.getId(), videoId); - } else if (apiAction == action.DELETE_VIDEOS) { - statusCode = new PeertubeAPI(contextReference.get()).deleteVideoPlaylist(playlist.getId(), videoId); - } else if (apiAction == action.GET_PLAYLIST_FOR_VIDEO) { - apiResponse = new PeertubeAPI(contextReference.get()).getPlaylistForVideo(videoId); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - listener.onActionDone(this.apiAction, apiResponse, statusCode); - } - - public enum action { - GET_PLAYLIST, - GET_LIST_VIDEOS, - CREATE_PLAYLIST, - DELETE_PLAYLIST, - ADD_VIDEOS, - DELETE_VIDEOS, - GET_PLAYLIST_FOR_VIDEO, - } - -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java deleted file mode 100644 index 294a718..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java +++ /dev/null @@ -1,98 +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 . */ - -import android.content.Context; -import android.os.AsyncTask; - -import java.lang.ref.WeakReference; - -import app.fedilab.fedilabtube.client.PeertubeAPI; -import app.fedilab.fedilabtube.client.entities.Error; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; - - -public class PostActionAsyncTask extends AsyncTask { - - private OnPostActionInterface listener; - private int statusCode; - private PeertubeAPI.StatusAction apiAction; - private String targetedId, targetedComment; - private String comment; - private WeakReference contextReference; - private Error error; - - - public PostActionAsyncTask(Context context, PeertubeAPI.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface) { - this.contextReference = new WeakReference<>(context); - this.listener = onPostActionInterface; - this.apiAction = apiAction; - this.targetedId = targetedId; - } - - @SuppressWarnings("unused") - public PostActionAsyncTask(Context context, String targetedId, String comment, String targetedComment, OnPostActionInterface onPostActionInterface) { - this.contextReference = new WeakReference<>(context); - this.listener = onPostActionInterface; - this.apiAction = PeertubeAPI.StatusAction.PEERTUBEREPLY; - this.targetedId = targetedId; - this.comment = comment; - this.targetedComment = targetedComment; - } - - public PostActionAsyncTask(Context context, PeertubeAPI.StatusAction apiAction, String targetedId, String comment, OnPostActionInterface onPostActionInterface) { - contextReference = new WeakReference<>(context); - this.listener = onPostActionInterface; - this.apiAction = apiAction; - this.targetedId = targetedId; - this.comment = comment; - } - - - @Override - protected Void doInBackground(Void... params) { - - PeertubeAPI peertubeAPI = new PeertubeAPI(contextReference.get()); - 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); - 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); - } - error = peertubeAPI.getError(); - return null; - } - - @Override - protected void onPostExecute(Void result) { - if (listener != null) { - listener.onPostAction(statusCode, apiAction, targetedId, error); - } - } - -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeChannelsAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeChannelsAsyncTask.java deleted file mode 100644 index af9dfab..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeChannelsAsyncTask.java +++ /dev/null @@ -1,65 +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 . */ - -import android.content.Context; -import android.content.SharedPreferences; -import android.database.sqlite.SQLiteDatabase; -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.Account; -import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface; -import app.fedilab.fedilabtube.sqlite.AccountDAO; -import app.fedilab.fedilabtube.sqlite.Sqlite; - - -public class RetrievePeertubeChannelsAsyncTask extends AsyncTask { - - - private APIResponse apiResponse; - private OnRetrievePeertubeInterface listener; - private WeakReference contextReference; - - - public RetrievePeertubeChannelsAsyncTask(Context context, OnRetrievePeertubeInterface onRetrievePeertubeInterface) { - this.contextReference = new WeakReference<>(context); - this.listener = onRetrievePeertubeInterface; - } - - @Override - protected Void doInBackground(Void... params) { - PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); - SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - String instance = Helper.getLiveInstance(contextReference.get()); - Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance); - if (account == null) { - account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance)); - } - apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername()); - return null; - } - - @Override - protected void onPostExecute(Void result) { - listener.onRetrievePeertubeChannels(apiResponse); - } -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeInformationAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeInformationAsyncTask.java deleted file mode 100644 index 9991073..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrievePeertubeInformationAsyncTask.java +++ /dev/null @@ -1,52 +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 . */ - -import android.content.Context; -import android.os.AsyncTask; - -import java.lang.ref.WeakReference; - -import app.fedilab.fedilabtube.client.HttpsConnection; -import app.fedilab.fedilabtube.client.PeertubeAPI; -import app.fedilab.fedilabtube.client.entities.PeertubeInformation; - - -public class RetrievePeertubeInformationAsyncTask extends AsyncTask { - - - public static PeertubeInformation peertubeInformation; - private WeakReference contextReference; - - - public RetrievePeertubeInformationAsyncTask(Context context) { - this.contextReference = new WeakReference<>(context); - } - - @Override - protected Void doInBackground(Void... params) { - PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get()); - try { - peertubeInformation = peertubeAPI.getPeertubeInformation(); - } catch (HttpsConnection.HttpsConnectionException e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - } -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/HttpsConnection.java b/app/src/main/java/app/fedilab/fedilabtube/client/HttpsConnection.java index 1a2beaa..4bfe07a 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/HttpsConnection.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/HttpsConnection.java @@ -56,10 +56,7 @@ import java.util.regex.Pattern; import javax.net.ssl.HttpsURLConnection; import app.fedilab.fedilabtube.R; -import app.fedilab.fedilabtube.client.entities.Error; -import app.fedilab.fedilabtube.helper.FileNameCleaner; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnDownloadInterface; @SuppressWarnings("unused") @@ -390,70 +387,6 @@ public class HttpsConnection { } - /*** - * Download method which works for http and https connections - * @param downloadUrl String download url - * @param listener OnDownloadInterface, listener which manages progress - */ - public void download(final String downloadUrl, final OnDownloadInterface listener) { - new Thread(() -> { - URL url; - HttpsURLConnection httpsURLConnection; - try { - url = new URL(downloadUrl); - if (proxy != null) - httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy); - else - httpsURLConnection = (HttpsURLConnection) url.openConnection(); - int responseCode = httpsURLConnection.getResponseCode(); - - // always check HTTP response code first - if (responseCode == HttpURLConnection.HTTP_OK) { - String fileName = ""; - String disposition = httpsURLConnection.getHeaderField("Content-Disposition"); - - if (disposition != null) { - // extracts file name from header field - int index = disposition.indexOf("filename="); - if (index > 0) { - fileName = disposition.substring(index + 10, - disposition.length() - 1); - } - } else { - // extracts file name from URL - fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1 - ); - } - fileName = FileNameCleaner.cleanFileName(fileName); - // opens input stream from the HTTP connection - InputStream inputStream = httpsURLConnection.getInputStream(); - File saveDir = context.getCacheDir(); - final String saveFilePath = saveDir + File.separator + fileName; - - // opens an output stream to save into file - FileOutputStream outputStream = new FileOutputStream(saveFilePath); - - int bytesRead; - byte[] buffer = new byte[CHUNK_SIZE]; - - while ((bytesRead = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } - outputStream.close(); - inputStream.close(); - } else { - final Error error = new Error(); - error.setError(String.valueOf(responseCode)); - - } - } catch (IOException e) { - Error error = new Error(); - error.setError(context.getString(R.string.toast_error)); - } - }).start(); - } - - public InputStream getPicture(final String downloadUrl) { URL url; diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsHorizontalListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsHorizontalListAdapter.java index aa4dab2..893ff93 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsHorizontalListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsHorizontalListAdapter.java @@ -22,7 +22,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; @@ -32,24 +31,18 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import app.fedilab.fedilabtube.R; -import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.Account; -import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; -import es.dmoral.toasty.Toasty; -public class AccountsHorizontalListAdapter extends RecyclerView.Adapter implements OnPostActionInterface { +public class AccountsHorizontalListAdapter extends RecyclerView.Adapter { EventListener listener; private List accounts; private Context context; - private AccountsHorizontalListAdapter accountsListAdapter; public AccountsHorizontalListAdapter(List accounts, EventListener listener) { this.accounts = accounts; - this.accountsListAdapter = this; this.listener = listener; } @@ -92,56 +85,6 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter position) - return accounts.get(position); - else - return null; - } - - @Override - public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) { - if (error != null) { - Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show(); - return; - } - - if (statusAction == PeertubeAPI.StatusAction.FOLLOW) { - /* if (action == RetrieveAccountsAsyncTask.Type.CHANNELS) { - SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new InstancesDAO(context, db).insertInstance(accounts.get(0).getAcct().split("@")[1], accounts.get(0).getAcct().split("@")[0], "PEERTUBE_CHANNEL"); - } else { - for (Account account : accounts) { - if (account.getId().equals(targetedId)) { - account.setFollowType(Account.followAction.FOLLOW); - account.setMakingAction(false); - } - } - accountsListAdapter.notifyDataSetChanged(); - }*/ - } - if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) { - for (Account account : accounts) { - if (account.getId().equals(targetedId)) { - account.setFollowType(Account.followAction.NOT_FOLLOW); - account.setMakingAction(false); - } - } - accountsListAdapter.notifyDataSetChanged(); - } - } - - private void notifyAccountChanged(Account account) { - for (int i = 0; i < accountsListAdapter.getItemCount(); i++) { - //noinspection ConstantConditions - if (accountsListAdapter.getItemAt(i) != null && accountsListAdapter.getItemAt(i).getId().equals(account.getId())) { - try { - accountsListAdapter.notifyItemChanged(i); - } catch (Exception ignored) { - } - } - } - } public interface EventListener { void click(String forAccount); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java index 79178f7..a3d9061 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java @@ -34,6 +34,9 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.ViewModelProvider; +import androidx.lifecycle.ViewModelStoreOwner; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -42,19 +45,18 @@ import java.util.List; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.ShowAccountActivity; -import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; +import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.HttpsConnection; import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.client.entities.Account; -import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.fragment.DisplayPlaylistsFragment; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; import app.fedilab.fedilabtube.viewmodel.AccountsVM; +import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; -public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostActionInterface { +public class AccountsListAdapter extends RecyclerView.Adapter { public AllAccountsRemoved allAccountsRemoved; private List accounts; @@ -128,7 +130,10 @@ public class AccountsListAdapter extends RecyclerView.Adapter new PostActionAsyncTask(context, PeertubeAPI.StatusAction.UNMUTE, account.getAcct(), AccountsListAdapter.this).execute()); + holder.account_action.setOnClickListener(v -> { + PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.UNMUTE, account.getAcct(), null, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.UNMUTE, apiResponse)); + }); } else { holder.account_action.hide(); } @@ -189,16 +194,15 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnActionInterface { +public class PeertubeAdapter extends RecyclerView.Adapter { private List peertubes; private Context context; @@ -166,11 +164,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter playlists; private LayoutInflater layoutInflater; @@ -121,6 +122,7 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte popup.getMenuInflater() .inflate(R.menu.playlist_menu, popup.getMenu()); popup.setOnMenuItemClickListener(item -> { + //noinspection SwitchStatementWithTooFewBranches switch (item.getItemId()) { case R.id.action_delete: AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -130,7 +132,9 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte .setPositiveButton(R.string.yes, (dialog, which) -> { playlists.remove(playlist); notifyDataSetChanged(); - new ManagePlaylistsAsyncTask(context, ManagePlaylistsAsyncTask.action.DELETE_PLAYLIST, playlist, null, null, PlaylistAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PlaylistsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class); + viewModel.manage(PlaylistsVM.action.DELETE_PLAYLIST, null, null, null).observe((LifecycleOwner) context, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.DELETE_PLAYLIST, apiResponse)); + if (playlists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE) textviewNoAction.setVisibility(View.VISIBLE); dialog.dismiss(); @@ -150,8 +154,8 @@ public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInte return convertView; } - @Override - public void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) { + @SuppressWarnings("unused") + public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { } diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java index 54f8401..9927b0b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/StatusListAdapter.java @@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.drawer; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; -import android.os.AsyncTask; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; @@ -35,6 +34,9 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.ViewModelProvider; +import androidx.lifecycle.ViewModelStoreOwner; import androidx.recyclerview.widget.RecyclerView; import java.util.List; @@ -43,20 +45,19 @@ import java.util.regex.Pattern; import app.fedilab.fedilabtube.PeertubeActivity; import app.fedilab.fedilabtube.R; -import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; +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.Error; import app.fedilab.fedilabtube.client.entities.Status; import app.fedilab.fedilabtube.client.entities.StatusDrawerParams; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.interfaces.OnPostActionInterface; +import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; import static android.content.Context.MODE_PRIVATE; -public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface { +public class StatusListAdapter extends RecyclerView.Adapter { private Context context; @@ -121,7 +122,8 @@ public class StatusListAdapter extends RecyclerView.Adapter dialog.dismiss()); builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { - new PostActionAsyncTask(context, PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class); + viewModel.post(PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, status.getId(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT, apiResponse)); dialog.dismiss(); }); builderInner.show(); @@ -173,18 +175,17 @@ public class StatusListAdapter extends RecyclerView.Adapter. */ - -import app.fedilab.fedilabtube.client.APIResponse; - -public interface OnActionInterface { - void onActionDone(APIResponse apiResponse, int statusCode); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnDownloadInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnDownloadInterface.java deleted file mode 100644 index 3b52269..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnDownloadInterface.java +++ /dev/null @@ -1,21 +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 . */ - -public interface OnDownloadInterface { - void onDownloaded(String saveFilePath, String downloadUrl, Error error); - - void onUpdateProgress(int progress); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPlaylistActionInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPlaylistActionInterface.java deleted file mode 100644 index 2db45e7..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPlaylistActionInterface.java +++ /dev/null @@ -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 . */ - -import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask; -import app.fedilab.fedilabtube.client.APIResponse; - -public interface OnPlaylistActionInterface { - void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostActionInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostActionInterface.java deleted file mode 100644 index 3621177..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostActionInterface.java +++ /dev/null @@ -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 . */ - -import app.fedilab.fedilabtube.client.PeertubeAPI; -import app.fedilab.fedilabtube.client.entities.Error; - -public interface OnPostActionInterface { - void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostStatusActionInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostStatusActionInterface.java deleted file mode 100644 index 220e526..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnPostStatusActionInterface.java +++ /dev/null @@ -1,21 +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 . */ - -import app.fedilab.fedilabtube.client.APIResponse; - -public interface OnPostStatusActionInterface { - void onPostStatusAction(APIResponse apiResponse); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsAccountInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsAccountInterface.java deleted file mode 100644 index 16aafc3..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsAccountInterface.java +++ /dev/null @@ -1,23 +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 . */ - -import java.util.List; - -import app.fedilab.fedilabtube.client.entities.Status; - -public interface OnRetrieveFeedsAccountInterface { - void onRetrieveFeedsAccount(List statuses); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsInterface.java deleted file mode 100644 index f5bdfd2..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrieveFeedsInterface.java +++ /dev/null @@ -1,21 +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 . */ - -import app.fedilab.fedilabtube.client.APIResponse; - -public interface OnRetrieveFeedsInterface { - void onRetrieveFeeds(APIResponse apiResponse); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrievePeertubeInterface.java b/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrievePeertubeInterface.java deleted file mode 100644 index 3a6008a..0000000 --- a/app/src/main/java/app/fedilab/fedilabtube/interfaces/OnRetrievePeertubeInterface.java +++ /dev/null @@ -1,25 +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 . */ - -import app.fedilab.fedilabtube.client.APIResponse; - -public interface OnRetrievePeertubeInterface { - void onRetrievePeertube(APIResponse apiResponse); - - void onRetrievePeertubeComments(APIResponse apiResponse); - - void onRetrievePeertubeChannels(APIResponse apiResponse); -} diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java index 862921e..844238e 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/ChannelsVM.java @@ -26,7 +26,6 @@ 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; diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java index c467ee7..e41de60 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java @@ -16,7 +16,6 @@ package app.fedilab.fedilabtube.viewmodel; import android.app.Application; import android.content.Context; -import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; @@ -27,7 +26,6 @@ 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 { diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java index 14b2d83..2c6b103 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/FeedsVM.java @@ -64,7 +64,7 @@ public class FeedsVM extends AndroidViewModel { return apiResponseMutableLiveData; } - private void update(Peertube peertube){ + private void update(Peertube peertube) { Context _mContext = this.application.getApplicationContext(); new Thread(() -> { try { @@ -82,7 +82,7 @@ public class FeedsVM extends AndroidViewModel { } - private void getSingle(String instanceName, String videoId){ + private void getSingle(String instanceName, String videoId) { Context _mContext = this.application.getApplicationContext(); new Thread(() -> { try { diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java index 28b398a..d078b1f 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java @@ -86,7 +86,7 @@ public class PlaylistsVM extends AndroidViewModel { apiResponse = new PeertubeAPI(_mContext).getPlaylistForVideo(videoId); } Handler mainHandler = new Handler(Looper.getMainLooper()); - if( apiResponse != null) { + if (apiResponse != null) { apiResponse.setStatusCode(statusCode); } APIResponse finalApiResponse = apiResponse; diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PostActionsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PostActionsVM.java index bd86f85..5c05ce8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PostActionsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PostActionsVM.java @@ -72,6 +72,7 @@ public class PostActionsVM extends AndroidViewModel { APIResponse apiResponse = new APIResponse(); apiResponse.setError(peertubeAPI.getError()); apiResponse.setStatusCode(statusCode); + apiResponse.setTargetedId(targetedId); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); mainHandler.post(myRunnable);