Behebe Crash bei Auswahl weiterer Techniker

master
Niko Diamadis 4 years ago
parent 9b7adff036
commit d6803cd343

@ -10,7 +10,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckedTextView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.view.forEach
import androidx.core.view.forEachIndexed
import androidx.core.view.get
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
@ -20,6 +23,7 @@ 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.dialog.MaterialDialogs
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.parse.ParseObject
@ -375,18 +379,25 @@ class ProjectFragment : Fragment() {
val checkedNames = mutableListOf<String>()
val previousSelection = currentSelection.toList()
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
val name = names[index]
if (previousSelection[index]) {
var disabledIndex = -1
val listView = (dialogInterface as AlertDialog).listView
while (disabledIndex + 1 < names.size && (listView[disabledIndex + 1] as TextView).text != name) {
disabledIndex++
}
if (disabledIndex != -1) (listView[disabledIndex + 1] as CheckedTextView).isChecked = true
} else {
if (isChecked) {
checkedNames.add(names[index])
if (!checkedNames.contains(name)) {
checkedNames.add(name)
}
} else {
checkedNames.remove(names[index])
checkedNames.remove(name)
}
}
}

Loading…
Cancel
Save