|
|
|
|
@ -6,22 +6,20 @@ import android.content.SharedPreferences
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.text.Html
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.*
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.CheckedTextView
|
|
|
|
|
import androidx.appcompat.app.AlertDialog
|
|
|
|
|
import androidx.core.view.get
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.navigation.fragment.navArgs
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
|
import com.afollestad.materialdialogs.list.isItemChecked
|
|
|
|
|
import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
|
|
|
|
import com.afollestad.materialdialogs.list.uncheckItems
|
|
|
|
|
import com.cyb3rko.techniklogger.*
|
|
|
|
|
import com.cyb3rko.techniklogger.CLASS_EINSATZ
|
|
|
|
|
import com.cyb3rko.techniklogger.COLUMN_TECHNIKER_ADMIN
|
|
|
|
|
import com.cyb3rko.techniklogger.NAME
|
|
|
|
|
import com.cyb3rko.techniklogger.SHARED_PREFERENCE
|
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentProjectBinding
|
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectTechniker
|
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerAdapter
|
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
|
import com.google.android.material.timepicker.MaterialTimePicker
|
|
|
|
|
import com.google.android.material.timepicker.TimeFormat
|
|
|
|
|
import com.parse.ParseObject
|
|
|
|
|
@ -42,7 +40,6 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
private var dauer = ""
|
|
|
|
|
private lateinit var einsatz: ParseObject
|
|
|
|
|
private lateinit var sharedPref: SharedPreferences
|
|
|
|
|
private val techniker: MutableList<ProjectTechniker> = mutableListOf()
|
|
|
|
|
private var time = ""
|
|
|
|
|
|
|
|
|
|
private val binding get() = _binding!!
|
|
|
|
|
@ -64,113 +61,83 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
technikerAdapter = ProjectTechnikerAdapter {
|
|
|
|
|
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
.show {
|
|
|
|
|
title(text = it.name)
|
|
|
|
|
val uhrzeit = if (it.uhrzeit == "0") time else it.uhrzeit
|
|
|
|
|
message(text = Html.fromHtml("<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>Wie möchtest du " +
|
|
|
|
|
"diesen Eintrag bearbeiten?"))
|
|
|
|
|
positiveButton(text = "Arbeitszeit ändern") { _ ->
|
|
|
|
|
var tempTime = ""
|
|
|
|
|
var time1 = Time(0)
|
|
|
|
|
var time2 = Time(0)
|
|
|
|
|
val builder = MaterialTimePicker.Builder().setTimeFormat(
|
|
|
|
|
TimeFormat.CLOCK_24H).setTitleText("Von")
|
|
|
|
|
val builder2 = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Bis")
|
|
|
|
|
val picker = builder.build()
|
|
|
|
|
val picker2 = builder2.build()
|
|
|
|
|
var hour: String
|
|
|
|
|
var minute: String
|
|
|
|
|
var hoursInMillis: Long
|
|
|
|
|
var minutesInMillis: Long
|
|
|
|
|
if (it.uhrzeit != "0") {
|
|
|
|
|
val times = it.uhrzeit.split(" - ")
|
|
|
|
|
builder.setHour(times[0].split(":")[0].toInt())
|
|
|
|
|
.setMinute(times[0].split(":")[1].toInt())
|
|
|
|
|
builder2.setHour(times[1].split(":")[0].toInt())
|
|
|
|
|
.setMinute(times[1].split(":")[1].toInt())
|
|
|
|
|
}
|
|
|
|
|
picker.addOnPositiveButtonClickListener {
|
|
|
|
|
hour = picker.hour.toString()
|
|
|
|
|
hour = if (hour.length != 1) hour else "0$hour"
|
|
|
|
|
minute = picker.minute.toString()
|
|
|
|
|
minute = if (minute.length != 1) minute else "0$minute"
|
|
|
|
|
hoursInMillis = picker.hour.toLong() * 3600000
|
|
|
|
|
minutesInMillis = picker.minute.toLong() * 60000
|
|
|
|
|
time1 = Time(hoursInMillis + minutesInMillis)
|
|
|
|
|
val testTime = time.split(" ")[0]
|
|
|
|
|
val testHour = testTime.split(":")[0]
|
|
|
|
|
val testMinutes = testTime.split(":")[1]
|
|
|
|
|
if (testHour > hour) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
} else if (testHour == hour && testMinutes > minute) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
} else {
|
|
|
|
|
tempTime += "${hour}:${minute} - "
|
|
|
|
|
activity?.let { it1 -> picker2.show(it1.supportFragmentManager, picker2.tag) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
picker2.addOnPositiveButtonClickListener { _ ->
|
|
|
|
|
hour = picker2.hour.toString()
|
|
|
|
|
hour = if (hour.length != 1) hour else "0$hour"
|
|
|
|
|
minute = picker2.minute.toString()
|
|
|
|
|
minute = if (minute.length != 1) minute else "0$minute"
|
|
|
|
|
hoursInMillis = hour.toLong() * 3600000
|
|
|
|
|
minutesInMillis = minute.toLong() * 60000
|
|
|
|
|
time2 = Time(hoursInMillis + minutesInMillis)
|
|
|
|
|
val testTime = time.split(" ")[2]
|
|
|
|
|
val testHour = testTime.split(":")[0]
|
|
|
|
|
val testMinutes = testTime.split(":")[1]
|
|
|
|
|
if (testHour < hour) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
return@addOnPositiveButtonClickListener
|
|
|
|
|
} else if (testHour == hour && testMinutes < minute) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
return@addOnPositiveButtonClickListener
|
|
|
|
|
}
|
|
|
|
|
tempTime += "${hour}:${minute}"
|
|
|
|
|
it.uhrzeit = tempTime
|
|
|
|
|
val tempDauer = DecimalFormat("#.#").format((time2.time - time1.time) / 3600 / 1000.toFloat())
|
|
|
|
|
it.dauer = tempDauer.replace(",", ".")
|
|
|
|
|
val uhrzeit = if (it.uhrzeit == "0") time else it.uhrzeit
|
|
|
|
|
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
|
|
|
|
|
"Wie möchtest du diesen Eintrag bearbeiten?"
|
|
|
|
|
|
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).apply {
|
|
|
|
|
put(COLUMN_EINSATZ_DAUER, dauerFloat)
|
|
|
|
|
put(COLUMN_EINSATZ_UHRZEIT, it.uhrzeit)
|
|
|
|
|
saveInBackground()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_VON, ParseObject.createWithoutData(CLASS_TECHNIKER, it.objectId))
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, objectId))
|
|
|
|
|
query.getFirstInBackground { obj, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
it.teilnahmeKey = obj.objectId
|
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).apply {
|
|
|
|
|
put(COLUMN_TEILNAHME_DAUER, dauerFloat)
|
|
|
|
|
put(COLUMN_TEILNAHME_UHRZEIT, it.uhrzeit)
|
|
|
|
|
saveInBackground()
|
|
|
|
|
}
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
}
|
|
|
|
|
activity?.let { it1 -> picker.show(it1.supportFragmentManager, picker.tag) }
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setTitle(it.name)
|
|
|
|
|
.setMessage(Html.fromHtml(message))
|
|
|
|
|
.setPositiveButton("Arbeitszeit ändern") { _, _ ->
|
|
|
|
|
var tempTime = ""
|
|
|
|
|
var time1 = Time(0)
|
|
|
|
|
var time2 = Time(0)
|
|
|
|
|
val builder = MaterialTimePicker.Builder().setTimeFormat(
|
|
|
|
|
TimeFormat.CLOCK_24H).setTitleText("Von")
|
|
|
|
|
val builder2 = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Bis")
|
|
|
|
|
val picker = builder.build()
|
|
|
|
|
val picker2 = builder2.build()
|
|
|
|
|
var hour: String
|
|
|
|
|
var minute: String
|
|
|
|
|
var hoursInMillis: Long
|
|
|
|
|
var minutesInMillis: Long
|
|
|
|
|
if (it.uhrzeit != "0") {
|
|
|
|
|
val times = it.uhrzeit.split(" - ")
|
|
|
|
|
builder.setHour(times[0].split(":")[0].toInt())
|
|
|
|
|
.setMinute(times[0].split(":")[1].toInt())
|
|
|
|
|
builder2.setHour(times[1].split(":")[0].toInt())
|
|
|
|
|
.setMinute(times[1].split(":")[1].toInt())
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Entfernen") { _ ->
|
|
|
|
|
techniker.remove(it)
|
|
|
|
|
picker.addOnPositiveButtonClickListener {
|
|
|
|
|
hour = picker.hour.toString()
|
|
|
|
|
hour = if (hour.length != 1) hour else "0$hour"
|
|
|
|
|
minute = picker.minute.toString()
|
|
|
|
|
minute = if (minute.length != 1) minute else "0$minute"
|
|
|
|
|
hoursInMillis = picker.hour.toLong() * 3600000
|
|
|
|
|
minutesInMillis = picker.minute.toLong() * 60000
|
|
|
|
|
time1 = Time(hoursInMillis + minutesInMillis)
|
|
|
|
|
val testTime = time.split(" ")[0]
|
|
|
|
|
val testHour = testTime.split(":")[0]
|
|
|
|
|
val testMinutes = testTime.split(":")[1]
|
|
|
|
|
if (testHour > hour) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
} else if (testHour == hour && testMinutes > minute) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
} else {
|
|
|
|
|
tempTime += "${hour}:${minute} - "
|
|
|
|
|
activity?.let { it1 -> picker2.show(it1.supportFragmentManager, picker2.tag) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
picker2.addOnPositiveButtonClickListener { _ ->
|
|
|
|
|
hour = picker2.hour.toString()
|
|
|
|
|
hour = if (hour.length != 1) hour else "0$hour"
|
|
|
|
|
minute = picker2.minute.toString()
|
|
|
|
|
minute = if (minute.length != 1) minute else "0$minute"
|
|
|
|
|
hoursInMillis = hour.toLong() * 3600000
|
|
|
|
|
minutesInMillis = minute.toLong() * 60000
|
|
|
|
|
time2 = Time(hoursInMillis + minutesInMillis)
|
|
|
|
|
val testTime = time.split(" ")[2]
|
|
|
|
|
val testHour = testTime.split(":")[0]
|
|
|
|
|
val testMinutes = testTime.split(":")[1]
|
|
|
|
|
if (testHour < hour) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
return@addOnPositiveButtonClickListener
|
|
|
|
|
} else if (testHour == hour && testMinutes < minute) {
|
|
|
|
|
Toasty.warning(myContext, "Zeitpunkt nicht im Zeitraum des Einsatzes", Toasty.LENGTH_LONG).show()
|
|
|
|
|
return@addOnPositiveButtonClickListener
|
|
|
|
|
}
|
|
|
|
|
tempTime += "${hour}:${minute}"
|
|
|
|
|
it.uhrzeit = tempTime
|
|
|
|
|
val tempDauer = DecimalFormat("#.#").format((time2.time - time1.time) / 3600 / 1000.toFloat())
|
|
|
|
|
it.dauer = tempDauer.replace(",", ".")
|
|
|
|
|
|
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
|
ParseObject.createWithoutData (CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground() {
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).apply {
|
|
|
|
|
put(COLUMN_EINSATZ_DAUER, dauerFloat)
|
|
|
|
|
put(COLUMN_EINSATZ_UHRZEIT, it.uhrzeit)
|
|
|
|
|
saveInBackground()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
@ -178,13 +145,13 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, objectId))
|
|
|
|
|
query.getFirstInBackground { obj, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
obj.deleteInBackground {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Löschung").show()
|
|
|
|
|
Log.e("TechnikLogger.TechLösch", it.message.toString())
|
|
|
|
|
it.teilnahmeKey = obj.objectId
|
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).apply {
|
|
|
|
|
put(COLUMN_TEILNAHME_DAUER, dauerFloat)
|
|
|
|
|
put(COLUMN_TEILNAHME_UHRZEIT, it.uhrzeit)
|
|
|
|
|
saveInBackground {
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -193,15 +160,45 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (techniker.size == 0) showDivider(false)
|
|
|
|
|
}
|
|
|
|
|
activity?.let { it1 -> picker.show(it1.supportFragmentManager, picker.tag) }
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Entfernen") { _, _ ->
|
|
|
|
|
val list = technikerAdapter.currentList.toMutableList()
|
|
|
|
|
list.remove(it)
|
|
|
|
|
technikerAdapter.submitList(list)
|
|
|
|
|
updateTechnikerCount(list.size)
|
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
|
showDivider(false)
|
|
|
|
|
}
|
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground()
|
|
|
|
|
} else {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_VON, ParseObject.createWithoutData(CLASS_TECHNIKER, it.objectId))
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, objectId))
|
|
|
|
|
query.getFirstInBackground { obj, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
obj.deleteInBackground {
|
|
|
|
|
if (it != null) {
|
|
|
|
|
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 (technikerAdapter.currentList.size == 0) showDivider(false)
|
|
|
|
|
}
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadData()
|
|
|
|
|
|
|
|
|
|
technikerAdapter.submitList(techniker as List<ProjectTechniker>?)
|
|
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(myContext)
|
|
|
|
|
binding.recyclerView.adapter = technikerAdapter
|
|
|
|
|
|
|
|
|
|
@ -219,26 +216,26 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
if (adminMode) {
|
|
|
|
|
binding.resetButton.visibility = View.VISIBLE
|
|
|
|
|
binding.resetButton.setOnClickListener {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setTitle("Techniker entfernen")
|
|
|
|
|
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
|
val query = ParseQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, objectId))
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(objects)
|
|
|
|
|
techniker.clear()
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
technikerAdapter.submitList(listOf())
|
|
|
|
|
showDivider(false)
|
|
|
|
|
binding.technikerView.text = "Techniker: 0"
|
|
|
|
|
updateTechnikerCount(0)
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Abbrechen", null)
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -249,10 +246,8 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
binding.titleView.text = ""
|
|
|
|
|
binding.dateView.text = ""
|
|
|
|
|
binding.locationView.text = ""
|
|
|
|
|
techniker.clear()
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
showDivider(false)
|
|
|
|
|
binding.technikerView.text = "Techniker: 0"
|
|
|
|
|
updateTechnikerCount(0)
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -280,6 +275,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
query2.findInBackground { objects2, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
if (objects2.isNotEmpty()) {
|
|
|
|
|
val techniker = mutableListOf<ProjectTechniker>()
|
|
|
|
|
objects2.forEach {
|
|
|
|
|
val teilnehmenderTechniker = it.getParseObject(COLUMN_TEILNAHME_VON)!!
|
|
|
|
|
val dauerEntry = it.getNumber(COLUMN_EINSATZ_DAUER)!!
|
|
|
|
|
@ -293,9 +289,8 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
time
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
updateTechnikerCount(techniker.size)
|
|
|
|
|
showDivider()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -313,7 +308,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun technikerExists(name: String): Boolean {
|
|
|
|
|
for (techniker in techniker) {
|
|
|
|
|
for (techniker in technikerAdapter.currentList) {
|
|
|
|
|
if (name == techniker.name) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
@ -322,41 +317,39 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun bothAdd(name: String) {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
.show {
|
|
|
|
|
message(text = "Möchtest du nur dich oder auch andere Techniker eintragen?")
|
|
|
|
|
positiveButton(text = "Mich") {
|
|
|
|
|
selfAdd(name, true)
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Andere") {
|
|
|
|
|
otherAdd()
|
|
|
|
|
}
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setMessage("Möchtest du nur dich oder auch andere Techniker eintragen?")
|
|
|
|
|
.setPositiveButton("Mich") { _, _ ->
|
|
|
|
|
selfAdd(name, true)
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Andere") { _, _ ->
|
|
|
|
|
otherAdd()
|
|
|
|
|
}
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun selfAdd(name: String, skip: Boolean = false) {
|
|
|
|
|
if (!technikerExists(name)) {
|
|
|
|
|
if (!skip) {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du dich als involvierter Techniker eintragen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setMessage("Möchtest du dich als involvierter Techniker eintragen?")
|
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData(CLASS_TECHNIKER, sharedPref.getString(TECHNIKER_ID, "")!!)
|
|
|
|
|
technikerObject.put(COLUMN_TECHNIKER_NAME, sharedPref.getString(NAME, "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Abbrechen", null)
|
|
|
|
|
.show()
|
|
|
|
|
} else {
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData(CLASS_TECHNIKER, sharedPref.getString(TECHNIKER_ID, "")!!)
|
|
|
|
|
technikerObject.put(COLUMN_TECHNIKER_NAME, sharedPref.getString(NAME, "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
.show {
|
|
|
|
|
message(text = "Du bist bereits eingetragen.")
|
|
|
|
|
positiveButton(text = "Ok")
|
|
|
|
|
}
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setMessage("Du bist bereits eingetragen.")
|
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -368,30 +361,52 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
if (e == null) {
|
|
|
|
|
objects.sortBy { it.getString(COLUMN_TECHNIKER_NAME) }
|
|
|
|
|
|
|
|
|
|
val currentSelection = mutableListOf<Int>()
|
|
|
|
|
val currentSelection = BooleanArray(objects.size)
|
|
|
|
|
val names = mutableListOf<String>()
|
|
|
|
|
objects.forEachIndexed { index, obj ->
|
|
|
|
|
val name = obj.getString(COLUMN_TECHNIKER_NAME)!!
|
|
|
|
|
names.add(name)
|
|
|
|
|
techniker.forEach {
|
|
|
|
|
if (name == it.name) currentSelection.add(index)
|
|
|
|
|
technikerAdapter.currentList.forEach {
|
|
|
|
|
if (name == it.name) {
|
|
|
|
|
currentSelection[index] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val intArray = currentSelection.toIntArray()
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
listItemsMultiChoice(items = names, initialSelection = intArray, disabledIndices = intArray)
|
|
|
|
|
positiveButton(text = "Hinzufügen") {
|
|
|
|
|
it.uncheckItems(intArray)
|
|
|
|
|
val checkedNames = mutableListOf<ParseObject>()
|
|
|
|
|
objects.forEachIndexed { index, obj ->
|
|
|
|
|
if (it.isItemChecked(index)) {
|
|
|
|
|
checkedNames.add(obj)
|
|
|
|
|
|
|
|
|
|
val checkedNames = mutableListOf<String>()
|
|
|
|
|
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setMultiChoiceItems(names.toTypedArray(), currentSelection) { dialogInterface, index, isChecked ->
|
|
|
|
|
val dialogList = (dialogInterface as AlertDialog).listView
|
|
|
|
|
val item = dialogList[index] as CheckedTextView
|
|
|
|
|
|
|
|
|
|
if (!item.isEnabled) {
|
|
|
|
|
item.isChecked = true
|
|
|
|
|
} else {
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
checkedNames.add(names[index])
|
|
|
|
|
} else {
|
|
|
|
|
checkedNames.remove(names[index])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
addTechniker(checkedNames)
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
.setPositiveButton("Hinzufügen") { _, _ ->
|
|
|
|
|
val newNameObjects = mutableListOf<ParseObject>()
|
|
|
|
|
objects.forEach {
|
|
|
|
|
if (checkedNames.contains(it.getString(COLUMN_TECHNIKER_NAME)!!)) {
|
|
|
|
|
newNameObjects.add(it)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
addTechniker(newNameObjects)
|
|
|
|
|
}
|
|
|
|
|
.create().apply {
|
|
|
|
|
setOnShowListener {
|
|
|
|
|
val dialogList = (it as AlertDialog).listView
|
|
|
|
|
currentSelection.forEachIndexed { index, b ->
|
|
|
|
|
if (b) dialogList[index].isEnabled = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.show()
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
@ -407,20 +422,10 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
entryObject.put(COLUMN_TEILNAHME_VON, it)
|
|
|
|
|
entryObject.put(COLUMN_TEILNAHME_AN, project)
|
|
|
|
|
entryList.add(entryObject)
|
|
|
|
|
techniker.add(ProjectTechniker(
|
|
|
|
|
dauer,
|
|
|
|
|
it.getString(COLUMN_TECHNIKER_NAME)!!,
|
|
|
|
|
it.objectId,
|
|
|
|
|
"0",
|
|
|
|
|
time
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
ParseObject.saveAllInBackground(entryList) {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
showDivider(true)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
loadData()
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", it.message.toString())
|
|
|
|
|
@ -428,12 +433,16 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateTechnikerCount(counter: Int) {
|
|
|
|
|
binding.technikerView.text = "Techniker: $counter"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showDivider(show: Boolean = true) {
|
|
|
|
|
binding.divider.visibility = if (show) View.VISIBLE else View.GONE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun emptyCheck() {
|
|
|
|
|
if (techniker.isEmpty()) {
|
|
|
|
|
if (technikerAdapter.currentList.isEmpty()) {
|
|
|
|
|
binding.divider.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|