|
|
|
|
@ -57,20 +57,35 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
register(
|
|
|
|
|
layoutResource = R.layout.item_recycler_techniker,
|
|
|
|
|
viewHolder = ::ProjectTechnikerViewHolder,
|
|
|
|
|
onBindBindViewHolder = { vh, _, text ->
|
|
|
|
|
vh.textView.text = text.name
|
|
|
|
|
onBindBindViewHolder = { vh, _, clickedTechniker ->
|
|
|
|
|
vh.textView.text = clickedTechniker.name
|
|
|
|
|
vh.itemView.setOnClickListener {
|
|
|
|
|
if (adminMode) {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
.show {
|
|
|
|
|
message(text = "Möchtest du \'${text.name}\' entfernen?")
|
|
|
|
|
message(text = "Möchtest du \'${clickedTechniker.name}\' entfernen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
techniker.remove(text)
|
|
|
|
|
einsatz.put("techniker", techniker)
|
|
|
|
|
einsatz.saveInBackground()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
techniker.remove(clickedTechniker)
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("von", ParseObject.createWithoutData("Techniker", clickedTechniker.key))
|
|
|
|
|
query.getFirstInBackground { obj, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
obj.deleteInBackground() {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
einsatz.saveInBackground()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Löschung").show()
|
|
|
|
|
Log.e("TechnikLogger.TechLösch", it.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (techniker.size == 0) showDivider(false)
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
@ -84,34 +99,6 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Einsatz")
|
|
|
|
|
query.getInBackground(childKey) { einsatz, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
val technikerIds = einsatz.getList<String>("techniker")!!
|
|
|
|
|
|
|
|
|
|
val queries = mutableListOf<ParseQuery<ParseObject>>()
|
|
|
|
|
technikerIds.forEach {
|
|
|
|
|
val tempQuery = ParseQuery.getQuery<ParseObject>("Techniker")
|
|
|
|
|
tempQuery.whereEqualTo("objectId", it.toString())
|
|
|
|
|
queries.add(tempQuery)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (queries.isNotEmpty()) {
|
|
|
|
|
val query2 = ParseQuery.or(queries)
|
|
|
|
|
query2.findInBackground { objects2, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
objects2.forEach {
|
|
|
|
|
techniker.add(ProjectTechnikerViewState.ProjectTechniker(it.getString("name")!!, it.objectId))
|
|
|
|
|
}
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
showDivider()
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Id-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e2.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binding.titleView.text = einsatz["name"].toString()
|
|
|
|
|
binding.locationView.text = einsatz["ort"].toString()
|
|
|
|
|
val dates = einsatz["datum"].toString().split(",")
|
|
|
|
|
@ -119,9 +106,33 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
val date = "${dateParts[2]}.${dateParts[1]}.${dateParts[0]}"
|
|
|
|
|
val time = if (dates.size > 1) ", ${dates[1]}" else ""
|
|
|
|
|
binding.dateView.text = date + time
|
|
|
|
|
|
|
|
|
|
val query2 = ParseQuery.getQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query2.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", childKey))
|
|
|
|
|
query2.include("von")
|
|
|
|
|
query2.findInBackground { objects2, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
if (objects2.isNotEmpty()) {
|
|
|
|
|
objects2.forEach {
|
|
|
|
|
val teilnehmenderTechniker = it.getParseObject("von")!!
|
|
|
|
|
techniker.add(ProjectTechnikerViewState.ProjectTechniker(teilnehmenderTechniker.getString("name")!!, teilnehmenderTechniker.objectId))
|
|
|
|
|
}
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
showDivider()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Teilnehmer-Abfrage").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e2.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Abruf fehlgeschlagen", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Einsatz-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.EinsSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -142,12 +153,20 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
einsatz.put("techniker", listOf<String>())
|
|
|
|
|
einsatz.saveInBackground()
|
|
|
|
|
techniker.clear()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(false)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
val query = ParseQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", childKey))
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(objects)
|
|
|
|
|
techniker.clear()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(false)
|
|
|
|
|
binding.technikerView.text = "Techniker: 0"
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
@ -185,28 +204,16 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du dich als involvierter Techniker eintragen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
val entry = ParseObject.createWithoutData("Einsatz", childKey)
|
|
|
|
|
entry.add("techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
entry.saveInBackground()
|
|
|
|
|
techniker.add(ProjectTechnikerViewState.ProjectTechniker(name, sharedPref.getString("technikerId", "")!!))
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(true)
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData("Techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
technikerObject.put("name", sharedPref.getString("name", "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val entry = ParseObject.createWithoutData("Einsatz", childKey)
|
|
|
|
|
entry.add("techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
entry.saveInBackground()
|
|
|
|
|
techniker.add(ProjectTechnikerViewState.ProjectTechniker(name, sharedPref.getString("technikerid", "")!!))
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(true)
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData("Techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
technikerObject.put("name", sharedPref.getString("name", "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
@ -219,22 +226,18 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
private fun otherAdd() {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Techniker")
|
|
|
|
|
val addTechniker = mutableListOf<ProjectTechnikerViewState.ProjectTechniker>()
|
|
|
|
|
|
|
|
|
|
addTechniker.clear()
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
objects.forEach {
|
|
|
|
|
addTechniker.add(ProjectTechnikerViewState.ProjectTechniker(it.getString("name")!!, it.objectId))
|
|
|
|
|
}
|
|
|
|
|
addTechniker.sortBy { it.name }
|
|
|
|
|
objects.sortBy { it.getString("name") }
|
|
|
|
|
|
|
|
|
|
val currentSelection = mutableListOf<Int>()
|
|
|
|
|
val names = mutableListOf<String>()
|
|
|
|
|
addTechniker.forEachIndexed { index, s ->
|
|
|
|
|
names.add(s.name)
|
|
|
|
|
objects.forEachIndexed { index, obj ->
|
|
|
|
|
val name = obj.getString("name")!!
|
|
|
|
|
names.add(name)
|
|
|
|
|
techniker.forEach {
|
|
|
|
|
if (s.name == it.name) currentSelection.add(index)
|
|
|
|
|
if (name == it.name) currentSelection.add(index)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val intArray = currentSelection.toIntArray()
|
|
|
|
|
@ -242,33 +245,47 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
listItemsMultiChoice(items = names, initialSelection = intArray, disabledIndices = intArray)
|
|
|
|
|
positiveButton(text = "Hinzufügen") {
|
|
|
|
|
it.uncheckItems(intArray)
|
|
|
|
|
val checkedNameKeys = mutableListOf<String>()
|
|
|
|
|
addTechniker.forEachIndexed { index, s ->
|
|
|
|
|
val checkedNames = mutableListOf<ParseObject>()
|
|
|
|
|
objects.forEachIndexed { index, obj ->
|
|
|
|
|
if (it.isItemChecked(index)) {
|
|
|
|
|
checkedNameKeys.add(s.key)
|
|
|
|
|
techniker.add(s)
|
|
|
|
|
checkedNames.add(obj)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
einsatz.addAll("techniker", checkedNameKeys)
|
|
|
|
|
einsatz.saveInBackground()
|
|
|
|
|
addTechniker.clear()
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(true)
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen") {
|
|
|
|
|
addTechniker.clear()
|
|
|
|
|
addTechniker(checkedNames)
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Id-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun addTechniker(newTechniker: List<ParseObject>) {
|
|
|
|
|
val project = ParseObject.createWithoutData("Einsatz", childKey)
|
|
|
|
|
val entryList = mutableListOf<ParseObject>()
|
|
|
|
|
newTechniker.forEach {
|
|
|
|
|
val entryObject = ParseObject("Teilnahme")
|
|
|
|
|
entryObject.put("von", it)
|
|
|
|
|
entryObject.put("an", project)
|
|
|
|
|
entryList.add(entryObject)
|
|
|
|
|
techniker.add(ProjectTechnikerViewState.ProjectTechniker(it.getString("name")!!, it.objectId))
|
|
|
|
|
}
|
|
|
|
|
ParseObject.saveAllInBackground(entryList) {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
showDivider(true)
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", it.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showDivider(show: Boolean = true) {
|
|
|
|
|
binding.divider.visibility = if (show) View.VISIBLE else View.GONE
|
|
|
|
|
}
|
|
|
|
|
|