2022-04-27 15:20:42 +02:00
|
|
|
package app.fedilab.android.viewmodel.mastodon;
|
|
|
|
/* Copyright 2021 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>. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application;
|
2022-09-15 16:06:05 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2022-04-27 15:20:42 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2022-09-24 15:27:57 +02:00
|
|
|
import androidx.annotation.Nullable;
|
2022-04-27 15:20:42 +02:00
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
2022-09-15 16:06:05 +02:00
|
|
|
import androidx.preference.PreferenceManager;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-06-27 18:16:41 +02:00
|
|
|
import java.util.ArrayList;
|
2022-04-27 15:20:42 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2022-09-15 16:06:05 +02:00
|
|
|
import app.fedilab.android.R;
|
2022-09-24 15:27:57 +02:00
|
|
|
import app.fedilab.android.activities.MainActivity;
|
2022-05-24 10:12:04 +02:00
|
|
|
import app.fedilab.android.client.endpoints.MastodonTimelinesService;
|
|
|
|
import app.fedilab.android.client.entities.api.Account;
|
|
|
|
import app.fedilab.android.client.entities.api.Conversation;
|
|
|
|
import app.fedilab.android.client.entities.api.Conversations;
|
|
|
|
import app.fedilab.android.client.entities.api.Marker;
|
|
|
|
import app.fedilab.android.client.entities.api.MastodonList;
|
|
|
|
import app.fedilab.android.client.entities.api.Pagination;
|
|
|
|
import app.fedilab.android.client.entities.api.Status;
|
|
|
|
import app.fedilab.android.client.entities.api.Statuses;
|
2022-07-09 17:34:08 +02:00
|
|
|
import app.fedilab.android.client.entities.api.Tag;
|
2022-06-19 17:26:39 +02:00
|
|
|
import app.fedilab.android.client.entities.app.BaseAccount;
|
2022-05-24 10:12:04 +02:00
|
|
|
import app.fedilab.android.client.entities.app.StatusCache;
|
|
|
|
import app.fedilab.android.client.entities.app.StatusDraft;
|
2022-09-24 15:27:57 +02:00
|
|
|
import app.fedilab.android.client.entities.app.Timeline;
|
2022-06-27 18:16:41 +02:00
|
|
|
import app.fedilab.android.client.entities.misskey.MisskeyNote;
|
2022-06-28 19:30:45 +02:00
|
|
|
import app.fedilab.android.client.entities.nitter.Nitter;
|
2022-06-27 18:16:41 +02:00
|
|
|
import app.fedilab.android.client.entities.peertube.PeertubeVideo;
|
2022-04-27 15:20:42 +02:00
|
|
|
import app.fedilab.android.exception.DBException;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.helper.MastodonHelper;
|
|
|
|
import app.fedilab.android.helper.TimelineHelper;
|
2022-09-24 15:27:57 +02:00
|
|
|
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
|
2022-04-27 15:20:42 +02:00
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Response;
|
|
|
|
import retrofit2.Retrofit;
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory;
|
2022-06-28 19:30:45 +02:00
|
|
|
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
public class TimelinesVM extends AndroidViewModel {
|
|
|
|
|
|
|
|
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
.readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
.connectTimeout(60, TimeUnit.SECONDS)
|
2022-05-23 14:53:37 +02:00
|
|
|
.callTimeout(60, TimeUnit.SECONDS)
|
2022-04-27 15:20:42 +02:00
|
|
|
.proxy(Helper.getProxy(getApplication().getApplicationContext()))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
private MutableLiveData<List<Account>> accountListMutableLiveData;
|
|
|
|
private MutableLiveData<List<StatusDraft>> statusDraftListMutableLiveData;
|
|
|
|
private MutableLiveData<Status> statusMutableLiveData;
|
|
|
|
private MutableLiveData<Statuses> statusesMutableLiveData;
|
2022-06-28 16:28:11 +02:00
|
|
|
private MutableLiveData<PeertubeVideo.Video> peertubeVideoMutableLiveData;
|
2022-04-27 15:20:42 +02:00
|
|
|
private MutableLiveData<Conversations> conversationListMutableLiveData;
|
|
|
|
private MutableLiveData<MastodonList> mastodonListMutableLiveData;
|
|
|
|
private MutableLiveData<List<MastodonList>> mastodonListListMutableLiveData;
|
|
|
|
private MutableLiveData<Marker> markerMutableLiveData;
|
2022-07-09 17:34:08 +02:00
|
|
|
private MutableLiveData<List<Status>> statusListMutableLiveData;
|
|
|
|
private MutableLiveData<List<Tag>> tagListMutableLiveData;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
public TimelinesVM(@NonNull Application application) {
|
|
|
|
super(application);
|
|
|
|
}
|
|
|
|
|
2022-06-27 18:16:41 +02:00
|
|
|
private MastodonTimelinesService initInstanceOnly(String instance) {
|
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
|
.baseUrl("https://" + instance)
|
2022-07-02 11:01:14 +02:00
|
|
|
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
2022-06-27 18:16:41 +02:00
|
|
|
.client(okHttpClient)
|
|
|
|
.build();
|
|
|
|
return retrofit.create(MastodonTimelinesService.class);
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-06-28 19:30:45 +02:00
|
|
|
private MastodonTimelinesService initInstanceXMLOnly(String instance) {
|
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
|
.baseUrl("https://" + instance)
|
|
|
|
.addConverterFactory(SimpleXmlConverterFactory.create())
|
|
|
|
.client(okHttpClient)
|
|
|
|
.build();
|
|
|
|
return retrofit.create(MastodonTimelinesService.class);
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
private MastodonTimelinesService init(String instance) {
|
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
|
.baseUrl("https://" + instance + "/api/v1/")
|
2022-07-02 11:01:14 +02:00
|
|
|
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
2022-04-27 15:20:42 +02:00
|
|
|
.client(okHttpClient)
|
|
|
|
.build();
|
|
|
|
return retrofit.create(MastodonTimelinesService.class);
|
|
|
|
}
|
|
|
|
|
2022-07-09 17:34:08 +02:00
|
|
|
public LiveData<List<Status>> getStatusTrends(String token, @NonNull String instance) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
statusListMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<List<Status>> publicTlCall = mastodonTimelinesService.getStatusTrends(token);
|
|
|
|
List<Status> statusList = null;
|
|
|
|
if (publicTlCall != null) {
|
|
|
|
try {
|
|
|
|
Response<List<Status>> publicTlResponse = publicTlCall.execute();
|
|
|
|
if (publicTlResponse.isSuccessful()) {
|
|
|
|
statusList = publicTlResponse.body();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
List<Status> finalStatusList = statusList;
|
|
|
|
Runnable myRunnable = () -> statusListMutableLiveData.setValue(finalStatusList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LiveData<List<Tag>> getTagsTrends(String token, @NonNull String instance) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
tagListMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<List<Tag>> publicTlCall = mastodonTimelinesService.getTagTrends(token);
|
|
|
|
List<Tag> tagList = null;
|
|
|
|
if (publicTlCall != null) {
|
|
|
|
try {
|
|
|
|
Response<List<Tag>> publicTlResponse = publicTlCall.execute();
|
|
|
|
if (publicTlResponse.isSuccessful()) {
|
|
|
|
tagList = publicTlResponse.body();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
List<Tag> finalTagList = tagList;
|
|
|
|
Runnable myRunnable = () -> tagListMutableLiveData.setValue(finalTagList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return tagListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
|
2022-06-28 19:30:45 +02:00
|
|
|
/**
|
|
|
|
* Public timeline for Nitter
|
|
|
|
*
|
|
|
|
* @param max_position Return results older than this id
|
|
|
|
* @return {@link LiveData} containing a {@link Statuses}
|
|
|
|
*/
|
2022-09-15 16:06:05 +02:00
|
|
|
public LiveData<Statuses> getNitter(
|
|
|
|
String accountsStr,
|
|
|
|
String max_position) {
|
|
|
|
Context context = getApplication().getApplicationContext();
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(context);
|
|
|
|
String instance = sharedpreferences.getString(context.getString(R.string.SET_NITTER_HOST), context.getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
|
2022-06-28 19:30:45 +02:00
|
|
|
MastodonTimelinesService mastodonTimelinesService = initInstanceXMLOnly(instance);
|
2022-09-14 18:35:22 +02:00
|
|
|
accountsStr = accountsStr.replaceAll("\\s", ",");
|
2022-06-28 19:30:45 +02:00
|
|
|
statusesMutableLiveData = new MutableLiveData<>();
|
2022-09-14 18:35:22 +02:00
|
|
|
String finalAccountsStr = accountsStr;
|
2022-06-28 19:30:45 +02:00
|
|
|
new Thread(() -> {
|
2022-09-14 18:35:22 +02:00
|
|
|
Call<Nitter> publicTlCall = mastodonTimelinesService.getNitter(finalAccountsStr, max_position);
|
2022-06-28 19:30:45 +02:00
|
|
|
Statuses statuses = new Statuses();
|
|
|
|
if (publicTlCall != null) {
|
|
|
|
try {
|
|
|
|
Response<Nitter> publicTlResponse = publicTlCall.execute();
|
2022-09-14 18:35:22 +02:00
|
|
|
|
2022-06-28 19:30:45 +02:00
|
|
|
if (publicTlResponse.isSuccessful()) {
|
|
|
|
Nitter rssResponse = publicTlResponse.body();
|
|
|
|
List<Status> statusList = new ArrayList<>();
|
2022-06-29 14:13:33 +02:00
|
|
|
if (rssResponse != null && rssResponse.mFeedItems != null) {
|
|
|
|
for (Nitter.FeedItem feedItem : rssResponse.mFeedItems) {
|
2022-09-15 16:06:05 +02:00
|
|
|
if (!feedItem.title.startsWith("RT by")) {
|
2022-09-14 18:07:51 +02:00
|
|
|
Status status = Nitter.convert(getApplication(), instance, feedItem);
|
|
|
|
statusList.add(status);
|
|
|
|
}
|
2022-06-28 19:30:45 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-18 11:43:23 +02:00
|
|
|
statuses.statuses = statusList;
|
2022-07-10 12:20:18 +02:00
|
|
|
String max_id = publicTlResponse.headers().get("min-id");
|
|
|
|
statuses.pagination = new Pagination();
|
|
|
|
statuses.pagination.max_id = max_id;
|
2022-06-28 19:30:45 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusesMutableLiveData;
|
|
|
|
}
|
|
|
|
|
2022-06-27 18:16:41 +02:00
|
|
|
/**
|
|
|
|
* Public timeline for Misskey
|
|
|
|
*
|
2022-06-28 16:45:58 +02:00
|
|
|
* @param untilId Return results older than this id
|
2022-06-27 18:16:41 +02:00
|
|
|
* @param limit Maximum number of results to return. Defaults to 20.
|
|
|
|
* @return {@link LiveData} containing a {@link Statuses}
|
|
|
|
*/
|
|
|
|
public LiveData<Statuses> getMisskey(@NonNull String instance,
|
2022-06-28 16:45:58 +02:00
|
|
|
String untilId,
|
2022-06-27 18:16:41 +02:00
|
|
|
Integer limit) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance);
|
|
|
|
statusesMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
MisskeyNote.MisskeyParams misskeyParams = new MisskeyNote.MisskeyParams();
|
2022-06-28 16:45:58 +02:00
|
|
|
misskeyParams.untilId = untilId;
|
2022-06-27 18:16:41 +02:00
|
|
|
misskeyParams.limit = limit;
|
|
|
|
Call<List<MisskeyNote>> publicTlCall = mastodonTimelinesService.getMisskey(misskeyParams);
|
|
|
|
Statuses statuses = new Statuses();
|
|
|
|
if (publicTlCall != null) {
|
|
|
|
try {
|
|
|
|
Response<List<MisskeyNote>> publicTlResponse = publicTlCall.execute();
|
|
|
|
if (publicTlResponse.isSuccessful()) {
|
|
|
|
List<MisskeyNote> misskeyNoteList = publicTlResponse.body();
|
|
|
|
List<Status> statusList = new ArrayList<>();
|
|
|
|
if (misskeyNoteList != null) {
|
|
|
|
for (MisskeyNote misskeyNote : misskeyNoteList) {
|
2022-07-11 13:34:01 +02:00
|
|
|
Status status = MisskeyNote.convert(misskeyNote, instance);
|
2022-06-27 18:16:41 +02:00
|
|
|
statusList.add(status);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 10:17:25 +02:00
|
|
|
statuses.statuses = TimelineHelper.filterStatus(getApplication(), statusList, Timeline.TimeLineEnum.PUBLIC);
|
2022-06-27 18:16:41 +02:00
|
|
|
statuses.pagination = new Pagination();
|
|
|
|
if (statusList.size() > 0) {
|
|
|
|
statuses.pagination.min_id = statusList.get(0).id;
|
|
|
|
statuses.pagination.max_id = statusList.get(statusList.size() - 1).id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusesMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public timeline for Peertube
|
|
|
|
*
|
|
|
|
* @param maxId Return results older than this id
|
|
|
|
* @param limit Maximum number of results to return. Defaults to 20.
|
|
|
|
* @return {@link LiveData} containing a {@link Statuses}
|
|
|
|
*/
|
|
|
|
public LiveData<Statuses> getPeertube(@NonNull String instance,
|
|
|
|
String maxId,
|
|
|
|
Integer limit) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance);
|
|
|
|
statusesMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<PeertubeVideo> publicTlCall = mastodonTimelinesService.getPeertube(maxId, "local", "-publishedAt", limit);
|
|
|
|
Statuses statuses = new Statuses();
|
|
|
|
if (publicTlCall != null) {
|
|
|
|
try {
|
|
|
|
Response<PeertubeVideo> publicTlResponse = publicTlCall.execute();
|
|
|
|
if (publicTlResponse.isSuccessful()) {
|
|
|
|
PeertubeVideo peertubeVideo = publicTlResponse.body();
|
|
|
|
List<Status> statusList = new ArrayList<>();
|
|
|
|
if (peertubeVideo != null) {
|
|
|
|
for (PeertubeVideo.Video video : peertubeVideo.data) {
|
|
|
|
Status status = PeertubeVideo.convert(video);
|
|
|
|
statusList.add(status);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 10:17:25 +02:00
|
|
|
statuses.statuses = TimelineHelper.filterStatus(getApplication(), statusList, Timeline.TimeLineEnum.PUBLIC);
|
2022-06-27 18:16:41 +02:00
|
|
|
statuses.pagination = new Pagination();
|
|
|
|
if (statusList.size() > 0) {
|
2022-06-28 16:45:58 +02:00
|
|
|
//These values are not used.
|
|
|
|
statuses.pagination.min_id = null;
|
|
|
|
statuses.pagination.max_id = null;
|
2022-06-27 18:16:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusesMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-28 16:28:11 +02:00
|
|
|
/**
|
|
|
|
* Returns details for a peertube video
|
|
|
|
*
|
|
|
|
* @return {@link LiveData} containing a {@link PeertubeVideo.Video}
|
|
|
|
*/
|
|
|
|
public LiveData<PeertubeVideo.Video> getPeertubeVideo(@NonNull String instance, String id) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance);
|
|
|
|
peertubeVideoMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<PeertubeVideo.Video> publicTlCall = mastodonTimelinesService.getPeertubeVideo(id);
|
|
|
|
PeertubeVideo.Video peertubeVideo = null;
|
|
|
|
try {
|
|
|
|
Response<PeertubeVideo.Video> videoResponse = publicTlCall.execute();
|
|
|
|
if (videoResponse.isSuccessful()) {
|
|
|
|
peertubeVideo = videoResponse.body();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
PeertubeVideo.Video finalPeertubeVideo = peertubeVideo;
|
|
|
|
Runnable myRunnable = () -> peertubeVideoMutableLiveData.setValue(finalPeertubeVideo);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return peertubeVideoMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-24 15:27:57 +02:00
|
|
|
public LiveData<Statuses> getTimeline(TimelineParams timelineParams) {
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
statusesMutableLiveData = new MutableLiveData<>();
|
2022-09-24 15:27:57 +02:00
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(timelineParams.instance);
|
2022-04-27 15:20:42 +02:00
|
|
|
new Thread(() -> {
|
|
|
|
Statuses statuses = new Statuses();
|
2022-09-24 15:27:57 +02:00
|
|
|
Call<List<Status>> timelineCall = null;
|
|
|
|
switch (timelineParams.type) {
|
|
|
|
case HOME:
|
|
|
|
timelineCall = mastodonTimelinesService.getHome(timelineParams.token, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit, timelineParams.local);
|
|
|
|
break;
|
|
|
|
case LOCAL:
|
|
|
|
timelineCall = mastodonTimelinesService.getPublic(timelineParams.token, true, false, timelineParams.onlyMedia, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit);
|
|
|
|
break;
|
|
|
|
case PUBLIC:
|
|
|
|
timelineCall = mastodonTimelinesService.getPublic(timelineParams.token, false, true, timelineParams.onlyMedia, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit);
|
|
|
|
break;
|
|
|
|
case TAG:
|
|
|
|
timelineCall = mastodonTimelinesService.getHashTag(timelineParams.token, timelineParams.hashtagTrim, timelineParams.local, timelineParams.onlyMedia, timelineParams.all, timelineParams.any, timelineParams.none, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit);
|
|
|
|
break;
|
|
|
|
case LIST:
|
|
|
|
timelineCall = mastodonTimelinesService.getList(timelineParams.token, timelineParams.listId, timelineParams.maxId, timelineParams.sinceId, timelineParams.minId, timelineParams.limit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (timelineCall != null) {
|
2022-04-27 15:20:42 +02:00
|
|
|
try {
|
2022-09-24 15:27:57 +02:00
|
|
|
Response<List<Status>> timelineResponse = timelineCall.execute();
|
|
|
|
if (timelineResponse.isSuccessful()) {
|
|
|
|
List<Status> statusList = timelineResponse.body();
|
2022-09-26 10:17:25 +02:00
|
|
|
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
2022-09-24 15:27:57 +02:00
|
|
|
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
2022-09-26 10:17:25 +02:00
|
|
|
|
2022-09-24 15:27:57 +02:00
|
|
|
if (statusList != null && statusList.size() > 0) {
|
|
|
|
if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP) {
|
|
|
|
Status newestStatus = new StatusCache(getApplication().getApplicationContext()).getNewestStatus(timelineParams.slug, timelineParams.instance, timelineParams.userId);
|
|
|
|
//When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole
|
|
|
|
if (newestStatus != null && statusList.get(statusList.size() - 1).id.compareToIgnoreCase(newestStatus.id) > 0) {
|
|
|
|
statusList.get(statusList.size() - 1).isFetchMore = true;
|
|
|
|
}
|
|
|
|
} else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.TOP && timelineParams.fetchingMissing) {
|
|
|
|
Status topStatus = new StatusCache(getApplication().getApplicationContext()).getTopFetchMore(timelineParams.slug, timelineParams.instance, timelineParams.slug, statusList.get(0).id);
|
|
|
|
if (topStatus != null && statusList.get(0).id.compareToIgnoreCase(topStatus.id) < 0) {
|
|
|
|
statusList.get(0).isFetchMore = true;
|
|
|
|
}
|
|
|
|
} else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.BOTTOM && timelineParams.fetchingMissing) {
|
|
|
|
Status bottomStatus = new StatusCache(getApplication().getApplicationContext()).getBottomFetchMore(timelineParams.slug, timelineParams.instance, timelineParams.slug, statusList.get(0).id);
|
|
|
|
if (bottomStatus != null && statusList.get(statusList.size() - 1).id.compareToIgnoreCase(bottomStatus.id) > 0) {
|
|
|
|
statusList.get(statusList.size() - 1).isFetchMore = true;
|
|
|
|
}
|
|
|
|
}
|
2022-06-11 18:19:37 +02:00
|
|
|
for (Status status : statuses.statuses) {
|
|
|
|
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
|
|
|
StatusCache statusCache = new StatusCache();
|
2022-09-24 15:27:57 +02:00
|
|
|
statusCache.instance = timelineParams.instance;
|
|
|
|
statusCache.user_id = timelineParams.userId;
|
2022-06-11 18:19:37 +02:00
|
|
|
statusCache.status = status;
|
2022-09-24 15:27:57 +02:00
|
|
|
statusCache.type = timelineParams.type;
|
2022-06-11 18:19:37 +02:00
|
|
|
statusCache.status_id = status.id;
|
|
|
|
try {
|
2022-09-24 15:27:57 +02:00
|
|
|
statusCacheDAO.insertOrUpdate(statusCache, timelineParams.slug);
|
2022-06-11 18:19:37 +02:00
|
|
|
} catch (DBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusesMutableLiveData;
|
|
|
|
}
|
|
|
|
|
2022-09-24 15:27:57 +02:00
|
|
|
public LiveData<Statuses> getTimelineCache(TimelineParams timelineParams) {
|
2022-04-27 15:20:42 +02:00
|
|
|
statusesMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
|
|
|
Statuses statuses = null;
|
|
|
|
try {
|
2022-09-24 15:27:57 +02:00
|
|
|
statuses = statusCacheDAO.geStatuses(timelineParams.slug, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId);
|
2022-04-27 15:20:42 +02:00
|
|
|
if (statuses != null) {
|
2022-09-26 10:17:25 +02:00
|
|
|
TimelineHelper.filterStatus(getApplication().getApplicationContext(), statuses.statuses, timelineParams.type, true);
|
2022-05-04 11:22:51 +02:00
|
|
|
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
|
|
|
statuses.pagination = new Pagination();
|
|
|
|
statuses.pagination.min_id = statuses.statuses.get(0).id;
|
|
|
|
statuses.pagination.max_id = statuses.statuses.get(statuses.statuses.size() - 1).id;
|
|
|
|
}
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
|
|
|
} catch (DBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Statuses finalStatuses = statuses;
|
|
|
|
Runnable myRunnable = () -> statusesMutableLiveData.setValue(finalStatuses);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusesMutableLiveData;
|
|
|
|
}
|
|
|
|
|
2022-09-24 15:27:57 +02:00
|
|
|
public static class TimelineParams {
|
|
|
|
|
|
|
|
public FragmentMastodonTimeline.DIRECTION direction;
|
|
|
|
public String instance;
|
|
|
|
public String token;
|
|
|
|
public Timeline.TimeLineEnum type;
|
|
|
|
public String slug;
|
|
|
|
public String userId;
|
|
|
|
public Boolean remote;
|
|
|
|
public Boolean onlyMedia;
|
|
|
|
public String hashtagTrim;
|
|
|
|
public List<String> all;
|
|
|
|
public List<String> any;
|
|
|
|
public List<String> none;
|
|
|
|
public String listId;
|
|
|
|
public Boolean fetchingMissing;
|
|
|
|
public String maxId;
|
|
|
|
public String sinceId;
|
|
|
|
public String minId;
|
|
|
|
public int limit = 40;
|
|
|
|
public Boolean local;
|
|
|
|
|
2022-09-24 17:26:44 +02:00
|
|
|
public TimelineParams(@NonNull Timeline.TimeLineEnum timeLineEnum, @Nullable FragmentMastodonTimeline.DIRECTION timelineDirection, @Nullable String ident) {
|
2022-09-24 15:27:57 +02:00
|
|
|
if (type != Timeline.TimeLineEnum.REMOTE) {
|
|
|
|
instance = MainActivity.currentInstance;
|
|
|
|
token = MainActivity.currentToken;
|
|
|
|
userId = MainActivity.currentUserID;
|
|
|
|
}
|
2022-09-24 17:26:44 +02:00
|
|
|
type = timeLineEnum;
|
|
|
|
direction = timelineDirection;
|
2022-09-24 15:27:57 +02:00
|
|
|
String key = type.getValue();
|
|
|
|
if (ident != null) {
|
|
|
|
key += "|" + ident;
|
|
|
|
}
|
|
|
|
slug = key;
|
|
|
|
}
|
2022-09-26 10:17:25 +02:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "direction: " + direction + "\n" +
|
|
|
|
"instance: " + instance + "\n" +
|
|
|
|
"token: " + token + "\n" +
|
|
|
|
"type: " + type + "\n" +
|
|
|
|
"slug: " + slug + "\n" +
|
|
|
|
"userId: " + userId + "\n" +
|
|
|
|
"remote: " + remote + "\n" +
|
|
|
|
"onlyMedia: " + onlyMedia + "\n" +
|
|
|
|
"local: " + local + "\n" +
|
|
|
|
"maxId: " + maxId + "\n" +
|
|
|
|
"sinceId: " + sinceId + "\n" +
|
|
|
|
"minId: " + minId + "\n";
|
|
|
|
}
|
2022-09-24 15:27:57 +02:00
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get user drafts
|
|
|
|
*
|
2022-05-24 10:12:04 +02:00
|
|
|
* @param account app.fedilab.android.client.entities.app.Account
|
2022-04-27 15:20:42 +02:00
|
|
|
* @return LiveData<ist < StatusDraft>>
|
|
|
|
*/
|
2022-06-19 17:26:39 +02:00
|
|
|
public LiveData<List<StatusDraft>> getDrafts(BaseAccount account) {
|
2022-04-27 15:20:42 +02:00
|
|
|
statusDraftListMutableLiveData = new MutableLiveData<>();
|
|
|
|
new Thread(() -> {
|
|
|
|
List<StatusDraft> statusCacheDAO = null;
|
|
|
|
try {
|
|
|
|
statusCacheDAO = new StatusDraft(getApplication().getApplicationContext()).geStatusDraftList(account);
|
|
|
|
} catch (DBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
List<StatusDraft> finalStatusCacheDAO = statusCacheDAO;
|
|
|
|
Runnable myRunnable = () -> statusDraftListMutableLiveData.setValue(finalStatusCacheDAO);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusDraftListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show conversations
|
|
|
|
*
|
|
|
|
* @return {@link LiveData} containing a {@link Conversations}
|
|
|
|
*/
|
|
|
|
public LiveData<Conversations> getConversations(@NonNull String instance, String token,
|
|
|
|
String maxId,
|
|
|
|
String sinceId,
|
|
|
|
String minId,
|
|
|
|
int limit) {
|
|
|
|
conversationListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Conversations conversations = null;
|
|
|
|
Call<List<Conversation>> conversationsCall = mastodonTimelinesService.getConversations(token, maxId, sinceId, minId, limit);
|
|
|
|
if (conversationsCall != null) {
|
|
|
|
conversations = new Conversations();
|
|
|
|
try {
|
|
|
|
Response<List<Conversation>> conversationsResponse = conversationsCall.execute();
|
|
|
|
if (conversationsResponse.isSuccessful()) {
|
|
|
|
conversations.conversations = conversationsResponse.body();
|
2022-05-04 11:22:51 +02:00
|
|
|
conversations.pagination = MastodonHelper.getPagination(conversationsResponse.headers());
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Conversations finalConversations = conversations;
|
|
|
|
Runnable myRunnable = () -> conversationListMutableLiveData.setValue(finalConversations);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
return conversationListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove conversation
|
|
|
|
*
|
|
|
|
* @param id ID of the conversation
|
|
|
|
*/
|
|
|
|
public void deleteConversation(@NonNull String instance, String token, @NonNull String id) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<Void> deleteStatusCall = mastodonTimelinesService.deleteConversation(token, id);
|
|
|
|
if (deleteStatusCall != null) {
|
|
|
|
try {
|
|
|
|
deleteStatusCall.execute();
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a conversation as read
|
|
|
|
*
|
|
|
|
* @param id ID of the conversation
|
|
|
|
* @return {@link LiveData} containing a {@link Status}
|
|
|
|
*/
|
|
|
|
public LiveData<Status> markReadConversation(@NonNull String instance, String token, @NonNull String id) {
|
|
|
|
statusMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Status status = null;
|
|
|
|
Call<Status> markReadConversationCall = mastodonTimelinesService.markReadConversation(token, id);
|
|
|
|
if (markReadConversationCall != null) {
|
|
|
|
try {
|
|
|
|
Response<Status> markReadConversationResponse = markReadConversationCall.execute();
|
|
|
|
if (markReadConversationResponse.isSuccessful()) {
|
|
|
|
status = markReadConversationResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Status finalStatus = status;
|
|
|
|
Runnable myRunnable = () -> statusMutableLiveData.setValue(finalStatus);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return statusMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch all lists that the user owns.
|
|
|
|
*
|
|
|
|
* @return {@link LiveData} containing a {@link List} of {@link MastodonList}s
|
|
|
|
*/
|
|
|
|
public LiveData<List<MastodonList>> getLists(@NonNull String instance, String token) {
|
|
|
|
mastodonListListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
List<MastodonList> mastodonListList = null;
|
|
|
|
Call<List<MastodonList>> getListsCall = mastodonTimelinesService.getLists(token);
|
|
|
|
if (getListsCall != null) {
|
|
|
|
try {
|
|
|
|
Response<List<MastodonList>> getListsResponse = getListsCall.execute();
|
|
|
|
if (getListsResponse.isSuccessful()) {
|
|
|
|
mastodonListList = getListsResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
List<MastodonList> finalMastodonListList = mastodonListList;
|
|
|
|
Runnable myRunnable = () -> mastodonListListMutableLiveData.setValue(finalMastodonListList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return mastodonListListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the list with the given ID. Used for verifying the title of a list,
|
|
|
|
* and which replies to show within that list.
|
|
|
|
*
|
|
|
|
* @param id ID of the list
|
|
|
|
* @return {@link LiveData} containing a {@link MastodonList}
|
|
|
|
*/
|
|
|
|
public LiveData<MastodonList> getList(@NonNull String instance, String token, @NonNull String id) {
|
|
|
|
mastodonListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
MastodonList mastodonList = null;
|
|
|
|
Call<MastodonList> getListCall = mastodonTimelinesService.getList(token, id);
|
|
|
|
if (getListCall != null) {
|
|
|
|
try {
|
|
|
|
Response<MastodonList> getListResponse = getListCall.execute();
|
|
|
|
if (getListResponse.isSuccessful()) {
|
|
|
|
mastodonList = getListResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
MastodonList finalMastodonList = mastodonList;
|
|
|
|
Runnable myRunnable = () -> mastodonListMutableLiveData.setValue(finalMastodonList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return mastodonListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new list.
|
|
|
|
*
|
|
|
|
* @param title The title of the list to be created.
|
|
|
|
* @param repliesPolicy Enumerable oneOf "followed", "list", "none". Defaults to "list".
|
|
|
|
* @return {@link LiveData} containing a {@link MastodonList}
|
|
|
|
*/
|
|
|
|
public LiveData<MastodonList> createList(@NonNull String instance, String token, @NonNull String title, String repliesPolicy) {
|
|
|
|
mastodonListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
MastodonList mastodonList = null;
|
|
|
|
Call<MastodonList> createListCall = mastodonTimelinesService.createList(token, title, repliesPolicy);
|
|
|
|
if (createListCall != null) {
|
|
|
|
try {
|
|
|
|
Response<MastodonList> createListResponse = createListCall.execute();
|
|
|
|
if (createListResponse.isSuccessful()) {
|
|
|
|
mastodonList = createListResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
MastodonList finalMastodonList = mastodonList;
|
|
|
|
Runnable myRunnable = () -> mastodonListMutableLiveData.setValue(finalMastodonList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return mastodonListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the title of a list, or which replies to show.
|
|
|
|
*
|
|
|
|
* @param id ID of the list
|
|
|
|
* @param title The title of the list to be updated.
|
|
|
|
* @param repliesPolicy Enumerable oneOf "followed", "list", "none".
|
|
|
|
* @return {@link LiveData} containing a {@link MastodonList}
|
|
|
|
*/
|
|
|
|
public LiveData<MastodonList> updateList(@NonNull String instance, String token, @NonNull String id, String title, String repliesPolicy) {
|
|
|
|
mastodonListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
MastodonList mastodonList = null;
|
|
|
|
Call<MastodonList> updateListCall = mastodonTimelinesService.updateList(token, id, title, repliesPolicy);
|
|
|
|
if (updateListCall != null) {
|
|
|
|
try {
|
|
|
|
Response<MastodonList> updateListResponse = updateListCall.execute();
|
|
|
|
if (updateListResponse.isSuccessful()) {
|
|
|
|
mastodonList = updateListResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
MastodonList finalMastodonList = mastodonList;
|
|
|
|
Runnable myRunnable = () -> mastodonListMutableLiveData.setValue(finalMastodonList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return mastodonListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a list
|
|
|
|
*
|
|
|
|
* @param id ID of the list
|
|
|
|
*/
|
|
|
|
public void deleteList(@NonNull String instance, String token, @NonNull String id) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<Void> deleteListCall = mastodonTimelinesService.deleteList(token, id);
|
|
|
|
if (deleteListCall != null) {
|
|
|
|
try {
|
|
|
|
deleteListCall.execute();
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View accounts in list
|
|
|
|
*
|
|
|
|
* @param id ID of the list
|
|
|
|
* @return {@link LiveData} containing a {@link List} of {@link Account}s
|
|
|
|
*/
|
|
|
|
public LiveData<List<Account>> getAccountsInList(@NonNull String instance, String token, @NonNull String id, String maxId, String sinceId, int limit) {
|
|
|
|
accountListMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
List<Account> accountList = null;
|
|
|
|
Call<List<Account>> getAccountsInListCall = mastodonTimelinesService.getAccountsInList(token, id, maxId, sinceId, limit);
|
|
|
|
if (getAccountsInListCall != null) {
|
|
|
|
try {
|
|
|
|
Response<List<Account>> getAccountsInListResponse = getAccountsInListCall.execute();
|
|
|
|
if (getAccountsInListResponse.isSuccessful()) {
|
|
|
|
accountList = getAccountsInListResponse.body();
|
|
|
|
}
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
List<Account> finalAccountList = accountList;
|
|
|
|
Runnable myRunnable = () -> accountListMutableLiveData.setValue(finalAccountList);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return accountListMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add accounts to the given list. Note that the user must be following these accounts.
|
|
|
|
*
|
|
|
|
* @param listId ID of the list
|
|
|
|
* @param accountIds Array of account IDs to add to the list.
|
|
|
|
*/
|
|
|
|
public void addAccountsList(@NonNull String instance, String token, @NonNull String listId, @NonNull List<String> accountIds) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<Void> addAccountsListCall = mastodonTimelinesService.addAccountsList(token, listId, accountIds);
|
|
|
|
if (addAccountsListCall != null) {
|
|
|
|
try {
|
|
|
|
addAccountsListCall.execute();
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove accounts from the given list.
|
|
|
|
*
|
|
|
|
* @param listId ID of the list
|
|
|
|
* @param accountIds Array of account IDs to remove from the list.
|
|
|
|
*/
|
|
|
|
public void deleteAccountsList(@NonNull String instance, String token, @NonNull String listId, @NonNull List<String> accountIds) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<Void> deleteAccountsListCall = mastodonTimelinesService.deleteAccountsList(token, listId, accountIds);
|
|
|
|
if (deleteAccountsListCall != null) {
|
|
|
|
try {
|
|
|
|
deleteAccountsListCall.execute();
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get saved timeline position
|
|
|
|
*
|
|
|
|
* @param timeline Array of markers to fetch. String enum anyOf "home", "notifications".
|
|
|
|
* If not provided, an empty object will be returned.
|
|
|
|
* @return {@link LiveData} containing a {@link Marker}
|
|
|
|
*/
|
|
|
|
public LiveData<Marker> getMarker(@NonNull String instance, String token, @NonNull List<String> timeline) {
|
|
|
|
markerMutableLiveData = new MutableLiveData<>();
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Marker marker = null;
|
|
|
|
Call<Marker> getMarkerCall = mastodonTimelinesService.getMarker(token, timeline);
|
|
|
|
if (getMarkerCall != null) {
|
|
|
|
try {
|
|
|
|
Response<Marker> getMarkerResponse = getMarkerCall.execute();
|
|
|
|
if (getMarkerResponse.isSuccessful()) {
|
|
|
|
marker = getMarkerResponse.body();
|
|
|
|
}
|
2022-05-16 19:01:02 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Marker finalMarker = marker;
|
|
|
|
Runnable myRunnable = () -> markerMutableLiveData.setValue(finalMarker);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
}).start();
|
|
|
|
return markerMutableLiveData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save position in timeline
|
|
|
|
*
|
|
|
|
* @param homeLastReadId ID of the last status read in the home timeline.
|
|
|
|
* @param notificationLastReadId ID of the last notification read.
|
|
|
|
*/
|
|
|
|
public void addMarker(@NonNull String instance, String token, String homeLastReadId, String notificationLastReadId) {
|
|
|
|
MastodonTimelinesService mastodonTimelinesService = init(instance);
|
|
|
|
new Thread(() -> {
|
|
|
|
Call<Void> addMarkerCall = mastodonTimelinesService.addMarker(token, homeLastReadId, notificationLastReadId);
|
|
|
|
if (addMarkerCall != null) {
|
|
|
|
try {
|
|
|
|
addMarkerCall.execute();
|
2022-06-01 16:37:01 +02:00
|
|
|
} catch (Exception e) {
|
2022-04-27 15:20:42 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
}
|