|
|
|
|
@ -7,14 +7,17 @@ import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import com.afollestad.materialdialogs.LayoutMode
|
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
|
|
|
|
import com.afollestad.materialdialogs.callbacks.onDismiss
|
|
|
|
|
import com.afollestad.materialdialogs.customview.customView
|
|
|
|
|
import com.cyb3rko.techniklogger.R
|
|
|
|
|
import com.cyb3rko.techniklogger.*
|
|
|
|
|
import com.cyb3rko.techniklogger.CLASS_TECHNIKER
|
|
|
|
|
import com.cyb3rko.techniklogger.COLUMN_TECHNIKER_ADMIN
|
|
|
|
|
import com.cyb3rko.techniklogger.COLUMN_TECHNIKER_ENTLASSEN
|
|
|
|
|
import com.cyb3rko.techniklogger.COLUMN_TECHNIKER_NAME
|
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentManageTechnikerBinding
|
|
|
|
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
|
|
|
|
import com.google.android.material.textfield.TextInputEditText
|
|
|
|
|
@ -29,17 +32,22 @@ class ManageTechnikerFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
private lateinit var techniker: MutableList<ParseObject>
|
|
|
|
|
private val technikerNames = mutableListOf<String>()
|
|
|
|
|
private val query = ParseQuery.getQuery<ParseObject>("Techniker")
|
|
|
|
|
private val query = ParseQuery.getQuery<ParseObject>(CLASS_TECHNIKER)
|
|
|
|
|
|
|
|
|
|
private val binding get() = _binding!!
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
|
|
override fun onCreateView(
|
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
|
container: ViewGroup?,
|
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
|
): View {
|
|
|
|
|
_binding = FragmentManageTechnikerBinding.inflate(inflater, container, false)
|
|
|
|
|
val root = binding.root
|
|
|
|
|
myContext = requireContext()
|
|
|
|
|
|
|
|
|
|
query.whereEqualTo("entlassen", false)
|
|
|
|
|
query.limit = 100000
|
|
|
|
|
query.whereEqualTo(COLUMN_TECHNIKER_ENTLASSEN, false)
|
|
|
|
|
query.orderByAscending(COLUMN_TECHNIKER_NAME)
|
|
|
|
|
query.limit = -1
|
|
|
|
|
|
|
|
|
|
fetchTechniker()
|
|
|
|
|
|
|
|
|
|
@ -51,12 +59,12 @@ class ManageTechnikerFragment : Fragment() {
|
|
|
|
|
val view = it.view
|
|
|
|
|
val newName = view.name.text.toString()
|
|
|
|
|
val newAdmin = view.admin.isChecked
|
|
|
|
|
ParseObject.create("Techniker").apply {
|
|
|
|
|
put("name", newName)
|
|
|
|
|
put("admin", newAdmin)
|
|
|
|
|
ParseObject.create(CLASS_TECHNIKER).apply {
|
|
|
|
|
put(COLUMN_TECHNIKER_NAME, newName)
|
|
|
|
|
put(COLUMN_TECHNIKER_ADMIN, newAdmin)
|
|
|
|
|
saveInBackground {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
Toast.makeText(myContext, "Hinzugefügt", Toast.LENGTH_SHORT).show()
|
|
|
|
|
Toasty.success(myContext, "Hinzugefügt").show()
|
|
|
|
|
showAnimation(true)
|
|
|
|
|
fetchTechniker()
|
|
|
|
|
} else {
|
|
|
|
|
@ -84,26 +92,30 @@ class ManageTechnikerFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
private fun fetchTechniker() {
|
|
|
|
|
technikerNames.clear()
|
|
|
|
|
binding.list.adapter = ArrayAdapter(myContext, android.R.layout.simple_list_item_1, technikerNames)
|
|
|
|
|
binding.list.adapter = ArrayAdapter(
|
|
|
|
|
myContext,
|
|
|
|
|
android.R.layout.simple_list_item_1,
|
|
|
|
|
technikerNames
|
|
|
|
|
)
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
techniker = objects.sortedBy {
|
|
|
|
|
it.getString("name")!!
|
|
|
|
|
}.toMutableList()
|
|
|
|
|
|
|
|
|
|
techniker = objects
|
|
|
|
|
objects.forEach {
|
|
|
|
|
technikerNames.add(it.getString("name")!!)
|
|
|
|
|
technikerNames.add(it.getString(COLUMN_TECHNIKER_NAME)!!)
|
|
|
|
|
}
|
|
|
|
|
technikerNames.sort()
|
|
|
|
|
|
|
|
|
|
val adapter = ArrayAdapter(myContext, android.R.layout.simple_list_item_1, technikerNames)
|
|
|
|
|
val adapter = ArrayAdapter(
|
|
|
|
|
myContext,
|
|
|
|
|
android.R.layout.simple_list_item_1,
|
|
|
|
|
technikerNames
|
|
|
|
|
)
|
|
|
|
|
binding.list.adapter = adapter
|
|
|
|
|
showAnimation(false)
|
|
|
|
|
|
|
|
|
|
binding.list.setOnItemClickListener { _, _, index, _ ->
|
|
|
|
|
val dialogView = layoutInflater.inflate(R.layout.techniker_dialog, null)
|
|
|
|
|
dialogView.findViewById<TextInputEditText>(R.id.name).setText(technikerNames[index])
|
|
|
|
|
dialogView.findViewById<SwitchMaterial>(R.id.admin).isChecked = techniker[index].getBoolean("admin")
|
|
|
|
|
dialogView.findViewById<SwitchMaterial>(R.id.admin).isChecked = techniker[index].getBoolean(COLUMN_TECHNIKER_ADMIN)
|
|
|
|
|
MaterialDialog(myContext, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
|
|
|
|
title(text = "Techniker-Info")
|
|
|
|
|
customView(0, dialogView, horizontalPadding = true)
|
|
|
|
|
@ -112,13 +124,15 @@ class ManageTechnikerFragment : Fragment() {
|
|
|
|
|
val newName = view.name.text.toString()
|
|
|
|
|
val newAdmin = view.admin.isChecked
|
|
|
|
|
val parseObject = techniker[index]
|
|
|
|
|
if (newName != parseObject.getString("name") || newAdmin != parseObject.getBoolean("admin")) {
|
|
|
|
|
if (newName != parseObject.getString(COLUMN_TECHNIKER_NAME) ||
|
|
|
|
|
newAdmin != parseObject.getBoolean(COLUMN_TECHNIKER_ADMIN)
|
|
|
|
|
) {
|
|
|
|
|
parseObject.apply {
|
|
|
|
|
put("name", newName)
|
|
|
|
|
put("admin", newAdmin)
|
|
|
|
|
put(COLUMN_TECHNIKER_NAME, newName)
|
|
|
|
|
put(COLUMN_TECHNIKER_ADMIN, newAdmin)
|
|
|
|
|
saveInBackground {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
Toast.makeText(myContext, "Gespeichert", Toast.LENGTH_SHORT).show()
|
|
|
|
|
Toasty.success(myContext, "Gespeichert").show()
|
|
|
|
|
showAnimation(true)
|
|
|
|
|
fetchTechniker()
|
|
|
|
|
} else {
|
|
|
|
|
@ -136,10 +150,10 @@ class ManageTechnikerFragment : Fragment() {
|
|
|
|
|
message(text = "Soll '$name' wirklich entlassen werden?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
techniker[index].apply {
|
|
|
|
|
put("entlassen", true)
|
|
|
|
|
put(COLUMN_TECHNIKER_ENTLASSEN, true)
|
|
|
|
|
saveInBackground {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
Toast.makeText(myContext, "Gespeichert", Toast.LENGTH_SHORT).show()
|
|
|
|
|
Toasty.success(myContext, "Gespeichert").show()
|
|
|
|
|
showAnimation(true)
|
|
|
|
|
fetchTechniker()
|
|
|
|
|
} else {
|
|
|
|
|
|