OpinionActivity.kt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.zswc.creativity.activity
  2. import android.app.Activity
  3. import android.content.Intent
  4. import android.os.Bundle
  5. import androidx.core.net.toUri
  6. import com.luck.picture.lib.PictureSelector
  7. import com.zswc.creativity.base.MBActivity
  8. import com.zswc.creativity.config.MIntentAction
  9. import com.zswc.creativity.databinding.ActivityOpinionBinding
  10. import com.zswc.creativity.inte.OnUploadCallback
  11. import com.zswc.creativity.utils.FileUtils
  12. import com.zswc.creativity.utils.OssUtils
  13. import com.zswc.creativity.vmodel.OpinionVModel
  14. import java.util.*
  15. /**
  16. *Created by shihuiyun
  17. *on 2020/9/24
  18. */
  19. class OpinionActivity : MBActivity<OpinionVModel, ActivityOpinionBinding>(), OnUploadCallback<String> {
  20. var type=1
  21. override fun __before() {
  22. super.__before()
  23. type= intent?.extras?.getInt("type", 1)!!
  24. }
  25. override fun init(savedInstanceState: Bundle?) {
  26. super.init(savedInstanceState)
  27. vm.type=type
  28. }
  29. override fun binding(): ActivityOpinionBinding {
  30. return ActivityOpinionBinding.inflate(layoutInflater)
  31. }
  32. override fun vmClass(): Class<OpinionVModel> {
  33. return OpinionVModel::class.java
  34. }
  35. override fun title(): String? {
  36. return if(type==1) {
  37. "意见反馈"
  38. }else{
  39. "举报投诉"
  40. }
  41. }
  42. override fun onUploadSuccess(t: String) {
  43. val ss: Array<String> = t.split(",".toRegex()).toTypedArray()
  44. vm.url.value = ss[1]
  45. }
  46. override fun onUploadError(error: String?) {
  47. TODO("Not yet implemented")
  48. }
  49. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  50. super.onActivityResult(requestCode, resultCode, data)
  51. if (resultCode != Activity.RESULT_OK) {
  52. return
  53. }
  54. if (requestCode == MIntentAction.REQUEST_CODE_THREE) {//图片
  55. val selectList = PictureSelector.obtainMultipleResult(data)
  56. val list = ArrayList<String>()
  57. if (null != selectList) {
  58. if(selectList[0].path.contains("content://")){
  59. val cr = this.contentResolver
  60. list.add( FileUtils.getFilePathFromContentUri(selectList[0].path.toUri(),cr))
  61. }else{
  62. list.add(selectList[0].path)
  63. }
  64. OssUtils(this, vm)
  65. .setUpLoad("idcard", list, this)
  66. }
  67. return
  68. }
  69. if (requestCode == MIntentAction.REQUEST_CODE_CAMERA) {//拍照
  70. //拍照
  71. val selectList = PictureSelector.obtainMultipleResult(data) ?: return
  72. val list = ArrayList<String>()
  73. if(selectList[0].path.contains("content://")){
  74. val cr = this.contentResolver
  75. list.add( FileUtils.getFilePathFromContentUri(selectList[0].path.toUri(),cr))
  76. }else{
  77. list.add(selectList[0].path)
  78. }
  79. OssUtils(this, vm)
  80. .setUpLoad("idcard", list, this)
  81. return
  82. }
  83. }
  84. }