|
|
@@ -1,24 +1,61 @@
|
|
|
package com.pan_american.android.ui.group_management.entry_and_exit_fee_draft
|
|
|
|
|
|
+import android.content.Intent
|
|
|
+import android.net.Uri
|
|
|
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.BaseRequest
|
|
|
+import com.pan_american.android.base.BaseResponse
|
|
|
+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.group_management.entry_and_exit_fee_detail.network.EntryAndExitGroupListRequest
|
|
|
+import com.pan_american.android.data.model.group_management.entry_and_exit_fee_detail.network.EntryAndExitGroupListResponse
|
|
|
+import com.pan_american.android.data.model.group_management.entry_and_exit_fee_draft.network.DraftFileTypeResponse
|
|
|
+import com.pan_american.android.data.model.group_management.entry_and_exit_fee_draft.network.DraftWordFileDownloadRequest
|
|
|
+import com.pan_american.android.data.model.group_management.entry_and_exit_fee_draft.network.DraftWordFileDownloadResponse
|
|
|
import com.pan_american.android.data.model.group_management.entry_and_exit_fee_draft.network.EntryAndExitDraftTotalResponse
|
|
|
+import com.pan_american.android.data.model.group_management.entry_and_exit_fee_draft.network.SynchronizeDraftToGroupRequest
|
|
|
import com.pan_american.android.data.network.APIService
|
|
|
import com.pan_american.android.data.network.ServiceCreator
|
|
|
import com.pan_american.android.databinding.FragmentEntryAndEntryFeeDraftTotalBinding
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
|
+import retrofit2.Call
|
|
|
+import retrofit2.Callback
|
|
|
+import retrofit2.Response
|
|
|
|
|
|
-class EntryAndExitFeeDraftTotalFragment : BaseFragment<FragmentEntryAndEntryFeeDraftTotalBinding>() {
|
|
|
+class EntryAndExitFeeDraftTotalFragment :
|
|
|
+ BaseFragment<FragmentEntryAndEntryFeeDraftTotalBinding>() {
|
|
|
|
|
|
private val apiService = ServiceCreator.create<APIService>()
|
|
|
|
|
|
+ private val entryAndExitGroupListRequest = EntryAndExitGroupListRequest().apply {
|
|
|
+ pageIndex = 1
|
|
|
+ pageSize = 10
|
|
|
+ }
|
|
|
+
|
|
|
+ private val groupNameList = ArrayList<Selector>()
|
|
|
+
|
|
|
+ private val wordTypeData = ArrayList<Selector>()
|
|
|
+
|
|
|
override fun getViewBinding(
|
|
|
inflater: LayoutInflater,
|
|
|
container: ViewGroup?,
|
|
|
@@ -74,28 +111,34 @@ class EntryAndExitFeeDraftTotalFragment : BaseFragment<FragmentEntryAndEntryFeeD
|
|
|
binding.checkEconomyClass.isChecked = choiceTwoJJ == 1
|
|
|
|
|
|
if (choiceTwoJJ == 1) {
|
|
|
- binding.economyClass.text = String.format(resources.getString(R.string.economy_class_price), outsideJJPay)
|
|
|
+ binding.economyClass.text =
|
|
|
+ String.format(resources.getString(R.string.economy_class_price), outsideJJPay)
|
|
|
economyTotalPayment += outsideJJPay
|
|
|
} else {
|
|
|
- binding.economyClass.text = String.format(resources.getString(R.string.economy_class_price), 0.0)
|
|
|
+ binding.economyClass.text =
|
|
|
+ String.format(resources.getString(R.string.economy_class_price), 0.0)
|
|
|
}
|
|
|
|
|
|
binding.checkBusinessClass.isChecked = choiceTwoGW == 1
|
|
|
|
|
|
if (choiceTwoGW == 1) {
|
|
|
- binding.businessClass.text = String.format(resources.getString(R.string.business_class_price), outsideGWPay)
|
|
|
+ binding.businessClass.text =
|
|
|
+ String.format(resources.getString(R.string.business_class_price), outsideGWPay)
|
|
|
bussinessTotalPayment += outsideGWPay
|
|
|
} else {
|
|
|
- binding.businessClass.text = String.format(resources.getString(R.string.business_class_price), 0.0)
|
|
|
+ binding.businessClass.text =
|
|
|
+ String.format(resources.getString(R.string.business_class_price), 0.0)
|
|
|
}
|
|
|
|
|
|
binding.checkFirstClass.isChecked = choiceTwoTD == 1
|
|
|
|
|
|
if (choiceTwoTD == 1) {
|
|
|
- binding.firstClass.text = String.format(resources.getString(R.string.first_class_price), outsideTDPay)
|
|
|
+ binding.firstClass.text =
|
|
|
+ String.format(resources.getString(R.string.first_class_price), outsideTDPay)
|
|
|
firstClassTotalPayment += outsideTDPay
|
|
|
} else {
|
|
|
- binding.firstClass.text = String.format(resources.getString(R.string.first_class_price), 0.0)
|
|
|
+ binding.firstClass.text =
|
|
|
+ String.format(resources.getString(R.string.first_class_price), 0.0)
|
|
|
}
|
|
|
|
|
|
binding.checkAccommodationFee.isChecked = choiceThree == 1
|
|
|
@@ -194,10 +237,6 @@ class EntryAndExitFeeDraftTotalFragment : BaseFragment<FragmentEntryAndEntryFeeD
|
|
|
|
|
|
override fun initEvents() {
|
|
|
|
|
|
- binding.draftName.setOnClickListener {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
binding.inBoardFee.setOnClickListener {
|
|
|
|
|
|
val bundle = Bundle().apply {
|
|
|
@@ -331,11 +370,11 @@ class EntryAndExitFeeDraftTotalFragment : BaseFragment<FragmentEntryAndEntryFeeD
|
|
|
}
|
|
|
|
|
|
binding.synchronizeToGroup.setOnClickListener {
|
|
|
-
|
|
|
+ getGroupList(1)
|
|
|
}
|
|
|
|
|
|
binding.exportDetailList.setOnClickListener {
|
|
|
-
|
|
|
+ getFileList()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -343,4 +382,373 @@ class EntryAndExitFeeDraftTotalFragment : BaseFragment<FragmentEntryAndEntryFeeD
|
|
|
fun updateView(response: EntryAndExitDraftTotalResponse) {
|
|
|
initViews()
|
|
|
}
|
|
|
+
|
|
|
+ private fun getGroupList(type: Int) {
|
|
|
+ apiService.getEntryAndExitGroupList(entryAndExitGroupListRequest).enqueue(object :
|
|
|
+ Callback<EntryAndExitGroupListResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<EntryAndExitGroupListResponse>,
|
|
|
+ response: Response<EntryAndExitGroupListResponse>
|
|
|
+ ) {
|
|
|
+ val listResponse = response.body()
|
|
|
+
|
|
|
+ if (listResponse != null) {
|
|
|
+ if (listResponse.code == 200) {
|
|
|
+ if (listResponse.data.size == 0) {
|
|
|
+ showMessage(resources.getString(R.string.no_data))
|
|
|
+ } else {
|
|
|
+
|
|
|
+ for (item in listResponse.data) {
|
|
|
+ groupNameList.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(groupNameList)
|
|
|
+ setLayoutId(R.layout.item_selector)
|
|
|
+ addBindView { itemView, data ->
|
|
|
+ itemView.findViewById<TextView>(R.id.selector_item_name)
|
|
|
+ .apply {
|
|
|
+ if (data.isNull) {
|
|
|
+ setTextColor(
|
|
|
+ ResourcesCompat.getColor(
|
|
|
+ resources,
|
|
|
+ R.color.text_color,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ setTextColor(
|
|
|
+ ResourcesCompat.getColor(
|
|
|
+ resources,
|
|
|
+ R.color.text_color_blue,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ text = data.groupName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.create()
|
|
|
+
|
|
|
+ selector.adapter = adapter
|
|
|
+
|
|
|
+ adapter.onRecyclerViewItemClick =
|
|
|
+ object :
|
|
|
+ ListAdapter.OnRecyclerViewItemClick<Selector> {
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
+ groupNameList[position].apply {
|
|
|
+ showGroupSynchronizePopup(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ popupWindow.dismiss()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ selectorContainer.setOnRefreshLoadMoreListener(object :
|
|
|
+ OnRefreshLoadMoreListener {
|
|
|
+ override fun onRefresh(p0: RefreshLayout) {
|
|
|
+ entryAndExitGroupListRequest.pageIndex = 1
|
|
|
+
|
|
|
+ selector.adapter!!.notifyItemRangeRemoved(
|
|
|
+ 0,
|
|
|
+ groupNameList.size
|
|
|
+ )
|
|
|
+
|
|
|
+ groupNameList.clear()
|
|
|
+
|
|
|
+ getGroupList(2)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onLoadMore(p0: RefreshLayout) {
|
|
|
+ entryAndExitGroupListRequest.pageIndex += 1
|
|
|
+
|
|
|
+ getGroupList(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,
|
|
|
+ groupNameList.size
|
|
|
+ )
|
|
|
+
|
|
|
+ groupNameList.clear()
|
|
|
+
|
|
|
+ entryAndExitGroupListRequest.apply {
|
|
|
+ pageIndex = 1
|
|
|
+ groupName = editable.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ getGroupList(2)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ popupWindow.showAtLocation(
|
|
|
+ binding.root,
|
|
|
+ Gravity.BOTTOM,
|
|
|
+ 0,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ entryAndExitGroupListRequest.pageIndex < getTotalPage(
|
|
|
+ listResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ 2 -> {
|
|
|
+ selectorContainer.finishRefresh()
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ entryAndExitGroupListRequest.pageIndex < getTotalPage(
|
|
|
+ listResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ 3 -> {
|
|
|
+ selectorContainer.finishLoadMore()
|
|
|
+ selectorContainer.setEnableLoadMore(
|
|
|
+ entryAndExitGroupListRequest.pageIndex < getTotalPage(
|
|
|
+ listResponse.count
|
|
|
+ )
|
|
|
+ )
|
|
|
+ selector.adapter!!.notifyItemInserted(groupNameList.size)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(listResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<EntryAndExitGroupListResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.group_list_get_failed)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getTotalPage(count: Int): Int {
|
|
|
+ var pageCount = count / 10
|
|
|
+
|
|
|
+ if (count % 10 > 0) {
|
|
|
+ pageCount += 1
|
|
|
+ }
|
|
|
+
|
|
|
+ return pageCount
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showGroupSynchronizePopup(groupInfo: Selector) {
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.alert))
|
|
|
+ setMessage(
|
|
|
+ String.format(
|
|
|
+ resources.getString(R.string.synchronize_draft_to_group_hint),
|
|
|
+ OASystem.entryAndExitDraftResponse.draftName,
|
|
|
+ groupInfo.name
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { dialog, _ ->
|
|
|
+ synchronizeDraftToGroup(groupInfo.id, OASystem.entryAndExitDraftResponse.id)
|
|
|
+
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun synchronizeDraftToGroup(groupId: Int, draftId: Int) {
|
|
|
+ apiService.synchronizeDraftToGroup(
|
|
|
+ SynchronizeDraftToGroupRequest(
|
|
|
+ groupId = groupId,
|
|
|
+ draftId = draftId
|
|
|
+ )
|
|
|
+ ).enqueue(object : Callback<BaseResponse> {
|
|
|
+ override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
|
|
|
+
|
|
|
+ val synchronizeResponse = response.body()
|
|
|
+
|
|
|
+ if (synchronizeResponse != null) {
|
|
|
+ if (synchronizeResponse.code == 200) {
|
|
|
+ showMessage(resources.getString(R.string.operate_success))
|
|
|
+ } else {
|
|
|
+ showMessage(synchronizeResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<BaseResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.interface_request_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getFileList() {
|
|
|
+
|
|
|
+ wordTypeData.clear()
|
|
|
+
|
|
|
+ apiService.getDraftFileList(BaseRequest())
|
|
|
+ .enqueue(object : Callback<DraftFileTypeResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<DraftFileTypeResponse>,
|
|
|
+ response: Response<DraftFileTypeResponse>
|
|
|
+ ) {
|
|
|
+ val listResponse = response.body()
|
|
|
+
|
|
|
+ if (listResponse != null) {
|
|
|
+ if (listResponse.code == 200) {
|
|
|
+
|
|
|
+ for (item in listResponse.data.wordTypeData) {
|
|
|
+ wordTypeData.add(item)
|
|
|
+ }
|
|
|
+
|
|
|
+ showWordTypeSelector()
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(listResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<DraftFileTypeResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.interface_request_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showWordTypeSelector() {
|
|
|
+ showSelector {
|
|
|
+ val adapter = ListAdapter.Builder<Selector>().apply {
|
|
|
+ setData(wordTypeData)
|
|
|
+ setLayoutId(R.layout.item_selector)
|
|
|
+ addBindView { itemView, data ->
|
|
|
+ itemView.findViewById<TextView>(R.id.selector_item_name).apply {
|
|
|
+ text = data.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.create()
|
|
|
+
|
|
|
+ selector.adapter = adapter
|
|
|
+
|
|
|
+ adapter.onRecyclerViewItemClick =
|
|
|
+ object : ListAdapter.OnRecyclerViewItemClick<Selector> {
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
+ downloadWordFile(wordTypeData[position])
|
|
|
+ popupWindow.dismiss()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun downloadWordFile(type: Selector) {
|
|
|
+
|
|
|
+ apiService.downloadDraftWordFile(
|
|
|
+ DraftWordFileDownloadRequest(
|
|
|
+ id = OASystem.entryAndExitDraftResponse.id,
|
|
|
+ subTypeId = type.id
|
|
|
+ )
|
|
|
+ ).enqueue(object : Callback<DraftWordFileDownloadResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<DraftWordFileDownloadResponse>,
|
|
|
+ response: Response<DraftWordFileDownloadResponse>
|
|
|
+ ) {
|
|
|
+ val urlResponse = response.body()
|
|
|
+
|
|
|
+ if (urlResponse != null) {
|
|
|
+ if (urlResponse.code == 200) {
|
|
|
+
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.hint))
|
|
|
+ setMessage(
|
|
|
+ String.format(
|
|
|
+ resources.getString(R.string.draft_document_generated),
|
|
|
+ OASystem.entryAndExitDraftResponse.draftName,
|
|
|
+ type.name
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { dialog, _ ->
|
|
|
+
|
|
|
+ val uri = Uri.parse(urlResponse.data)
|
|
|
+ startActivity(Intent(Intent.ACTION_VIEW, uri))
|
|
|
+
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(urlResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<DraftWordFileDownloadResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.interface_request_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|