1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-06-05 21:09:11 +02:00

Allow to report videos and accounts

This commit is contained in:
Thomas
2020-07-21 18:49:13 +02:00
parent f454b42376
commit 1f61e7f613
9 changed files with 163 additions and 3 deletions

View File

@ -17,6 +17,7 @@ package app.fedilab.fedilabtube;
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;
@ -36,7 +37,11 @@ import org.jetbrains.annotations.NotNull;
import app.fedilab.fedilabtube.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask;
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.fedilabtube.client.entities.Account;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import static app.fedilab.fedilabtube.helper.Helper.academies;
@ -100,6 +105,14 @@ public class MainActivity extends AppCompatActivity {
myVideosItem.setVisible(true);
playslistItem.setVisible(true);
subscriptionItem.setVisible(true);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(MainActivity.this);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance);
if( account != null) {
new UpdateAccountInfoAsyncTask(MainActivity.this, account.getToken(), account.getClient_id(), account.getClient_secret(), account.getRefresh_token(), account.getInstance()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} else {
instanceItem.setVisible(true);
uploadItem.setVisible(false);

View File

@ -30,6 +30,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
@ -38,6 +39,7 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
@ -296,8 +298,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_webview, menu);
menu.findItem(R.id.action_go).setVisible(false);
getMenuInflater().inflate(R.menu.main_peertube, menu);
return true;
}
@ -306,10 +307,45 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}else if (item.getItemId() == R.id.action_report) {
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
Button report_video = dialogView.findViewById(R.id.report_video);
Button report_account = dialogView.findViewById(R.id.report_account);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(PeertubeAPI.reportType.ACCOUNT, alertDialog));
return true;
}
return super.onOptionsItemSelected(item);
}
private void reportAlert(PeertubeAPI.reportType type, androidx.appcompat.app.AlertDialog alertDialog){
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
EditText report_content = dialogView.findViewById(R.id.report_content);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create();
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
if( type == PeertubeAPI.reportType.VIDEO) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_VIDEO, peertube.getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
alertDialog.dismiss();
alertDialog2.dismiss();
}else if (type == PeertubeAPI.reportType.ACCOUNT) {
new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.REPORT_ACCOUNT, peertube.getAccount().getId(), report_content.getText().toString(), PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
alertDialog.dismiss();
alertDialog2.dismiss();
}
});
alertDialog2.show();
}
public FullScreenMediaController.fullscreen getFullscreen() {
return fullscreen;
}
@ -705,8 +741,13 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
@Override
public void onPostAction(int statusCode, PeertubeAPI.StatusAction statusAction, String userId, Error error) {
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT)
if (peertube.isCommentsEnabled() && statusAction == PeertubeAPI.StatusAction.PEERTUBECOMMENT) {
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( statusAction == PeertubeAPI.StatusAction.REPORT_ACCOUNT) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show();
}else if( statusAction == PeertubeAPI.StatusAction.REPORT_VIDEO) {
Toasty.success(PeertubeActivity.this, getString(R.string.successful_video_report), Toasty.LENGTH_LONG).show();
}
}
private void initFullscreenDialog() {

View File

@ -78,6 +78,10 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
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;

View File

@ -77,6 +77,11 @@ public class PeertubeAPI {
private APIResponse apiResponse;
private Error APIError;
public enum reportType {
ACCOUNT,
COMMENT,
VIDEO
}
public PeertubeAPI(Context context) {
this.context = context;
@ -772,6 +777,34 @@ public class PeertubeAPI {
}
public int report(reportType type, String id, String reason) {
actionCode = -1;
try {
HashMap<String, String> params = new HashMap<>();
switch (type){
case VIDEO:
params.put("video", id);
break;
case ACCOUNT:
params.put("account", id);
break;
case COMMENT:
params.put("comment", id);
break;
}
params.put("reason", reason);
HttpsConnection httpsConnection = new HttpsConnection(context);
httpsConnection.post(getAbsoluteUrl("/abuses"), 30, params, null);
actionCode = httpsConnection.getActionCode();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return actionCode;
}
public APIResponse createAccount(AccountCreation accountCreation) {
apiResponse = new APIResponse();
@ -1842,6 +1875,8 @@ public class PeertubeAPI {
PEERTUBEREPLY,
PEERTUBEDELETECOMMENT,
PEERTUBEDELETEVIDEO,
REPORT_ACCOUNT,
REPORT_VIDEO
}
}