Hinzufügen von neuem Einsatz ermöglicht
parent
588d1fffa7
commit
d40965a44c
@ -0,0 +1,70 @@
|
||||
package com.cyb3rko.techniklogger
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.datepicker.MaterialDatePicker
|
||||
import com.google.firebase.database.DatabaseReference
|
||||
import com.google.firebase.database.FirebaseDatabase
|
||||
import es.dmoral.toasty.Toasty
|
||||
import kotlinx.android.synthetic.main.activity_einsatz_pusher.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class EinsatzPusher : AppCompatActivity() {
|
||||
|
||||
private lateinit var databaseReference: DatabaseReference
|
||||
private var date = ""
|
||||
private val simpleDateFormat = SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY)
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Suppress("DEPRECATION")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_einsatz_pusher)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
databaseReference = FirebaseDatabase.getInstance().getReference("einsätze")
|
||||
|
||||
val builder = MaterialDatePicker.Builder.datePicker().setTitleText("Datum")
|
||||
val picker = builder.build()
|
||||
|
||||
date_button.setOnClickListener {
|
||||
picker.addOnPositiveButtonClickListener {
|
||||
date = simpleDateFormat.format(Date(it))
|
||||
date_view.text = Html.fromHtml("<b>Datum:</b><br/>${date}")
|
||||
}
|
||||
picker.show(supportFragmentManager, picker.tag)
|
||||
}
|
||||
|
||||
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)
|
||||
startActivity(Intent(applicationContext, MainActivity::class.java))
|
||||
} else {
|
||||
Toasty.error(applicationContext, "Fülle alle Felder aus")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,13 @@
|
||||
package com.cyb3rko.techniklogger.recycler
|
||||
|
||||
import java.util.*
|
||||
|
||||
sealed class ProjectViewState {
|
||||
|
||||
data class ProjectEntry(
|
||||
val childKey: String,
|
||||
val text: String,
|
||||
val location: String,
|
||||
val date: String
|
||||
val date: Date
|
||||
) : ProjectViewState()
|
||||
}
|
||||
|
||||
@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="20dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:text="Einsatz hinzufügen"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginTop="15dp"
|
||||
app:startIconTintMode="src_in"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
|
||||
android:hint="Name">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/nameEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginTop="15dp"
|
||||
app:startIconTintMode="src_in"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
|
||||
android:hint="Ort">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/locationEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginTop="15dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Datum:\n---"
|
||||
android:textAlignment="center"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:foregroundGravity="center_vertical"
|
||||
android:layout_marginStart="20dp"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/date_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:padding="10dp"
|
||||
android:layout_marginStart="50dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:textSize="12dp"
|
||||
android:text="Datum auswählen" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/finished_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="35dp"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:textSize="12dp"
|
||||
android:text="Fertig" />
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue