package com.pan_american.android.ui.group_op.ground_convey_payment_insert

import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.CheckedTextView
import android.widget.PopupWindow
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bin.david.form.core.SmartTable
import com.bin.david.form.data.style.FontStyle
import com.pan_american.android.OASystem
import com.pan_american.android.R
import com.pan_american.android.base.BaseActivity
import com.pan_american.android.base.BaseResponse
import com.pan_american.android.base.ListAdapter
import com.pan_american.android.data.model.common.entity.Selector
import com.pan_american.android.data.model.common.entity.SiftListItem
import com.pan_american.android.data.model.common.network.GroupCostDataRequest
import com.pan_american.android.data.model.common.network.GroupCurrencyRequest
import com.pan_american.android.data.model.common.network.GroupCurrencyResponse
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.adapter.GroundConveyFooterAdapter
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.adapter.GroundConveyHeaderAdapter
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.adapter.GroundConveyTableAdapter
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.entity.GroundConveyCost
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.entity.GroundConveyTableItem
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.network.GroundConveyCostDetailResponse
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.network.GroundConveyPaymentResourceRequest
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.network.GroundConveyPaymentResponse
import com.pan_american.android.data.model.group_op.ground_convey_payment_insert.network.UpdateGroundConveyDetailRequest
import com.pan_american.android.data.network.APIService
import com.pan_american.android.data.network.ServiceCreator
import com.pan_american.android.databinding.ActivityGroundConveyPaymentDetailBinding
import com.pan_american.android.databinding.LayoutTitleBinding
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class GroundConveyPaymentDetailActivity : BaseActivity<ActivityGroundConveyPaymentDetailBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

    private var groupId = 0

    private var paymentId = 0

    private val apiService = ServiceCreator.create<APIService>()

    private var paymentWayList = ArrayList<Selector>()

    private var currencyList = ArrayList<Selector>()

    private var tableInitialization = ArrayList<SiftListItem>()

    private var carTouristGuides = ArrayList<GroundConveyTableItem>()

    private var checkedItemId = ArrayList<Int>()

    private lateinit var adapter: GroundConveyTableAdapter

    private var headerAdapter = GroundConveyHeaderAdapter()

    private var footerAdapter = GroundConveyFooterAdapter()

    private var currencyId = 0

    private var currencySelect = false

    private var paymentMarkId = 0

    private var paymentMarkSelect = false

    private var paymentWayId = 0

    private var paymentWaySelect = false

    private var totalPrice = 0.0

    private val regex = Regex("^-?\\d+(\\.\\d{1,2})?\$")

    private val updateGroundConveyDetailRequest = UpdateGroundConveyDetailRequest()

    private var isAuditGM = -1

    private var showItemList = ArrayList<GroundConveyTableItem>()

    private var itemMaxId = 0

    private var groundConveyCostInit = false

    private var groundConveyCostCurrency = ""

    private var groundConveyCostExchangeRate = 0.0

    private var groundConveyCostList = ArrayList<GroundConveyCost>()

    override fun getViewBinding() = ActivityGroundConveyPaymentDetailBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        screenAdaptation(binding)

        intent.apply {
            groupId = getIntExtra("groupId", 0)
            paymentId = getIntExtra("paymentId", 0)
            headerAdapter.setGroupName(getStringExtra("teamName").toString())
            isAuditGM = getIntExtra("isAuditGM", -1)
        }

        initTitle()

        getGroundConveyDetailResource()
    }

    override fun initTitle() {
        titleBinding = LayoutTitleBinding.bind(binding.root).apply {
            titleText.text = resources.getString(R.string.cost_entry_detail)

            rightTextField.apply {
                visibility = View.VISIBLE
                text = resources.getString(R.string.show_cost)
            }

            backButton.setOnClickListener {
                back()
            }

            rightTextField.setOnClickListener {

                val groundConveyCostPopView = View.inflate(OASystem.context, R.layout.popup_cost_table, null)
                popupWindow = PopupWindow(groundConveyCostPopView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)

                showPopupWindow {

                    val currencyAbbr = groundConveyCostPopView.findViewById<TextView>(R.id.currency_abbr)
                    val exchangeRate = groundConveyCostPopView.findViewById<TextView>(R.id.exchange_rate)
                    val groundConveyCostTable = groundConveyCostPopView.findViewById<SmartTable<GroundConveyCost>>(R.id.table)

                    groundConveyCostTable.config.apply {
                        isShowXSequence = false
                        isShowYSequence = false
                        tableTitleStyle = FontStyle(50, ResourcesCompat.getColor(resources, R.color.text_color, theme))
                        contentStyle = FontStyle(40, ResourcesCompat.getColor(resources, R.color.text_color, theme))
                    }

                    if (!groundConveyCostInit) {
                        apiService.getGroundConveyCostData(GroupCostDataRequest(groupId, OASystem.C_TABLE_GROUND_CONVEY)).enqueue(object : Callback<GroundConveyCostDetailResponse> {
                            override fun onResponse(
                                call: Call<GroundConveyCostDetailResponse>,
                                response: Response<GroundConveyCostDetailResponse>
                            ) {

                                val costResponse = response.body()

                                if (costResponse != null) {
                                    if (costResponse.code == 200) {

                                        groundConveyCostCurrency = costResponse.data.modulePromptInfos[0].currencyCode
                                        groundConveyCostExchangeRate = costResponse.data.modulePromptInfos[0].rate

                                        groundConveyCostList = costResponse.data.modulePromptInfos[0].data

                                        currencyAbbr.text = groundConveyCostCurrency
                                        exchangeRate.text = groundConveyCostExchangeRate.toString()

                                        groundConveyCostTable.setData(groundConveyCostList)

                                        groundConveyCostInit = true

                                    } else {
                                        showMessage(costResponse.msg)
                                    }
                                }
                            }

                            override fun onFailure(call: Call<GroundConveyCostDetailResponse>, t: Throwable) {
                                showErrorInfo(R.string.ground_convey_cost_get_failed)
                            }
                        })
                    } else {
                        currencyAbbr.text = groundConveyCostCurrency
                        exchangeRate.text = groundConveyCostExchangeRate.toString()

                        groundConveyCostTable.setData(groundConveyCostList)
                    }

                    popupWindow.showAtLocation(binding.root, Gravity.BOTTOM, 0, 0)
                }
            }
        }
    }

    override fun initViews() {

        binding.paymentList.itemAnimator!!.changeDuration = 0

        if (!canBeEdit()) {
            binding.commit.setText(resources.getString(R.string.back))
        } else {
            binding.commit.setText(resources.getString(R.string.submit))
        }

        headerAdapter.setCanBeEdit(canBeEdit())
        footerAdapter.setCanBeEdit(canBeEdit())

        initList()
    }

    override fun initEvents() {

        binding.commit.setOnClickListener {

            if (!canBeEdit()) {
                back()
                return@setOnClickListener
            }

            updateGroundConveyDetailRequest.diId = groupId
            updateGroundConveyDetailRequest.ctggrId = paymentId

            if (!currencySelect) {
                showMessage(resources.getString(R.string.payment_currency_hint))
                return@setOnClickListener
            } else {
                updateGroundConveyDetailRequest.currency = currencyId
            }

            if (footerAdapter.getPaymentPercentage().isBlank() || !footerAdapter.getPaymentPercentage().matches(regex)
            ) {
                showMessage(resources.getString(R.string.payment_percentage_input_hint))
                return@setOnClickListener
            } else {
                updateGroundConveyDetailRequest.payPercentage =
                    footerAdapter.getPaymentPercentage().toDouble()
            }

            if (footerAdapter.getPayee().isBlank()) {
                showMessage(resources.getString(R.string.payee_hint))
                return@setOnClickListener
            } else {
                updateGroundConveyDetailRequest.payee = footerAdapter.getPayee()
            }

            if (!paymentMarkSelect) {
                showMessage(resources.getString(R.string.payment_mark_hint))
                return@setOnClickListener
            } else {
                updateGroundConveyDetailRequest.orbitalPrivateTransfer = paymentMarkId
            }

            if (!paymentWaySelect) {
                showMessage(resources.getString(R.string.payment_way_hint))
                return@setOnClickListener
            } else {
                updateGroundConveyDetailRequest.payDId = paymentWayId
            }

            updateGroundConveyDetail()

        }
    }

    private fun getGroundConveyDetailResource() {

        apiService.initGroundConveyDetailResource(GroundConveyPaymentResourceRequest(paymentId))
            .enqueue(object : Callback<GroundConveyPaymentResponse> {
                override fun onResponse(
                    call: Call<GroundConveyPaymentResponse>,
                    response: Response<GroundConveyPaymentResponse>
                ) {
                    val resourceResponse = response.body()

                    if (resourceResponse != null) {
                        if (resourceResponse.code == 200) {
                            for (item in resourceResponse.data.payment) {
                                paymentWayList.add(item)
                            }

                            for (item in resourceResponse.data.tableInitialization) {
                                tableInitialization.add(item)
                            }

                            for (item in resourceResponse.data.carTouristGuides) {
                                if (itemMaxId < item.id) {
                                    itemMaxId = item.id
                                }
                                carTouristGuides.add(item)
                            }

                            OASystem.unitList = resourceResponse.data.ssdv

                            for (item in resourceResponse.data.checkedItemId) {
                                if (!checkedItemId.contains(item)) {
                                    checkedItemId.add(item)
                                }
                            }

                            for (item in tableInitialization) {
                                for (checkedItem in checkedItemId) {
                                    if (item.id == checkedItem) {
                                        item.isChecked = true
                                    }
                                }
                            }

                            for ((i, item) in carTouristGuides.withIndex()) {

                                if (item.id == 0) {
                                    carTouristGuides[i].id = itemMaxId + i
                                    carTouristGuides[i].isNew = true
                                }

                                for (checkedItem in checkedItemId) {
                                    if (item.sId == checkedItem) {
                                        totalPrice += item.price * item.count
                                    }
                                }

                                if (checkedItemId.contains(item.sId)) {
                                    showItemList.add(item)
                                }
                            }

                            headerAdapter.setCurrencyCode(resourceResponse.data.creditCardPayment.paymentCurrencyName)
                            currencyId = resourceResponse.data.creditCardPayment.paymentCurrency

                            if (resourceResponse.data.creditCardPayment.paymentCurrency != 0 && resourceResponse.data.creditCardPayment.paymentCurrencyName.isNotBlank()) {
                                for (item in carTouristGuides) {
                                    item.currencyStr = resourceResponse.data.creditCardPayment.paymentCurrencyName
                                }
                                currencySelect = true
                            }

                            binding.paymentTotal.text = String.format(
                                resources.getString(R.string.price_and_currency_format),
                                totalPrice,
                                headerAdapter.getCurrencyCode()
                            )

                            footerAdapter.setPayee(resourceResponse.data.creditCardPayment.payee)

                            footerAdapter.setPaymentPercentage(resourceResponse.data.creditCardPayment.payPercentage.toString())

                            footerAdapter.setPaymentMark(OASystem.paymentMark[resourceResponse.data.creditCardPayment.orbitalPrivateTransfer].name)

                            paymentMarkId =
                                resourceResponse.data.creditCardPayment.orbitalPrivateTransfer

                            paymentMarkSelect = true

                            run {
                                for (item in paymentWayList) {
                                    if (item.id == resourceResponse.data.creditCardPayment.payDId) {
                                        footerAdapter.setPaymentWay(item.name)

                                        paymentWayId = item.id
                                        paymentWaySelect = true

                                        return@run
                                    }
                                }
                            }

                            getGroupCurrency()

                        } else {
                            showMessage(resourceResponse.msg)
                        }
                    }
                }

                override fun onFailure(
                    call: Call<GroundConveyPaymentResponse>, t: Throwable
                ) {
                    showErrorInfo(R.string.op_payment_list_get_failed)
                }
            })
    }

    private fun getGroupCurrency() {
        apiService.getGroupCurrency(GroupCurrencyRequest(groupId, OASystem.C_TABLE_GROUND_CONVEY))
            .enqueue(object : Callback<GroupCurrencyResponse> {
                override fun onResponse(
                    call: Call<GroupCurrencyResponse>, response: Response<GroupCurrencyResponse>
                ) {
                    val currencyResponse = response.body()

                    if (currencyResponse != null) {
                        if (currencyResponse.code == 200) {

                            for (item in currencyResponse.data.teamRates) {
                                currencyList.add(item)
                            }

                            initViews()

                            initEvents()

                        } else {
                            showMessage(currencyResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<GroupCurrencyResponse>, t: Throwable) {
                    showErrorInfo(R.string.group_currency_get_failed)
                }
            })
    }

    private fun initList() {
        val layoutManager = LinearLayoutManager(OASystem.context)

        layoutManager.initialPrefetchItemCount = 5

        binding.paymentList.layoutManager = layoutManager

        binding.paymentList.setItemViewCacheSize(50)

        headerAdapter.onItemClick = object : GroundConveyHeaderAdapter.OnItemClick {
            override fun onCurrencyCodeClick() {
                showSelector {
                    val selectorAdapter = ListAdapter.Builder<Selector>().apply {
                        setData(currencyList)
                        setLayoutId(R.layout.item_selector)
                        addBindView { itemView, data ->
                            itemView.findViewById<TextView>(R.id.selector_item_name).apply {
                                text =
                                    String.format(
                                        resources.getString(R.string.currency_name_code_format),
                                        data.currencyName,
                                        data.currencyCode
                                    )

                                if (currencyId == data.currencyId) {
                                    setTextColor(ResourcesCompat.getColor(resources, R.color.text_color_blue, null))
                                } else {
                                    setTextColor(ResourcesCompat.getColor(resources, R.color.text_color, null))
                                }
                            }
                        }
                    }.create()

                    selector.adapter = selectorAdapter

                    selectorAdapter.onRecyclerViewItemClick =
                        object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                            override fun onItemClick(position: Int) {
                                headerAdapter.setCurrencyCode(currencyList[position].currencyCode)
                                binding.paymentTotal.text = String.format(
                                    resources.getString(R.string.price_and_currency_format),
                                    totalPrice,
                                    currencyList[position].currencyCode
                                )

                                currencyId = currencyList[position].currencyId
                                currencySelect = true

                                for ((i, item) in carTouristGuides.withIndex()) {
                                    item.currencyStr = headerAdapter.getCurrencyCode()
                                    binding.paymentList.adapter!!.notifyItemChanged(i)
                                }

                                popupWindow.dismiss()
                            }
                        }
                }
            }

            override fun onPaymentTypeClick() {
                val popView = View.inflate(OASystem.context, R.layout.popup_sift_list, null)
                popupWindow = PopupWindow(
                    popView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
                )

                showPopupWindow {

                    //初始化RecyclerView
                    selector = popView.findViewById(R.id.selector_list)

                    val paymentTypeAdapter = ListAdapter.Builder<SiftListItem>().setData(tableInitialization)
                        .setLayoutId(R.layout.item_customer_sift_long).addBindView { itemView, data ->

                            itemView.findViewById<CheckedTextView>(R.id.customer_sift).apply {
                                isChecked = data.isChecked
                                text = data.name
                            }

                        }.create()

                    val staggeredGridLayoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)

                    selector.layoutManager = staggeredGridLayoutManager
                    selector.adapter = paymentTypeAdapter

                    paymentTypeAdapter.onRecyclerViewItemClick =
                        object : ListAdapter.OnRecyclerViewItemClick<SiftListItem> {
                            override fun onItemClick(position: Int) {

                                tableInitialization[position].apply {

                                    val oldList = ArrayList<GroundConveyTableItem>()

                                    for (item in showItemList) {
                                        oldList.add(item)
                                    }

                                    if (isChecked) {
                                        isChecked = false
                                        checkedItemId.remove(id)

                                        showItemList.clear()

                                        for ((i, item) in carTouristGuides.withIndex()) {
                                            if (item.sId == id) {
                                                totalPrice -= carTouristGuides[i].price * carTouristGuides[i].count
                                            }

                                            if (checkedItemId.contains(item.sId)) {
                                                showItemList.add(item)
                                            }
                                        }

                                        showItemList.removeIf { item ->
                                            item.sId == id
                                        }

                                    } else {
                                        isChecked = true
                                        checkedItemId.add(id)

                                        showItemList.clear()

                                        for ((i, item) in carTouristGuides.withIndex()) {
                                            if (item.sId == id) {
                                                totalPrice += carTouristGuides[i].price * carTouristGuides[i].count
                                            }

                                            if (checkedItemId.contains(item.sId)) {
                                                showItemList.add(item)
                                            }
                                        }
                                    }

                                    val diffUtil = DiffUtil.calculateDiff(ListRefreshCallback(oldList, showItemList))
                                    diffUtil.dispatchUpdatesTo(adapter)

                                    binding.paymentTotal.text = String.format(
                                        resources.getString(R.string.price_and_currency_format),
                                        totalPrice,
                                        headerAdapter.getCurrencyCode()
                                    )

                                    paymentTypeAdapter.notifyItemChanged(position)
                                }
                            }
                        }

                    popView.findViewById<TextView>(R.id.commit).setOnClickListener {
                        popupWindow.dismiss()
                    }

                    popupWindow.showAtLocation(binding.root, Gravity.BOTTOM, 0, 0)
                }
            }
        }

        adapter = GroundConveyTableAdapter(showItemList)
        adapter.setCanBeEdit(canBeEdit())
        adapter.setHasStableIds(true)

        adapter.onItemTextChanged =
            object : GroundConveyTableAdapter.OnItemTextChanged {
                override fun onPriceTextChanged(position: Int) {

                    for (item in carTouristGuides) {
                        if (showItemList[position].id == item.id) {
                            item.apply {
                                prePrice = price * count
                                price = adapter.price
                            }

                            totalPrice =
                                totalPrice - item.prePrice + item.price * item.count

                            binding.paymentTotal.text = String.format(
                                resources.getString(R.string.price_and_currency_format),
                                totalPrice,
                                headerAdapter.getCurrencyCode()
                            )
                        }
                    }
                }

                override fun onPriceContentChanged(position: Int) {

                    for (item in carTouristGuides) {
                        if (showItemList[position].id == item.id) {
                            item.priceContent = adapter.priceContentText
                        }
                    }
                }

                override fun onCountChanged(position: Int) {

                    for (item in carTouristGuides) {
                        if (showItemList[position].id == item.id) {
                            item.apply {
                                prePrice = price * count
                                count = adapter.count.toInt()
                            }

                            totalPrice =
                                totalPrice - item.prePrice + item.price * item.count

                            binding.paymentTotal.text = String.format(
                                resources.getString(R.string.price_and_currency_format),
                                totalPrice,
                                headerAdapter.getCurrencyCode()
                            )
                        }
                    }
                }
            }

        adapter.onItemClick =
            object : GroundConveyTableAdapter.OnItemClick {
                override fun onUnitClick(itemPosition: Int) {
                    showSelector {
                        val unitAdapter = ListAdapter.Builder<Selector>().apply {
                            setData(OASystem.unitList)
                            setLayoutId(R.layout.item_selector)
                            addBindView { itemView, data ->
                                itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                            }
                        }.create()

                        selector.adapter = unitAdapter

                        unitAdapter.onRecyclerViewItemClick = object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                            override fun onItemClick(position: Int) {
                                OASystem.unitList[position].apply {

                                    for (item in carTouristGuides) {
                                        if (showItemList[position].id == item.id) {
                                            item.units = id
                                            adapter.notifyItemChanged(itemPosition)
                                        }
                                    }
                                    popupWindow.dismiss()
                                }
                            }
                        }
                    }
                }
            }

        footerAdapter.onItemClick = object : GroundConveyFooterAdapter.OnItemClick {
            override fun paymentMarkClick() {
                showSelector {
                    val selectorAdapter = ListAdapter.Builder<Selector>().apply {
                        setData(OASystem.paymentMark)
                        setLayoutId(R.layout.item_selector)
                        addBindView { itemView, data ->
                            itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                        }
                    }.create()

                    selector.adapter = selectorAdapter

                    selectorAdapter.onRecyclerViewItemClick =
                        object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                            override fun onItemClick(position: Int) {
                                footerAdapter.setPaymentMark(OASystem.paymentMark[position].name)

                                paymentMarkId = OASystem.paymentMark[position].id
                                paymentMarkSelect = true

                                popupWindow.dismiss()
                            }
                        }
                }
            }

            override fun paymentWayClick() {
                showSelector {
                    val selectorAdapter = ListAdapter.Builder<Selector>().apply {
                        setData(paymentWayList)
                        setLayoutId(R.layout.item_selector)
                        addBindView { itemView, data ->
                            itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                        }
                    }.create()

                    selector.adapter = selectorAdapter

                    selectorAdapter.onRecyclerViewItemClick =
                        object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                            override fun onItemClick(position: Int) {
                                footerAdapter.setPaymentWay(paymentWayList[position].name)

                                paymentWayId = paymentWayList[position].id
                                paymentWaySelect = true

                                popupWindow.dismiss()
                            }
                        }
                }
            }
        }

        val concatAdapter = ConcatAdapter(headerAdapter, adapter, footerAdapter)

        binding.paymentList.adapter = concatAdapter
    }

    private fun updateGroundConveyDetail() {

        binding.commit.setButtonStatus(1)

        for (item in carTouristGuides) {
            if (item.isNew) {
                item.id = 0
            }
        }

        updateGroundConveyDetailRequest.opContentList = carTouristGuides

        val selectCheck = ArrayList<String>()

        for (item in checkedItemId) {
            selectCheck.add(item.toString())
        }

        updateGroundConveyDetailRequest.selectCheck = selectCheck

//        val file = File(filesDir, "data.txt")
//        if (file.exists()) {
//            file.delete()
//        }
//        file.createNewFile()
//        val writer = FileWriter(file)
//        writer.append(Gson().toJson(updateGroundConveyDetailRequest))
//        writer.flush()
//        writer.close()

        apiService.updateGroundConveyDetail(updateGroundConveyDetailRequest)
            .enqueue(object : Callback<BaseResponse> {
                override fun onResponse(
                    call: Call<BaseResponse>, response: Response<BaseResponse>
                ) {

                    val updateResponse = response.body()

                    if (updateResponse != null) {
                        if (updateResponse.code == 200) {
                            showMessage(resources.getString(R.string.update_success))

                            OASystem.needRefresh = true

                            back()
                        } else {

                            binding.commit.setButtonStatus(0)

                            showMessage(updateResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<BaseResponse>, t: Throwable) {

                    binding.commit.setButtonStatus(0)

                    showErrorInfo(R.string.update_error)
                }
            })
    }

    private fun canBeEdit(): Boolean {
        return OASystem.authorization(OASystem.GROUND_CONVEY_PAYMENT_INSERT, OASystem.EDIT) and (isAuditGM == 0)
    }

    class ListRefreshCallback(private val oldList: ArrayList<GroundConveyTableItem>, private val newList: ArrayList<GroundConveyTableItem>): DiffUtil.Callback() {
        override fun getOldListSize(): Int {
            return oldList.size
        }

        override fun getNewListSize(): Int {
            return newList.size
        }

        override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
            return oldList[oldItemPosition].id == newList[newItemPosition].id
        }

        override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
            return oldList[oldItemPosition].id == newList[newItemPosition].id
        }

    }
}