Skip to content

Commit

Permalink
user model update in sample, corrected annotation for method update i…
Browse files Browse the repository at this point in the history
…n lib
  • Loading branch information
luca committed Oct 21, 2019
1 parent 3681fec commit 05e4e92
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 95 deletions.
58 changes: 29 additions & 29 deletions lib/src/main/java/com/kirkbushman/zammad/ZammadApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ interface ZammadApi {
fun updateUser(
@Path("id") id: Int,

organizationId: Int? = null,
organization: String? = null,
active: Boolean? = null,
login: String? = null,
firstname: String? = null,
lastname: String? = null,
email: String? = null,
image: String? = null,
imageSource: String? = null,
web: String? = null,
phone: String? = null,
fax: String? = null,
mobile: String? = null,
department: String? = null,
street: String? = null,
zip: String? = null,
city: String? = null,
country: String? = null,
address: String? = null,
isVip: Boolean? = null,
isVerified: Boolean? = null,
note: String? = null,
source: String? = null,
lastLogin: String? = null,
loginFailed: Int? = null,
outOfOffice: Boolean? = null,
outOfOfficeStartAt: String? = null,
outOfOfficeEndAt: String? = null,
outOfOfficeReplacementId: Int? = null,
@Field("organization_id") organizationId: Int? = null,
@Field("organization") organization: String? = null,
@Field("active") active: Boolean? = null,
@Field("login") login: String? = null,
@Field("firstname") firstname: String? = null,
@Field("lastname") lastname: String? = null,
@Field("email") email: String? = null,
@Field("image") image: String? = null,
@Field("image_source") imageSource: String? = null,
@Field("web") web: String? = null,
@Field("phone") phone: String? = null,
@Field("fax") fax: String? = null,
@Field("mobile") mobile: String? = null,
@Field("department") department: String? = null,
@Field("street") street: String? = null,
@Field("zip") zip: String? = null,
@Field("city") city: String? = null,
@Field("country") country: String? = null,
@Field("address") address: String? = null,
@Field("vip") isVip: Boolean? = null,
@Field("verified") isVerified: Boolean? = null,
@Field("note") note: String? = null,
@Field("source") source: String? = null,
@Field("last_login") lastLogin: String? = null,
@Field("login_failed") loginFailed: Int? = null,
@Field("out_of_office") outOfOffice: Boolean? = null,
@Field("out_of_office_start_at") outOfOfficeStartAt: String? = null,
@Field("out_of_office_end_at") outOfOfficeEndAt: String? = null,
@Field("out_of_office_replacement_id") outOfOfficeReplacementId: Int? = null,

@HeaderMap header: HashMap<String, String>
): Call<User>
Expand Down
1 change: 1 addition & 0 deletions sampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<activity android:name=".activities.AttachmentActivity" />
<activity android:name=".activities.AttachmentsActivity" />
<activity android:name=".activities.UserActivity" />
<activity android:name=".activities.UserUpdateActivity" />
<activity android:name=".activities.UsersActivity" />
<activity android:name=".activities.GroupActivity" />
<activity android:name=".activities.GroupUpdateActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.kirkbushman.sampleapp.R
import com.kirkbushman.sampleapp.SampleApplication
import com.kirkbushman.sampleapp.controllers.GroupsController
import com.kirkbushman.sampleapp.controllers.OnGroupCallback
import com.kirkbushman.sampleapp.controllers.OnUpDelCallback
import com.kirkbushman.sampleapp.doAsync
import com.kirkbushman.sampleapp.showToast
import com.kirkbushman.zammad.models.Group
Expand All @@ -17,7 +17,7 @@ class GroupsActivity : AppCompatActivity() {

private val groups = ArrayList<Group>()
private val controller by lazy {
GroupsController(object : OnGroupCallback {
GroupsController(object : OnUpDelCallback {

override fun onClick(position: Int) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.kirkbushman.sampleapp.R
import com.kirkbushman.sampleapp.SampleApplication
import com.kirkbushman.sampleapp.controllers.OnOrganizationCallback
import com.kirkbushman.sampleapp.controllers.OnUpDelCallback
import com.kirkbushman.sampleapp.controllers.OrganizationsController
import com.kirkbushman.sampleapp.doAsync
import com.kirkbushman.sampleapp.showToast
Expand All @@ -17,7 +17,7 @@ class OrganizationsActivity : AppCompatActivity() {

private val organizations = ArrayList<Organization>()
private val controller by lazy {
OrganizationsController(object : OnOrganizationCallback {
OrganizationsController(object : OnUpDelCallback {

override fun onClick(position: Int) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.kirkbushman.sampleapp.R
import com.kirkbushman.sampleapp.SampleApplication
import com.kirkbushman.sampleapp.controllers.OnPriorityCallback
import com.kirkbushman.sampleapp.controllers.OnUpDelCallback
import com.kirkbushman.sampleapp.controllers.PrioritiesController
import com.kirkbushman.sampleapp.doAsync
import com.kirkbushman.sampleapp.showToast
Expand All @@ -17,7 +17,7 @@ class PrioritiesActivity : AppCompatActivity() {

private val priorities = ArrayList<TicketPriority>()
private val controller by lazy {
PrioritiesController(object : OnPriorityCallback {
PrioritiesController(object : OnUpDelCallback {

override fun onClick(position: Int) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.kirkbushman.sampleapp.R
import com.kirkbushman.sampleapp.SampleApplication
import com.kirkbushman.sampleapp.controllers.OnStateCallback
import com.kirkbushman.sampleapp.controllers.OnUpDelCallback
import com.kirkbushman.sampleapp.controllers.StatesController
import com.kirkbushman.sampleapp.doAsync
import com.kirkbushman.sampleapp.showToast
Expand All @@ -17,7 +17,7 @@ class StatesActivity : AppCompatActivity() {

private val states = ArrayList<TicketState>()
private val controller by lazy {
StatesController(object : OnStateCallback {
StatesController(object : OnUpDelCallback {

override fun onClick(position: Int) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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.sampleapp.showToast
import com.kirkbushman.zammad.models.User
import kotlinx.android.synthetic.main.activity_user_update.*

class UserUpdateActivity : AppCompatActivity() {

companion object {

private const val PARAM_USER = "intent_param_user"

fun start(context: Context, user: User) {

val intent = Intent(context, UserUpdateActivity::class.java)
intent.putExtra(PARAM_USER, user)

context.startActivity(intent)
}
}

private val client by lazy { SampleApplication.instance.getClient() }
private val user by lazy { intent.getParcelableExtra<User>(PARAM_USER)!! }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_update)

user_firstname.setText(user.firstname)
user_lastname.setText(user.lastname)
user_active.isChecked = user.active
user_email.setText(user.email)
user_phone.setText(user.phone)
user_mobile.setText(user.mobile)
user_note.setText(user.note)

bttn_submit.setOnClickListener {

val firstname = user_firstname.text.toString()
val lastname = user_lastname.text.toString()
val active = user_active.isChecked
val email = user_email.text.toString()
val phone = user_phone.text.toString()
val mobile = user_mobile.text.toString()
val note = user_note.text.toString()

doAsync(doWork = {

client?.updateUser(
id = user.id,
firstname = firstname,
lastname = lastname,
active = active,
email = email,
phone = phone,
mobile = mobile,
note = note
)
}, onPost = {

showToast("User Updated!")
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.kirkbushman.sampleapp.R
import com.kirkbushman.sampleapp.SampleApplication
import com.kirkbushman.sampleapp.controllers.OnClickCallback
import com.kirkbushman.sampleapp.controllers.OnUpDelCallback
import com.kirkbushman.sampleapp.controllers.UsersController
import com.kirkbushman.sampleapp.doAsync
import com.kirkbushman.sampleapp.showToast
import com.kirkbushman.zammad.models.User
import kotlinx.android.synthetic.main.activity_users.*

Expand All @@ -16,13 +17,31 @@ class UsersActivity : AppCompatActivity() {

private val users = ArrayList<User>()
private val controller by lazy {
UsersController(object : OnClickCallback {
UsersController(object : OnUpDelCallback {

override fun onClick(position: Int) {

val user = users[position]
UserActivity.start(this@UsersActivity, user)
}

override fun onUpdateClick(position: Int) {

val user = users[position]
UserUpdateActivity.start(this@UsersActivity, user)
}

override fun onDeleteClick(position: Int) {

doAsync(doWork = {

val user = users[position]
client?.deleteUser(user)
}, onPost = {

showToast("User deleted!")
})
}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kirkbushman.sampleapp.models.empty
import com.kirkbushman.sampleapp.models.group
import com.kirkbushman.zammad.models.Group

class GroupsController(private val callback: OnGroupCallback) : EpoxyController() {
class GroupsController(private val callback: OnUpDelCallback) : EpoxyController() {

private val groups = ArrayList<Group>()

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kirkbushman.sampleapp.controllers

interface OnGroupCallback : OnClickCallback {
interface OnUpDelCallback : OnClickCallback {

fun onUpdateClick(position: Int)
fun onDeleteClick(position: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kirkbushman.sampleapp.models.empty
import com.kirkbushman.sampleapp.models.organization
import com.kirkbushman.zammad.models.Organization

class OrganizationsController(private val callback: OnOrganizationCallback) : EpoxyController() {
class OrganizationsController(private val callback: OnUpDelCallback) : EpoxyController() {

private val organizations = ArrayList<Organization>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kirkbushman.sampleapp.models.empty
import com.kirkbushman.sampleapp.models.priority
import com.kirkbushman.zammad.models.TicketPriority

class PrioritiesController(private val callback: OnPriorityCallback) : EpoxyController() {
class PrioritiesController(private val callback: OnUpDelCallback) : EpoxyController() {

private val priorities = ArrayList<TicketPriority>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kirkbushman.sampleapp.models.empty
import com.kirkbushman.sampleapp.models.state
import com.kirkbushman.zammad.models.TicketState

class StatesController(private val callback: OnStateCallback) : EpoxyController() {
class StatesController(private val callback: OnUpDelCallback) : EpoxyController() {

private val states = ArrayList<TicketState>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kirkbushman.sampleapp.models.empty
import com.kirkbushman.sampleapp.models.user
import com.kirkbushman.zammad.models.User

class UsersController(private val callback: OnClickCallback) : EpoxyController() {
class UsersController(private val callback: OnUpDelCallback) : EpoxyController() {

private val users = ArrayList<User>()

Expand All @@ -29,6 +29,8 @@ class UsersController(private val callback: OnClickCallback) : EpoxyController()
id(it.id)
user(it)
clickListener { _, _, _, position -> callback.onClick(position) }
updateListener { _, _, _, position -> callback.onUpdateClick(position) }
deleteListener { _, _, _, position -> callback.onDeleteClick(position) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kirkbushman.sampleapp.models

import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
Expand All @@ -18,6 +19,11 @@ abstract class UserModel : EpoxyModelWithHolder<UserHolder>() {
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
lateinit var clickListener: View.OnClickListener

@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
lateinit var updateListener: View.OnClickListener
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
lateinit var deleteListener: View.OnClickListener

override fun bind(holder: UserHolder) {

val userNameText = "${user.firstname} ${user.lastname}"
Expand All @@ -26,10 +32,16 @@ abstract class UserModel : EpoxyModelWithHolder<UserHolder>() {
holder.userCreated.text = user.createdAt.toString()

holder.container.setOnClickListener(clickListener)

holder.userUpdate.setOnClickListener(updateListener)
holder.userDelete.setOnClickListener(deleteListener)
}

override fun unbind(holder: UserHolder) {
holder.container.setOnClickListener(null)

holder.userUpdate.setOnClickListener(null)
holder.userDelete.setOnClickListener(null)
}
}

Expand All @@ -39,4 +51,7 @@ class UserHolder : KotlinHolder() {
val userName by bind<TextView>(R.id.user_name)
val userId by bind<TextView>(R.id.user_id)
val userCreated by bind<TextView>(R.id.user_created)

val userUpdate by bind<Button>(R.id.user_update)
val userDelete by bind<Button>(R.id.user_delete)
}
Loading

0 comments on commit 05e4e92

Please sign in to comment.