2017-08-18 17:50:54 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Mastalab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Mastalab 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 Mastalab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
package fr.gouv.etalab.mastodon.asynctasks;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.AsyncTask;
|
2017-08-19 19:02:42 +02:00
|
|
|
import android.os.SystemClock;
|
2017-08-18 17:50:54 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import fr.gouv.etalab.mastodon.client.API;
|
|
|
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 18/08/2017.
|
|
|
|
* Retrieves replies to a toot
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class RetrieveRepliesAsyncTask extends AsyncTask<Void, Void, Void> {
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private APIResponse apiResponse;
|
|
|
|
private OnRetrieveRepliesInterface listener;
|
|
|
|
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RetrieveRepliesAsyncTask(Context context, List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses, OnRetrieveRepliesInterface onRetrieveRepliesInterface){
|
|
|
|
this.context = context;
|
|
|
|
this.statuses = statuses;
|
|
|
|
this.listener = onRetrieveRepliesInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
|
|
|
|
API api = new API(context);
|
|
|
|
for (fr.gouv.etalab.mastodon.client.Entities.Status status : statuses) {
|
|
|
|
fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext((status.getReblog() != null) ? status.getReblog().getId() : status.getId());
|
2017-08-19 19:02:42 +02:00
|
|
|
SystemClock.sleep(25);
|
2017-08-18 17:50:54 +02:00
|
|
|
status.setReplies(statusContext.getDescendants());
|
|
|
|
}
|
|
|
|
apiResponse = new APIResponse();
|
|
|
|
apiResponse.setStatuses(statuses);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
listener.onRetrieveReplies(apiResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|