2023-01-22 15:22:59 +01:00
|
|
|
package app.fedilab.android.mastodon.client.entities.api;
|
2022-04-27 15:20:42 +02:00
|
|
|
/* 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>. */
|
|
|
|
|
2022-09-30 16:57:49 +02:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
import com.google.gson.Gson;
|
2022-04-27 15:20:42 +02:00
|
|
|
import com.google.gson.annotations.SerializedName;
|
2022-06-19 19:24:42 +02:00
|
|
|
import com.google.gson.reflect.TypeToken;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
import java.util.Date;
|
2022-05-21 17:45:23 +02:00
|
|
|
import java.util.List;
|
2022-04-27 15:20:42 +02:00
|
|
|
|
|
|
|
public class Notification {
|
|
|
|
|
|
|
|
@SerializedName("id")
|
|
|
|
public String id;
|
|
|
|
@SerializedName("type")
|
|
|
|
public String type;
|
|
|
|
@SerializedName("created_at")
|
|
|
|
public Date created_at;
|
2022-07-19 14:28:25 +02:00
|
|
|
@SerializedName("emoji")
|
|
|
|
public String emoji;
|
2022-04-27 15:20:42 +02:00
|
|
|
@SerializedName("account")
|
|
|
|
public Account account;
|
|
|
|
@SerializedName("status")
|
|
|
|
public Status status;
|
2022-09-30 16:47:40 +02:00
|
|
|
@SerializedName("cached")
|
|
|
|
public boolean cached;
|
2022-11-18 17:40:25 +01:00
|
|
|
public Filter filteredByApp;
|
2023-03-07 19:02:39 +01:00
|
|
|
public transient PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM;
|
2022-05-21 17:45:23 +02:00
|
|
|
public transient List<Notification> relatedNotifications;
|
2023-03-07 19:02:39 +01:00
|
|
|
public transient boolean isFetchMore;
|
2022-09-30 18:54:01 +02:00
|
|
|
|
2022-06-19 19:24:42 +02:00
|
|
|
/**
|
|
|
|
* Serialized a list of Notification class
|
|
|
|
*
|
|
|
|
* @param notifications List of {@link Notification} to serialize
|
|
|
|
* @return String serialized emoji list
|
|
|
|
*/
|
|
|
|
public static String notificationsToStringStorage(List<Notification> notifications) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
try {
|
|
|
|
return gson.toJson(notifications);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unserialized a notification List
|
|
|
|
*
|
|
|
|
* @param serializedNotificationList String serialized Status list
|
|
|
|
* @return List of {@link Notification}
|
|
|
|
*/
|
|
|
|
public static List<Notification> restoreNotificationsFromString(String serializedNotificationList) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
try {
|
|
|
|
return gson.fromJson(serializedNotificationList, new TypeToken<List<Notification>>() {
|
|
|
|
}.getType());
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 18:37:29 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(@Nullable Object obj) {
|
|
|
|
boolean same = false;
|
|
|
|
if (obj instanceof Notification) {
|
|
|
|
same = this.id.equals(((Notification) obj).id);
|
|
|
|
}
|
|
|
|
return same;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum PositionFetchMore {
|
|
|
|
TOP,
|
|
|
|
BOTTOM
|
|
|
|
}
|
|
|
|
|
2022-04-27 15:20:42 +02:00
|
|
|
}
|