|
|
@@ -3,19 +3,33 @@ package com.pan_american.android.ui.group_management.group_info
|
|
|
import android.os.Bundle
|
|
|
import android.text.Editable
|
|
|
import android.text.TextWatcher
|
|
|
+import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
+import android.widget.EditText
|
|
|
+import android.widget.LinearLayout
|
|
|
+import android.widget.PopupWindow
|
|
|
import android.widget.TextView
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.pan_american.android.OASystem
|
|
|
import com.pan_american.android.R
|
|
|
import com.pan_american.android.base.BaseFragment
|
|
|
import com.pan_american.android.base.CustomAlertDialog
|
|
|
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.network.SelectorResponse
|
|
|
+import com.pan_american.android.data.model.group_management.group_info.network.GetGroupCountryListRequest
|
|
|
+import com.pan_american.android.data.network.APIService
|
|
|
+import com.pan_american.android.data.network.ServiceCreator
|
|
|
import com.pan_american.android.databinding.FragmentGroupInfoBaseBinding
|
|
|
import com.pan_american.android.util.MoneyInputFilter
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
|
|
|
+import retrofit2.Call
|
|
|
+import retrofit2.Callback
|
|
|
+import retrofit2.Response
|
|
|
|
|
|
class GroupInfoBaseFragment : BaseFragment<FragmentGroupInfoBaseBinding>() {
|
|
|
|
|
|
@@ -25,6 +39,12 @@ class GroupInfoBaseFragment : BaseFragment<FragmentGroupInfoBaseBinding>() {
|
|
|
|
|
|
private var opPercentageSubLevel = listOf<String>()
|
|
|
|
|
|
+ private val getGroupCountryListRequest = GetGroupCountryListRequest()
|
|
|
+
|
|
|
+ private var counrtyData = ArrayList<Selector>()
|
|
|
+
|
|
|
+ private val apiService = ServiceCreator.create<APIService>()
|
|
|
+
|
|
|
override fun getViewBinding(
|
|
|
inflater: LayoutInflater, container: ViewGroup?, bundle: Bundle?
|
|
|
) = FragmentGroupInfoBaseBinding.inflate(layoutInflater, container, false)
|
|
|
@@ -63,6 +83,7 @@ class GroupInfoBaseFragment : BaseFragment<FragmentGroupInfoBaseBinding>() {
|
|
|
groupName.setText(OASystem.groupOperationRequest.teamName)
|
|
|
clientName.setText(OASystem.groupOperationRequest.clientName)
|
|
|
customerDepartment.setText(OASystem.groupOperationRequest.clientUnit)
|
|
|
+ city.text = OASystem.groupOperationRequest.cityName
|
|
|
visitCountry.setText(OASystem.groupOperationRequest.visitCountry)
|
|
|
visitDate.text = OASystem.groupOperationRequest.visitDate
|
|
|
visitDays.setText("${OASystem.groupOperationRequest.visitDays}")
|
|
|
@@ -292,6 +313,16 @@ class GroupInfoBaseFragment : BaseFragment<FragmentGroupInfoBaseBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ binding.city.setOnClickListener {
|
|
|
+ getGroupCountryListRequest.apply {
|
|
|
+ pageIndex = 1
|
|
|
+ search = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ counrtyData.clear()
|
|
|
+ getGroupCountryList(1)
|
|
|
+ }
|
|
|
+
|
|
|
binding.customerDepartment.addTextChangedListener(object : TextWatcher {
|
|
|
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
|
|
|
|
|
@@ -626,4 +657,223 @@ class GroupInfoBaseFragment : BaseFragment<FragmentGroupInfoBaseBinding>() {
|
|
|
binding.groupName.setText(String.format(resources.getString(R.string.group_name_format), binding.customerDepartment.text, binding.visitCountry.text, binding.visitDays.text))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private fun getGroupCountryList(type: Int) {
|
|
|
+ apiService.getGroupCountryDataSource(getGroupCountryListRequest)
|
|
|
+ .enqueue(object :
|
|
|
+ Callback<SelectorResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<SelectorResponse>,
|
|
|
+ response: Response<SelectorResponse>
|
|
|
+ ) {
|
|
|
+ val dataResponse = response.body()
|
|
|
+
|
|
|
+ if (dataResponse != null) {
|
|
|
+ if (dataResponse.code == 200) {
|
|
|
+
|
|
|
+ for (item in dataResponse.data) {
|
|
|
+ if (OASystem.entryAndExitLastChoiceCity.id != item.id) {
|
|
|
+ counrtyData.add(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ when (type) {
|
|
|
+ 1 -> {
|
|
|
+
|
|
|
+ val popView = View.inflate(
|
|
|
+ OASystem.context,
|
|
|
+ R.layout.popup_smart_refresh_selector,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ popupWindow = PopupWindow(
|
|
|
+ popView,
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+ ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
+ )
|
|
|
+
|
|
|
+ showPopupWindow {
|
|
|
+ val searchView: LinearLayout =
|
|
|
+ popView.findViewById(R.id.search_view)
|
|
|
+ searchView.visibility = View.VISIBLE
|
|
|
+
|
|
|
+ val searchText: EditText =
|
|
|
+ popView.findViewById(R.id.search_text)
|
|
|
+
|
|
|
+ selector = popView.findViewById(R.id.selector_list)
|
|
|
+
|
|
|
+ selectorContainer =
|
|
|
+ popView.findViewById(R.id.selector_refresh_container)
|
|
|
+ selectorContainer.setEnableRefresh(true)
|
|
|
+ selectorContainer.setEnableLoadMore(true)
|
|
|
+
|
|
|
+ val layoutManager = LinearLayoutManager(OASystem.context)
|
|
|
+ selector.layoutManager = layoutManager
|
|
|
+
|
|
|
+ val adapter =
|
|
|
+ ListAdapter.Builder<Selector>()
|
|
|
+ .apply {
|
|
|
+ setData(counrtyData)
|
|
|
+ setLayoutId(R.layout.item_selector)
|
|
|
+ addBindView { itemView, data ->
|
|
|
+ itemView.findViewById<TextView>(R.id.selector_item_name)
|
|
|
+ .apply {
|
|
|
+ text = data.name
|
|
|
+
|
|
|
+ if (OASystem.groupOperationRequest.cityId == data.id) {
|
|
|
+ setTextColor(
|
|
|
+ ResourcesCompat.getColor(
|
|
|
+ resources,
|
|
|
+ R.color.text_color_blue,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ setTextColor(
|
|
|
+ ResourcesCompat.getColor(
|
|
|
+ resources,
|
|
|
+ R.color.text_color,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.create()
|
|
|
+
|
|
|
+ selector.adapter = adapter
|
|
|
+
|
|
|
+ adapter.onRecyclerViewItemClick =
|
|
|
+ object :
|
|
|
+ ListAdapter.OnRecyclerViewItemClick<Selector> {
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
+ counrtyData[position].apply {
|
|
|
+ binding.city.text = name
|
|
|
+
|
|
|
+ OASystem.groupOperationRequest.cityId = id
|
|
|
+ }
|
|
|
+
|
|
|
+ popupWindow.dismiss()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ selectorContainer.setOnRefreshLoadMoreListener(object :
|
|
|
+ OnRefreshLoadMoreListener {
|
|
|
+ override fun onRefresh(p0: RefreshLayout) {
|
|
|
+ getGroupCountryListRequest.pageIndex = 1
|
|
|
+
|
|
|
+ selector.adapter!!.notifyItemRangeRemoved(
|
|
|
+ 0,
|
|
|
+ counrtyData.size
|
|
|
+ )
|
|
|
+
|
|
|
+ counrtyData.clear()
|
|
|
+
|
|
|
+ getGroupCountryList(2)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onLoadMore(p0: RefreshLayout) {
|
|
|
+ getGroupCountryListRequest.pageIndex += 1
|
|
|
+
|
|
|
+ getGroupCountryList(3)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ searchText.addTextChangedListener(object : TextWatcher {
|
|
|
+ override fun beforeTextChanged(
|
|
|
+ p0: CharSequence?,
|
|
|
+ p1: Int,
|
|
|
+ p2: Int,
|
|
|
+ p3: Int
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTextChanged(
|
|
|
+ p0: CharSequence?,
|
|
|
+ p1: Int,
|
|
|
+ p2: Int,
|
|
|
+ p3: Int
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun afterTextChanged(editable: Editable?) {
|
|
|
+
|
|
|
+ adapter.notifyItemRangeRemoved(
|
|
|
+ 0,
|
|
|
+ counrtyData.size
|
|
|
+ )
|
|
|
+
|
|
|
+ counrtyData.clear()
|
|
|
+
|
|
|
+ getGroupCountryListRequest.apply {
|
|
|
+ pageIndex = 1
|
|
|
+ search = editable.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ getGroupCountryList(2)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ popupWindow.showAtLocation(
|
|
|
+ binding.root,
|
|
|
+ Gravity.BOTTOM,
|
|
|
+ 0,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ getGroupCountryListRequest.pageIndex < getTotalPage(
|
|
|
+ dataResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ 2 -> {
|
|
|
+ selectorContainer.finishRefresh()
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ getGroupCountryListRequest.pageIndex < getTotalPage(
|
|
|
+ dataResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ 3 -> {
|
|
|
+ selectorContainer.finishLoadMore()
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ getGroupCountryListRequest.pageIndex < getTotalPage(
|
|
|
+ dataResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(counrtyData.size)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(dataResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(
|
|
|
+ p0: Call<SelectorResponse>,
|
|
|
+ p1: Throwable
|
|
|
+ ) {
|
|
|
+ showErrorInfo(R.string.base_resource_data_get_failed)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getTotalPage(count: Int): Int {
|
|
|
+ var pageCount = count / 10
|
|
|
+
|
|
|
+ if (count % 10 > 0) {
|
|
|
+ pageCount += 1
|
|
|
+ }
|
|
|
+
|
|
|
+ return pageCount
|
|
|
+ }
|
|
|
}
|