aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/iitems
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-24 01:47:03 -0500
committerGitHub <noreply@github.com>2018-12-24 01:47:03 -0500
commit697d01882ba8b1dbb85484ba3bf6e810e32448fc (patch)
treef59d2407ffbd724200e3c79eb366a8da1efe0829 /app/src/main/kotlin/com/pitchedapps/frost/iitems
parentc45b30e28f451699f3be828a1201260ed27e321e (diff)
downloadfrost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.gz
frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.bz2
frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.zip
Enhancement/ktlint (#1259)
* Add spotless * Reformat code * Apply license header * Add remaining license headers
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/iitems')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt53
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt41
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt62
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt29
4 files changed, 129 insertions, 56 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
index 1211b742..6eacf48e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.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.content.Context
@@ -32,25 +48,25 @@ interface ClickableIItemContract {
companion object {
fun bindEvents(adapter: IAdapter<IItem<*, *>>) {
adapter.fastAdapter.withSelectable(false)
- .withOnClickListener { v, _, item, _ ->
- if (item is ClickableIItemContract) {
- item.click(v!!.context)
- true
- } else
- false
- }
+ .withOnClickListener { v, _, item, _ ->
+ if (item is ClickableIItemContract) {
+ item.click(v!!.context)
+ true
+ } else
+ false
+ }
}
}
-
}
/**
* Generic header item
* Not clickable with an accent color
*/
-open class HeaderIItem(val text: String?,
- itemId: Int = R.layout.iitem_header)
- : KauIItem<HeaderIItem, HeaderIItem.ViewHolder>(R.layout.iitem_header, ::ViewHolder, itemId) {
+open class HeaderIItem(
+ val text: String?,
+ itemId: Int = R.layout.iitem_header
+) : KauIItem<HeaderIItem, HeaderIItem.ViewHolder>(R.layout.iitem_header, ::ViewHolder, itemId) {
class ViewHolder(itemView: View) : FastAdapter.ViewHolder<HeaderIItem>(itemView) {
@@ -66,18 +82,18 @@ open class HeaderIItem(val text: String?,
text.text = null
}
}
-
}
/**
* Generic text item
* Clickable with text color
*/
-open class TextIItem(val text: String?,
- override val url: String?,
- itemId: Int = R.layout.iitem_text)
- : KauIItem<TextIItem, TextIItem.ViewHolder>(R.layout.iitem_text, ::ViewHolder, itemId),
- ClickableIItemContract {
+open class TextIItem(
+ val text: String?,
+ override val url: String?,
+ itemId: Int = R.layout.iitem_text
+) : KauIItem<TextIItem, TextIItem.ViewHolder>(R.layout.iitem_text, ::ViewHolder, itemId),
+ ClickableIItemContract {
class ViewHolder(itemView: View) : FastAdapter.ViewHolder<TextIItem>(itemView) {
@@ -93,5 +109,4 @@ open class TextIItem(val text: String?,
text.text = null
}
}
-
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt
index 4a7356b0..651a4a2a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.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
@@ -21,9 +37,9 @@ import com.pitchedapps.frost.utils.Prefs
/**
* Created by Allan Wang on 30/12/17.
*/
-class MenuContentIItem(val data: MenuItem)
- : KauIItem<MenuContentIItem, MenuContentIItem.ViewHolder>(R.layout.iitem_menu, ::ViewHolder),
- ClickableIItemContract {
+class MenuContentIItem(val data: MenuItem) :
+ KauIItem<MenuContentIItem, MenuContentIItem.ViewHolder>(R.layout.iitem_menu, ::ViewHolder),
+ ClickableIItemContract {
override val url: String?
get() = data.url
@@ -42,9 +58,9 @@ class MenuContentIItem(val data: MenuItem)
val iconUrl = item.data.pic
if (iconUrl != null)
GlideApp.with(itemView)
- .load(iconUrl)
- .transform(FrostGlide.roundCorner)
- .into(icon.visible())
+ .load(iconUrl)
+ .transform(FrostGlide.roundCorner)
+ .into(icon.visible())
else
icon.gone()
content.text = item.data.name
@@ -59,12 +75,11 @@ class MenuContentIItem(val data: MenuItem)
}
}
-class MenuHeaderIItem(val data: MenuHeader) : HeaderIItem(data.header,
- itemId = R.id.item_menu_header)
-
-class MenuFooterIItem(val data: MenuFooterItem)
- : TextIItem(data.name, data.url, R.id.item_menu_footer)
+class MenuHeaderIItem(val data: MenuHeader) : HeaderIItem(
+ data.header,
+ itemId = R.id.item_menu_header
+)
-class MenuFooterSmallIItem(val data: MenuFooterItem)
- : TextIItem(data.name, data.url, R.id.item_menu_footer_small)
+class MenuFooterIItem(val data: MenuFooterItem) : TextIItem(data.name, data.url, R.id.item_menu_footer)
+class MenuFooterSmallIItem(val data: MenuFooterItem) : TextIItem(data.name, data.url, R.id.item_menu_footer_small)
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
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt
index 506d1cab..51201d09 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/TabIItem.kt
@@ -1,10 +1,30 @@
+/*
+ * 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
import android.widget.ImageView
import android.widget.TextView
import ca.allanwang.kau.iitems.KauIItem
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.invisible
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.visible
+import ca.allanwang.kau.utils.withAlpha
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter_extensions.drag.IDraggable
@@ -16,8 +36,8 @@ import com.pitchedapps.frost.utils.Prefs
* Created by Allan Wang on 26/11/17.
*/
class TabIItem(val item: FbItem) : KauIItem<TabIItem, TabIItem.ViewHolder>(
- R.layout.iitem_tab_preview,
- { ViewHolder(it) }
+ R.layout.iitem_tab_preview,
+ { ViewHolder(it) }
), IDraggable<TabIItem, IItem<*, *>> {
override fun withIsDraggable(draggable: Boolean): TabIItem = this
@@ -45,6 +65,5 @@ class TabIItem(val item: FbItem) : KauIItem<TabIItem, TabIItem.ViewHolder>(
image.setImageDrawable(null)
text.visible().text = null
}
-
}
-} \ No newline at end of file
+}