|
@@ -1,12 +1,13 @@
|
|
|
package com.pan_american.android.ui.resource_management.airplane_three_code
|
|
|
|
|
|
import android.os.Bundle
|
|
|
-import android.view.View
|
|
|
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.data.model.resource_management.airplane_three_code.entity.AirplaneThreeCode
|
|
|
+import com.pan_american.android.data.model.resource_management.airplane_three_code.network.AirplaneThreeCodeDetailRequest
|
|
|
+import com.pan_american.android.data.model.resource_management.airplane_three_code.network.AirplaneThreeCodeDetailResponse
|
|
|
import com.pan_american.android.data.network.APIService
|
|
|
import com.pan_american.android.data.network.ServiceCreator
|
|
|
import com.pan_american.android.databinding.ActivityAddAirplaneThreeCodeBinding
|
|
@@ -19,7 +20,11 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
|
|
|
private lateinit var titleBinding: LayoutTitleBinding
|
|
|
|
|
|
- private lateinit var airplaneThreeCode: AirplaneThreeCode
|
|
|
+ private var threeCodeId = 0
|
|
|
+
|
|
|
+ private val apiService = ServiceCreator.create<APIService>()
|
|
|
+
|
|
|
+ private val airplaneThreeCode = AirplaneThreeCode()
|
|
|
|
|
|
private var fromList = false
|
|
|
|
|
@@ -29,7 +34,13 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
super.onCreate(savedInstanceState)
|
|
|
screenAdaptation(binding)
|
|
|
|
|
|
- fromList = intent.getBooleanExtra("fromList", false)
|
|
|
+ intent.apply {
|
|
|
+ fromList = getBooleanExtra("fromList", false)
|
|
|
+
|
|
|
+ if (fromList) {
|
|
|
+ threeCodeId = getIntExtra("id", 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
initTitle()
|
|
|
initViews()
|
|
@@ -55,22 +66,25 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
|
|
|
if (fromList) {
|
|
|
|
|
|
- airplaneThreeCode =
|
|
|
- intent.getSerializableExtra("airplaneResource") as AirplaneThreeCode
|
|
|
- initAirplaneResourceInfo()
|
|
|
+ getAirplaneThreeCodeById()
|
|
|
|
|
|
binding.commit.setText(resources.getString(R.string.update))
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
binding.commit.setText(resources.getString(R.string.add))
|
|
|
-
|
|
|
- airplaneThreeCode = AirplaneThreeCode()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun initEvents() {
|
|
|
|
|
|
binding.commit.setOnClickListener {
|
|
|
+
|
|
|
+ if (!OASystem.authorization(OASystem.THREE_CODE_RESOURCE, OASystem.EDIT)) {
|
|
|
+ back()
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
+
|
|
|
if (intent.getBooleanExtra("fromList", false)) {
|
|
|
initAirplaneResource(2)
|
|
|
updateAirplaneResource()
|
|
@@ -81,7 +95,42 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun getAirplaneThreeCodeById() {
|
|
|
+
|
|
|
+ apiService.getAirplaneThreeCodeDetailById(AirplaneThreeCodeDetailRequest(threeCodeId)).enqueue(object : Callback<AirplaneThreeCodeDetailResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<AirplaneThreeCodeDetailResponse>,
|
|
|
+ response: Response<AirplaneThreeCodeDetailResponse>
|
|
|
+ ) {
|
|
|
+ val detailResponse = response.body()
|
|
|
+
|
|
|
+ if (detailResponse != null) {
|
|
|
+ if (detailResponse.code == 200) {
|
|
|
+ airplaneThreeCode.apply {
|
|
|
+ id = threeCodeId
|
|
|
+ three = detailResponse.data.three
|
|
|
+ four = detailResponse.data.four
|
|
|
+ airPort = detailResponse.data.airPort
|
|
|
+ airPort_En = detailResponse.data.airPort_En
|
|
|
+ city = detailResponse.data.city
|
|
|
+ remark = detailResponse.data.remark
|
|
|
+ }
|
|
|
+
|
|
|
+ initAirplaneResourceInfo()
|
|
|
+ } else {
|
|
|
+ showMessage(detailResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<AirplaneThreeCodeDetailResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.airplane_three_code_detail_get_failed)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
private fun initAirplaneResourceInfo() {
|
|
|
+
|
|
|
binding.apply {
|
|
|
threeCode.setText(airplaneThreeCode.three)
|
|
|
fourCode.setText(airplaneThreeCode.four)
|
|
@@ -100,7 +149,7 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
airplaneNameEn.isEnabled(false)
|
|
|
otherInfo.isEnabled(false)
|
|
|
|
|
|
- commit.visibility = View.GONE
|
|
|
+ commit.setText(resources.getString(R.string.back))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -123,8 +172,6 @@ class AddAirplaneThreeCodeActivity : BaseActivity<ActivityAddAirplaneThreeCodeBi
|
|
|
|
|
|
binding.commit.setButtonStatus(1)
|
|
|
|
|
|
- val apiService = ServiceCreator.create<APIService>()
|
|
|
-
|
|
|
apiService.airplaneThreeCodeOperation(airplaneThreeCode)
|
|
|
.enqueue(object : Callback<BaseResponse> {
|
|
|
override fun onResponse(
|