feat:初步完成特权卡发布新增视频功能
This commit is contained in:
@@ -35,7 +35,10 @@ class PrivilegeViewModel : BaseViewModel() {
|
|||||||
description: String,
|
description: String,
|
||||||
effectDay: Int,
|
effectDay: Int,
|
||||||
erbanNoStr: String,
|
erbanNoStr: String,
|
||||||
cardUrl: String
|
cardUrl: String,
|
||||||
|
duration: Long?,
|
||||||
|
cardType: Int,
|
||||||
|
effectUrl: String?,
|
||||||
) {
|
) {
|
||||||
safeLaunch(
|
safeLaunch(
|
||||||
block = {
|
block = {
|
||||||
@@ -46,6 +49,9 @@ class PrivilegeViewModel : BaseViewModel() {
|
|||||||
effectDay,
|
effectDay,
|
||||||
erbanNoStr,
|
erbanNoStr,
|
||||||
cardUrl,
|
cardUrl,
|
||||||
|
duration,
|
||||||
|
cardType,
|
||||||
|
effectUrl,
|
||||||
AvRoomDataManager.get().roomUid.toString()
|
AvRoomDataManager.get().roomUid.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -59,5 +65,4 @@ class PrivilegeViewModel : BaseViewModel() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -4,15 +4,22 @@ import android.annotation.SuppressLint
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
|
import android.util.Log
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
|
import com.bumptech.glide.request.transition.Transition
|
||||||
|
import com.chuhai.utils.PathUtils
|
||||||
import com.hjq.toast.ToastUtils
|
import com.hjq.toast.ToastUtils
|
||||||
import com.netease.nim.uikit.common.util.sys.ScreenUtil
|
import com.netease.nim.uikit.common.util.sys.ScreenUtil
|
||||||
|
import com.netease.nim.uikit.support.glide.GlideApp
|
||||||
import com.nnbc123.app.ErbanTakePhotoActivity.TakePhotoCallBack
|
import com.nnbc123.app.ErbanTakePhotoActivity.TakePhotoCallBack
|
||||||
import com.nnbc123.app.R
|
import com.nnbc123.app.R
|
||||||
import com.nnbc123.app.application.XChatApplication
|
import com.nnbc123.app.application.XChatApplication
|
||||||
@@ -24,21 +31,25 @@ import com.nnbc123.app.common.util.BitmapUtil
|
|||||||
import com.nnbc123.app.databinding.DialogCreatePrivilegeCardBinding
|
import com.nnbc123.app.databinding.DialogCreatePrivilegeCardBinding
|
||||||
import com.nnbc123.app.takephoto.model.TResult
|
import com.nnbc123.app.takephoto.model.TResult
|
||||||
import com.nnbc123.app.ui.utils.ImageLoadUtils
|
import com.nnbc123.app.ui.utils.ImageLoadUtils
|
||||||
import com.nnbc123.app.ui.utils.ImageLoadUtilsV2
|
|
||||||
import com.nnbc123.app.ui.widget.dialog.CommonTipDialog
|
import com.nnbc123.app.ui.widget.dialog.CommonTipDialog
|
||||||
import com.nnbc123.core.file.FileModel
|
import com.nnbc123.core.file.FileModel
|
||||||
import com.nnbc123.core.privilege.bean.PrivilegeCardInfo
|
import com.nnbc123.core.privilege.bean.PrivilegeCardInfo
|
||||||
import com.nnbc123.core.utils.Logger
|
import com.nnbc123.core.utils.Logger
|
||||||
import com.nnbc123.core.utils.TextUtils
|
import com.nnbc123.core.utils.TextUtils
|
||||||
import com.nnbc123.library.common.file.FileHelper
|
import com.nnbc123.library.common.file.FileHelper
|
||||||
import com.nnbc123.library.common.glide.GlideUtils
|
|
||||||
import com.nnbc123.library.common.photo.PhotoProviderNew
|
import com.nnbc123.library.common.photo.PhotoProviderNew
|
||||||
|
import com.nnbc123.library.common.support.PathHelper
|
||||||
import com.nnbc123.library.common.util.PhotoCompressCallback
|
import com.nnbc123.library.common.util.PhotoCompressCallback
|
||||||
import com.nnbc123.library.common.util.PhotoCompressUtil
|
import com.nnbc123.library.common.util.PhotoCompressUtil
|
||||||
import com.nnbc123.library.easyphoto.constant.Type
|
import com.nnbc123.library.easyphoto.constant.Type
|
||||||
|
import com.nnbc123.library.easyphoto.models.album.entity.Photo
|
||||||
import com.nnbc123.library.utils.SingleToastUtil
|
import com.nnbc123.library.utils.SingleToastUtil
|
||||||
|
import com.nnbc123.library.utils.codec.MD5Utils
|
||||||
import com.yalantis.ucrop.UCrop
|
import com.yalantis.ucrop.UCrop
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -82,6 +93,9 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
private var saveTipDialog: CommonTipDialog? = null
|
private var saveTipDialog: CommonTipDialog? = null
|
||||||
|
|
||||||
private var mUrl = ""
|
private var mUrl = ""
|
||||||
|
private var effectUrl: String? = null
|
||||||
|
private var cardType = 0
|
||||||
|
private var duration: Long? = null
|
||||||
|
|
||||||
private var mUri: Uri? = null
|
private var mUri: Uri? = null
|
||||||
private var mJob: Job? = null
|
private var mJob: Job? = null
|
||||||
@@ -103,8 +117,11 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
binding.edExplain.setText(it.description)
|
binding.edExplain.setText(it.description)
|
||||||
binding.edValid.setText(it.effectDay.toString())
|
binding.edValid.setText(it.effectDay.toString())
|
||||||
binding.edId.setText(it.erbanNoStr)
|
binding.edId.setText(it.erbanNoStr)
|
||||||
ImageLoadUtilsV2.loadImage(binding.ivPic, it.cardUrl)
|
loadImage(it.cardUrl)
|
||||||
this.mUrl = it.cardUrl
|
this.mUrl = it.cardUrl
|
||||||
|
this.duration = it.duration
|
||||||
|
this.cardType = it.cardType
|
||||||
|
this.effectUrl = it.effectUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.edName.addTextChangedListener(object : TextWatcher {
|
binding.edName.addTextChangedListener(object : TextWatcher {
|
||||||
@@ -184,10 +201,12 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
|
|
||||||
binding.ivPic.setOnClickListener {
|
binding.ivPic.setOnClickListener {
|
||||||
mUri = Uri.parse("file://${FileHelper.getRootCacheDir()?.path}/${getNowTime()}.jpg")
|
mUri = Uri.parse("file://${FileHelper.getRootCacheDir()?.path}/${getNowTime()}.jpg")
|
||||||
PhotoProviderNew.photoProvider(
|
PhotoProviderNew.photoVideoProvider(
|
||||||
this,
|
this,
|
||||||
canChooseGif = true,
|
canChooseGif = true,
|
||||||
resultCode = REQUEST_CODE_OPEN_PHOTO_PROVIDER
|
resultCode = REQUEST_CODE_OPEN_PHOTO_PROVIDER,
|
||||||
|
maxFileSize = 1024 * 1024 * 100,
|
||||||
|
videoMaxSecond = 15,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
binding.tvCancel.setOnClickListener {
|
binding.tvCancel.setOnClickListener {
|
||||||
@@ -228,7 +247,10 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
binding.edExplain.text.toString(),
|
binding.edExplain.text.toString(),
|
||||||
binding.edValid.text.toString().toInt(),
|
binding.edValid.text.toString().toInt(),
|
||||||
binding.edId.text.toString(),
|
binding.edId.text.toString(),
|
||||||
mUrl
|
mUrl,
|
||||||
|
duration,
|
||||||
|
cardType,
|
||||||
|
effectUrl
|
||||||
)
|
)
|
||||||
saveTipDialog?.dismiss()
|
saveTipDialog?.dismiss()
|
||||||
}
|
}
|
||||||
@@ -266,32 +288,11 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
if (resultCode == BaseActivity.RESULT_OK) {
|
if (resultCode == BaseActivity.RESULT_OK) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQUEST_CODE_OPEN_PHOTO_PROVIDER -> data?.let {
|
REQUEST_CODE_OPEN_PHOTO_PROVIDER -> data?.let {
|
||||||
val photos = PhotoProviderNew.getResultPhotoList(it) ?: return
|
val photo = PhotoProviderNew.getResultPhotoList(it)?.firstOrNull() ?: return
|
||||||
if (photos.isNotEmpty()) {
|
onPhotoResult(photo)
|
||||||
val photo = photos[0]
|
|
||||||
if(photo.path.endsWith(Type.GIF) || photo.type.endsWith(Type.GIF)){
|
|
||||||
FileModel.get()
|
|
||||||
.uploadFile(photo.path)
|
|
||||||
.compose(bindToLifecycle())
|
|
||||||
.subscribe { url: String?, throwable: Throwable? ->
|
|
||||||
if (throwable != null) {
|
|
||||||
SingleToastUtil.showToast("上传失败")
|
|
||||||
} else {
|
|
||||||
url?.let { it1 ->
|
|
||||||
GlideUtils.instance().loadUriGiftAndCrossFadeRound(
|
|
||||||
it1, binding.ivPic, 10f)
|
|
||||||
}
|
|
||||||
if (url != null) {
|
|
||||||
mUrl = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
crop(photo.uri, photo.size, mUri)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
UCrop.REQUEST_CROP ->{
|
|
||||||
|
UCrop.REQUEST_CROP -> {
|
||||||
mUri?.path?.let {
|
mUri?.path?.let {
|
||||||
mJob = PhotoCompressUtil.compress(
|
mJob = PhotoCompressUtil.compress(
|
||||||
context as Activity,
|
context as Activity,
|
||||||
@@ -300,25 +301,7 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
object : PhotoCompressCallback {
|
object : PhotoCompressCallback {
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun onSuccess(compressedImg: String) {
|
override fun onSuccess(compressedImg: String) {
|
||||||
FileModel.get()
|
uploadImage(compressedImg)
|
||||||
.uploadFile(compressedImg)
|
|
||||||
.compose(bindToLifecycle())
|
|
||||||
.subscribe { url: String?, throwable: Throwable? ->
|
|
||||||
if (throwable != null) {
|
|
||||||
SingleToastUtil.showToast("上传失败")
|
|
||||||
} else {
|
|
||||||
ImageLoadUtils.loadRectImage(
|
|
||||||
context,
|
|
||||||
url,
|
|
||||||
binding.ivPic,
|
|
||||||
R.drawable.default_cover,
|
|
||||||
ScreenUtil.dip2px(10f)
|
|
||||||
)
|
|
||||||
if (url != null) {
|
|
||||||
mUrl = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFail(e: Throwable) {
|
override fun onFail(e: Throwable) {
|
||||||
@@ -386,25 +369,12 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun takeSuccess(result: TResult?) {
|
override fun takeSuccess(result: TResult?) {
|
||||||
FileModel.get()
|
val path = result?.image?.compressPath
|
||||||
.uploadFile(result?.image?.compressPath)
|
if (path == null) {
|
||||||
.compose(bindToLifecycle())
|
SingleToastUtil.showToast("文件不存在")
|
||||||
.subscribe { url: String?, throwable: Throwable? ->
|
return
|
||||||
if (throwable != null) {
|
}
|
||||||
SingleToastUtil.showToast("上传失败")
|
uploadImage(path)
|
||||||
} else {
|
|
||||||
ImageLoadUtils.loadRectImage(
|
|
||||||
context,
|
|
||||||
url,
|
|
||||||
binding.ivPic,
|
|
||||||
R.drawable.default_cover,
|
|
||||||
ScreenUtil.dip2px(10f)
|
|
||||||
)
|
|
||||||
if (url != null) {
|
|
||||||
mUrl = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun takeFail(result: TResult?, msg: String?) {
|
override fun takeFail(result: TResult?, msg: String?) {
|
||||||
@@ -420,4 +390,111 @@ class CreatePrivilegeCardDialog : BaseDialog<DialogCreatePrivilegeCardBinding>()
|
|||||||
mJob?.cancel()
|
mJob?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun uploadFile(path: String, onSuccess: (String) -> Unit) {
|
||||||
|
val d = FileModel.get()
|
||||||
|
.uploadFile(path)
|
||||||
|
.compose(bindToLifecycle())
|
||||||
|
.subscribe { url: String?, throwable: Throwable? ->
|
||||||
|
if (throwable != null || url.isNullOrEmpty()) {
|
||||||
|
SingleToastUtil.showToast("上传失败")
|
||||||
|
} else {
|
||||||
|
onSuccess.invoke(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun uploadImage(path: String) {
|
||||||
|
Log.d(TAG, "uploadImage path:${path}")
|
||||||
|
uploadFile(path) {
|
||||||
|
loadImage(path)
|
||||||
|
mUrl = it
|
||||||
|
cardType = 0
|
||||||
|
effectUrl = null
|
||||||
|
duration = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun uploadGif(path: String) {
|
||||||
|
Log.d(TAG, "uploadGif path:${path}")
|
||||||
|
uploadFile(path) {
|
||||||
|
loadImage(path)
|
||||||
|
mUrl = it
|
||||||
|
cardType = 1
|
||||||
|
effectUrl = null
|
||||||
|
duration = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun uploadVideo(photo: Photo) {
|
||||||
|
val path = photo.path
|
||||||
|
Log.d(TAG, "uploadVideo path:${path}")
|
||||||
|
GlideApp.with(this).asBitmap().dontTransform().load(path)
|
||||||
|
.into(object : CustomTarget<Bitmap>() {
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Bitmap,
|
||||||
|
transition: Transition<in Bitmap>?
|
||||||
|
) {
|
||||||
|
val outPath = getImageTempPath(path)
|
||||||
|
lifecycleScope.launch {
|
||||||
|
Log.d(TAG, "uploadVideo 开始保存封面 outPath:${outPath}")
|
||||||
|
val saveResult = com.chuhai.utils.ImageUtils.save(
|
||||||
|
resource,
|
||||||
|
outPath,
|
||||||
|
Bitmap.CompressFormat.JPEG, true
|
||||||
|
)
|
||||||
|
if (saveResult) {
|
||||||
|
Log.d(TAG, "uploadVideo 封面保存成功")
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
uploadFile(outPath) { cover ->
|
||||||
|
uploadFile(path) { video ->
|
||||||
|
loadImage(cover)
|
||||||
|
this@CreatePrivilegeCardDialog.cardType = 2
|
||||||
|
this@CreatePrivilegeCardDialog.duration = photo.duration
|
||||||
|
this@CreatePrivilegeCardDialog.effectUrl = video
|
||||||
|
this@CreatePrivilegeCardDialog.mUrl = cover
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "uploadVideo 保存失败")
|
||||||
|
SingleToastUtil.showToast("文件解析失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
Log.d(TAG, "uploadVideo 封面解析失败")
|
||||||
|
SingleToastUtil.showToast("视频解析失败")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadImage(path: String) {
|
||||||
|
ImageLoadUtils.loadRectImage(
|
||||||
|
context,
|
||||||
|
path,
|
||||||
|
binding.ivPic,
|
||||||
|
R.drawable.default_cover,
|
||||||
|
ScreenUtil.dip2px(10f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onPhotoResult(photo: Photo) {
|
||||||
|
val path = photo.path
|
||||||
|
Log.d(TAG, "onPhotoResult path:$path")
|
||||||
|
if (path.endsWith("mp4") || photo.type.endsWith(Type.VIDEO)) {
|
||||||
|
uploadVideo(photo)
|
||||||
|
} else if (photo.path.endsWith(Type.GIF) || photo.type.endsWith(Type.GIF)) {
|
||||||
|
uploadGif(path)
|
||||||
|
} else {
|
||||||
|
crop(photo.uri, photo.size, mUri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getImageTempPath(path: String): String {
|
||||||
|
return PathUtils.plusPathNotNull(
|
||||||
|
PathHelper.getExternalDownloadCachePath(),
|
||||||
|
"${MD5Utils.getMD5String(path)}.jpeg"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
@@ -25,5 +25,11 @@ data class PrivilegeCardInfo(
|
|||||||
val updateTime: String = "",
|
val updateTime: String = "",
|
||||||
val sendNick: String = "",
|
val sendNick: String = "",
|
||||||
val sendUid: Long = 0L,
|
val sendUid: Long = 0L,
|
||||||
val cardNum: Int = 0
|
val cardNum: Int = 0,
|
||||||
|
//卡片类型 0 图片 1 gif 2 mp4
|
||||||
|
val cardType: Int = 0,
|
||||||
|
// 时长毫秒
|
||||||
|
val duration: Long? = null,
|
||||||
|
// 视频特效url
|
||||||
|
val effectUrl: String? = null
|
||||||
) : Serializable
|
) : Serializable
|
@@ -19,9 +19,31 @@ object PrivilegeModel : BaseModel() {
|
|||||||
api.getPrivilegeCardList(cardStatus, roomUid)
|
api.getPrivilegeCardList(cardStatus, roomUid)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun savePrivilegeCard(cardName: String, dailyNum: Int, description: String, effectDay: Int, erbanNoStr: String, cardUrl: String, roomUid: String): String? =
|
suspend fun savePrivilegeCard(
|
||||||
|
cardName: String,
|
||||||
|
dailyNum: Int,
|
||||||
|
description: String,
|
||||||
|
effectDay: Int,
|
||||||
|
erbanNoStr: String,
|
||||||
|
cardUrl: String,
|
||||||
|
duration: Long?,
|
||||||
|
cardType: Int,
|
||||||
|
effectUrl: String?,
|
||||||
|
roomUid: String
|
||||||
|
): String? =
|
||||||
launchRequest {
|
launchRequest {
|
||||||
api.savePrivilegeCard(cardName, dailyNum, description, effectDay, erbanNoStr, cardUrl, roomUid)
|
api.savePrivilegeCard(
|
||||||
|
cardName,
|
||||||
|
dailyNum,
|
||||||
|
description,
|
||||||
|
effectDay,
|
||||||
|
erbanNoStr,
|
||||||
|
cardUrl,
|
||||||
|
cardType,
|
||||||
|
duration,
|
||||||
|
effectUrl,
|
||||||
|
roomUid
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun deletePrivilegeCard(id: Int): String? =
|
suspend fun deletePrivilegeCard(id: Int): String? =
|
||||||
@@ -55,6 +77,9 @@ object PrivilegeModel : BaseModel() {
|
|||||||
@Query("effectDay") effectDay: Int,
|
@Query("effectDay") effectDay: Int,
|
||||||
@Query("erbanNoStr") erbanNoStr: String,
|
@Query("erbanNoStr") erbanNoStr: String,
|
||||||
@Query("cardUrl") cardUrl: String,
|
@Query("cardUrl") cardUrl: String,
|
||||||
|
@Query("cardType") cardType: Int,
|
||||||
|
@Query("duration") duration: Long?,
|
||||||
|
@Query("effectUrl") effectUrl: String?,
|
||||||
@Query("roomUid") roomUid: String
|
@Query("roomUid") roomUid: String
|
||||||
): ServiceResult<String>
|
): ServiceResult<String>
|
||||||
|
|
||||||
|
@@ -55,13 +55,24 @@ object PhotoProviderNew {
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun photoProviderPublish(activity: Activity, maxSelect: Int = 1, canChooseGif: Boolean = false, resultCode: Int, isClearCache: Boolean = true) {
|
fun photoProviderPublish(
|
||||||
|
activity: Activity,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
canChooseGif: Boolean = false,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(activity, false, false, GlideEngine())//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
EasyPhotos.createAlbum(
|
||||||
|
activity,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GlideEngine()
|
||||||
|
)//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setGif(canChooseGif)
|
.setGif(canChooseGif)
|
||||||
.filter(JPEG, JPG, PNG, WEBP)
|
.filter(JPEG, JPG, PNG, WEBP)
|
||||||
@@ -73,30 +84,46 @@ object PhotoProviderNew {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun videoProvider(activity: Activity, maxSelect: Int = 1, resultCode: Int, isClearCache: Boolean = true) {
|
fun videoProvider(
|
||||||
|
activity: Activity,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(activity, false, false, GlideEngine())
|
EasyPhotos.createAlbum(activity, false, false, GlideEngine())
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setPuzzleMenu(false)
|
.setPuzzleMenu(false)
|
||||||
.onlyVideo()
|
.onlyVideo()
|
||||||
.setCleanMenu(false)
|
.setCleanMenu(false)
|
||||||
.start(resultCode)
|
.start(resultCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun photoProvider(activity: Activity, maxSelect: Int = 1, canChooseGif: Boolean = false, resultCode: Int, isClearCache: Boolean = true) {
|
fun photoProvider(
|
||||||
|
activity: Activity,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
canChooseGif: Boolean = false,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(activity, false, false, GlideEngine())//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
EasyPhotos.createAlbum(
|
||||||
|
activity,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GlideEngine()
|
||||||
|
)//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setGif(canChooseGif)
|
.setGif(canChooseGif)
|
||||||
.setPuzzleMenu(false)
|
.setPuzzleMenu(false)
|
||||||
@@ -107,13 +134,24 @@ object PhotoProviderNew {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun photoProvider(activity: FragmentActivity, maxSelect: Int = 1, canChooseGif: Boolean = false, resultCode: Int, isClearCache: Boolean = true) {
|
fun photoProvider(
|
||||||
|
activity: FragmentActivity,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
canChooseGif: Boolean = false,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(activity, false, false, GlideEngine())//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
EasyPhotos.createAlbum(
|
||||||
|
activity,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GlideEngine()
|
||||||
|
)//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setGif(canChooseGif)
|
.setGif(canChooseGif)
|
||||||
.setPuzzleMenu(false)
|
.setPuzzleMenu(false)
|
||||||
@@ -124,13 +162,25 @@ object PhotoProviderNew {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun photoProvider(fragment: Fragment, maxSelect: Int = 1, canChooseGif: Boolean = false, resultCode: Int, isClearCache: Boolean = true, minFileSize: Long = 0L) {
|
fun photoProvider(
|
||||||
|
fragment: Fragment,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
canChooseGif: Boolean = false,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true,
|
||||||
|
minFileSize: Long = 0L
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(fragment, false, false, GlideEngine())//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
EasyPhotos.createAlbum(
|
||||||
|
fragment,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GlideEngine()
|
||||||
|
)//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setGif(canChooseGif)
|
.setGif(canChooseGif)
|
||||||
.setMinFileSize(minFileSize)
|
.setMinFileSize(minFileSize)
|
||||||
@@ -142,19 +192,39 @@ object PhotoProviderNew {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun photoVideoProvider(fragment: Fragment, maxSelect: Int = 1, canChooseGif: Boolean = false, resultCode: Int, isClearCache: Boolean = true, minFileSize: Long = 0L) {
|
fun photoVideoProvider(
|
||||||
|
fragment: Fragment,
|
||||||
|
maxSelect: Int = 1,
|
||||||
|
canChooseGif: Boolean = false,
|
||||||
|
resultCode: Int,
|
||||||
|
isClearCache: Boolean = true,
|
||||||
|
minFileSize: Long = 0L,
|
||||||
|
maxFileSize: Long = Long.MAX_VALUE,
|
||||||
|
videoMaxSecond: Int = -1
|
||||||
|
) {
|
||||||
cancelJop()
|
cancelJop()
|
||||||
mPhotoJob = MainScope().launch {
|
mPhotoJob = MainScope().launch {
|
||||||
if (isClearCache && isClearByTime()) {
|
if (isClearCache && isClearByTime()) {
|
||||||
withContext(Dispatchers.IO) { clearCache() }
|
withContext(Dispatchers.IO) { clearCache() }
|
||||||
}
|
}
|
||||||
EasyPhotos.createAlbum(fragment, false, false, GlideEngine())//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
EasyPhotos.createAlbum(
|
||||||
|
fragment,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
GlideEngine()
|
||||||
|
)//参数说明:上下文,是否显示相机按钮,是否使用宽高数据(false时宽高数据为0,扫描速度更快),[配置Glide为图片加载引擎](https://github.com/HuanTanSheng/EasyPhotos/wiki/12-%E9%85%8D%E7%BD%AEImageEngine%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%80%E6%9C%89%E5%9B%BE%E7%89%87%E5%8A%A0%E8%BD%BD%E5%BA%93)
|
||||||
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
.setCount(maxSelect)//参数说明:最大可选数,默认1
|
||||||
.setGif(canChooseGif)
|
.setGif(canChooseGif)
|
||||||
.setVideo(true)
|
.setVideo(true)
|
||||||
.setMinFileSize(minFileSize)
|
.setMinFileSize(minFileSize)
|
||||||
|
.setMaxFileSize(maxFileSize)
|
||||||
.setPuzzleMenu(false)
|
.setPuzzleMenu(false)
|
||||||
.setCleanMenu(false)
|
.setCleanMenu(false)
|
||||||
|
.apply {
|
||||||
|
if (videoMaxSecond > 0) {
|
||||||
|
setVideoMaxSecond(videoMaxSecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
.start(resultCode)
|
.start(resultCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,7 +270,10 @@ object PhotoProviderNew {
|
|||||||
val path = "$foldPath${it.name}"
|
val path = "$foldPath${it.name}"
|
||||||
if (FileHelper.copyFileFromUri(it.uri, path, true)) {
|
if (FileHelper.copyFileFromUri(it.uri, path, true)) {
|
||||||
newPaths.add(path)
|
newPaths.add(path)
|
||||||
Logger.debug(TAG, "path: ${it.path} , displayName: ${it.name} , newPath: $path ")
|
Logger.debug(
|
||||||
|
TAG,
|
||||||
|
"path: ${it.path} , displayName: ${it.name} , newPath: $path "
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,8 +288,12 @@ object PhotoProviderNew {
|
|||||||
*/
|
*/
|
||||||
fun clearCache() {
|
fun clearCache() {
|
||||||
Logger.debug(
|
Logger.debug(
|
||||||
TAG, "clearCache => mLastSelectTime: ${TimeUtils.getDateTimeString(
|
TAG, "clearCache => mLastSelectTime: ${
|
||||||
mLastSelectTime, TIME_FORMAT)}")
|
TimeUtils.getDateTimeString(
|
||||||
|
mLastSelectTime, TIME_FORMAT
|
||||||
|
)
|
||||||
|
}"
|
||||||
|
)
|
||||||
FileHelper.removeAllFile(getInternalPath() + File.separator)
|
FileHelper.removeAllFile(getInternalPath() + File.separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user