Async calls for admin API
This commit is contained in:
parent
8fee558da1
commit
d9f573285c
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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<Void, Void, Void> {
|
||||
|
||||
private OnAdminActionInterface listener;
|
||||
private API.adminAction action;
|
||||
private String id;
|
||||
private WeakReference<Context> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, String> params){
|
||||
public APIResponse adminDo(adminAction action, String id, AdminAction adminAction){
|
||||
apiResponse = new APIResponse();
|
||||
String endpoint = null;
|
||||
HashMap<String, String> 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 {
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
public class AccountCreation {
|
||||
|
||||
private String username;
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue