|
|
|
@ -18,9 +18,9 @@ import androidx.navigation.fragment.navArgs
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import com.cyb3rko.techniklogger.*
|
|
|
|
import com.cyb3rko.techniklogger.*
|
|
|
|
import com.cyb3rko.techniklogger.data.ParseController
|
|
|
|
import com.cyb3rko.techniklogger.data.ParseController
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentProjectBinding
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentMissionBinding
|
|
|
|
import com.cyb3rko.techniklogger.data.ProjectTechniker
|
|
|
|
import com.cyb3rko.techniklogger.data.Participation
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerAdapter
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ParticipationAdapter
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
|
import com.google.android.material.timepicker.MaterialTimePicker
|
|
|
|
import com.google.android.material.timepicker.MaterialTimePicker
|
|
|
|
import com.google.android.material.timepicker.TimeFormat
|
|
|
|
import com.google.android.material.timepicker.TimeFormat
|
|
|
|
@ -30,12 +30,12 @@ import java.sql.Time
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
class ProjectFragment : Fragment() {
|
|
|
|
class MissionFragment : Fragment() {
|
|
|
|
private var _binding: FragmentProjectBinding? = null
|
|
|
|
private var _binding: FragmentMissionBinding? = null
|
|
|
|
private lateinit var myContext: Context
|
|
|
|
private lateinit var myContext: Context
|
|
|
|
private val args: ProjectFragmentArgs by navArgs()
|
|
|
|
private val args: MissionFragmentArgs by navArgs()
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var technikerAdapter: ProjectTechnikerAdapter
|
|
|
|
private lateinit var technikerAdapter: ParticipationAdapter
|
|
|
|
private var adminMode = false
|
|
|
|
private var adminMode = false
|
|
|
|
private var objectId = ""
|
|
|
|
private var objectId = ""
|
|
|
|
private var dauer = ""
|
|
|
|
private var dauer = ""
|
|
|
|
@ -49,7 +49,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
container: ViewGroup?,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View {
|
|
|
|
): View {
|
|
|
|
_binding = FragmentProjectBinding.inflate(inflater, container, false)
|
|
|
|
_binding = FragmentMissionBinding.inflate(inflater, container, false)
|
|
|
|
val root = binding.root
|
|
|
|
val root = binding.root
|
|
|
|
myContext = requireContext()
|
|
|
|
myContext = requireContext()
|
|
|
|
|
|
|
|
|
|
|
|
@ -58,7 +58,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
|
|
objectId = args.objectId
|
|
|
|
objectId = args.objectId
|
|
|
|
|
|
|
|
|
|
|
|
technikerAdapter = ProjectTechnikerAdapter {
|
|
|
|
technikerAdapter = ParticipationAdapter {
|
|
|
|
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
|
|
|
|
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
|
|
|
|
val uhrzeit = if (it.uhrzeit == "0") time else it.uhrzeit
|
|
|
|
val uhrzeit = if (it.uhrzeit == "0") time else it.uhrzeit
|
|
|
|
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
|
|
|
|
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
|
|
|
|
@ -139,7 +139,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
saveInBackground()
|
|
|
|
saveInBackground()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ParseController.fetchSingleTeilnahme(objectId, it.objectId) { entry, e ->
|
|
|
|
ParseController.fetchParticipation(objectId, it.objectId) { entry, e ->
|
|
|
|
if (e == null) {
|
|
|
|
if (e == null) {
|
|
|
|
it.teilnahmeKey = entry!!.objectId
|
|
|
|
it.teilnahmeKey = entry!!.objectId
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
val dauerFloat = it.dauer.toFloat()
|
|
|
|
@ -170,7 +170,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
if (it.teilnahmeKey != "0") {
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground()
|
|
|
|
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ParseController.fetchSingleTeilnahme(objectId, it.objectId) { entry, e ->
|
|
|
|
ParseController.fetchParticipation(objectId, it.objectId) { entry, e ->
|
|
|
|
if (e == null) {
|
|
|
|
if (e == null) {
|
|
|
|
entry!!.deleteInBackground {
|
|
|
|
entry!!.deleteInBackground {
|
|
|
|
if (it != null) {
|
|
|
|
if (it != null) {
|
|
|
|
@ -213,7 +213,7 @@ class ProjectFragment : Fragment() {
|
|
|
|
.setTitle("Techniker entfernen")
|
|
|
|
.setTitle("Techniker entfernen")
|
|
|
|
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
.setPositiveButton("Ja") { _, _ ->
|
|
|
|
ParseController.fetchTeilnahmen(objectId, false) { entries, e ->
|
|
|
|
ParseController.fetchParticipations(objectId, false) { entries, e ->
|
|
|
|
if (e == null) {
|
|
|
|
if (e == null) {
|
|
|
|
ParseObject.deleteAllInBackground(entries)
|
|
|
|
ParseObject.deleteAllInBackground(entries)
|
|
|
|
technikerAdapter.submitList(listOf())
|
|
|
|
technikerAdapter.submitList(listOf())
|
|
|
|
@ -247,29 +247,29 @@ class ProjectFragment : Fragment() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun loadData() {
|
|
|
|
private fun loadData() {
|
|
|
|
ParseController.fetchProject(objectId) { project, e ->
|
|
|
|
ParseController.fetchMission(objectId) { mission, e ->
|
|
|
|
if (e == null) {
|
|
|
|
if (e == null) {
|
|
|
|
binding.titleView.text = project!!.getString(COLUMN_EINSATZ_NAME)
|
|
|
|
binding.titleView.text = mission!!.getString(COLUMN_EINSATZ_NAME)
|
|
|
|
binding.locationView.text = project.getString(COLUMN_EINSATZ_ORT)
|
|
|
|
binding.locationView.text = mission.getString(COLUMN_EINSATZ_ORT)
|
|
|
|
val dates = project.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
|
|
|
|
val dates = mission.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
|
|
|
|
val dateParts = dates[0].split(".")
|
|
|
|
val dateParts = dates[0].split(".")
|
|
|
|
val date = "${dateParts[2]}.${dateParts[1]}.${dateParts[0]}"
|
|
|
|
val date = "${dateParts[2]}.${dateParts[1]}.${dateParts[0]}"
|
|
|
|
dauer = project.getNumber(COLUMN_EINSATZ_DAUER)!!.toString()
|
|
|
|
dauer = mission.getNumber(COLUMN_EINSATZ_DAUER)!!.toString()
|
|
|
|
if (dates.size > 1) time = dates[1]
|
|
|
|
if (dates.size > 1) time = dates[1]
|
|
|
|
val time = if (dates.size > 1) ", ${dates[1]}" else ", $dauer h"
|
|
|
|
val time = if (dates.size > 1) ", ${dates[1]}" else ", $dauer h"
|
|
|
|
binding.dateView.text = date + time
|
|
|
|
binding.dateView.text = date + time
|
|
|
|
|
|
|
|
|
|
|
|
ParseController.fetchTeilnahmen(objectId, true) { entries, e2 ->
|
|
|
|
ParseController.fetchParticipations(objectId, true) { entries, e2 ->
|
|
|
|
if (e2 == null) {
|
|
|
|
if (e2 == null) {
|
|
|
|
if (entries.isNotEmpty()) {
|
|
|
|
if (entries.isNotEmpty()) {
|
|
|
|
val techniker = mutableListOf<ProjectTechniker>()
|
|
|
|
val techniker = mutableListOf<Participation>()
|
|
|
|
entries.forEach {
|
|
|
|
entries.forEach {
|
|
|
|
val teilnehmenderTechniker = it.getParseObject(COLUMN_TEILNAHME_VON)!!
|
|
|
|
val teilnehmenderTechniker = it.getParseObject(COLUMN_TEILNAHME_VON)!!
|
|
|
|
val dauerEntry = it.getNumber(COLUMN_EINSATZ_DAUER)!!
|
|
|
|
val dauerEntry = it.getNumber(COLUMN_EINSATZ_DAUER)!!
|
|
|
|
val dauer = if (dauerEntry == 0) project.getNumber(COLUMN_TEILNAHME_DAUER)!!.toString() else dauerEntry.toString()
|
|
|
|
val dauer = if (dauerEntry == 0) mission.getNumber(COLUMN_TEILNAHME_DAUER)!!.toString() else dauerEntry.toString()
|
|
|
|
val time = it.getString(COLUMN_EINSATZ_UHRZEIT)!!
|
|
|
|
val time = it.getString(COLUMN_EINSATZ_UHRZEIT)!!
|
|
|
|
techniker.add(
|
|
|
|
techniker.add(
|
|
|
|
ProjectTechniker(
|
|
|
|
Participation(
|
|
|
|
dauer,
|
|
|
|
dauer,
|
|
|
|
teilnehmenderTechniker.getString(COLUMN_EINSATZ_NAME)!!,
|
|
|
|
teilnehmenderTechniker.getString(COLUMN_EINSATZ_NAME)!!,
|
|
|
|
teilnehmenderTechniker.objectId,
|
|
|
|
teilnehmenderTechniker.objectId,
|