refs #4678
This commit is contained in:
parent
491008a4a3
commit
a8df499138
|
@ -11,17 +11,22 @@ import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import es.verdnatura.R
|
import es.verdnatura.R
|
||||||
import es.verdnatura.databinding.FragmentExpeditionLoadunloadDeliveryBinding
|
import es.verdnatura.databinding.FragmentExpeditionLoadunloadDeliveryBinding
|
||||||
import es.verdnatura.db.ExpedicionDatabase
|
import es.verdnatura.db.ExpedicionDatabase
|
||||||
import es.verdnatura.domain.toast
|
import es.verdnatura.domain.toast
|
||||||
import es.verdnatura.presentation.base.BaseFragment
|
import es.verdnatura.presentation.base.BaseFragment
|
||||||
|
import es.verdnatura.presentation.base.database
|
||||||
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
||||||
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
||||||
import es.verdnatura.presentation.view.feature.delivery.adapters.ExpeditionLoadUnloadAdapter
|
import es.verdnatura.presentation.view.feature.delivery.adapters.ExpeditionLoadUnloadAdapter
|
||||||
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
|
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
|
||||||
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
|
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +75,7 @@ class LoadUnloadFragment(
|
||||||
|
|
||||||
override fun onAttach(context: Context) {
|
override fun onAttach(context: Context) {
|
||||||
super.onAttach(context)
|
super.onAttach(context)
|
||||||
// db = database(requireContext().applicationContext)
|
db = database(requireContext().applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@ -280,37 +285,61 @@ class LoadUnloadFragment(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createList(list: List<ExpeditionInfoLoadUnload>) {
|
private fun createList(list: List<ExpeditionInfoLoadUnload>) {
|
||||||
myList = list as MutableList<ExpeditionInfoLoadUnload>
|
|
||||||
|
/* if (list.isEmpty()) {
|
||||||
|
getExpeditionTable(route)
|
||||||
|
} else {
|
||||||
|
updateExpeditionTable(list)
|
||||||
|
getExpeditionTable(route)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
db.expedicionDao().insert(list.filter { it.routeFk == route }
|
||||||
|
.filter { it.addressFk == addressFk })
|
||||||
|
myList = db.expedicionDao().getAll(route) as MutableList<ExpeditionInfoLoadUnload>
|
||||||
|
// myList = list as MutableList<ExpeditionInfoLoadUnload>
|
||||||
|
}
|
||||||
if (addressFk != 0) {
|
if (addressFk != 0) {
|
||||||
myList =
|
myList =
|
||||||
list.filter { it.addressFk == addressFk } as MutableList<ExpeditionInfoLoadUnload>
|
myList.filter { it.addressFk == addressFk } as MutableList<ExpeditionInfoLoadUnload>
|
||||||
}
|
}
|
||||||
adapter = ExpeditionLoadUnloadAdapter(myList)
|
adapter = ExpeditionLoadUnloadAdapter(myList)
|
||||||
binding.expeditionloadunloadRecyclerview.adapter = adapter
|
binding.expeditionloadunloadRecyclerview.adapter = adapter
|
||||||
binding.expeditionloadunloadRecyclerview.layoutManager =
|
binding.expeditionloadunloadRecyclerview.layoutManager =
|
||||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||||
binding.mainToolbar.toolbarSubtitle.text =
|
binding.mainToolbar.toolbarSubtitle.text =
|
||||||
getString(R.string.summaryCount, myList.filter { it.code == state }.size, myList.size)
|
getString(
|
||||||
|
R.string.summaryCount,
|
||||||
|
myList.filter { it.code == state }.size,
|
||||||
|
myList.size
|
||||||
|
)
|
||||||
|
|
||||||
|
setListPosition(myList)
|
||||||
|
}
|
||||||
|
|
||||||
setListPosition(list)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private fun updateExpeditionTable(list: MutableList<ExpeditionInfoLoadUnload>) {
|
private fun updateExpeditionTable(list: List<ExpeditionInfoLoadUnload>) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
for (l in list) {
|
db.expedicionDao().insert(list.filter { it.routeFk == route }
|
||||||
println("la route es $route y $addressFk")
|
.filter { it.addressFk == addressFk })
|
||||||
if (l.addressFk == addressFk) {
|
|
||||||
|
|
||||||
var newList =
|
|
||||||
db.expedicionDao().insert(list.filter { it.routeFk == route }.filter { it.addressFk == addressFk } as MutableList<ExpeditionInfoLoadUnload>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
private fun getExpeditionTable(myRoute: Int) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
myList = db.expedicionDao().getAll(myRoute) as MutableList<ExpeditionInfoLoadUnload>
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setListPosition(list: MutableList<ExpeditionInfoLoadUnload>) {
|
private fun setListPosition(list: MutableList<ExpeditionInfoLoadUnload>) {
|
||||||
for (i in list.indices) {
|
for (i in list.indices) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ Expedition(
|
||||||
)
|
)
|
||||||
|
|
||||||
class ExpeditionList(
|
class ExpeditionList(
|
||||||
var list: List<ExpeditionInfoLoadUnload> = listOf()
|
var list: List<ExpeditionInfoLoadUnload> = listOf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@Entity(tableName = "expedition")
|
@Entity(tableName = "expedition")
|
||||||
|
@ -68,8 +68,10 @@ class ExpeditionInfoLoadUnload(
|
||||||
var street: String,
|
var street: String,
|
||||||
var code: String?,
|
var code: String?,
|
||||||
var nickname: String,
|
var nickname: String,
|
||||||
var postalCode: Int
|
var postalCode: Int,
|
||||||
|
var isError: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
@Entity(tableName = "expeditionPending")
|
@Entity(tableName = "expeditionPending")
|
||||||
class ExpeditionInfoPending(
|
class ExpeditionInfoPending(
|
||||||
@PrimaryKey var id: Int,
|
@PrimaryKey var id: Int,
|
||||||
|
|
Loading…
Reference in New Issue