fedilab-Android-App/app/src/main/java/app/fedilab/android/asynctasks/UpdateCredentialAsyncTask.java

73 lines
2.9 KiB
Java
Raw Normal View History

/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* 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.
*
2019-05-18 11:10:30 +02:00
* 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.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
2019-05-18 11:10:30 +02:00
package app.fedilab.android.asynctasks;
import android.content.Context;
2021-01-19 17:43:51 +01:00
import android.os.Handler;
import android.os.Looper;
2017-10-27 15:09:26 +02:00
2018-04-22 18:02:00 +02:00
import java.io.ByteArrayInputStream;
2017-10-27 15:09:26 +02:00
import java.lang.ref.WeakReference;
2018-08-18 17:37:53 +02:00
import java.util.HashMap;
2017-10-27 15:09:26 +02:00
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.interfaces.OnUpdateCredentialInterface;
/**
* Created by Thomas on 05/06/2017.
* Update account credential
*/
2021-01-19 17:43:51 +01:00
public class UpdateCredentialAsyncTask {
2021-01-19 17:43:51 +01:00
private final String display_name;
private final String note;
private final String avatarName;
private final String headerName;
private final boolean senstive;
private final ByteArrayInputStream avatar;
private final ByteArrayInputStream header;
private final API.accountPrivacy privacy;
private final OnUpdateCredentialInterface listener;
private final WeakReference<Context> contextReference;
private final HashMap<String, String> customFields;
private APIResponse apiResponse;
2019-09-06 17:55:14 +02:00
public UpdateCredentialAsyncTask(Context context, HashMap<String, String> customFields, String display_name, String note, ByteArrayInputStream avatar, String avatarName, ByteArrayInputStream header, String headerName, API.accountPrivacy privacy, boolean senstive, OnUpdateCredentialInterface onUpdateCredentialInterface) {
2017-10-27 15:09:26 +02:00
this.contextReference = new WeakReference<>(context);
this.display_name = display_name;
this.note = note;
this.avatar = avatar;
this.header = header;
this.listener = onUpdateCredentialInterface;
this.privacy = privacy;
2018-04-23 07:00:12 +02:00
this.avatarName = avatarName;
this.headerName = headerName;
2018-08-18 17:37:53 +02:00
this.customFields = customFields;
this.senstive = senstive;
2021-01-19 17:43:51 +01:00
doInBackground();
}
2021-01-19 17:43:51 +01:00
protected void doInBackground() {
new Thread(() -> {
apiResponse = new API(this.contextReference.get()).updateCredential(display_name, note, avatar, avatarName, header, headerName, privacy, customFields, senstive);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> listener.onUpdateCredential(apiResponse);
mainHandler.post(myRunnable);
}).start();
}
}