1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-03-30 03:20:04 +02:00
This commit is contained in:
Thomas 2020-09-08 10:11:11 +02:00
parent 014302c3a8
commit 7588a48cb5
36 changed files with 164 additions and 889 deletions

View File

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

View File

@ -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.

View File

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

View File

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

View File

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

View File

@ -15,6 +15,8 @@ package app.fedilab.fedilabtube;
* see <http://www.gnu.org/licenses>. */
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) {

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <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.AccountCreation;
import app.fedilab.fedilabtube.interfaces.OnPostStatusActionInterface;
public class CreatePeertubeAccountAsyncTask extends AsyncTask<Void, Void, Void> {
private OnPostStatusActionInterface listener;
private APIResponse apiResponse;
private AccountCreation accountCreation;
private WeakReference<Context> 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);
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Void, Void, Void> {
private OnPlaylistActionInterface listener;
private APIResponse apiResponse;
private int statusCode;
private action apiAction;
private WeakReference<Context> 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,
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Void, Void, Void> {
private OnPostActionInterface listener;
private int statusCode;
private PeertubeAPI.StatusAction apiAction;
private String targetedId, targetedComment;
private String comment;
private WeakReference<Context> 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);
}
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Void, Void, Void> {
private APIResponse apiResponse;
private OnRetrievePeertubeInterface listener;
private WeakReference<Context> 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);
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Void, Void, Void> {
public static PeertubeInformation peertubeInformation;
private WeakReference<Context> 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) {
}
}

View File

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

View File

