diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt index 06bc0604..e8332955 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * 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. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.iitems import android.view.View @@ -26,23 +42,24 @@ import com.pitchedapps.frost.utils.launchWebOverlay /** * Created by Allan Wang on 27/12/17. */ -class NotificationIItem(val notification: FrostNotif, val cookie: String) : KauIItem<NotificationIItem, NotificationIItem.ViewHolder>( +class NotificationIItem(val notification: FrostNotif, val cookie: String) : + KauIItem<NotificationIItem, NotificationIItem.ViewHolder>( R.layout.iitem_notification, ::ViewHolder -) { + ) { companion object { fun bindEvents(adapter: ItemAdapter<NotificationIItem>) { adapter.fastAdapter.withSelectable(false) - .withOnClickListener { v, _, item, position -> - val notif = item.notification - if (notif.unread) { - FrostRunnable.markNotificationRead(v!!.context, notif.id, item.cookie) - adapter.set(position, NotificationIItem(notif.copy(unread = false), item.cookie)) - } - // TODO temp fix. If url is dependent, we cannot load it directly - v!!.context.launchWebOverlay(if (notif.url.isIndependent) notif.url else FbItem.NOTIFICATIONS.url) - true + .withOnClickListener { v, _, item, position -> + val notif = item.notification + if (notif.unread) { + FrostRunnable.markNotificationRead(v!!.context, notif.id, item.cookie) + adapter.set(position, NotificationIItem(notif.copy(unread = false), item.cookie)) } + // TODO temp fix. If url is dependent, we cannot load it directly + v!!.context.launchWebOverlay(if (notif.url.isIndependent) notif.url else FbItem.NOTIFICATIONS.url) + true + } } //todo see if necessary @@ -52,12 +69,17 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : KauI private class Diff : DiffCallback<NotificationIItem> { override fun areItemsTheSame(oldItem: NotificationIItem, newItem: NotificationIItem) = - oldItem.notification.id == newItem.notification.id + oldItem.notification.id == newItem.notification.id override fun areContentsTheSame(oldItem: NotificationIItem, newItem: NotificationIItem) = - oldItem.notification == newItem.notification + oldItem.notification == newItem.notification - override fun getChangePayload(oldItem: NotificationIItem, oldItemPosition: Int, newItem: NotificationIItem, newItemPosition: Int): Any? { + override fun getChangePayload( + oldItem: NotificationIItem, + oldItemPosition: Int, + newItem: NotificationIItem, + newItemPosition: Int + ): Any? { return newItem } } @@ -75,15 +97,17 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : KauI override fun bindView(item: NotificationIItem, payloads: MutableList<Any>) { val notif = item.notification - frame.background = createSimpleRippleDrawable(Prefs.textColor, - Prefs.nativeBgColor(notif.unread)) + frame.background = createSimpleRippleDrawable( + Prefs.textColor, + Prefs.nativeBgColor(notif.unread) + ) content.setTextColor(Prefs.textColor) date.setTextColor(Prefs.textColor.withAlpha(150)) val glide = glide glide.load(notif.img) - .transform(FrostGlide.roundCorner) - .into(avatar) + .transform(FrostGlide.roundCorner) + .into(avatar) if (notif.thumbnailUrl != null) glide.load(notif.thumbnailUrl).into(thumbnail.visible()) @@ -101,4 +125,4 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) : KauI date.text = null } } -}
\ No newline at end of file +} |