|
|
|
|
@ -39,8 +39,10 @@ class MissionFragment : Fragment() {
|
|
|
|
|
private val args: MissionFragmentArgs by navArgs()
|
|
|
|
|
|
|
|
|
|
private var objectId = ""
|
|
|
|
|
private var time = ""
|
|
|
|
|
private var date = ""
|
|
|
|
|
private var dateTime = ""
|
|
|
|
|
private var duration = 0f
|
|
|
|
|
private var time = ""
|
|
|
|
|
private lateinit var participationAdapter: ParticipationAdapter
|
|
|
|
|
private var adminMode = false
|
|
|
|
|
private lateinit var sharedPref: SharedPreferences
|
|
|
|
|
@ -84,6 +86,7 @@ class MissionFragment : Fragment() {
|
|
|
|
|
ParseController.fetchParticipations(objectId, false) { entries, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(entries)
|
|
|
|
|
initializeRecyclerView()
|
|
|
|
|
participationAdapter.submitList(listOf())
|
|
|
|
|
showDivider(false)
|
|
|
|
|
updateTechnikerCount(0)
|
|
|
|
|
@ -112,13 +115,13 @@ class MissionFragment : Fragment() {
|
|
|
|
|
private fun loadData() {
|
|
|
|
|
ParseController.fetchMission(objectId) { mission, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
val date = SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(mission!!.date())
|
|
|
|
|
time = mission.time()
|
|
|
|
|
date = SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(mission!!.date())
|
|
|
|
|
duration = mission.duration
|
|
|
|
|
val prettyDuration = duration.toPrettyString()
|
|
|
|
|
|
|
|
|
|
time = if (time != "") ", $time ($prettyDuration h)" else ", $prettyDuration h"
|
|
|
|
|
val dateTime = date + time
|
|
|
|
|
val tempTime = mission.time()
|
|
|
|
|
time = if (tempTime != "") "$tempTime Uhr ($prettyDuration h)" else "$prettyDuration h"
|
|
|
|
|
dateTime = "$date, $time"
|
|
|
|
|
|
|
|
|
|
binding.apply {
|
|
|
|
|
if (titleView.text != mission.name) {
|
|
|
|
|
@ -168,14 +171,20 @@ class MissionFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun isRecyclerViewInitialized() = this::participationAdapter.isInitialized
|
|
|
|
|
|
|
|
|
|
private fun initializeRecyclerView() {
|
|
|
|
|
if (this::participationAdapter.isInitialized) {
|
|
|
|
|
if (isRecyclerViewInitialized()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
participationAdapter = ParticipationAdapter(duration) {
|
|
|
|
|
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
|
|
|
|
|
val uhrzeit = if (it.time == "0") time else it.time
|
|
|
|
|
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
|
|
|
|
|
val uhrzeit = if (it.time == "0") {
|
|
|
|
|
time
|
|
|
|
|
} else {
|
|
|
|
|
"${it.time} Uhr (${it.duration.toPrettyString()} h)"
|
|
|
|
|
}
|
|
|
|
|
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit<br/><br/>" +
|
|
|
|
|
"Wie möchtest du diesen Eintrag bearbeiten?"
|
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
|
@ -263,14 +272,15 @@ class MissionFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Entfernen") { _, _ ->
|
|
|
|
|
val list = participationAdapter.currentList.toMutableList()
|
|
|
|
|
list.remove(it)
|
|
|
|
|
val subList = list.filter { filteredParticipation ->
|
|
|
|
|
filteredParticipation.name == it.name
|
|
|
|
|
}
|
|
|
|
|
list.remove(subList[0])
|
|
|
|
|
participationAdapter.submitList(list)
|
|
|
|
|
updateTechnikerCount(list.size)
|
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
|
showDivider(false)
|
|
|
|
|
}
|
|
|
|
|
if (list.isEmpty()) showDivider(false)
|
|
|
|
|
|
|
|
|
|
Participation.emptyObject(it.objectId).deleteInBackground()
|
|
|
|
|
if (participationAdapter.currentList.size == 0) showDivider(false)
|
|
|
|
|
loadParticipations()
|
|
|
|
|
}
|
|
|
|
|
.show()
|
|
|
|
|
@ -281,11 +291,13 @@ class MissionFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun memberExists(name: String): Boolean {
|
|
|
|
|
if (isRecyclerViewInitialized()) {
|
|
|
|
|
for (member in participationAdapter.currentList) {
|
|
|
|
|
if (name == member.name) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -327,12 +339,14 @@ class MissionFragment : Fragment() {
|
|
|
|
|
if (e == null) {
|
|
|
|
|
val currentSelection = BooleanArray(members.size)
|
|
|
|
|
memberNames.forEachIndexed { index, name ->
|
|
|
|
|
if (isRecyclerViewInitialized()) {
|
|
|
|
|
participationAdapter.currentList.forEach {
|
|
|
|
|
if (name == it.name) {
|
|
|
|
|
currentSelection[index] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val checkedNames = mutableListOf<String>()
|
|
|
|
|
val previousSelection = currentSelection.toList()
|
|
|
|
|
@ -406,9 +420,7 @@ class MissionFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun emptyCheck() {
|
|
|
|
|
if (this::participationAdapter.isInitialized &&
|
|
|
|
|
participationAdapter.currentList.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (isRecyclerViewInitialized() && participationAdapter.currentList.isEmpty()) {
|
|
|
|
|
binding.divider.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|