Füge Verwaltung für Techniker hinzu

master
Niko Diamadis 5 years ago
parent fe5c7ca98c
commit c8523a9e9a

@ -68,6 +68,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
implementation 'com.airbnb.android:lottie:3.7.0'
implementation 'com.amitshekhar.android:android-networking:1.0.2'

@ -108,11 +108,17 @@ class ListingFragment : Fragment() {
val action = ListingFragmentDirections.navigateToPusher()
findNavController().navigate(action)
}
binding.fab2.setOnClickListener {
closeFABMenu()
ExportBuilder(myContext, data, binding)
}
binding.fab3.setOnClickListener {
closeFABMenu()
findNavController().navigate(R.id.navigation_manage_techniker)
}
binding.fabBgLayout.setOnClickListener {
closeFABMenu()
}
@ -192,10 +198,12 @@ class ListingFragment : Fragment() {
isFABOpen = true
binding.fabLayout1.visibility = View.VISIBLE
binding.fabLayout2.visibility = View.VISIBLE
binding.fabLayout3.visibility = View.VISIBLE
binding.fabBgLayout.visibility = View.VISIBLE
binding.fab.animate().rotationBy(180f)
binding.fabLayout1.animate().translationY(-resources.getDimension(R.dimen.first_fab))
binding.fabLayout2.animate().translationY(-resources.getDimension(R.dimen.second_fab))
binding.fabLayout3.animate().translationY(-resources.getDimension(R.dimen.third_fab))
}
private fun closeFABMenu() {
@ -204,13 +212,15 @@ class ListingFragment : Fragment() {
binding.fab.animate().rotation(0f)
binding.fabLayout1.animate().translationY(0f)
binding.fabLayout2.animate().translationY(0f)
binding.fabLayout2.animate().translationY(0f).setListener(object: Animator.AnimatorListener {
binding.fabLayout3.animate().translationY(0f)
binding.fabLayout3.animate().translationY(0f).setListener(object: Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator?) {}
override fun onAnimationEnd(animation: Animator?) {
if (!isFABOpen) {
binding.fabLayout1.visibility = View.GONE
binding.fabLayout2.visibility = View.GONE
binding.fabLayout3.visibility = View.GONE
}
}

@ -0,0 +1,144 @@
package com.cyb3rko.techniklogger.fragments
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.LayoutMode
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.customview.customView
import com.cyb3rko.techniklogger.R
import com.cyb3rko.techniklogger.databinding.FragmentManageTechnikerBinding
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textfield.TextInputEditText
import com.parse.ParseObject
import com.parse.ParseQuery
import es.dmoral.toasty.Toasty
import kotlinx.android.synthetic.main.techniker_dialog.view.*
class ManageTechnikerFragment : Fragment() {
private var _binding: FragmentManageTechnikerBinding? = null
private lateinit var myContext: Context
private lateinit var techniker: MutableList<ParseObject>
private val technikerNames = mutableListOf<String>()
private val query = ParseQuery.getQuery<ParseObject>("Techniker")
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentManageTechnikerBinding.inflate(inflater, container, false)
val root = binding.root
myContext = requireContext()
query.whereEqualTo("entlassen", false)
query.limit = 100000
fetchTechniker()
binding.fab.setOnClickListener {
MaterialDialog(myContext, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
title(text = "Techniker hinzufügen")
customView(R.layout.techniker_dialog, horizontalPadding = true)
positiveButton(text = "Hinzufügen") {
val view = it.view
val newName = view.name.text.toString()
val newAdmin = view.admin.isChecked
ParseObject.create("Techniker").apply {
put("name", newName)
put("admin", newAdmin)
saveInBackground {
if (it == null) {
Toast.makeText(myContext, "Hinzugefügt", Toast.LENGTH_SHORT).show()
fetchTechniker()
} else {
Toasty.error(myContext, "Fehler bei Speicherung").show()
Log.e("TechnikLogger.Techniker", it.message.toString())
}
}
}
}
}
}
return root
}
private fun fetchTechniker() {
query.findInBackground { objects, e ->
if (e == null) {
techniker = objects.sortedBy {
it.getString("name")!!
}.toMutableList()
technikerNames.clear()
objects.forEach {
technikerNames.add(it.getString("name")!!)
}
technikerNames.sort()
val adapter = ArrayAdapter(myContext, android.R.layout.simple_list_item_1, technikerNames)
binding.list.adapter = adapter
binding.list.setOnItemClickListener { _, _, index, _ ->
val dialogView = layoutInflater.inflate(R.layout.techniker_dialog, null)
dialogView.findViewById<TextInputEditText>(R.id.name).setText(technikerNames[index])
dialogView.findViewById<SwitchMaterial>(R.id.admin).isChecked = techniker[index].getBoolean("admin")
MaterialDialog(myContext, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
title(text = "Techniker-Info")
customView(0, dialogView, horizontalPadding = true)
onDismiss {
val view = it.view
val newName = view.name.text.toString()
val newAdmin = view.admin.isChecked
val parseObject = techniker[index]
if (newName != parseObject.getString("name") || newAdmin != parseObject.getBoolean("admin")) {
parseObject.apply {
put("name", newName)
put("admin", newAdmin)
saveInBackground {
if (it == null) {
Toast.makeText(myContext, "Gespeichert", Toast.LENGTH_SHORT).show()
fetchTechniker()
} else {
Toasty.error(myContext, "Fehler bei Speicherung").show()
Log.e("TechnikLogger.Techniker", it.message.toString())
}
}
}
}
}
negativeButton(text = "Entlassen") {
val name = technikerNames[index]
MaterialDialog(myContext).show {
title(text = "Entlassung")
message(text = "Soll '$name' wirklich entlassen werden?")
positiveButton(text = "Ja") {
techniker[index].apply {
put("entlassen", true)
saveInBackground {
if (it == null) {
Toast.makeText(myContext, "Gespeichert", Toast.LENGTH_SHORT).show()
fetchTechniker()
} else {
Toasty.error(myContext, "Fehler bei Speicherung").show()
Log.e("TechnikLogger.Techniker", it.message.toString())
}
}
}
}
negativeButton(text = "Nein")
}
}
}
}
}
}
}
}

@ -366,6 +366,7 @@ class ProjectFragment : Fragment() {
private fun otherAdd() {
val query = ParseQuery.getQuery<ParseObject>("Techniker")
query.whereEqualTo("entlassen", false)
query.findInBackground { objects, e ->
if (e == null) {

@ -63,11 +63,11 @@
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="12dp"
android:padding="8dp"
android:clipToPadding="false"
android:layout_marginEnd="23dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:layout_marginBottom="23dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end"
android:visibility="gone">
@ -94,11 +94,11 @@
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="12dp"
android:padding="8dp"
android:clipToPadding="false"
android:layout_marginEnd="23dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:layout_marginBottom="23dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end"
android:visibility="gone">
@ -118,18 +118,46 @@
</LinearLayout>
<LinearLayout
android:id="@+id/fab_layout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="8dp"
android:clipToPadding="false"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="Techniker verwalten" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:srcCompat="@drawable/_icon_techniker"
app:fabSize="mini" />
</LinearLayout>
<LinearLayout
android:id="@+id/fab_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/fab_margin"
android:gravity="center_vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:clipToPadding="false"
android:padding="12dp"
android:layout_marginBottom="@dimen/fab_margin"
android:padding="16dp"
android:layout_gravity="bottom|end"
tools:visibility="visible">
@ -137,7 +165,6 @@
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:gravity="center_vertical"
android:tint="@color/drawableTint"
app:srcCompat="@drawable/_icon_dot_menu"

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:src="@drawable/_icon_add"
android:tint="@color/drawableTint" />
</RelativeLayout>

@ -0,0 +1,41 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="35dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:lines="1"
android:singleLine="true"
android:inputType="textPersonName"
android:hint="Name"
tools:ignore="HardcodedText" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Admin"
android:textSize="16sp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/admin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
</LinearLayout>

@ -66,6 +66,12 @@
android:defaultValue=""/>
</fragment>
<fragment
android:id="@+id/navigation_manage_techniker"
android:name="com.cyb3rko.techniklogger.fragments.ManageTechnikerFragment"
android:label="Techniker verwalten"
tools:layout="@layout/fragment_manage_techniker" />
<fragment
android:id="@+id/navigation_about"
android:name="com.cyb3rko.techniklogger.fragments.AboutFragment"

@ -3,4 +3,5 @@
<dimen name="first_fab">60dp</dimen>
<dimen name="second_fab">120dp</dimen>
<dimen name="third_fab">180dp</dimen>
</resources>
Loading…
Cancel
Save