|
|
|
|
@ -61,7 +61,118 @@ class MissionFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
objectId = args.objectId
|
|
|
|
|
|
|
|
|
|
participationAdapter = ParticipationAdapter {
|
|
|
|
|
loadData()
|
|
|
|
|
|
|
|
|
|
binding.addButton.setOnClickListener {
|
|
|
|
|
val name = sharedPref.getString(NAME, "invalid")!!
|
|
|
|
|
if (!adminMode) selfAdd(name) else bothAdd(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emptyCheck()
|
|
|
|
|
|
|
|
|
|
if (adminMode || sharedPref.getString(TECHNIKER_ID, "")!!.isNotBlank()) {
|
|
|
|
|
binding.addButton.visibility = View.VISIBLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adminMode) {
|
|
|
|
|
binding.resetButton.visibility = View.VISIBLE
|
|
|
|
|
binding.resetButton.setOnClickListener {
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setTitle("Techniker entfernen")
|
|
|
|
|
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
|
ParseController.fetchParticipations(objectId, false) { entries, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(entries)
|
|
|
|
|
participationAdapter.submitList(listOf())
|
|
|
|
|
showDivider(false)
|
|
|
|
|
updateTechnikerCount(0)
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Abbrechen", null)
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binding.swipeRefreshLayout.apply {
|
|
|
|
|
setProgressBackgroundColorSchemeResource(R.color.refreshLayoutBackground)
|
|
|
|
|
setColorSchemeResources(R.color.refreshLayoutArrow)
|
|
|
|
|
setOnRefreshListener {
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
duration = mission.duration
|
|
|
|
|
val prettyDuration = duration.toPrettyString()
|
|
|
|
|
|
|
|
|
|
time = if (time != "") ", $time ($prettyDuration h)" else ", $prettyDuration h"
|
|
|
|
|
val dateTime = date + time
|
|
|
|
|
|
|
|
|
|
binding.apply {
|
|
|
|
|
if (titleView.text != mission.name) {
|
|
|
|
|
titleView.text = mission.name
|
|
|
|
|
}
|
|
|
|
|
if (dateView.text != dateTime) {
|
|
|
|
|
dateView.text = dateTime
|
|
|
|
|
}
|
|
|
|
|
if (locationView.text != mission.location) {
|
|
|
|
|
locationView.text = mission.location
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadParticipations()
|
|
|
|
|
} else {
|
|
|
|
|
if (e.message != null) {
|
|
|
|
|
if (e.message != "results not cached") {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Einsatz-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.EinsSuche", e.message.toString())
|
|
|
|
|
} else {
|
|
|
|
|
Log.d("TechnikLogger.EinsSuche", "Empty cache, fetching data immediately.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
binding.swipeRefreshLayout.isRefreshing = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun loadParticipations() {
|
|
|
|
|
ParseController.fetchParticipations(objectId, true) { participations, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
if (participations.isNotEmpty()) {
|
|
|
|
|
participations.forEach {
|
|
|
|
|
if (it.duration == 0f) it.setDuration(duration)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initializeRecyclerView()
|
|
|
|
|
|
|
|
|
|
participationAdapter.submitList(participations)
|
|
|
|
|
updateTechnikerCount(participations.size)
|
|
|
|
|
showDivider()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Teilnehmer-Abfrage").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e2.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun initializeRecyclerView() {
|
|
|
|
|
if (this::participationAdapter.isInitialized) {
|
|
|
|
|
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/>" +
|
|
|
|
|
@ -165,113 +276,8 @@ class MissionFragment : Fragment() {
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadData()
|
|
|
|
|
|
|
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(myContext)
|
|
|
|
|
binding.recyclerView.adapter = participationAdapter
|
|
|
|
|
|
|
|
|
|
binding.addButton.setOnClickListener {
|
|
|
|
|
val name = sharedPref.getString(NAME, "invalid")!!
|
|
|
|
|
if (!adminMode) selfAdd(name) else bothAdd(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emptyCheck()
|
|
|
|
|
|
|
|
|
|
if (adminMode || sharedPref.getString(TECHNIKER_ID, "")!!.isNotBlank()) {
|
|
|
|
|
binding.addButton.visibility = View.VISIBLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adminMode) {
|
|
|
|
|
binding.resetButton.visibility = View.VISIBLE
|
|
|
|
|
binding.resetButton.setOnClickListener {
|
|
|
|
|
MaterialAlertDialogBuilder(myContext)
|
|
|
|
|
.setTitle("Techniker entfernen")
|
|
|
|
|
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
|
ParseController.fetchParticipations(objectId, false) { entries, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(entries)
|
|
|
|
|
participationAdapter.submitList(listOf())
|
|
|
|
|
showDivider(false)
|
|
|
|
|
updateTechnikerCount(0)
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Techniker-Abfrage", Toasty.LENGTH_SHORT).show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.setNegativeButton("Abbrechen", null)
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binding.swipeRefreshLayout.apply {
|
|
|
|
|
setProgressBackgroundColorSchemeResource(R.color.refreshLayoutBackground)
|
|
|
|
|
setColorSchemeResources(R.color.refreshLayoutArrow)
|
|
|
|
|
setOnRefreshListener {
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
duration = mission.duration
|
|
|
|
|
val prettyDuration = duration.toPrettyString()
|
|
|
|
|
|
|
|
|
|
time = if (time != "") ", $time ($prettyDuration h)" else ", $prettyDuration h"
|
|
|
|
|
val dateTime = date + time
|
|
|
|
|
|
|
|
|
|
binding.apply {
|
|
|
|
|
if (titleView.text != mission.name) {
|
|
|
|
|
titleView.text = mission.name
|
|
|
|
|
}
|
|
|
|
|
if (dateView.text != dateTime) {
|
|
|
|
|
dateView.text = dateTime
|
|
|
|
|
}
|
|
|
|
|
if (locationView.text != mission.location) {
|
|
|
|
|
locationView.text = mission.location
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadParticipations()
|
|
|
|
|
} else {
|
|
|
|
|
if (e.message != null) {
|
|
|
|
|
if (e.message != "results not cached") {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Einsatz-Suche").show()
|
|
|
|
|
Log.e("TechnikLogger.EinsSuche", e.message.toString())
|
|
|
|
|
} else {
|
|
|
|
|
Log.d("TechnikLogger.EinsSuche", "Empty cache, fetching data immediately.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
binding.swipeRefreshLayout.isRefreshing = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun loadParticipations() {
|
|
|
|
|
ParseController.fetchParticipations(objectId, true) { participations, e2 ->
|
|
|
|
|
if (e2 == null) {
|
|
|
|
|
if (participations.isNotEmpty()) {
|
|
|
|
|
participations.forEach {
|
|
|
|
|
if (it.duration == 0f) it.setDuration(duration)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
participationAdapter.submitList(participations)
|
|
|
|
|
updateTechnikerCount(participations.size)
|
|
|
|
|
showDivider()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(myContext, "Fehler bei Teilnehmer-Abfrage").show()
|
|
|
|
|
Log.e("TechnikLogger.TechSuche", e2.message.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun memberExists(name: String): Boolean {
|
|
|
|
|
@ -400,7 +406,9 @@ class MissionFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun emptyCheck() {
|
|
|
|
|
if (participationAdapter.currentList.isEmpty()) {
|
|
|
|
|
if (this::participationAdapter.isInitialized &&
|
|
|
|
|
participationAdapter.currentList.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
binding.divider.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|