diff --git a/app/src/main/java/app/fedilab/android/asynctasks/PostAdminActionAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/PostAdminActionAsyncTask.java new file mode 100644 index 000000000..b532440c6 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/asynctasks/PostAdminActionAsyncTask.java @@ -0,0 +1,64 @@ +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * 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. + * + * Fedilab 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 Fedilab; if not, + * see . */ +package app.fedilab.android.asynctasks; + +import android.content.Context; +import android.os.AsyncTask; + +import java.lang.ref.WeakReference; +import app.fedilab.android.client.API; +import app.fedilab.android.client.APIResponse; +import app.fedilab.android.client.Entities.AdminAction; +import app.fedilab.android.interfaces.OnAdminActionInterface; + + + +/** + * Created by Thomas on 18/06/2019. + * Makes actions for post admin calls + */ + +public class PostAdminActionAsyncTask extends AsyncTask { + + private OnAdminActionInterface listener; + private API.adminAction action; + private String id; + private WeakReference contextReference; + private APIResponse apiResponse; + private AdminAction adminAction; + + + + public PostAdminActionAsyncTask(Context context, API.adminAction action, String id, AdminAction adminAction, OnAdminActionInterface onAdminActionInterface){ + this.contextReference = new WeakReference<>(context); + this.listener = onAdminActionInterface; + this.action = action; + this.id = id; + this.adminAction = adminAction; + } + + + @Override + protected Void doInBackground(Void... params) { + apiResponse = new API(contextReference.get()).adminDo(action, id, adminAction); + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.onAdminAction(apiResponse); + } + +} diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index ea38eacfe..4fae69426 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -48,11 +48,13 @@ import java.util.Map; import app.fedilab.android.R; import app.fedilab.android.activities.LoginActivity; import app.fedilab.android.activities.MainActivity; +import app.fedilab.android.asynctasks.PostAdminActionAsyncTask; import app.fedilab.android.asynctasks.RetrieveOpenCollectiveAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.client.Entities.Account; import app.fedilab.android.client.Entities.AccountAdmin; import app.fedilab.android.client.Entities.AccountCreation; +import app.fedilab.android.client.Entities.AdminAction; import app.fedilab.android.client.Entities.Application; import app.fedilab.android.client.Entities.Attachment; import app.fedilab.android.client.Entities.Card; @@ -278,9 +280,10 @@ public class API { * @param id String can for an account or a status * @return APIResponse */ - public APIResponse adminDo(adminAction action, String id, HashMap params){ + public APIResponse adminDo(adminAction action, String id, AdminAction adminAction){ apiResponse = new APIResponse(); String endpoint = null; + HashMap params = null; switch (action){ case ENABLE: endpoint = String.format("/admin/accounts/%s/enable", id); @@ -310,7 +313,26 @@ public class API { endpoint = String.format("/admin/reports/%s/resolve", id); break; case MODERATION_ACTION: + params = new HashMap<>(); + switch (adminAction.getType()){ + case NONE: + params.put("type","none"); + break; + case DISABLE: + params.put("type","disable"); + break; + case SILENCE: + params.put("type","silence"); + break; + case SUSPEND: + params.put("type","suspend"); + break; + } endpoint = String.format("/admin/accounts/%s/action", id); + params.put("send_email_notification", String.valueOf(adminAction.isSend_email_notification())); + if( adminAction.getText() != null) { + params.put("text", adminAction.getText()); + } break; } try { diff --git a/app/src/main/java/app/fedilab/android/client/Entities/AccountCreation.java b/app/src/main/java/app/fedilab/android/client/Entities/AccountCreation.java index 70787fd33..2d38eba37 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/AccountCreation.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/AccountCreation.java @@ -1,5 +1,18 @@ package app.fedilab.android.client.Entities; - +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * 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. + * + * Fedilab 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 Fedilab; if not, + * see . */ public class AccountCreation { private String username; diff --git a/app/src/main/java/app/fedilab/android/client/Entities/AdminAction.java b/app/src/main/java/app/fedilab/android/client/Entities/AdminAction.java new file mode 100644 index 000000000..8c989273d --- /dev/null +++ b/app/src/main/java/app/fedilab/android/client/Entities/AdminAction.java @@ -0,0 +1,58 @@ +package app.fedilab.android.client.Entities; +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * 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. + * + * Fedilab 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 Fedilab; if not, + * see . */ +public class AdminAction { + + + public enum adminActionType{ + NONE, + DISABLE, + SILENCE, + SUSPEND + } + + private adminActionType type; + private boolean send_email_notification; + private String text; + + + public adminActionType getType() { + return type; + } + + public void setType(adminActionType type) { + this.type = type; + } + + public boolean isSend_email_notification() { + return send_email_notification; + } + + public void setSend_email_notification(boolean send_email_notification) { + this.send_email_notification = send_email_notification; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + + + +} diff --git a/app/src/main/java/app/fedilab/android/interfaces/OnAdminActionInterface.java b/app/src/main/java/app/fedilab/android/interfaces/OnAdminActionInterface.java new file mode 100644 index 000000000..f5ee194c6 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/interfaces/OnAdminActionInterface.java @@ -0,0 +1,25 @@ +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * 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. + * + * Fedilab 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 Fedilab; if not, + * see . */ +package app.fedilab.android.interfaces; + +import app.fedilab.android.client.APIResponse; + +/** + * Created by Thomas on 08/06/2019. + * Interface when an admin action is done GET/POST + */ +public interface OnAdminActionInterface { + void onAdminAction(APIResponse apiResponse); +}