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:
		| @@ -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); | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										10
									
								
								app/src/main/res/drawable/ic_baseline_report_24.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/src/main/res/drawable/ic_baseline_report_24.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:width="24dp" | ||||
|     android:height="24dp" | ||||
|     android:viewportWidth="24" | ||||
|     android:viewportHeight="24" | ||||
|     android:tint="?attr/colorControlNormal"> | ||||
|   <path | ||||
|       android:fillColor="@android:color/white" | ||||
|       android:pathData="M15.73,3L8.27,3L3,8.27v7.46L8.27,21h7.46L21,15.73L21,8.27L15.73,3zM12,17.3c-0.72,0 -1.3,-0.58 -1.3,-1.3 0,-0.72 0.58,-1.3 1.3,-1.3 0.72,0 1.3,0.58 1.3,1.3 0,0.72 -0.58,1.3 -1.3,1.3zM13,13h-2L11,7h2v6z"/> | ||||
| </vector> | ||||
							
								
								
									
										16
									
								
								app/src/main/res/layout/popup_report.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/src/main/res/layout/popup_report.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto"> | ||||
|     <EditText | ||||
|         android:hint="@string/report_helper" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:id="@+id/report_content" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" | ||||
|         android:importantForAutofill="no" | ||||
|         android:inputType="text" /> | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
							
								
								
									
										26
									
								
								app/src/main/res/layout/popup_report_choice.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/src/main/res/layout/popup_report_choice.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto"> | ||||
|     <Button | ||||
|         style="@style/Base.Widget.AppCompat.Button.Colored" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:id="@+id/report_video" | ||||
|         android:text="@string/report_video" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|     <Button | ||||
|         style="@style/Base.Widget.AppCompat.Button.Colored" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:id="@+id/report_account" | ||||
|         android:text="@string/report_account" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/report_video" /> | ||||
|  | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
							
								
								
									
										9
									
								
								app/src/main/res/menu/main_peertube.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								app/src/main/res/menu/main_peertube.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto"> | ||||
|     <item | ||||
|         android:id="@+id/action_report" | ||||
|         android:icon="@drawable/ic_baseline_report_24" | ||||
|         android:title="@string/report" | ||||
|         app:showAsAction="ifRoom" /> | ||||
| </menu> | ||||
| @@ -167,4 +167,10 @@ | ||||
|     <string name="peertube_video_unblacklist"><![CDATA[Votre vidéo <b>%1$s</b> n’est plus blacklisté]]></string> | ||||
|     <string name="toast_code_error">Une erreur s’est produite ! L’instance n’a retourné aucun code d\autorisation !</string> | ||||
|     <string name="subscriptions">Abonnements</string> | ||||
|     <string name="report">Signaler</string> | ||||
|     <string name="report_video">Signaler la vidéo</string> | ||||
|     <string name="report_account">Signaler le compte</string> | ||||
|     <string name="report_helper">Quelques explications concernant votre signalement…</string> | ||||
|     <string name="successful_report">Le compte a été signalé !</string> | ||||
|     <string name="successful_video_report">La vidéo a été signalée !</string> | ||||
| </resources> | ||||
		Reference in New Issue
	
	Block a user