|
|
|
|
@ -12,7 +12,11 @@ import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
|
import androidx.navigation.fragment.navArgs
|
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog
|
|
|
|
|
import com.cyb3rko.techniklogger.R
|
|
|
|
|
import com.cyb3rko.techniklogger.*
|
|
|
|
|
import com.cyb3rko.techniklogger.CLASS_EINSATZ
|
|
|
|
|
import com.cyb3rko.techniklogger.COLUMN_EINSATZ_JAHR
|
|
|
|
|
import com.cyb3rko.techniklogger.CURRENT_YEAR
|
|
|
|
|
import com.cyb3rko.techniklogger.SHARED_PREFERENCE
|
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentEinsatzPusherBinding
|
|
|
|
|
import com.google.android.material.datepicker.MaterialDatePicker
|
|
|
|
|
import com.google.android.material.timepicker.MaterialTimePicker
|
|
|
|
|
@ -44,7 +48,11 @@ class EinsatzPusherFragment : Fragment() {
|
|
|
|
|
// This property is only valid between onCreateView and onDestroyView.
|
|
|
|
|
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 = FragmentEinsatzPusherBinding.inflate(inflater, container, false)
|
|
|
|
|
val root = binding.root
|
|
|
|
|
myContext = requireContext()
|
|
|
|
|
@ -52,9 +60,12 @@ class EinsatzPusherFragment : Fragment() {
|
|
|
|
|
getArgumentInformation()
|
|
|
|
|
restoreInformation()
|
|
|
|
|
|
|
|
|
|
val builder = MaterialDatePicker.Builder.datePicker().setTitleText("Datum")
|
|
|
|
|
val builder2 = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Von")
|
|
|
|
|
val builder3 = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Bis")
|
|
|
|
|
val builder = MaterialDatePicker.Builder.datePicker()
|
|
|
|
|
.setTitleText("Datum")
|
|
|
|
|
val builder2 = MaterialTimePicker.Builder()
|
|
|
|
|
.setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Von")
|
|
|
|
|
val builder3 = MaterialTimePicker.Builder()
|
|
|
|
|
.setTimeFormat(TimeFormat.CLOCK_24H).setTitleText("Bis")
|
|
|
|
|
|
|
|
|
|
binding.dateButton.setOnClickListener {
|
|
|
|
|
if (date != "") {
|
|
|
|
|
@ -116,8 +127,8 @@ class EinsatzPusherFragment : Fragment() {
|
|
|
|
|
.show {
|
|
|
|
|
message(0, "Möchtest du diesen Einsatz entfernen?")
|
|
|
|
|
positiveButton(0, "Ja") {
|
|
|
|
|
val query = ParseQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", childKey))
|
|
|
|
|
val query = ParseQuery<ParseObject>(CLASS_TEILNAHME)
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData(CLASS_EINSATZ, childKey))
|
|
|
|
|
query.findInBackground { objects, e ->
|
|
|
|
|
if (e == null) {
|
|
|
|
|
ParseObject.deleteAllInBackground(objects) {
|
|
|
|
|
@ -146,14 +157,23 @@ class EinsatzPusherFragment : Fragment() {
|
|
|
|
|
val location = binding.locationEditText.text.toString()
|
|
|
|
|
|
|
|
|
|
if (name != "" && location != "" && time != "") {
|
|
|
|
|
entry.put("name", name)
|
|
|
|
|
entry.put("ort", location)
|
|
|
|
|
entry.put(COLUMN_EINSATZ_NAME, name)
|
|
|
|
|
entry.put(COLUMN_EINSATZ_ORT, location)
|
|
|
|
|
val dateTimes = date.split(".")
|
|
|
|
|
var dateTime = "${dateTimes[2]}.${dateTimes[1]}.${dateTimes[0]}"
|
|
|
|
|
if (time != "") dateTime += ",$time"
|
|
|
|
|
entry.put("datum", dateTime)
|
|
|
|
|
entry.put("dauer", duration.toFloat())
|
|
|
|
|
entry.saveInBackground() {
|
|
|
|
|
entry.put(COLUMN_EINSATZ_DATUM, dateTime)
|
|
|
|
|
entry.put(COLUMN_EINSATZ_DAUER, duration.toFloat())
|
|
|
|
|
val sharedPref = context?.getSharedPreferences(
|
|
|
|
|
SHARED_PREFERENCE,
|
|
|
|
|
Context.MODE_PRIVATE
|
|
|
|
|
)
|
|
|
|
|
val jahrObject = ParseObject.createWithoutData(
|
|
|
|
|
CLASS_JAHR,
|
|
|
|
|
sharedPref?.getString(CURRENT_YEAR, "")!!
|
|
|
|
|
)
|
|
|
|
|
entry.put(COLUMN_EINSATZ_JAHR, jahrObject)
|
|
|
|
|
entry.saveInBackground {
|
|
|
|
|
if (it == null) {
|
|
|
|
|
findNavController().navigate(R.id.navigation_listing)
|
|
|
|
|
} else {
|
|
|
|
|
@ -195,9 +215,9 @@ class EinsatzPusherFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (childKey == "") {
|
|
|
|
|
entry = ParseObject("Einsatz")
|
|
|
|
|
entry = ParseObject(CLASS_EINSATZ)
|
|
|
|
|
} else {
|
|
|
|
|
entry = ParseObject.createWithoutData("Einsatz", childKey)
|
|
|
|
|
entry = ParseObject.createWithoutData(CLASS_EINSATZ, childKey)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|