Skip to content

Commit

Permalink
added more notifications fields, expanded state, testing in the sampl…
Browse files Browse the repository at this point in the history
…e app
  • Loading branch information
luca committed Nov 28, 2019
1 parent 6fe180e commit 3b6836b
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 25 deletions.
2 changes: 2 additions & 0 deletions lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,14 @@ interface ZammadApi {

@GET("/api/v1/online_notifications")
fun onlineNotifications(
@Query("expand") expanded: Boolean,
@HeaderMap header: HashMap<String, String>
): Call<List<OnlineNotification>>

@GET("/api/v1/online_notifications/{id}")
fun onlineNotification(
@Path("id") id: Int,
@Query("expand") expanded: Boolean,
@HeaderMap header: HashMap<String, String>
): Call<OnlineNotification>

Expand Down
8 changes: 4 additions & 4 deletions lib/src/main/java/com/kirkbushman/zammad/ZammadClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,10 @@ class ZammadClient(
return res.body()
}

fun onlineNotifications(): List<OnlineNotification>? {
fun onlineNotifications(expanded: Boolean = false): List<OnlineNotification>? {

val authMap = getHeaderMap()
val req = api.onlineNotifications(authMap)
val req = api.onlineNotifications(expanded, authMap)
val res = req.execute()

if (!res.isSuccessful) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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")
}
1 change: 1 addition & 0 deletions sampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<activity android:name=".activities.StatesActivity" />
<activity android:name=".activities.ObjectActivity" />
<activity android:name=".activities.ObjectsActivity" />
<activity android:name=".activities.NotificationActivity" />
<activity android:name=".activities.NotificationsActivity" />
<activity android:name=".activities.ArticleActivity" />
<activity android:name=".activities.ArticlesActivity" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

Expand All @@ -37,7 +41,7 @@ class NotificationsActivity : AppCompatActivity() {

doAsync(doWork = {

notifications.addAll(client?.onlineNotifications() ?: listOf())
notifications.addAll(client?.onlineNotifications(true) ?: listOf())
}, onPost = {

controller.setItems(notifications)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class NotificationsController(callback: OnClickCallback) : BaseController<Online
notification {
id(item.id)
notification(item)
clickListener { _, _, _, position -> callback.onClick(position) }
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,13 +15,29 @@ abstract class NotificationModel : EpoxyModelWithHolder<NotificationHolder>() {
@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<TextView>(R.id.notification_text)
val container by bind<LinearLayout>(R.id.container)
val notificationObj by bind<TextView>(R.id.notification_obj)
val notificationType by bind<TextView>(R.id.notification_type)
val notificationUser by bind<TextView>(R.id.notification_user)
val notificationCreated by bind<TextView>(R.id.notification_created)
}
14 changes: 14 additions & 0 deletions sampleapp/src/main/res/layout/activity_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/notification_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
/>

</LinearLayout>
52 changes: 39 additions & 13 deletions sampleapp/src/main/res/layout/item_notification.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/notification_text"
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">

<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:layout_margin="8dp" />
android:layout_height="wrap_content">

<TextView
android:id="@+id/notification_obj"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:layout_margin="8dp" />

<TextView
android:id="@+id/notification_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp" />

<TextView
android:id="@+id/notification_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp" />

<TextView
android:id="@+id/notification_created"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp" />

</LinearLayout>

</LinearLayout>
</com.google.android.material.card.MaterialCardView>

0 comments on commit 3b6836b

Please sign in to comment.