@ -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<RecyclerView.ViewHolder> implements OnPostActionInterface {
public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
EventListener listener;
private List<Account> accounts;
private Context context;
private AccountsHorizontalListAdapter accountsListAdapter;
public AccountsHorizontalListAdapter(List<Account> accounts, EventListener listener) {
this.accounts = accounts;
this.accountsListAdapter = this;
this.listener = listener;
}
@ -92,56 +85,6 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
return accounts.size();
}
private Account getItemAt(int position) {
if (accounts.size() > 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);

View File

@ -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<RecyclerView.ViewHolder> implements OnPostActionInterface {
public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public AllAccountsRemoved allAccountsRemoved;
private List<Account> accounts;
@ -128,7 +130,10 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
.show();
});
} else if (type == AccountsVM.accountFetch.MUTED) {
holder.account_action.setOnClickListener(v -> 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<RecyclerView.ViewH
return accounts.size();
}
@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();
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (statusAction == PeertubeAPI.StatusAction.FOLLOW) {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
if (account.getId().equals(apiResponse.getTargetedId())) {
account.setFollowType(Account.followAction.FOLLOW);
account.setMakingAction(false);
}
@ -209,7 +213,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
Account tmpAccount = null;
int position = 0;
for (Account account : accounts) {
if (account.getAcct().equals(targetedId)) {
if (account.getAcct().equals(apiResponse.getTargetedId())) {
tmpAccount = account;
break;
}
@ -222,7 +226,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
if (statusAction == PeertubeAPI.StatusAction.UNFOLLOW) {
for (Account account : accounts) {
if (account.getId().equals(targetedId)) {
if (account.getId().equals(apiResponse.getTargetedId())) {
account.setFollowType(Account.followAction.NOT_FOLLOW);
account.setMakingAction(false);
}

View File

@ -36,14 +36,12 @@ import app.fedilab.fedilabtube.PeertubeActivity;
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.ShowAccountActivity;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnActionInterface;
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnActionInterface {
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<Peertube> peertubes;
private Context context;
@ -166,11 +164,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
@Override
public void onActionDone(APIResponse apiResponse, int statusCode) {
}
static class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout main_container, bottom_container;
ImageView peertube_profile, peertube_video_image;

View File

@ -17,7 +17,6 @@ package app.fedilab.fedilabtube.drawer;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -30,6 +29,9 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import com.bumptech.glide.Glide;
@ -38,13 +40,12 @@ import java.util.Map;
import app.fedilab.fedilabtube.PlaylistsActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.Playlist;
import app.fedilab.fedilabtube.interfaces.OnPlaylistActionInterface;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
public class PlaylistAdapter extends BaseAdapter implements OnPlaylistActionInterface {
public class PlaylistAdapter extends BaseAdapter {
private List<Playlist> 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) {
}

View File

@ -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<RecyclerView.ViewHolder> implements OnPostActionInterface {
public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
@ -121,7 +122,8 @@ public class StatusListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
builderInner.setMessage(R.string.delete_comment_confirm);
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> 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<RecyclerView.ViewHol
Helper.loadGiF(context, accountForUrl, holder.status_account_profile);
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String targetedId, Error error) {
public void manageVIewPostActions(PeertubeAPI.StatusAction statusAction, APIResponse apiResponse) {
if (error != null) {
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return;
}
if (statusAction == PeertubeAPI.StatusAction.PEERTUBEDELETECOMMENT) {
int position = 0;
for (Status status : statuses) {
if (status.getId().equals(targetedId)) {
if (status.getId().equals(apiResponse.getTargetedId())) {
statuses.remove(status);
statusListAdapter.notifyItemRemoved(position);
break;

View File

@ -65,7 +65,7 @@ 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 DisplayPlaylistsFragment extends Fragment {

View File

@ -44,14 +44,11 @@ import java.util.List;
import app.fedilab.fedilabtube.R;
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.drawer.AccountsHorizontalListAdapter;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.interfaces.OnPostActionInterface;
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
import app.fedilab.fedilabtube.viewmodel.SearchVM;
@ -61,7 +58,7 @@ import static app.fedilab.fedilabtube.viewmodel.FeedsVM.Type.POVERVIEW;
import static app.fedilab.fedilabtube.viewmodel.FeedsVM.Type.PSUBSCRIPTIONS;
public class DisplayStatusFragment extends Fragment implements OnPostActionInterface, AccountsHorizontalListAdapter.EventListener {
public class DisplayStatusFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener {
private LinearLayoutManager mLayoutManager;
@ -415,11 +412,6 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
}
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
}
@Override
public void click(String forAccount) {
this.forAccount = forAccount;

View File

@ -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 <http://www.gnu.org/licenses>. */
import app.fedilab.fedilabtube.client.APIResponse;
public interface OnActionInterface {
void onActionDone(APIResponse apiResponse, int statusCode);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
public interface OnDownloadInterface {
void onDownloaded(String saveFilePath, String downloadUrl, Error error);
void onUpdateProgress(int progress);
}

View File

@ -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.asynctasks.ManagePlaylistsAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
public interface OnPlaylistActionInterface {
void onActionDone(ManagePlaylistsAsyncTask.action actionType, APIResponse apiResponse, int statusCode);
}

View File

@ -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.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
public interface OnPostActionInterface {
void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
import app.fedilab.fedilabtube.client.APIResponse;
public interface OnPostStatusActionInterface {
void onPostStatusAction(APIResponse apiResponse);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
import java.util.List;
import app.fedilab.fedilabtube.client.entities.Status;
public interface OnRetrieveFeedsAccountInterface {
void onRetrieveFeedsAccount(List<Status> statuses);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
import app.fedilab.fedilabtube.client.APIResponse;
public interface OnRetrieveFeedsInterface {
void onRetrieveFeeds(APIResponse apiResponse);
}

View File

@ -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 <http://www.gnu.org/licenses>. */
import app.fedilab.fedilabtube.client.APIResponse;
public interface OnRetrievePeertubeInterface {
void onRetrievePeertube(APIResponse apiResponse);
void onRetrievePeertubeComments(APIResponse apiResponse);
void onRetrievePeertubeChannels(APIResponse apiResponse);
}

View File

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

View File

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

View File

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

View File

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

View File

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