|
|
|
@ -1,5 +1,8 @@
|
|
|
|
package com.cyb3rko.techniklogger
|
|
|
|
package com.cyb3rko.techniklogger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.view.MenuItem
|
|
|
|
@ -17,6 +20,8 @@ import com.cyb3rko.techniklogger.recycler.ProjectTechnikerViewHolder
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerViewState
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerViewState
|
|
|
|
import com.google.firebase.database.*
|
|
|
|
import com.google.firebase.database.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import es.dmoral.toasty.Toasty
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.IndexOutOfBoundsException
|
|
|
|
import java.lang.IndexOutOfBoundsException
|
|
|
|
|
|
|
|
|
|
|
|
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
|
|
|
|
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
|
|
|
|
@ -24,20 +29,29 @@ import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
|
|
|
|
import kotlinx.android.synthetic.main.activity_project.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_project.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_project.recycler_view
|
|
|
|
import kotlinx.android.synthetic.main.activity_project.recycler_view
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
class ProjectActivity : AppCompatActivity() {
|
|
|
|
class ProjectActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var adminMode = false
|
|
|
|
private var childKey = ""
|
|
|
|
private var childKey = ""
|
|
|
|
private val techniker: MutableList<ProjectTechnikerViewState.ProjectTechniker> = mutableListOf()
|
|
|
|
|
|
|
|
private lateinit var databaseReference: DatabaseReference
|
|
|
|
private lateinit var databaseReference: DatabaseReference
|
|
|
|
|
|
|
|
private lateinit var sharedPref: SharedPreferences
|
|
|
|
|
|
|
|
private val techniker: MutableList<ProjectTechnikerViewState.ProjectTechniker> = mutableListOf()
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
childKey = intent.extras?.getString("childKey").toString()
|
|
|
|
childKey = intent.extras?.getString("childKey").toString()
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_project)
|
|
|
|
setContentView(R.layout.activity_project)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sharedPref = getSharedPreferences("Safe", 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sharedPref.getBoolean("admin", false)) {
|
|
|
|
|
|
|
|
adminMode = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
|
|
|
|
|
|
|
|
databaseReference = FirebaseDatabase.getInstance().getReference(childKey)
|
|
|
|
databaseReference = FirebaseDatabase.getInstance().getReference("einsätze").child(childKey)
|
|
|
|
|
|
|
|
|
|
|
|
val adapter = adapterOf<ProjectTechnikerViewState> {
|
|
|
|
val adapter = adapterOf<ProjectTechnikerViewState> {
|
|
|
|
register(
|
|
|
|
register(
|
|
|
|
@ -45,7 +59,17 @@ class ProjectActivity : AppCompatActivity() {
|
|
|
|
viewHolder = ::ProjectTechnikerViewHolder,
|
|
|
|
viewHolder = ::ProjectTechnikerViewHolder,
|
|
|
|
onBindBindViewHolder = { vh, _, text ->
|
|
|
|
onBindBindViewHolder = { vh, _, text ->
|
|
|
|
vh.textView.text = text.name
|
|
|
|
vh.textView.text = text.name
|
|
|
|
vh.itemView.setOnClickListener {
|
|
|
|
if (adminMode) {
|
|
|
|
|
|
|
|
vh.itemView.setOnClickListener {
|
|
|
|
|
|
|
|
MaterialDialog(this@ProjectActivity)
|
|
|
|
|
|
|
|
.show {
|
|
|
|
|
|
|
|
message(0, "Möchtest du \'${text.name}\' entfernen?")
|
|
|
|
|
|
|
|
positiveButton(0, "Ja") {
|
|
|
|
|
|
|
|
databaseReference.child("techniker").child(text.key).removeValue()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
negativeButton(0, "Abbrechen")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -53,21 +77,23 @@ class ProjectActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
|
|
val listener = object: ChildEventListener {
|
|
|
|
val listener = object: ChildEventListener {
|
|
|
|
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
techniker.add(techniker.size, ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString()))
|
|
|
|
techniker.add(techniker.size, ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString(), snapshot.key!!))
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
techniker.sortBy { it.name }
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
showDivider()
|
|
|
|
showDivider()
|
|
|
|
|
|
|
|
techniker_view.text = "Techniker: ${techniker.size}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onChildRemoved(snapshot: DataSnapshot) {
|
|
|
|
override fun onChildRemoved(snapshot: DataSnapshot) {
|
|
|
|
techniker.remove(ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString()))
|
|
|
|
techniker.remove(ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString(), snapshot.key!!))
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
emptyCheck()
|
|
|
|
emptyCheck()
|
|
|
|
|
|
|
|
techniker_view.text = "Techniker: ${techniker.size}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
@ -148,9 +174,55 @@ class ProjectActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun toggleAdminMode() {
|
|
|
|
|
|
|
|
if (!adminMode) {
|
|
|
|
|
|
|
|
var adminKey = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val listener = object: ChildEventListener {
|
|
|
|
|
|
|
|
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
|
|
|
|
if (snapshot.key == "admin_key") {
|
|
|
|
|
|
|
|
adminKey = snapshot.value.toString()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
override fun onChildRemoved(snapshot: DataSnapshot) {}
|
|
|
|
|
|
|
|
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
override fun onCancelled(error: DatabaseError) {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FirebaseDatabase.getInstance().reference.addChildEventListener(listener)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MaterialDialog(this)
|
|
|
|
|
|
|
|
.title(0, "Bitte gebe den Admin-Key ein")
|
|
|
|
|
|
|
|
.show {
|
|
|
|
|
|
|
|
input(hint = "Admin-Key", waitForPositiveButton = false) { _, inputKey ->
|
|
|
|
|
|
|
|
positiveButton {
|
|
|
|
|
|
|
|
if (inputKey.toString() == adminKey) {
|
|
|
|
|
|
|
|
sharedPref.edit().putBoolean("admin", true).apply()
|
|
|
|
|
|
|
|
val intent = Intent(applicationContext, MainActivity::class.java)
|
|
|
|
|
|
|
|
startActivity(intent)
|
|
|
|
|
|
|
|
finishAffinity()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Toasty.error(applicationContext, "Ungültiger Key").show()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
positiveButton(0, "Speichern")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sharedPref.edit().putBoolean("admin", false).apply()
|
|
|
|
|
|
|
|
val intent = Intent(applicationContext, MainActivity::class.java)
|
|
|
|
|
|
|
|
startActivity(intent)
|
|
|
|
|
|
|
|
finishAffinity()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
menuInflater.inflate(R.menu.menu_main, menu)
|
|
|
|
menuInflater.inflate(R.menu.menu_main, menu)
|
|
|
|
|
|
|
|
if (adminMode) {
|
|
|
|
|
|
|
|
menu.findItem(R.id.action_admin).title = "Admin-Zugriff deaktivieren"
|
|
|
|
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -161,6 +233,7 @@ class ProjectActivity : AppCompatActivity() {
|
|
|
|
when (item.itemId) {
|
|
|
|
when (item.itemId) {
|
|
|
|
android.R.id.home -> finish()
|
|
|
|
android.R.id.home -> finish()
|
|
|
|
R.id.action_rename -> showNameDialog()
|
|
|
|
R.id.action_rename -> showNameDialog()
|
|
|
|
|
|
|
|
R.id.action_admin -> toggleAdminMode()
|
|
|
|
// R.id.action_icons -> setContentView(AboutIcons(applicationContext, R.drawable::class.java).setTitle("Benutzte Icons").get())
|
|
|
|
// R.id.action_icons -> setContentView(AboutIcons(applicationContext, R.drawable::class.java).setTitle("Benutzte Icons").get())
|
|
|
|
// R.id.action_libraries -> LibsBuilder().start(this)
|
|
|
|
// R.id.action_libraries -> LibsBuilder().start(this)
|
|
|
|
// R.id.action_privacy_policy ->
|
|
|
|
// R.id.action_privacy_policy ->
|
|
|
|
|