|
@@ -9,6 +9,7 @@ import android.graphics.BitmapFactory
|
|
|
import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.provider.MediaStore
|
|
|
+import android.provider.OpenableColumns
|
|
|
import android.text.Editable
|
|
|
import android.text.TextWatcher
|
|
|
import android.util.Base64
|
|
@@ -18,6 +19,7 @@ import android.widget.EditText
|
|
|
import android.widget.LinearLayout
|
|
|
import android.widget.PopupWindow
|
|
|
import android.widget.TextView
|
|
|
+import androidx.activity.result.ActivityResultCallback
|
|
|
import androidx.activity.result.ActivityResultLauncher
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
|
import androidx.core.app.ActivityCompat
|
|
@@ -34,23 +36,27 @@ import com.pan_american.android.base.BaseResponse
|
|
|
import com.pan_american.android.base.CardAdapter
|
|
|
import com.pan_american.android.base.CustomAlertDialog
|
|
|
import com.pan_american.android.base.ListAdapter
|
|
|
+import com.pan_american.android.data.model.common.entity.FileListItem
|
|
|
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_invite_official.invite_data.network.InviteDataDetailRequest
|
|
|
-import com.pan_american.android.data.model.group_invite_official.invite_data.network.InviteDataDetailResponse
|
|
|
-import com.pan_american.android.data.model.group_invite_official.invite_data.network.UpdateInviteDetailRequest
|
|
|
import com.pan_american.android.data.model.customer_resource.company_customer.network.BusinessCardInfoRequest
|
|
|
import com.pan_american.android.data.model.customer_resource.company_customer.network.BusinessCardInfoResponse
|
|
|
+import com.pan_american.android.data.model.group_invite_official.invite_data.network.InviteDataDetailResponse
|
|
|
+import com.pan_american.android.data.model.group_invite_official.invite_data.network.UpdateInviteDetailRequest
|
|
|
import com.pan_american.android.data.network.APIService
|
|
|
import com.pan_american.android.data.network.ServiceCreator
|
|
|
import com.pan_american.android.databinding.ActivityAddInviteDataBinding
|
|
|
import com.pan_american.android.databinding.LayoutTitleBinding
|
|
|
+import okhttp3.MediaType
|
|
|
+import okhttp3.MultipartBody
|
|
|
+import okhttp3.RequestBody
|
|
|
import retrofit2.Call
|
|
|
import retrofit2.Callback
|
|
|
import retrofit2.Response
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
import java.io.File
|
|
|
|
|
|
+
|
|
|
class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
|
|
|
private var fromList = false
|
|
@@ -65,12 +71,12 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
|
|
|
private val groupSelected = ArrayList<Selector>()
|
|
|
|
|
|
- private lateinit var adapter: CardAdapter<Selector>
|
|
|
+ private lateinit var groupNameAdapter: CardAdapter<Selector>
|
|
|
|
|
|
private var updateInviteDataDetailRequest = UpdateInviteDetailRequest()
|
|
|
|
|
|
//监听拍照事件回调
|
|
|
- private lateinit var result: ActivityResultLauncher<Intent>
|
|
|
+ private lateinit var getPhotoResult: ActivityResultLauncher<Intent>
|
|
|
|
|
|
//名片识别,图片Uri
|
|
|
private lateinit var imageUri: Uri
|
|
@@ -87,6 +93,12 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
//识别后地址可能存在多行
|
|
|
private var locationOCR = ""
|
|
|
|
|
|
+ private var fileListItem = ArrayList<FileListItem>()
|
|
|
+
|
|
|
+ private lateinit var fileListAdapter: CardAdapter<FileListItem>
|
|
|
+
|
|
|
+ private lateinit var fileSelectResult: ActivityResultLauncher<Intent>
|
|
|
+
|
|
|
override fun getViewBinding() = ActivityAddInviteDataBinding.inflate(layoutInflater)
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
@@ -97,7 +109,7 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
dataId = getIntExtra("data_id", 0)
|
|
|
}
|
|
|
|
|
|
- result = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
|
|
+ getPhotoResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
|
|
if (it.resultCode == Activity.RESULT_OK) {
|
|
|
|
|
|
telephoneOCR = ""
|
|
@@ -109,6 +121,32 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fileSelectResult = registerForActivityResult(
|
|
|
+ ActivityResultContracts.StartActivityForResult(),
|
|
|
+ ActivityResultCallback { result ->
|
|
|
+ if (result.resultCode == RESULT_OK) {
|
|
|
+ val data: Intent? = result.data
|
|
|
+ if (data != null) {
|
|
|
+ val selectedImageUri = data.data
|
|
|
+ if (selectedImageUri != null) {
|
|
|
+
|
|
|
+ fileListItem.add(FileListItem().apply {
|
|
|
+ fileName = File(uri2Path(selectedImageUri)).name
|
|
|
+
|
|
|
+ if (fileName.isBlank()) {
|
|
|
+ showMessage(resources.getString(R.string.file_select_error_hint))
|
|
|
+ return@ActivityResultCallback
|
|
|
+ }
|
|
|
+
|
|
|
+ uri = selectedImageUri
|
|
|
+ })
|
|
|
+
|
|
|
+ initFileNameList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
initTitle()
|
|
|
|
|
|
getGroupNameList()
|
|
@@ -184,6 +222,7 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
|
|
|
override fun initEvents() {
|
|
|
+
|
|
|
binding.add.setOnClickListener {
|
|
|
val selectorList = ArrayList<Selector>()
|
|
|
|
|
@@ -291,6 +330,10 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ binding.upload.setOnClickListener {
|
|
|
+ openFileManager()
|
|
|
+ }
|
|
|
+
|
|
|
binding.commit.setOnClickListener {
|
|
|
if (!OASystem.authorization(OASystem.INVITE_DATA, OASystem.EDIT)) {
|
|
|
back()
|
|
@@ -440,7 +483,8 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
|
|
|
private fun getInviteDataDetail() {
|
|
|
- apiService.getInviteDataDetailById(InviteDataDetailRequest(dataId)).enqueue(object : Callback<InviteDataDetailResponse> {
|
|
|
+
|
|
|
+ apiService.getInviteDataDetailById(dataId).enqueue(object : Callback<InviteDataDetailResponse> {
|
|
|
override fun onResponse(
|
|
|
call: Call<InviteDataDetailResponse>,
|
|
|
response: Response<InviteDataDetailResponse>
|
|
@@ -453,7 +497,7 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
detailResponse.data.apply {
|
|
|
|
|
|
updateInviteDataDetailRequest.id = id
|
|
|
- updateInviteDataDetailRequest.createUserId = createUserId
|
|
|
+ updateInviteDataDetailRequest.createUserId = OASystem.userInfo.userId
|
|
|
|
|
|
binding.country.setText(country)
|
|
|
binding.city.setText(city)
|
|
@@ -484,6 +528,20 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
initGroupNameList()
|
|
|
}
|
|
|
|
|
|
+ if (sndFilePathItem.size > 0) {
|
|
|
+
|
|
|
+ for (item in sndFilePathItem) {
|
|
|
+ fileListItem.add(FileListItem().apply {
|
|
|
+ fileName = item.substringAfterLast("/")
|
|
|
+ url = item
|
|
|
+ fromServer = true
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ initFileNameList()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
binding.contactsFax.setText(fax)
|
|
|
binding.otherInfo.setText(remark)
|
|
|
}
|
|
@@ -504,7 +562,7 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
val layoutManager = LinearLayoutManager(OASystem.context)
|
|
|
binding.groupList.layoutManager = layoutManager
|
|
|
|
|
|
- adapter = CardAdapter.Builder<Selector>().apply {
|
|
|
+ groupNameAdapter = CardAdapter.Builder<Selector>().apply {
|
|
|
setData(groupSelected)
|
|
|
setLayoutId(R.layout.item_delete_button_selector)
|
|
|
setCanDelete(OASystem.authorization(OASystem.INVITE_DATA, OASystem.EDIT))
|
|
@@ -513,9 +571,9 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
}.create()
|
|
|
|
|
|
- binding.groupList.adapter = adapter
|
|
|
+ binding.groupList.adapter = groupNameAdapter
|
|
|
|
|
|
- adapter.onRecyclerViewItemClick = object : CardAdapter.OnRecyclerViewItemClick<Selector> {
|
|
|
+ groupNameAdapter.onRecyclerViewItemClick = object : CardAdapter.OnRecyclerViewItemClick<Selector> {
|
|
|
override fun onItemClick(position: Int) {
|
|
|
|
|
|
}
|
|
@@ -537,11 +595,121 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun initFileNameList() {
|
|
|
+ val layoutManager = LinearLayoutManager(OASystem.context)
|
|
|
+ binding.inviteDataFileList.layoutManager = layoutManager
|
|
|
+
|
|
|
+ fileListAdapter = CardAdapter.Builder<FileListItem>().apply {
|
|
|
+ setData(fileListItem)
|
|
|
+ setLayoutId(R.layout.item_delete_button_selector)
|
|
|
+ setCanDelete(OASystem.authorization(OASystem.INVITE_DATA, OASystem.EDIT))
|
|
|
+ addBindView { itemView, data ->
|
|
|
+ itemView.findViewById<TextView>(R.id.left_text).text = data.fileName
|
|
|
+ }
|
|
|
+ }.create()
|
|
|
+
|
|
|
+ binding.inviteDataFileList.adapter = fileListAdapter
|
|
|
+
|
|
|
+ fileListAdapter.onRecyclerViewItemClick = object : CardAdapter.OnRecyclerViewItemClick<FileListItem> {
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onItemDelete(position: Int) {
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.alert))
|
|
|
+ if (fileListItem[position].fromServer) {
|
|
|
+ setMessage(String.format(resources.getString(R.string.file_uploaded_delete_hint), fileListItem[position].fileName))
|
|
|
+ } else {
|
|
|
+ setMessage(String.format(resources.getString(R.string.delete_alert_text), fileListItem[position].fileName))
|
|
|
+ }
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { _, _ ->
|
|
|
+
|
|
|
+ if (fileListItem[position].fromServer) {
|
|
|
+
|
|
|
+ deleteFileFromServer(position)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ fileListItem.removeAt(position)
|
|
|
+ binding.inviteDataFileList.adapter!!.notifyItemRemoved(position)
|
|
|
+ binding.inviteDataFileList.adapter!!.notifyItemRangeChanged(position, fileListItem.size - position)
|
|
|
+
|
|
|
+ showMessage(resources.getString(R.string.delete_success))
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun deleteFileFromServer(position: Int) {
|
|
|
+
|
|
|
+ apiService.deleteInviteDataFile(updateInviteDataDetailRequest.id, fileListItem[position].fileName).enqueue(object : Callback<BaseResponse> {
|
|
|
+ override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
|
|
|
+
|
|
|
+ val deleteResponse = response.body()
|
|
|
+
|
|
|
+ if (deleteResponse != null) {
|
|
|
+ if (deleteResponse.code == 200) {
|
|
|
+
|
|
|
+ fileListItem.removeAt(position)
|
|
|
+ binding.inviteDataFileList.adapter!!.notifyItemRemoved(position)
|
|
|
+ binding.inviteDataFileList.adapter!!.notifyItemRangeChanged(position, fileListItem.size - position)
|
|
|
+
|
|
|
+ showMessage(resources.getString(R.string.delete_success))
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(deleteResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(p0: Call<BaseResponse>, p1: Throwable) {
|
|
|
+ showErrorInfo(R.string.delete_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
private fun updateInviteData() {
|
|
|
|
|
|
binding.commit.setButtonStatus(1)
|
|
|
|
|
|
- apiService.updateInviteData(updateInviteDataDetailRequest).enqueue(object : Callback<BaseResponse> {
|
|
|
+ val requestBody = MultipartBody.Builder().setType(MultipartBody.FORM).apply {
|
|
|
+ addFormDataPart("Id", updateInviteDataDetailRequest.id.toString())
|
|
|
+ addFormDataPart("Country", updateInviteDataDetailRequest.country)
|
|
|
+ addFormDataPart("City", updateInviteDataDetailRequest.city)
|
|
|
+ addFormDataPart("UnitName", updateInviteDataDetailRequest.unitName)
|
|
|
+ addFormDataPart("UnitWeb", updateInviteDataDetailRequest.unitWeb)
|
|
|
+ addFormDataPart("Field", updateInviteDataDetailRequest.field)
|
|
|
+ addFormDataPart("Address", updateInviteDataDetailRequest.address)
|
|
|
+ addFormDataPart("UnitInfo", updateInviteDataDetailRequest.unitInfo)
|
|
|
+ addFormDataPart("Contact", updateInviteDataDetailRequest.contact)
|
|
|
+ addFormDataPart("Job", updateInviteDataDetailRequest.job)
|
|
|
+ addFormDataPart("Tel", updateInviteDataDetailRequest.tel)
|
|
|
+ addFormDataPart("Email", updateInviteDataDetailRequest.email)
|
|
|
+ addFormDataPart("WeChat", updateInviteDataDetailRequest.weChat)
|
|
|
+ addFormDataPart("FaceBook", updateInviteDataDetailRequest.faceBook)
|
|
|
+ addFormDataPart("Ins", updateInviteDataDetailRequest.ins)
|
|
|
+ addFormDataPart("Delegation", updateInviteDataDetailRequest.delegation)
|
|
|
+ addFormDataPart("Fax", updateInviteDataDetailRequest.fax)
|
|
|
+ addFormDataPart("Remark", updateInviteDataDetailRequest.remark)
|
|
|
+ addFormDataPart("Status", updateInviteDataDetailRequest.status.toString())
|
|
|
+ addFormDataPart("CreateUserId", updateInviteDataDetailRequest.createUserId.toString())
|
|
|
+ for (item in fileListItem) {
|
|
|
+ if (!item.fromServer) {
|
|
|
+ val file = contentResolver.openInputStream(item.uri)!!
|
|
|
+ val fileRequestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file.readBytes())
|
|
|
+ addFormDataPart("Files", item.fileName, fileRequestBody)
|
|
|
+ file.close()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.build()
|
|
|
+
|
|
|
+ apiService.updateInviteData(requestBody).enqueue(object : Callback<BaseResponse> {
|
|
|
override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
|
|
|
|
|
|
val updateResponse = response.body()
|
|
@@ -593,7 +761,7 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
//启动相机程序
|
|
|
val intent = Intent("android.media.action.IMAGE_CAPTURE")
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
|
|
|
- result.launch(intent)
|
|
|
+ getPhotoResult.launch(intent)
|
|
|
}
|
|
|
|
|
|
private fun getBusinessCardInfo() {
|
|
@@ -708,4 +876,26 @@ class AddInviteDataActivity : BaseActivity<ActivityAddInviteDataBinding>() {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ private fun uri2Path(uri: Uri): String {
|
|
|
+ var filePath = ""
|
|
|
+ val projection = arrayOf(OpenableColumns.DISPLAY_NAME)
|
|
|
+ contentResolver.query(uri, projection, null, null, null)?.use { cursor ->
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ val columnIndex =
|
|
|
+ cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)
|
|
|
+ filePath = cursor.getString(columnIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return filePath
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun openFileManager() {
|
|
|
+ val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
|
|
+ intent.addCategory(Intent.CATEGORY_OPENABLE)
|
|
|
+ intent.setType("*/*") // Use specific MIME type if you know the file type (e.g., "text/plain" for .txt files)
|
|
|
+
|
|
|
+ fileSelectResult.launch(intent)
|
|
|
+ }
|
|
|
}
|