From 3b6836b6a21dbaaef37b4b804b05597b54f80ac0 Mon Sep 17 00:00:00 2001 From: luca Date: Thu, 28 Nov 2019 11:09:53 +0100 Subject: [PATCH] added more notifications fields, expanded state, testing in the sample app --- .../java/com/kirkbushman/zammad/ZammadApi.kt | 2 + .../com/kirkbushman/zammad/ZammadClient.kt | 8 +-- .../zammad/models/OnlineNotification.kt | 20 +++++-- sampleapp/src/main/AndroidManifest.xml | 1 + .../activities/NotificationActivity.kt | 44 ++++++++++++++++ .../activities/NotificationsActivity.kt | 8 ++- .../controllers/NotificationsController.kt | 1 + .../sampleapp/models/NotificationModel.kt | 22 +++++++- .../main/res/layout/activity_notification.xml | 14 +++++ .../src/main/res/layout/item_notification.xml | 52 ++++++++++++++----- 10 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationActivity.kt create mode 100644 sampleapp/src/main/res/layout/activity_notification.xml diff --git a/lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt b/lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt index dce32a1..412a717 100644 --- a/lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt +++ b/lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt @@ -407,12 +407,14 @@ interface ZammadApi { @GET("/api/v1/online_notifications") fun onlineNotifications( + @Query("expand") expanded: Boolean, @HeaderMap header: HashMap ): Call> @GET("/api/v1/online_notifications/{id}") fun onlineNotification( @Path("id") id: Int, + @Query("expand") expanded: Boolean, @HeaderMap header: HashMap ): Call diff --git a/lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt b/lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt index 28308e5..57af97d 100644 --- a/lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt +++ b/lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt @@ -1173,10 +1173,10 @@ class ZammadClient( return res.body() } - fun onlineNotifications(): List? { + fun onlineNotifications(expanded: Boolean = false): List? { val authMap = getHeaderMap() - val req = api.onlineNotifications(authMap) + val req = api.onlineNotifications(expanded, authMap) val res = req.execute() if (!res.isSuccessful) { @@ -1191,10 +1191,10 @@ class ZammadClient( return res.body() } - fun onlineNotification(id: Int): OnlineNotification? { + fun onlineNotification(id: Int, expanded: Boolean = false): OnlineNotification? { val authMap = getHeaderMap() - val req = api.onlineNotification(id, authMap) + val req = api.onlineNotification(id, expanded, authMap) val res = req.execute() if (!res.isSuccessful) { diff --git a/lib/src/main/java/com/kirkbushman/zammad/models/OnlineNotification.kt b/lib/src/main/java/com/kirkbushman/zammad/models/OnlineNotification.kt index aa3d416..c0e6e55 100644 --- a/lib/src/main/java/com/kirkbushman/zammad/models/OnlineNotification.kt +++ b/lib/src/main/java/com/kirkbushman/zammad/models/OnlineNotification.kt @@ -18,12 +18,24 @@ data class OnlineNotification( @Json(name = "o_id") val objId: Int, + @Json(name = "object_lookup_id") + val objLookupId: Int, + @Json(name = "object") - val objectType: String?, + val obj: String?, + + @Json(name = "type_lookup_id") + val typeLookupId: Int, @Json(name = "type") val type: NotificationType?, + @Json(name = "user_id") + val userId: Int, + + @Json(name = "user") + val user: String?, + @Json(name = "seen") val seen: Boolean, @@ -49,7 +61,7 @@ data class OnlineNotification( enum class NotificationType(val typeStr: String) { - CREATE("create"), - UPDATE("update"), - ESCALATION("escalation") + @Json(name = "create") CREATE("create"), + @Json(name = "update") UPDATE("update"), + @Json(name = "escalation") ESCALATION("escalation") } diff --git a/sampleapp/src/main/AndroidManifest.xml b/sampleapp/src/main/AndroidManifest.xml index e646c48..862da94 100644 --- a/sampleapp/src/main/AndroidManifest.xml +++ b/sampleapp/src/main/AndroidManifest.xml @@ -59,6 +59,7 @@ + diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationActivity.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationActivity.kt new file mode 100644 index 0000000..4b1b71c --- /dev/null +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationActivity.kt @@ -0,0 +1,44 @@ +package com.kirkbushman.sampleapp.activities + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.kirkbushman.sampleapp.R +import com.kirkbushman.sampleapp.SampleApplication +import com.kirkbushman.sampleapp.doAsync +import com.kirkbushman.zammad.models.OnlineNotification +import kotlinx.android.synthetic.main.activity_notification.* + +class NotificationActivity : AppCompatActivity() { + + companion object { + + private const val PARAM_NOTIFICATION = "intent_param_notification" + + fun start(context: Context, notification: OnlineNotification) { + + val intent = Intent(context, NotificationActivity::class.java) + intent.putExtra(PARAM_NOTIFICATION, notification) + + context.startActivity(intent) + } + } + + private val client by lazy { SampleApplication.instance.getClient() } + private val notification by lazy { intent.getParcelableExtra(PARAM_NOTIFICATION) as OnlineNotification } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_notification) + + var newNotification: OnlineNotification? = null + doAsync(doWork = { + + newNotification = client?.onlineNotification(notification.id, true) + }, onPost = { + + notification_text.text = newNotification.toString() + }) + } +} diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationsActivity.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationsActivity.kt index fc53373..728b97a 100644 --- a/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationsActivity.kt +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/NotificationsActivity.kt @@ -18,7 +18,11 @@ class NotificationsActivity : AppCompatActivity() { private val controller by lazy { NotificationsController(object : OnClickCallback { - override fun onClick(position: Int) {} + override fun onClick(position: Int) { + + val notification = notifications[position] + NotificationActivity.start(this@NotificationsActivity, notification) + } }) } @@ -37,7 +41,7 @@ class NotificationsActivity : AppCompatActivity() { doAsync(doWork = { - notifications.addAll(client?.onlineNotifications() ?: listOf()) + notifications.addAll(client?.onlineNotifications(true) ?: listOf()) }, onPost = { controller.setItems(notifications) diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/NotificationsController.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/NotificationsController.kt index 06672ed..1fbd8cc 100644 --- a/sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/NotificationsController.kt +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/NotificationsController.kt @@ -10,6 +10,7 @@ class NotificationsController(callback: OnClickCallback) : BaseController callback.onClick(position) } } } } diff --git a/sampleapp/src/main/java/com/kirkbushman/sampleapp/models/NotificationModel.kt b/sampleapp/src/main/java/com/kirkbushman/sampleapp/models/NotificationModel.kt index 629725f..4d3b46f 100644 --- a/sampleapp/src/main/java/com/kirkbushman/sampleapp/models/NotificationModel.kt +++ b/sampleapp/src/main/java/com/kirkbushman/sampleapp/models/NotificationModel.kt @@ -1,5 +1,7 @@ package com.kirkbushman.sampleapp.models +import android.view.View +import android.widget.LinearLayout import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass @@ -13,13 +15,29 @@ abstract class NotificationModel : EpoxyModelWithHolder() { @EpoxyAttribute lateinit var notification: OnlineNotification + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) + lateinit var clickListener: View.OnClickListener + override fun bind(holder: NotificationHolder) { - holder.notificationText.text = notification.id.toString() + holder.notificationObj.text = notification.obj + holder.notificationType.text = notification.type?.typeStr ?: "" + holder.notificationUser.text = notification.user ?: "" + holder.notificationCreated.text = notification.createdAt + + holder.container.setOnClickListener(clickListener) + } + + override fun unbind(holder: NotificationHolder) { + holder.container.setOnClickListener(null) } } class NotificationHolder : KotlinHolder() { - val notificationText by bind(R.id.notification_text) + val container by bind(R.id.container) + val notificationObj by bind(R.id.notification_obj) + val notificationType by bind(R.id.notification_type) + val notificationUser by bind(R.id.notification_user) + val notificationCreated by bind(R.id.notification_created) } diff --git a/sampleapp/src/main/res/layout/activity_notification.xml b/sampleapp/src/main/res/layout/activity_notification.xml new file mode 100644 index 0000000..1fabb1f --- /dev/null +++ b/sampleapp/src/main/res/layout/activity_notification.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/sampleapp/src/main/res/layout/item_notification.xml b/sampleapp/src/main/res/layout/item_notification.xml index ee76692..0c5330a 100644 --- a/sampleapp/src/main/res/layout/item_notification.xml +++ b/sampleapp/src/main/res/layout/item_notification.xml @@ -1,15 +1,41 @@ - - - - + + + android:layout_height="wrap_content"> + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file