Bearbeiten von Einsätzen ermöglicht

master
Niko Diamadis 6 years ago
parent 136fe31ff4
commit 161e8371df

@ -4,8 +4,11 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.text.Html
import android.text.SpannableStringBuilder
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
@ -16,20 +19,27 @@ import java.util.*
class EinsatzPusher : AppCompatActivity() {
private lateinit var childKey: String
private lateinit var databaseReference: DatabaseReference
private lateinit var databaseReferenceNew: DatabaseReference
private var date = ""
private lateinit var location: String
private lateinit var name: String
private val simpleDateFormat = SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY)
@SuppressLint("SetTextI18n")
@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
getBundleInformation()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_einsatz_pusher)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
databaseReference = FirebaseDatabase.getInstance().getReference("einsätze")
restoreInformation()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val builder = MaterialDatePicker.Builder.datePicker().setTitleText("Datum")
val picker = builder.build()
@ -41,30 +51,79 @@ class EinsatzPusher : AppCompatActivity() {
picker.show(supportFragmentManager, picker.tag)
}
if (childKey != "null") {
delete_button.visibility = View.VISIBLE
delete_button.setOnClickListener {
MaterialDialog(this)
.show {
message(0, "Möchtest du diesen Einsatz entfernen?")
positiveButton(0, "Ja") {
databaseReferenceNew.removeValue()
finish()
startActivity(Intent(applicationContext, MainActivity::class.java))
}
negativeButton(0, "Abbrechen")
}
}
}
finished_button.setOnClickListener {
val name = nameEditText.text.toString()
val location = locationEditText.text.toString()
if (name != "" && location != "" && date != "") {
val databaseReferenceNew = databaseReference.push()
databaseReferenceNew.child("name").setValue(name)
databaseReferenceNew.child("location").setValue(location)
databaseReferenceNew.child("date").setValue(date)
finish()
startActivity(Intent(applicationContext, MainActivity::class.java))
} else {
Toasty.error(applicationContext, "Fülle alle Felder aus")
Toasty.error(applicationContext, "Fülle alle Felder aus").show()
}
}
}
private fun getBundleInformation() {
childKey = intent.extras?.getString("childKey").toString()
name = intent.extras?.getString("name").toString()
location = intent.extras?.getString("location").toString()
date = intent.extras?.getString("date").toString()
}
private fun restoreInformation() {
if (name != "null") {
nameEditText.text = SpannableStringBuilder(name)
}
if (location != "null") {
locationEditText.text = SpannableStringBuilder(location)
}
if (date != "null") {
date_view.text = "Datum:\n$date"
}
if (childKey == "null") {
databaseReferenceNew = databaseReference.push()
} else {
databaseReferenceNew = databaseReference.child(childKey)
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
when (item.itemId) {
android.R.id.home -> finish()
android.R.id.home -> {
finish()
startActivity(Intent(applicationContext, MainActivity::class.java))
}
}
return super.onOptionsItemSelected(item)
}
override fun onBackPressed() {
finish()
startActivity(Intent(applicationContext, MainActivity::class.java))
}
}

@ -75,6 +75,18 @@ class MainActivity : AppCompatActivity() {
.setKey(text.childKey)
.start()
}
if (adminMode) {
vh.itemView.setOnLongClickListener {
val intent = Intent(applicationContext, EinsatzPusher::class.java)
intent.putExtra("childKey", text.childKey)
intent.putExtra("name", text.text)
intent.putExtra("location", text.location)
intent.putExtra("date", SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(text.date))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
true
}
}
}
)
}

@ -109,7 +109,20 @@
android:layout_marginEnd="25dp"
android:layout_marginTop="35dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:textSize="12dp"
android:textSize="12sp"
android:text="Fertig" />
<com.google.android.material.button.MaterialButton
android:id="@+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="20dp"
android:visibility="gone"
style="@style/Widget.MaterialComponents.Button"
android:textSize="12sp"
android:text="Einsatz entfernen" />
</LinearLayout>
Loading…
Cancel
Save