diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index 8a08fdb..79a417d 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -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); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index ee62422..bb3e979 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -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() { diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java index 281ad97..654c4f8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/PostActionAsyncTask.java @@ -78,6 +78,10 @@ public class PostActionAsyncTask extends AsyncTask { 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; diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java index 1d3ff17..527dcbf 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java @@ -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 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 } } diff --git a/app/src/main/res/drawable/ic_baseline_report_24.xml b/app/src/main/res/drawable/ic_baseline_report_24.xml new file mode 100644 index 0000000..811e67b --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_report_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/popup_report.xml b/app/src/main/res/layout/popup_report.xml new file mode 100644 index 0000000..38fef75 --- /dev/null +++ b/app/src/main/res/layout/popup_report.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/popup_report_choice.xml b/app/src/main/res/layout/popup_report_choice.xml new file mode 100644 index 0000000..0cecdd5 --- /dev/null +++ b/app/src/main/res/layout/popup_report_choice.xml @@ -0,0 +1,26 @@ + + +