Compare commits
8 Commits
97daec8f5d
...
c3373d3ba4
| Author | SHA1 | Date |
|---|---|---|
|
|
c3373d3ba4 | 3 years ago |
|
|
c60e506de8 | 3 years ago |
|
|
c85b95eacd | 3 years ago |
|
|
d1bd33609e | 3 years ago |
|
|
aa7dd38d06 | 3 years ago |
|
|
6fb7c4058e | 3 years ago |
|
|
206a86d944 | 3 years ago |
|
|
6e0b4c19da | 3 years ago |
@ -0,0 +1,94 @@
|
||||
package com.cyb3rko.techniklogger.modals
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.cyb3rko.techniklogger.data.objects.Member
|
||||
import com.cyb3rko.techniklogger.databinding.MemberDialogBinding
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
internal class MemberBottomSheet(
|
||||
private val member: Member? = null,
|
||||
private val action: (member: Member?) -> Unit
|
||||
): BottomSheetDialogFragment() {
|
||||
private lateinit var binding: MemberDialogBinding
|
||||
|
||||
private var mode = -1
|
||||
private lateinit var mMember: Member
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = MemberDialogBinding.inflate(layoutInflater)
|
||||
if (member == null) {
|
||||
mode = MODE_ADD
|
||||
} else {
|
||||
mMember = member.copy()
|
||||
binding.name.setText(mMember.name)
|
||||
binding.admin.isChecked = mMember.admin
|
||||
mode = MODE_EDIT
|
||||
}
|
||||
if (mode == MODE_ADD) {
|
||||
binding.title.text = "Techniker hinzufügen"
|
||||
binding.button.text = "Hinzufügen"
|
||||
} else {
|
||||
binding.title.text = "Techniker-Info"
|
||||
binding.button.text = "Entlassen"
|
||||
}
|
||||
binding.button.setOnClickListener {
|
||||
val newName = binding.name.text.toString()
|
||||
val newAdmin = binding.admin.isChecked
|
||||
|
||||
if (mode == MODE_ADD) {
|
||||
Member().apply {
|
||||
setAdmin(newAdmin)
|
||||
setName(newName)
|
||||
action(this)
|
||||
dismiss()
|
||||
}
|
||||
} else {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("Entlassung")
|
||||
.setMessage("Soll '${mMember.name}' wirklich entlassen werden?")
|
||||
.setPositiveButton("Ja") { _ , _ ->
|
||||
mMember.apply {
|
||||
retire()
|
||||
action(this)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Nein", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
if (mode == MODE_EDIT && ::binding.isInitialized) {
|
||||
val newName = binding.name.text.toString()
|
||||
val newAdmin = binding.admin.isChecked
|
||||
val adminChanged = newAdmin != mMember.admin
|
||||
val nameChanged = newName != mMember.name
|
||||
if (adminChanged || nameChanged) {
|
||||
mMember.apply {
|
||||
setAdmin(newAdmin)
|
||||
setName(newName)
|
||||
action(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "Member Bottom Sheet"
|
||||
const val MODE_ADD = 0
|
||||
const val MODE_EDIT = 1
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bitmap
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:src="@drawable/_icon_calendar"
|
||||
android:tint="@color/adaptiveDrawableTint" />
|
||||
Binary file not shown.
@ -1,7 +1,8 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distrubutionSha256Sum=6147605a23b4eff6c334927a86ff3508cb5d6722cd624c97ded4c2e8640f1f87
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
Loading…
Reference in New Issue