chinwag-android/app/src/main/java/com/keylesspalace/tusky/entity/Notification.kt
pandasoft0 63e4c1d4e0 Add CLEAR and FILTER buttons to notifications (#1168)
* Issue tuskyapp#762 add clear notifications button to the top of the Notifications adapter

* Issue tuskyapp#764 add the notifications filter

* Update notifications top bar buttons

* Replace PopupMenu with PopupWindow. Save notifications filter to the account table

* Disable hide top bar on empty content at the notification screen

* Add app bar behavior to the sw640 notification layout

* Fix issue with click on top notification tab
2019-04-09 19:13:54 +02:00

74 lines
2.2 KiB
Kotlin

/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* 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.
*
* Tusky 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 Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity
import com.google.gson.*
import com.google.gson.annotations.JsonAdapter
data class Notification(
val type: Type,
val id: String,
val account: Account,
val status: Status?) {
@JsonAdapter(NotificationTypeAdapter::class)
enum class Type(val presentation: String) {
UNKNOWN("unknown"),
MENTION("mention"),
REBLOG("reblog"),
FAVOURITE("favourite"),
FOLLOW("follow");
companion object {
@JvmStatic
fun byString(s: String): Type {
values().forEach {
if (s == it.presentation)
return it
}
return UNKNOWN
}
val asList = listOf(MENTION,REBLOG,FAVOURITE,FOLLOW)
}
override fun toString(): String {
return presentation
}
}
override fun hashCode(): Int {
return id.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other !is Notification) {
return false
}
val notification = other as Notification?
return notification?.id == this.id
}
class NotificationTypeAdapter : JsonDeserializer<Type> {
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: java.lang.reflect.Type, context: JsonDeserializationContext): Notification.Type {
return Notification.Type.byString(json.asString)
}
}
}