Fixe ProjectAdapter für korrektes Aktualisieren der Daten

master
Niko Diamadis 4 years ago
parent 53fd0a2e0a
commit 38a2d90ca9
Signed by: niko
GPG Key ID: BE53B0B17B1B142E

@ -9,6 +9,7 @@ import android.view.*
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cyb3rko.techniklogger.*
import com.cyb3rko.techniklogger.databinding.FragmentListingBinding
import com.cyb3rko.techniklogger.recycler.ProjectEntry
@ -26,7 +27,6 @@ class ListingFragment : Fragment() {
private var adminMode: Boolean? = null
private lateinit var projectsAdapter: ProjectsAdapter
private val data: MutableList<ProjectEntry> = mutableListOf()
private var isFABOpen = false
private lateinit var sharedPref: SharedPreferences
private lateinit var sharedPrefEditor: SharedPreferences.Editor
@ -94,7 +94,7 @@ class ListingFragment : Fragment() {
binding.fab2.setOnClickListener {
closeFABMenu()
ExportBuilder(myContext, data, binding)
ExportBuilder(myContext, projectsAdapter.currentList, binding)
}
binding.fab3.setOnClickListener {
@ -135,10 +135,11 @@ class ListingFragment : Fragment() {
query.findInBackground { objects, e ->
if (e == null) {
val data = mutableListOf<ProjectEntry>()
objects.forEach {
val dates = it.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
val time = if (dates.size > 1) dates[1] else ""
data.add(data.size, ProjectEntry(
data.add(ProjectEntry(
SimpleDateFormat("yyyy.MM.dd", Locale.GERMANY).parse(dates[0])!!,
it.getInt(COLUMN_EINSATZ_DAUER).toString(),
it.getString(COLUMN_EINSATZ_ORT)!!,
@ -152,9 +153,16 @@ class ListingFragment : Fragment() {
binding.swipeRefreshLayout.isRefreshing = false
projectsAdapter.submitList(data)
(requireActivity() as MainActivity).setActionBarSubtitle(objects.size.toString())
projectsAdapter.registerAdapterDataObserver(object: RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
binding.recyclerView.smoothScrollToPosition(0)
}
})
} else {
binding.swipeRefreshLayout.isRefreshing = false
if (data.isEmpty()) {
if (projectsAdapter.currentList.isEmpty()) {
showAnimation(true, false)
}
Toasty.error(myContext, "Abruf fehlgeschlagen", Toasty.LENGTH_SHORT).show()

@ -25,7 +25,7 @@ class ProjectsAdapter(
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val entry = getItem(position)
val entry = currentList[position]
holder.textView.text = entry.name
holder.locationView.text = entry.location
if (entry.duration != "null") {
@ -44,6 +44,8 @@ class ProjectsAdapter(
}
}
override fun getItemCount() = currentList.size
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val locationView: TextView = view.findViewById(R.id.item_location)
val dateView: TextView = view.findViewById(R.id.item_date)

Loading…
Cancel
Save