|
|
|
|
@ -23,7 +23,9 @@ import com.cyb3rko.techniklogger.utils.About
|
|
|
|
|
import com.google.firebase.database.*
|
|
|
|
|
import es.dmoral.toasty.Toasty
|
|
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
|
|
|
|
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter
|
|
|
|
|
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
|
|
|
|
|
import me.ibrahimyilmaz.kiel.core.RecyclerViewHolder
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
@ -45,6 +47,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
sharedPrefEditor.apply()
|
|
|
|
|
|
|
|
|
|
databaseReference = FirebaseDatabase.getInstance().reference
|
|
|
|
|
databaseReference.keepSynced(true)
|
|
|
|
|
|
|
|
|
|
if (sharedPref.getString("name", "") == "") {
|
|
|
|
|
showNameDialog()
|
|
|
|
|
@ -92,38 +95,6 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val listener = object: ChildEventListener {
|
|
|
|
|
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
|
try {
|
|
|
|
|
data.add(
|
|
|
|
|
data.size, ProjectViewState.ProjectEntry(
|
|
|
|
|
snapshot.key!!,
|
|
|
|
|
snapshot.child("name").value.toString(),
|
|
|
|
|
snapshot.child("location").value.toString(),
|
|
|
|
|
SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).parse(snapshot.child("date").value.toString())!!,
|
|
|
|
|
snapshot.child("duration").value.toString(),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
data.sortBy { it.date }
|
|
|
|
|
hideProgress()
|
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
} catch (exception: Exception) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
|
|
override fun onChildRemoved(snapshot: DataSnapshot) {}
|
|
|
|
|
|
|
|
|
|
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
|
|
override fun onCancelled(error: DatabaseError) {
|
|
|
|
|
Toast.makeText(applicationContext, "Abruf fehlgeschlagen", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adapter.submitList(data as List<ProjectViewState>?)
|
|
|
|
|
val linearLayoutManager = LinearLayoutManager(applicationContext)
|
|
|
|
|
linearLayoutManager.reverseLayout = true
|
|
|
|
|
@ -131,7 +102,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
recycler_view.layoutManager = linearLayoutManager
|
|
|
|
|
recycler_view.adapter = adapter
|
|
|
|
|
|
|
|
|
|
databaseReference.child("einsätze").addChildEventListener(listener)
|
|
|
|
|
databaseReference.child("einsätze").addChildEventListener(loadEntries(adapter))
|
|
|
|
|
|
|
|
|
|
floatingActionButton.setOnClickListener {
|
|
|
|
|
startActivity(Intent(applicationContext, EinsatzPusher::class.java))
|
|
|
|
|
@ -206,6 +177,39 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun loadEntries(adapter: RecyclerViewAdapter<ProjectViewState, RecyclerViewHolder<ProjectViewState>>): ChildEventListener {
|
|
|
|
|
return object: ChildEventListener {
|
|
|
|
|
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
|
|
|
|
|
try {
|
|
|
|
|
val element = ProjectViewState.ProjectEntry(
|
|
|
|
|
snapshot.key!!,
|
|
|
|
|
snapshot.child("name").value.toString(),
|
|
|
|
|
snapshot.child("location").value.toString(),
|
|
|
|
|
SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).parse(snapshot.child("date").value.toString())!!,
|
|
|
|
|
snapshot.child("duration").value.toString(),
|
|
|
|
|
)
|
|
|
|
|
data.add(data.size, element)
|
|
|
|
|
data.sortBy { it.date }
|
|
|
|
|
hideProgress()
|
|
|
|
|
adapter.notifyDataSetChanged()
|
|
|
|
|
recycler_view.scheduleLayoutAnimation()
|
|
|
|
|
recycler_view.scrollBy(0, -10000)
|
|
|
|
|
} catch (exception: Exception) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
|
|
override fun onChildRemoved(snapshot: DataSnapshot) {}
|
|
|
|
|
|
|
|
|
|
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {}
|
|
|
|
|
|
|
|
|
|
override fun onCancelled(error: DatabaseError) {
|
|
|
|
|
Toast.makeText(applicationContext, "Abruf fehlgeschlagen", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun hideProgress() {
|
|
|
|
|
loading_animation.visibility = View.GONE
|
|
|
|
|
loading_animation.cancelAnimation()
|
|
|
|
|
|