Zeige Arbeitszeit in Einsatz nur, wenn sie sich unterscheidet

master
Niko Diamadis 4 years ago
parent 08c2aea03b
commit 1244c6e703
Signed by: niko
GPG Key ID: BE53B0B17B1B142E

@ -61,7 +61,118 @@ class MissionFragment : Fragment() {
objectId = args.objectId 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, "")) { if (adminMode || it.name == sharedPref.getString(NAME, "")) {
val uhrzeit = if (it.time == "0") time else it.time val uhrzeit = if (it.time == "0") time else it.time
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" + val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
@ -165,113 +276,8 @@ class MissionFragment : Fragment() {
.show() .show()
} }
} }
loadData()
binding.recyclerView.layoutManager = LinearLayoutManager(myContext) binding.recyclerView.layoutManager = LinearLayoutManager(myContext)
binding.recyclerView.adapter = participationAdapter 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 { private fun memberExists(name: String): Boolean {
@ -400,7 +406,9 @@ class MissionFragment : Fragment() {
} }
private fun emptyCheck() { private fun emptyCheck() {
if (participationAdapter.currentList.isEmpty()) { if (this::participationAdapter.isInitialized &&
participationAdapter.currentList.isEmpty())
{
binding.divider.visibility = View.GONE binding.divider.visibility = View.GONE
} }
} }

@ -12,6 +12,7 @@ import com.cyb3rko.techniklogger.data.objects.Participation
import com.cyb3rko.techniklogger.toPrettyString import com.cyb3rko.techniklogger.toPrettyString
internal class ParticipationAdapter( internal class ParticipationAdapter(
private val missionDuration: Float,
val action: (participation: Participation) -> Unit val action: (participation: Participation) -> Unit
) : ListAdapter<Participation, ParticipationAdapter.ViewHolder>(ParticipationDiffCallback) { ) : ListAdapter<Participation, ParticipationAdapter.ViewHolder>(ParticipationDiffCallback) {
@ -22,7 +23,11 @@ internal class ParticipationAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val entry = getItem(position) val entry = getItem(position)
val title = "${entry.name}, ${entry.duration.toPrettyString()} h" val title = if (missionDuration == entry.duration) {
entry.name
} else {
"${entry.name}, ${entry.duration.toPrettyString()} h"
}
holder.titleView.text = title holder.titleView.text = title
holder.titleView.setOnClickListener { holder.titleView.setOnClickListener {
action(entry) action(entry)

Loading…
Cancel
Save