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.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import es.verdnatura.R
|
||||
import es.verdnatura.databinding.FragmentExpeditionLoadunloadDeliveryBinding
|
||||
import es.verdnatura.db.ExpedicionDatabase
|
||||
import es.verdnatura.domain.toast
|
||||
import es.verdnatura.presentation.base.BaseFragment
|
||||
import es.verdnatura.presentation.base.database
|
||||
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
||||
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
||||
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.viewmodels.DeliveryViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
|
||||
|
||||
|
@ -70,7 +75,7 @@ class LoadUnloadFragment(
|
|||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
// db = database(requireContext().applicationContext)
|
||||
db = database(requireContext().applicationContext)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
|
@ -280,37 +285,61 @@ class LoadUnloadFragment(
|
|||
}
|
||||
|
||||
private fun createList(list: List<ExpeditionInfoLoadUnload>) {
|
||||
myList = list as MutableList<ExpeditionInfoLoadUnload>
|
||||
if (addressFk != 0) {
|
||||
myList =
|
||||
list.filter { it.addressFk == addressFk } as MutableList<ExpeditionInfoLoadUnload>
|
||||
}
|
||||
adapter = ExpeditionLoadUnloadAdapter(myList)
|
||||
binding.expeditionloadunloadRecyclerview.adapter = adapter
|
||||
binding.expeditionloadunloadRecyclerview.layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
binding.mainToolbar.toolbarSubtitle.text =
|
||||
getString(R.string.summaryCount, myList.filter { it.code == state }.size, myList.size)
|
||||
|
||||
setListPosition(list)
|
||||
/* 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) {
|
||||
myList =
|
||||
myList.filter { it.addressFk == addressFk } as MutableList<ExpeditionInfoLoadUnload>
|
||||
}
|
||||
adapter = ExpeditionLoadUnloadAdapter(myList)
|
||||
binding.expeditionloadunloadRecyclerview.adapter = adapter
|
||||
binding.expeditionloadunloadRecyclerview.layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
binding.mainToolbar.toolbarSubtitle.text =
|
||||
getString(
|
||||
R.string.summaryCount,
|
||||
myList.filter { it.code == state }.size,
|
||||
myList.size
|
||||
)
|
||||
|
||||
setListPosition(myList)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* private fun updateExpeditionTable(list: MutableList<ExpeditionInfoLoadUnload>) {
|
||||
private fun updateExpeditionTable(list: List<ExpeditionInfoLoadUnload>) {
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
for (l in list) {
|
||||
println("la route es $route y $addressFk")
|
||||
if (l.addressFk == addressFk) {
|
||||
db.expedicionDao().insert(list.filter { it.routeFk == route }
|
||||
.filter { it.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>) {
|
||||
for (i in list.indices) {
|
||||
|
|
|
@ -54,7 +54,7 @@ Expedition(
|
|||
)
|
||||
|
||||
class ExpeditionList(
|
||||
var list: List<ExpeditionInfoLoadUnload> = listOf()
|
||||
var list: List<ExpeditionInfoLoadUnload> = listOf(),
|
||||
)
|
||||
|
||||
@Entity(tableName = "expedition")
|
||||
|
@ -68,8 +68,10 @@ class ExpeditionInfoLoadUnload(
|
|||
var street: String,
|
||||
var code: String?,
|
||||
var nickname: String,
|
||||
var postalCode: Int
|
||||
var postalCode: Int,
|
||||
var isError: Boolean = false
|
||||
)
|
||||
|
||||
@Entity(tableName = "expeditionPending")
|
||||
class ExpeditionInfoPending(
|
||||
@PrimaryKey var id: Int,
|
||||
|
@ -93,9 +95,9 @@ class ExpeditionInfoSummary(
|
|||
var routeFk: Int,
|
||||
var addressFk: Int,
|
||||
var itemPackingType: String?,
|
||||
var total: Int ,
|
||||
var delivery: Int= 0 ,
|
||||
var lost: Int = 0 ,
|
||||
var total: Int,
|
||||
var delivery: Int = 0,
|
||||
var lost: Int = 0,
|
||||
var delivered: Int = 0
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue