|
|
|
|
@ -14,7 +14,11 @@ 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.R
|
|
|
|
|
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
|
|
|
|
|
@ -43,19 +47,23 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
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 = FragmentProjectBinding.inflate(inflater, container, false)
|
|
|
|
|
val root = binding.root
|
|
|
|
|
myContext = requireContext()
|
|
|
|
|
|
|
|
|
|
sharedPref = myContext.getSharedPreferences("Safe", 0)
|
|
|
|
|
adminMode = sharedPref.getBoolean("admin", false)
|
|
|
|
|
sharedPref = myContext.getSharedPreferences(SHARED_PREFERENCE, 0)
|
|
|
|
|
adminMode = sharedPref.getBoolean(COLUMN_TECHNIKER_ADMIN, false)
|
|
|
|
|
|
|
|
|
|
objectId = args.objectId
|
|
|
|
|
einsatz = ParseObject.createWithoutData("Einsatz", objectId)
|
|
|
|
|
einsatz = ParseObject.createWithoutData(CLASS_EINSATZ, objectId)
|
|
|
|
|
|
|
|
|
|
technikerAdapter = ProjectTechnikerAdapter {
|
|
|
|
|
if (adminMode || it.name == sharedPref.getString("name", "")) {
|
|
|
|
|
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
|
|
|
|
|
MaterialDialog(myContext)
|
|
|
|
|
.show {
|
|
|
|
|
title(text = it.name)
|
|
|
|
|
@ -127,22 +135,22 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
|
ParseObject.createWithoutData("Teilnahme", it.teilnahmeKey).apply {
|
|
|
|
|
put("dauer", dauerFloat)
|
|
|
|
|
put("uhrzeit", it.uhrzeit)
|
|
|
|
|
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>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("von", ParseObject.createWithoutData("Techniker", it.objectId))
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", objectId))
|
|
|
|
|
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("Teilnahme", it.teilnahmeKey).apply {
|
|
|
|
|
put("dauer", dauerFloat)
|
|
|
|
|
put("uhrzeit", it.uhrzeit)
|
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).apply {
|
|
|
|
|
put(COLUMN_TEILNAHME_DAUER, dauerFloat)
|
|
|
|
|
put(COLUMN_TEILNAHME_UHRZEIT, it.uhrzeit)
|
|
|
|
|
saveInBackground()
|
|
|
|
|
}
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
@ -160,14 +168,14 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
negativeButton(text = "Entfernen") { _ ->
|
|
|
|
|
techniker.remove(it)
|
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
|
ParseObject.createWithoutData ("Teilnahme", it.teilnahmeKey).deleteInBackground() {
|
|
|
|
|
ParseObject.createWithoutData (CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground() {
|
|
|
|
|
technikerAdapter.submitList(techniker)
|
|
|
|
|
binding.technikerView.text = "Techniker: ${techniker.size}"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("von", ParseObject.createWithoutData("Techniker", it.objectId))
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", objectId))
|
|
|
|
|
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 {
|
|
|
|
|
@ -198,13 +206,13 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
binding.recyclerView.adapter = technikerAdapter
|
|
|
|
|
|
|
|
|
|
binding.addButton.setOnClickListener {
|
|
|
|
|
val name = sharedPref.getString("name", "invalid")!!
|
|
|
|
|
val name = sharedPref.getString(NAME, "invalid")!!
|
|
|
|
|
if (!adminMode) selfAdd(name) else bothAdd(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emptyCheck()
|
|
|
|
|
|
|
|
|
|
if (adminMode || sharedPref.getString("technikerId", "")!!.isNotBlank()) {
|
|
|
|
|
if (adminMode || sharedPref.getString(TECHNIKER_ID, "")!!.isNotBlank()) {
|
|
|
|
|
binding.addButton.visibility = View.VISIBLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -214,8 +222,8 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
val query = ParseQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", objectId))
|
|
|
|
|
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)
|
|
|
|
|
@ -253,33 +261,33 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun loadData() {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Einsatz")
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>(CLASS_EINSATZ)
|
|
|
|
|
query.getInBackground(objectId) { einsatz, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
binding.titleView.text = einsatz["name"].toString()
|
|
|
|
|
binding.locationView.text = einsatz["ort"].toString()
|
|
|
|
|
val dates = einsatz["datum"].toString().split(",")
|
|
|
|
|
binding.titleView.text = einsatz.getString(COLUMN_EINSATZ_NAME)
|
|
|
|
|
binding.locationView.text = einsatz.getString(COLUMN_EINSATZ_ORT)
|
|
|
|
|
val dates = einsatz.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
|
|
|
|
|
val dateParts = dates[0].split(".")
|
|
|
|
|
val date = "${dateParts[2]}.${dateParts[1]}.${dateParts[0]}"
|
|
|
|
|
dauer = einsatz.getNumber("dauer")!!.toString()
|
|
|
|
|
dauer = einsatz.getNumber(COLUMN_EINSATZ_DAUER)!!.toString()
|
|
|
|
|
if (dates.size > 1) time = dates[1]
|
|
|
|
|
val time = if (dates.size > 1) ", ${dates[1]}" else ", $dauer h"
|
|
|
|
|
binding.dateView.text = date + time
|
|
|
|
|
|
|
|
|
|
val query2 = ParseQuery.getQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query2.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", objectId))
|
|
|
|
|
query2.include("von")
|
|
|
|
|
val query2 = ParseQuery.getQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
query2.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, objectId))
|
|
|
|
|
query2.include(COLUMN_TEILNAHME_VON)
|
|
|
|
|
query2.findInBackground { objects2, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
if (objects2.isNotEmpty()) {
|
|
|
|
|
objects2.forEach {
|
|
|
|
|
val teilnehmenderTechniker = it.getParseObject("von")!!
|
|
|
|
|
val dauerEntry = it.getNumber("dauer")!!
|
|
|
|
|
val dauer = if (dauerEntry == 0) einsatz.getNumber("dauer")!!.toString() else dauerEntry.toString()
|
|
|
|
|
val time = it.getString("uhrzeit")!!
|
|
|
|
|
val teilnehmenderTechniker = it.getParseObject(COLUMN_TEILNAHME_VON)!!
|
|
|
|
|
val dauerEntry = it.getNumber(COLUMN_EINSATZ_DAUER)!!
|
|
|
|
|
val dauer = if (dauerEntry == 0) einsatz.getNumber(COLUMN_TEILNAHME_DAUER)!!.toString() else dauerEntry.toString()
|
|
|
|
|
val time = it.getString(COLUMN_EINSATZ_UHRZEIT)!!
|
|
|
|
|
techniker.add(ProjectTechniker(
|
|
|
|
|
dauer,
|
|
|
|
|
teilnehmenderTechniker.getString("name")!!,
|
|
|
|
|
teilnehmenderTechniker.getString(COLUMN_EINSATZ_NAME)!!,
|
|
|
|
|
teilnehmenderTechniker.objectId,
|
|
|
|
|
it.objectId,
|
|
|
|
|
time
|
|
|
|
|
@ -296,7 +304,6 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Einsatz-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.EinsSuche", e.message.toString())
|
|
|
|
|
@ -333,15 +340,15 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
MaterialDialog(myContext).show {
|
|
|
|
|
message(text = "Möchtest du dich als involvierter Techniker eintragen?")
|
|
|
|
|
positiveButton(text = "Ja") {
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData("Techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
technikerObject.put("name", sharedPref.getString("name", "")!!)
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData(CLASS_TECHNIKER, sharedPref.getString(TECHNIKER_ID, "")!!)
|
|
|
|
|
technikerObject.put(COLUMN_TECHNIKER_NAME, sharedPref.getString(NAME, "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
negativeButton(text = "Abbrechen")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData("Techniker", sharedPref.getString("technikerId", "")!!)
|
|
|
|
|
technikerObject.put("name", sharedPref.getString("name", "")!!)
|
|
|
|
|
val technikerObject = ParseObject.createWithoutData(CLASS_TECHNIKER, sharedPref.getString(TECHNIKER_ID, "")!!)
|
|
|
|
|
technikerObject.put(COLUMN_TECHNIKER_NAME, sharedPref.getString(NAME, "")!!)
|
|
|
|
|
addTechniker(listOf(technikerObject))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -354,17 +361,17 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun otherAdd() {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Techniker")
|
|
|
|
|
query.whereEqualTo("entlassen", false)
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>(CLASS_TECHNIKER)
|
|
|
|
|
query.whereEqualTo(COLUMN_TECHNIKER_ENTLASSEN, false)
|
|
|
|
|
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
objects.sortBy { it.getString("name") }
|
|
|
|
|
objects.sortBy { it.getString(COLUMN_TECHNIKER_NAME) }
|
|
|
|
|
|
|
|
|
|
val currentSelection = mutableListOf<Int>()
|
|
|
|
|
val names = mutableListOf<String>()
|
|
|
|
|
objects.forEachIndexed { index, obj ->
|
|
|
|
|
val name = obj.getString("name")!!
|
|
|
|
|
val name = obj.getString(COLUMN_TECHNIKER_NAME)!!
|
|
|
|
|
names.add(name)
|
|
|
|
|
techniker.forEach {
|
|
|
|
|
if (name == it.name) currentSelection.add(index)
|
|
|
|
|
@ -393,16 +400,16 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun addTechniker(newTechniker: List<ParseObject>) {
|
|
|
|
|
val project = ParseObject.createWithoutData("Einsatz", objectId)
|
|
|
|
|
val project = ParseObject.createWithoutData(CLASS_EINSATZ, objectId)
|
|
|
|
|
val entryList = mutableListOf<ParseObject>()
|
|
|
|
|
newTechniker.forEach {
|
|
|
|
|
val entryObject = ParseObject("Teilnahme")
|
|
|
|
|
entryObject.put("von", it)
|
|
|
|
|
entryObject.put("an", project)
|
|
|
|
|
val entryObject = ParseObject(CLASS_TEILNAHME)
|
|
|
|
|
entryObject.put(COLUMN_TEILNAHME_VON, it)
|
|
|
|
|
entryObject.put(COLUMN_TEILNAHME_AN, project)
|
|
|
|
|
entryList.add(entryObject)
|
|
|
|
|
techniker.add(ProjectTechniker(
|
|
|
|
|
dauer,
|
|
|
|
|
it.getString("name")!!,
|
|
|
|
|
it.getString(COLUMN_TECHNIKER_NAME)!!,
|
|
|
|
|
it.objectId,
|
|
|
|
|
"0",
|
|
|
|
|
time
|
|
|
|
|
|