Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Last active September 12, 2019 19:34
Show Gist options
  • Save Lavanyagaur22/85d74dce8b3d772feb5c9cbaa94601b1 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/85d74dce8b3d772feb5c9cbaa94601b1 to your computer and use it in GitHub Desktop.
override fun onBindViewHolder(holder: TaskHolder, position: Int) {
val currentTask = notes[position]
var title_task = currentTask.title
var desc_task = currentTask.desc
var id_task = currentTask.id.toString()
var checkBool = true
with(holder.itemView) {
user_switch.isChecked = false
title_tv.text = currentTask.title
desc_tv.text = currentTask.desc
id_tv.text = currentTask.id.toString()
if (currentTask.firstName.isNotEmpty()) {
user_switch.isChecked=true
firstName_tv.text = "${currentTask.firstName} ${currentTask.lastName}"
} else {
firstName_tv.text = "User not assigned!"
}
}
holder.itemView.setOnClickListener {
//Used for updating details of user
val inflatedView = LayoutInflater.from(context)
.inflate(org.aerogear.graphqlandroid.R.layout.alert_update_task, null, false)
inflatedView.etId.setText(id_task, TextView.BufferType.EDITABLE)
inflatedView.etTitle.setText(title_task, TextView.BufferType.EDITABLE)
inflatedView.etDesc.setText(desc_task, TextView.BufferType.EDITABLE)
val customAlert: AlertDialog = AlertDialog.Builder(context)
.setView(inflatedView)
.setTitle("Update the details of the Task")
.setNegativeButton("No") { dialog, which ->
dialog.dismiss()
}
.setPositiveButton("Yes") { dialog, which ->
val id = inflatedView.etId.text.toString()
val titleEt = inflatedView.etTitle.text.toString()
val description = inflatedView.etDesc.text.toString()
if (context is MainActivity) this.context.updateTask(
id,
titleEt,
description
)
dialog.dismiss()
}
.create()
customAlert.show()
}
holder.itemView.user_switch.setOnCheckedChangeListener { buttonView, isChecked ->
if (holder.itemView.user_switch.isPressed) {
if (isChecked && checkBool) {
//Used for assigning user
val inflatedView =
LayoutInflater.from(context)
.inflate(org.aerogear.graphqlandroid.R.layout.alertfrag_create_user, null, false)
inflatedView.etTaskIdUser.setText(id_task, TextView.BufferType.EDITABLE)
inflatedView.etTitleUser.setText(title_task, TextView.BufferType.EDITABLE)
val customAlert: AlertDialog = AlertDialog.Builder(context)
.setView(inflatedView)
.setTitle("Assign the User a task")
.setNegativeButton("No") { dialog, which ->
buttonView.setChecked(false)
dialog.dismiss()
}
.setPositiveButton("Yes") { dialog, which ->
val taskId = inflatedView.etTaskIdUser.text.toString()
val title = inflatedView.etTitleUser.text.toString()
val firstName = inflatedView.etFirstName.text.toString()
val lastName = inflatedView.etLastName.text.toString()
val email = inflatedView.etEmail.text.toString()
if (context is MainActivity) this.context.createUser(
title,
firstName,
lastName,
email,
id_task
)
dialog.dismiss()
checkBool = true
}
.create()
customAlert.show()
} else {
Log.e("False empty", "-----")
}
editor.putBoolean(currentTask.id.toString(), isChecked)
editor.apply()
}
}
holder.itemView.imgUser.setOnClickListener {
//Used for updating details of user
val inflatedView =
LayoutInflater.from(context).inflate(R.layout.alert_update_user, null, false)
inflatedView.etIdassigned.setText(id_task, TextView.BufferType.EDITABLE)
inflatedView.etFname.setText(currentTask.firstName, TextView.BufferType.EDITABLE)
inflatedView.etLname.setText(currentTask.lastName, TextView.BufferType.EDITABLE)
inflatedView.etLEmailUSer.setText(currentTask.email, TextView.BufferType.EDITABLE)
inflatedView.etIdUSer.setText(currentTask.userId, TextView.BufferType.EDITABLE)
inflatedView.etTitleUser.setText(currentTask.title, TextView.BufferType.EDITABLE)
val customAlert: AlertDialog = AlertDialog.Builder(context)
.setView(inflatedView)
.setTitle("Update details of the User")
.setNegativeButton("No") { dialog, which ->
dialog.dismiss()
}
.setPositiveButton("Yes") { dialog, which ->
val taskId = inflatedView.etIdassigned.text.toString()
val userId = inflatedView.etIdUSer.text.toString()
val title = inflatedView.etTitleUser.text.toString()
val firstName = inflatedView.etFname.text.toString()
val lastName = inflatedView.etLname.text.toString()
val email = inflatedView.etLEmailUSer.text.toString()
if (context is MainActivity) this.context.updateUser(
userId,
taskId,
title,
firstName,
lastName,
email
)
dialog.dismiss()
}
.create()
customAlert.show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment