|
@@ -1,5 +1,6 @@
|
|
package com.swago.user
|
|
package com.swago.user
|
|
|
|
|
|
|
|
+import android.Manifest
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
import android.text.Editable
|
|
import android.text.Editable
|
|
@@ -17,6 +18,7 @@ import com.bumptech.glide.Glide
|
|
import com.huantansheng.easyphotos.EasyPhotos
|
|
import com.huantansheng.easyphotos.EasyPhotos
|
|
import com.huantansheng.easyphotos.callback.SelectCallback
|
|
import com.huantansheng.easyphotos.callback.SelectCallback
|
|
import com.huantansheng.easyphotos.models.album.entity.Photo
|
|
import com.huantansheng.easyphotos.models.album.entity.Photo
|
|
|
|
+import com.permissionx.guolindev.PermissionX
|
|
import com.swago.baseswago.UserVm
|
|
import com.swago.baseswago.UserVm
|
|
import com.swago.baseswago.activity.BaseXActivity
|
|
import com.swago.baseswago.activity.BaseXActivity
|
|
import com.swago.baseswago.constant.ARouteConstant
|
|
import com.swago.baseswago.constant.ARouteConstant
|
|
@@ -204,45 +206,54 @@ class EditInfoActivity : BaseXActivity<ActivityUserEditBinding>() {
|
|
|
|
|
|
binding.ivAvatar.setOnClickListener(object : NoDoubleClickListener() {
|
|
binding.ivAvatar.setOnClickListener(object : NoDoubleClickListener() {
|
|
override fun onClick() {
|
|
override fun onClick() {
|
|
- EasyPhotos.createAlbum(
|
|
|
|
- this@EditInfoActivity,
|
|
|
|
- false,
|
|
|
|
- false,
|
|
|
|
- GlideEngine.getInstance()
|
|
|
|
- )
|
|
|
|
- .setFileProviderAuthority(AppContext.getContext().packageName + "/fileprovider")
|
|
|
|
- .setCount(1)//参数说明:最大可选数,默认1
|
|
|
|
- .start(object : SelectCallback() {
|
|
|
|
- override fun onResult(
|
|
|
|
- picList: ArrayList<Photo>?,
|
|
|
|
- isOriginal: Boolean
|
|
|
|
- ) {
|
|
|
|
- if (picList != null && picList.size > 0) {
|
|
|
|
- Glide.with(this@EditInfoActivity).load(picList[0].uri.toString())
|
|
|
|
- .error(R.mipmap.default_avatar).into(binding.ivAvatar)
|
|
|
|
- Luban.with(this@EditInfoActivity)
|
|
|
|
- .load(picList[0].path)
|
|
|
|
- .ignoreBy(100)
|
|
|
|
- .setCompressListener(object : OnCompressListener {
|
|
|
|
- override fun onStart() {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onSuccess(file: File?) {
|
|
|
|
- SwagoLoading.showLoadingDialog(this@EditInfoActivity)
|
|
|
|
- userVm.uploadFile(file.toString())
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onError(e: Throwable?) {}
|
|
|
|
-
|
|
|
|
- }).launch()
|
|
|
|
|
|
+ if (!PermissionX.isGranted(AppContext.getContext(), Manifest.permission.READ_MEDIA_IMAGES) && PermissionX.isGranted(AppContext.getContext(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)){
|
|
|
|
+ val intent = Intent(Intent.ACTION_GET_CONTENT)
|
|
|
|
+ intent.type = "image/*"
|
|
|
|
+ intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
|
|
|
+ startActivityForResult(intent, 112)
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ EasyPhotos.createAlbum(
|
|
|
|
+ this@EditInfoActivity,
|
|
|
|
+ false,
|
|
|
|
+ false,
|
|
|
|
+ GlideEngine.getInstance()
|
|
|
|
+ )
|
|
|
|
+ .setFileProviderAuthority(AppContext.getContext().packageName + "/fileprovider")
|
|
|
|
+ .setCount(1)//参数说明:最大可选数,默认1
|
|
|
|
+ .start(object : SelectCallback() {
|
|
|
|
+ override fun onResult(
|
|
|
|
+ picList: ArrayList<Photo>?,
|
|
|
|
+ isOriginal: Boolean
|
|
|
|
+ ) {
|
|
|
|
+ if (picList != null && picList.size > 0) {
|
|
|
|
+ Glide.with(this@EditInfoActivity).load(picList[0].uri.toString())
|
|
|
|
+ .error(R.mipmap.default_avatar).into(binding.ivAvatar)
|
|
|
|
+ Luban.with(this@EditInfoActivity)
|
|
|
|
+ .load(picList[0].path)
|
|
|
|
+ .ignoreBy(100)
|
|
|
|
+ .setCompressListener(object : OnCompressListener {
|
|
|
|
+ override fun onStart() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onSuccess(file: File?) {
|
|
|
|
+ SwagoLoading.showLoadingDialog(this@EditInfoActivity)
|
|
|
|
+ userVm.uploadFile(file.toString())
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onError(e: Throwable?) {}
|
|
|
|
+
|
|
|
|
+ }).launch()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- override fun onCancel() {
|
|
|
|
|
|
+ override fun onCancel() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
})
|
|
})
|
|
|
|
|
|
}
|
|
}
|
|
@@ -267,6 +278,12 @@ class EditInfoActivity : BaseXActivity<ActivityUserEditBinding>() {
|
|
this@EditInfoActivity.country = country.name
|
|
this@EditInfoActivity.country = country.name
|
|
binding.tvEditCountry.text = country.name
|
|
binding.tvEditCountry.text = country.name
|
|
}
|
|
}
|
|
|
|
+ } else if (requestCode == 112 && resultCode == RESULT_OK){
|
|
|
|
+ data?.data?.let {
|
|
|
|
+ FileUtil.getRealPathFromURI(it)?.let { path ->
|
|
|
|
+ userVm.uploadFile(path)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|