feat: 媒体文件上传控件优化(一) https://jira.shanqu.cc/browse/GHZSCY-6282
This commit is contained in:
@ -21,6 +21,8 @@ import com.gh.common.view.RichEditor
|
||||
import com.gh.gamecenter.CropImageActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.base.activity.ToolBarActivity
|
||||
import com.gh.gamecenter.common.entity.LocalVideoEntity
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.core.runOnIoThread
|
||||
@ -30,6 +32,7 @@ import com.gh.gamecenter.feature.entity.GameEntity
|
||||
import com.gh.gamecenter.qa.editor.*
|
||||
import com.gh.gamecenter.feature.entity.AnswerEntity
|
||||
import com.gh.gamecenter.feature.entity.ArticleEntity
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.qa.entity.EditorInsertEntity
|
||||
import com.gh.gamecenter.video.poster.PosterEditActivity
|
||||
import com.gh.gamecenter.video.upload.UploadManager
|
||||
@ -502,7 +505,7 @@ abstract class BaseRichEditorActivity<VM : BaseRichEditorViewModel> constructor(
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
this@BaseRichEditorActivity,
|
||||
LocalMediaActivity.ChooseType.VIDEO,
|
||||
ChooseType.VIDEO,
|
||||
maxChooseCount,
|
||||
if (mtaEventName() == "提问帖") "发提问帖" else "发帖子"
|
||||
), INSERT_MEDIA_VIDEO_CODE
|
||||
@ -531,7 +534,7 @@ abstract class BaseRichEditorActivity<VM : BaseRichEditorViewModel> constructor(
|
||||
val maxChooseCount = if (imageCount + 10 <= MAX_IMAGE_COUNT) 10 else MAX_IMAGE_COUNT - imageCount
|
||||
val intent = LocalMediaActivity.getIntent(
|
||||
this@BaseRichEditorActivity,
|
||||
LocalMediaActivity.ChooseType.IMAGE,
|
||||
ChooseType.IMAGE,
|
||||
maxChooseCount,
|
||||
if (mtaEventName() == "提问帖") "发提问帖" else "发帖子"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ import com.gh.gamecenter.core.runOnUiThread
|
||||
import com.gh.gamecenter.core.utils.MD5Utils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.entity.ForumDetailEntity
|
||||
import com.gh.gamecenter.entity.LocalVideoEntity
|
||||
import com.gh.gamecenter.common.entity.LocalVideoEntity
|
||||
import com.gh.gamecenter.entity.QuoteCountEntity
|
||||
import com.gh.gamecenter.qa.BbsType
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
@ -39,8 +39,6 @@ import retrofit2.HttpException
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.collections.LinkedHashMap
|
||||
import kotlin.collections.set
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ import com.gh.gamecenter.common.entity.SensorsEvent
|
||||
import com.gh.gamecenter.common.retrofit.Response
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.common.utils.ImageUtils.getIdealImageUrl
|
||||
import com.gh.gamecenter.common.view.DragListener
|
||||
import com.gh.gamecenter.common.view.DraggableBigImageView
|
||||
import com.gh.gamecenter.common.view.Gh_RelativeLayout
|
||||
import com.gh.gamecenter.core.runOnIoThread
|
||||
@ -815,18 +816,18 @@ class ImageViewerActivity : BaseActivity(), OnPageChangeListener {
|
||||
if (mBigImageView == null) {
|
||||
mBigImageView = imageView
|
||||
}
|
||||
imageView.setDragListener(object : DraggableBigImageView.DragListener {
|
||||
override fun onRelease(draggableBigImageView: DraggableBigImageView, scale: Float) {
|
||||
imageView.setDragListener(object : DragListener {
|
||||
override fun onRelease(scale: Float) {
|
||||
updateOriginPosition(mViewPager.currentItem)
|
||||
performExitAnimation(draggableBigImageView, scale, isFadeOnly())
|
||||
performExitAnimation(imageView, scale, isFadeOnly())
|
||||
}
|
||||
|
||||
override fun onDrag(draggableBigImageView: DraggableBigImageView, fraction: Float) {
|
||||
override fun onDrag(fraction: Float) {
|
||||
mBackgroundView.alpha = 1 - fraction
|
||||
mIndicatorMask.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun onRestore(draggableBigImageView: DraggableBigImageView, fraction: Float) {
|
||||
override fun onRestore(fraction: Float) {
|
||||
mBackgroundView.alpha = 1F
|
||||
// mIndicatorMask.goneIf(mUrlList?.size == 1)
|
||||
if (mUrlList?.size != 1 || mAnswerEntity != null) {
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
class LocalVideoEntity(
|
||||
var id: String = "",
|
||||
var filePath: String = "",
|
||||
var poster: String = "",
|
||||
var contentUri: Uri? = null,
|
||||
var duration: Long = 0,
|
||||
var format: String = "",
|
||||
var size: Long = 0
|
||||
) : Parcelable
|
||||
@ -3,7 +3,6 @@ package com.gh.gamecenter.game.upload
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.text.TextPaint
|
||||
@ -29,18 +28,21 @@ import com.gh.gamecenter.WebActivity
|
||||
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
|
||||
import com.gh.gamecenter.common.callback.OnListClickListener
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.common.view.choosepic.ChoosePicAdapter
|
||||
import com.gh.gamecenter.core.utils.GsonUtils
|
||||
import com.gh.gamecenter.core.utils.MtaHelper
|
||||
import com.gh.gamecenter.core.utils.SpanBuilder
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.databinding.FragmentGameUploadBinding
|
||||
import com.gh.gamecenter.feature.entity.InstallGameEntity
|
||||
import com.gh.gamecenter.feature.game.SelectGameAdapter
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Util_System_Keyboard
|
||||
import com.lightgame.utils.Utils
|
||||
import com.zhihu.matisse.Matisse
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
import io.reactivex.disposables.Disposable
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
@ -86,7 +88,6 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
mViewModel.upLoadSuccess.observe(viewLifecycleOwner, Observer {
|
||||
if (it) {
|
||||
ToastUtils.showToast("上传成功")
|
||||
MtaHelper.onEvent("游戏上传", "游戏上传", "上传成功")
|
||||
mUploadDialog.dismiss()
|
||||
requireActivity().finish()
|
||||
} else {
|
||||
@ -119,17 +120,11 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
5,
|
||||
object : OnListClickListener {
|
||||
override fun <T : Any?> onListClick(view: View?, position: Int, data: T) {
|
||||
MtaHelper.onEvent("游戏上传", "游戏图片", "添加图片")
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
val intent = LocalMediaActivity.getIntent(requireContext(), ChooseType.IMAGE, 1, "游戏上传")
|
||||
startActivityForResult(intent, MEDIA_STORE_REQUEST)
|
||||
}
|
||||
}
|
||||
) {
|
||||
MtaHelper.onEvent(
|
||||
"游戏上传",
|
||||
"游戏图片",
|
||||
"删除图片"
|
||||
)
|
||||
}
|
||||
mAdapter?.setPicItem(R.layout.game_upload_pic_item)
|
||||
mAdapter?.setSuggestAddPicIcon(R.drawable.icon_pic_add)
|
||||
@ -147,19 +142,13 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
1,
|
||||
object : OnListClickListener {
|
||||
override fun <T : Any?> onListClick(view: View?, position: Int, data: T) {
|
||||
MtaHelper.onEvent("游戏上传", "游戏图标", "添加图片")
|
||||
PermissionHelper.checkStoragePermissionBeforeAction(requireActivity()) {
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
val intent = LocalMediaActivity.getIntent(requireContext(), ChooseType.IMAGE, 1, "游戏上传")
|
||||
startActivityForResult(intent, MEDIA_ICON_STORE_REQUEST)
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
MtaHelper.onEvent(
|
||||
"游戏上传",
|
||||
"游戏图标",
|
||||
"删除图片"
|
||||
)
|
||||
}
|
||||
mIconAdapter?.setPicItem(R.layout.game_upload_pic_item)
|
||||
mIconAdapter?.setSuggestAddPicIcon(R.drawable.icon_pic_add)
|
||||
@ -194,18 +183,15 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
private fun initListener() {
|
||||
|
||||
mBinding.chooseGameLl.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏上传", "安装包", "点我选择")
|
||||
showSelectDialog()
|
||||
}
|
||||
mBinding.gameIsNetworkingRg.setOnCheckedChangeListener { _, checkedId ->
|
||||
when (checkedId) {
|
||||
R.id.gameNetworkingRb -> {
|
||||
mIsOnline = "yes"
|
||||
MtaHelper.onEvent("游戏上传", "是否联网", "需要联网")
|
||||
}
|
||||
R.id.gameNoNetworkingRb -> {
|
||||
mIsOnline = "no"
|
||||
MtaHelper.onEvent("游戏上传", "是否联网", "无需联网")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,15 +199,12 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
when (checkedId) {
|
||||
R.id.gameLanguageChineseRb -> {
|
||||
mGameLanguage = "中文"
|
||||
MtaHelper.onEvent("游戏上传", "游戏语言", "中文")
|
||||
}
|
||||
R.id.gameLanguageEnglishRb -> {
|
||||
mGameLanguage = "英文"
|
||||
MtaHelper.onEvent("游戏上传", "游戏语言", "英文")
|
||||
}
|
||||
R.id.gameLanguageOtherRb -> {
|
||||
mGameLanguage = "其他"
|
||||
MtaHelper.onEvent("游戏上传", "游戏语言", "其他")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,21 +212,17 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
when (checkedId) {
|
||||
R.id.gameTypeLocalRb -> {
|
||||
mGameType = "local"
|
||||
MtaHelper.onEvent("游戏上传", "游戏类型", "单机")
|
||||
}
|
||||
R.id.gameTypeOnlineRb -> {
|
||||
mGameType = "online"
|
||||
MtaHelper.onEvent("游戏上传", "游戏类型", "网游")
|
||||
}
|
||||
R.id.gameTypeOtherRb -> {
|
||||
mGameType = "other"
|
||||
MtaHelper.onEvent("游戏上传", "游戏类型", "其他")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mBinding.addGameLabeTv.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏上传", "游戏标签", "添加标签")
|
||||
if (mTags.size < mMaxTagSize) {
|
||||
showAddTagDialog()
|
||||
} else {
|
||||
@ -256,7 +235,6 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
}
|
||||
|
||||
private fun commit() {
|
||||
MtaHelper.onEvent("游戏上传", "提交", "提交")
|
||||
if (TextUtils.isEmpty(mBinding.tvChoose.text.toString())) {
|
||||
ToastUtils.showToast("请先选择游戏安装包")
|
||||
return
|
||||
@ -471,11 +449,9 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
}
|
||||
|
||||
back.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏上传", "安装包", "关闭")
|
||||
mSelectGameDialog?.cancel()
|
||||
}
|
||||
manualBtn.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏上传", "安装包", "从设备上选择")
|
||||
val intent = CleanApkActivity.getIntent(requireContext(), true)
|
||||
PermissionHelper.checkManageAllFilesOrStoragePermissionBeforeAction(requireActivity()) {
|
||||
startActivityForResult(intent, CHOOSE_LOCAL_APK)
|
||||
@ -499,32 +475,20 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (data == null) return
|
||||
if (requestCode == MEDIA_STORE_REQUEST || requestCode == MEDIA_ICON_STORE_REQUEST) {
|
||||
val selectedImage = data.data ?: return
|
||||
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
|
||||
val selectedPaths = Matisse.obtainResult(data) ?: return
|
||||
val picturePath = PathUtils.getPath(requireContext(), selectedPaths[0])
|
||||
|
||||
val cursor = requireContext().contentResolver.query(selectedImage, filePathColumn, null, null, null)
|
||||
?: return
|
||||
cursor.moveToFirst()
|
||||
Utils.log("picturePath = $picturePath")
|
||||
|
||||
try {
|
||||
val columnIndex = cursor.getColumnIndex(filePathColumn[0])
|
||||
val picturePath = cursor.getString(columnIndex)
|
||||
cursor.close()
|
||||
|
||||
Utils.log("picturePath = $picturePath")
|
||||
|
||||
val file = File(picturePath)
|
||||
if (file.length() > 5 * 1024 * 1024) {
|
||||
ToastUtils.showToast(getString(R.string.pic_max_hint, 5))
|
||||
val file = File(picturePath)
|
||||
if (file.length() > 5 * 1024 * 1024) {
|
||||
ToastUtils.showToast(getString(R.string.pic_max_hint, 5))
|
||||
} else {
|
||||
if (requestCode == MEDIA_STORE_REQUEST) {
|
||||
mAdapter!!.addFileList(picturePath)
|
||||
} else {
|
||||
if (requestCode == MEDIA_STORE_REQUEST) {
|
||||
mAdapter!!.addFileList(picturePath)
|
||||
} else {
|
||||
mIconAdapter!!.addFileList(picturePath)
|
||||
}
|
||||
mIconAdapter!!.addFileList(picturePath)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.showToast(e.message ?: "")
|
||||
}
|
||||
} else if (requestCode == CHOOSE_LOCAL_APK) {
|
||||
val packageName = data.getStringExtra(EntranceConsts.KEY_PACKAGENAME) ?: ""
|
||||
@ -610,7 +574,6 @@ class GameUploadFragment : ToolbarFragment() {
|
||||
labelTv.text = tag
|
||||
labelView.findViewById<View>(R.id.picDelIv).setOnClickListener {
|
||||
if (mTags.contains(tag)) {
|
||||
MtaHelper.onEvent("游戏上传", "游戏标签", "删除标签")
|
||||
mBinding.gameLabelFl.removeView(labelView)
|
||||
mTags.remove(tag)
|
||||
mBinding.gameLabelFl.goneIf(mTags.isEmpty())
|
||||
|
||||
@ -16,12 +16,13 @@ import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.common.util.NewLogUtils
|
||||
import com.gh.gamecenter.common.utils.PermissionHelper
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.setRootBackgroundDrawable
|
||||
import com.gh.gamecenter.common.utils.toColor
|
||||
import com.gh.gamecenter.common.utils.toDrawable
|
||||
import com.gh.gamecenter.databinding.DialogChooseGameCollectionCoverTypeBinding
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.gamecollection.publish.GameCollectionEditActivity.Companion.REQUEST_CODE_IMAGE
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.halo.assistant.HaloApp
|
||||
|
||||
class ChooseGameCollectionCoverTypeDialog : BaseDialogFragment() {
|
||||
@ -42,7 +43,7 @@ class ChooseGameCollectionCoverTypeDialog : BaseDialogFragment() {
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.IMAGE,
|
||||
ChooseType.IMAGE,
|
||||
1,
|
||||
"创建游戏单"
|
||||
), REQUEST_CODE_IMAGE
|
||||
|
||||
@ -10,20 +10,20 @@ import android.view.View
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.CropImageActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
|
||||
import com.gh.gamecenter.common.base.fragment.WaitingDialogFragment
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.common.entity.ErrorEntity
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.utils.*
|
||||
import com.gh.gamecenter.databinding.FragmentBackgroundPreviewBinding
|
||||
import com.gh.gamecenter.feature.entity.BackgroundImageEntity
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.login.user.UserManager
|
||||
import com.gh.gamecenter.login.user.UserViewModel
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.zhihu.matisse.Matisse
|
||||
import io.reactivex.Single
|
||||
@ -282,7 +282,7 @@ class BackgroundPreviewFragment : ToolbarFragment() {
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.IMAGE,
|
||||
ChooseType.IMAGE,
|
||||
1,
|
||||
"个性背景"
|
||||
), MEDIA_STORE_REQUEST
|
||||
|
||||
@ -12,12 +12,13 @@ import com.gh.gamecenter.CropImageActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
|
||||
import com.gh.gamecenter.common.base.fragment.WaitingDialogFragment
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.PermissionHelper
|
||||
import com.gh.gamecenter.common.utils.viewModelProvider
|
||||
import com.gh.gamecenter.common.view.GridSpacingItemColorDecoration
|
||||
import com.gh.gamecenter.databinding.PersonalityBackgroundFragmentBinding
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.login.user.UserViewModel
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.zhihu.matisse.Matisse
|
||||
|
||||
@ -75,7 +76,7 @@ class PersonalityBackgroundFragment : ToolbarFragment() {
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.IMAGE,
|
||||
ChooseType.IMAGE,
|
||||
1,
|
||||
"个性背景"
|
||||
), MEDIA_STORE_REQUEST
|
||||
|
||||
@ -28,6 +28,7 @@ import com.gh.gamecenter.common.baselist.ListAdapter
|
||||
import com.gh.gamecenter.common.baselist.ListFragment
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts.KEY_COMMENT_ID
|
||||
import com.gh.gamecenter.common.eventbus.EBReuse
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.syncpage.SyncDataEntity
|
||||
import com.gh.gamecenter.common.syncpage.SyncFieldConstants
|
||||
import com.gh.gamecenter.common.syncpage.SyncPageRepository
|
||||
@ -38,10 +39,10 @@ import com.gh.gamecenter.databinding.ItemCommentEditImageBinding
|
||||
import com.gh.gamecenter.eventbus.EBCommentSuccess
|
||||
import com.gh.gamecenter.feature.entity.CommentEntity
|
||||
import com.gh.gamecenter.feature.eventbus.EBDeleteComment
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.qa.comment.CommentActivity.Companion.GAME_COLLECTION_ID
|
||||
import com.gh.gamecenter.qa.comment.CommentActivity.Companion.GAME_COLLECTION_TITLE
|
||||
import com.gh.gamecenter.qa.comment.CommentActivity.Companion.QUESTION_ID
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Util_System_Keyboard
|
||||
import com.lightgame.utils.Utils
|
||||
@ -494,7 +495,7 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
|
||||
val maxChooseCount = 9 - mViewModel.pictureList.size
|
||||
val intent = LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.IMAGE,
|
||||
ChooseType.IMAGE,
|
||||
maxChooseCount,
|
||||
"评论列表"
|
||||
)
|
||||
@ -521,11 +522,6 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
|
||||
return
|
||||
}
|
||||
|
||||
if (mShowInputOnly) {
|
||||
// Fuck pm
|
||||
MtaHelper.onEvent("帖子详情", "评论详情-全部回复", "发送")
|
||||
}
|
||||
|
||||
mViewModel.postPictureAndComment(content, mCommentEntity)
|
||||
}
|
||||
|
||||
|
||||
@ -1,148 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ImageView
|
||||
import android.widget.PopupWindow
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.gh.gamecenter.common.base.activity.ToolBarActivity
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.utils.updateStatusBarColor
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.zhihu.matisse.Matisse
|
||||
import com.zhihu.matisse.MimeType
|
||||
import com.zhihu.matisse.internal.entity.Album
|
||||
import com.zhihu.matisse.internal.entity.SelectionSpec
|
||||
import com.zhihu.matisse.internal.model.AlbumCollection
|
||||
|
||||
/**
|
||||
* 选择本地视频/图片
|
||||
*/
|
||||
class LocalMediaActivity : ToolBarActivity(), AlbumCollection.AlbumCallbacks {
|
||||
private var mLocalMediaFragment: LocalMediaFragment? = null
|
||||
private lateinit var mAlbumsSpinner: VideoAlbumsSpanner
|
||||
private lateinit var mAlbumsAdapter: VideoAlbumsAdapter
|
||||
private val mAlbumCollection = AlbumCollection()
|
||||
private var mIsFirstAlbumLoad = true
|
||||
private var mChooseType = ""
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.activity_video_tablayout_viewpager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
updateStatusBarColor(R.color.ui_surface, R.color.ui_surface)
|
||||
mChooseType = intent.getStringExtra(EntranceConsts.KEY_TYPE) ?: ""
|
||||
if (mChooseType == ChooseType.VIDEO.value) {
|
||||
setNavigationTitle("本地视频")
|
||||
} else {
|
||||
setNavigationTitle("本地图片")
|
||||
}
|
||||
mLocalMediaFragment = LocalMediaFragment().apply { arguments = intent.extras }
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, mLocalMediaFragment!!, LocalMediaFragment::class.java.name)
|
||||
.commitAllowingStateLoss()
|
||||
initAlbumsSpinner()
|
||||
mTitleTv.setOnClickListener {
|
||||
mAlbumsSpinner.show(findViewById<View>(R.id.container).height)
|
||||
setPhotoNavigationTitle(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initAlbumsSpinner() {
|
||||
mAlbumsSpinner = VideoAlbumsSpanner(this)
|
||||
mAlbumsAdapter = VideoAlbumsAdapter(this)
|
||||
|
||||
mAlbumsSpinner.setPopupAnchorView(findViewById(R.id.normal_toolbar))
|
||||
mAlbumsSpinner.setAdapter(mAlbumsAdapter)
|
||||
mAlbumsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
mAlbumCollection.setStateCurrentSelection(position)
|
||||
mAlbumsAdapter.cursor.moveToPosition(position)
|
||||
val album = Album.valueOf(mAlbumsAdapter.cursor)
|
||||
if (album.isAll && SelectionSpec.getInstance().capture) {
|
||||
album.addCaptureCount()
|
||||
}
|
||||
if (mLocalMediaFragment?.isAdded == true) {
|
||||
mLocalMediaFragment?.loadVideos(album)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mAlbumsSpinner.setDismissListener(PopupWindow.OnDismissListener {
|
||||
setPhotoNavigationTitle(false)
|
||||
})
|
||||
//必须加这行代码,[SelectionSpec]是单例模式,下次使用必须先更新MimeType
|
||||
val mimeType = if (mChooseType == ChooseType.VIDEO.value) {
|
||||
MimeType.ofVideo()
|
||||
} else {
|
||||
MimeType.ofImage()
|
||||
}
|
||||
val maxChooseCount = intent.getIntExtra(EntranceConsts.KEY_CHOOSE_MAX_COUNT, 1)
|
||||
Matisse.from(this).choose(mimeType).showSingleMediaType(true).maxSelectable(maxChooseCount)
|
||||
mAlbumCollection.onCreate(this, this)
|
||||
mAlbumCollection.loadAlbums()
|
||||
}
|
||||
|
||||
override fun onAlbumLoad(cursor: Cursor?) {
|
||||
if (mIsFirstAlbumLoad) {
|
||||
mIsFirstAlbumLoad = false
|
||||
mAlbumsAdapter.swapCursor(cursor)
|
||||
mBaseHandler.post {
|
||||
cursor?.moveToPosition(mAlbumCollection.currentSelection)
|
||||
val album = Album.valueOf(cursor)
|
||||
if (album.isAll && SelectionSpec.getInstance().capture) {
|
||||
album.addCaptureCount()
|
||||
}
|
||||
if (mLocalMediaFragment?.isAdded == true) {
|
||||
mLocalMediaFragment?.loadVideos(album)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onAlbumReset() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun setPhotoNavigationTitle(up: Boolean) {
|
||||
val drawable = ContextCompat.getDrawable(
|
||||
HaloApp.getInstance().application,
|
||||
if (up) R.drawable.ic_video_arrow_up else R.drawable.ic_video_arrow_down
|
||||
)
|
||||
val arrowIv = findViewById<ImageView>(R.id.arrowIv)
|
||||
arrowIv?.setImageDrawable(drawable)
|
||||
}
|
||||
|
||||
override fun isAutoResetViewBackgroundEnabled(): Boolean = true
|
||||
|
||||
override fun onDarkModeChanged() {
|
||||
super.onDarkModeChanged()
|
||||
updateStatusBarColor(R.color.ui_surface, R.color.ui_surface)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getIntent(context: Context, chooseType: ChooseType, maxChooseCount: Int = 1, entrance: String): Intent {
|
||||
return Intent(context, LocalMediaActivity::class.java).apply {
|
||||
putExtra(EntranceConsts.KEY_TYPE, chooseType.value)
|
||||
putExtra(EntranceConsts.KEY_CHOOSE_MAX_COUNT, maxChooseCount)
|
||||
putExtra(EntranceConsts.KEY_ENTRANCE, entrance)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class ChooseType(val value: String) {
|
||||
VIDEO("video"),
|
||||
IMAGE("image")
|
||||
}
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.core.utils.TimeUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.common.utils.goneIf
|
||||
import com.gh.gamecenter.common.utils.toDrawable
|
||||
import com.gh.gamecenter.common.utils.ImageUtils
|
||||
import com.gh.gamecenter.databinding.LocalVideoItemBinding
|
||||
import com.zhihu.matisse.internal.entity.Item
|
||||
import com.zhihu.matisse.internal.ui.adapter.RecyclerViewCursorAdapter
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
|
||||
class LocalMediaAdapter(
|
||||
val context: Context,
|
||||
val mChooseType: String,
|
||||
val maxChooseSize: Int,
|
||||
val entrance: String,
|
||||
val callback: (ArrayList<Item>) -> Unit
|
||||
) : RecyclerViewCursorAdapter<LocalVideoPreviewViewHolder>(null) {
|
||||
private val mSelectedMediaList = arrayListOf<Item>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LocalVideoPreviewViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.local_video_item, parent, false)
|
||||
return LocalVideoPreviewViewHolder(LocalVideoItemBinding.bind(view))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: LocalVideoPreviewViewHolder, cursor: Cursor?, position: Int) {
|
||||
val item = Item.valueOf(cursor)
|
||||
holder.binding.durationTv.goneIf(mChooseType == LocalMediaActivity.ChooseType.IMAGE.value)
|
||||
val path = "file:///${PathUtils.getPath(context, item.contentUri)}"
|
||||
ImageUtils.displayResizeMedia(holder.binding.preview, path, 200, 200)
|
||||
holder.binding.durationTv.text = TimeUtils.formatVideoDuration(item.duration / 1000)
|
||||
val drawable = if (mSelectedMediaList.contains(item)) {
|
||||
if (maxChooseSize == 1) {
|
||||
R.drawable.ic_choose_media_selected.toDrawable()
|
||||
} else {
|
||||
R.drawable.ic_choose_media_bg.toDrawable()
|
||||
}
|
||||
} else {
|
||||
R.drawable.ic_choose_media_normal.toDrawable()
|
||||
}
|
||||
holder.binding.checkImageView.setImageDrawable(drawable)
|
||||
if (mSelectedMediaList.contains(item) && maxChooseSize > 1) {
|
||||
holder.binding.chooseCountTv.visibility = View.VISIBLE
|
||||
holder.binding.chooseCountTv.text = (mSelectedMediaList.indexOf(item) + 1).toString()
|
||||
} else {
|
||||
holder.binding.chooseCountTv.visibility = View.GONE
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
if (mSelectedMediaList.contains(item)) {
|
||||
mSelectedMediaList.remove(item)
|
||||
notifyDataSetChanged()
|
||||
callback.invoke(mSelectedMediaList)
|
||||
} else {
|
||||
if (maxChooseSize == 1) {
|
||||
mSelectedMediaList.clear()
|
||||
}
|
||||
if (mSelectedMediaList.size < maxChooseSize) {
|
||||
mSelectedMediaList.add(item)
|
||||
notifyDataSetChanged()
|
||||
callback.invoke(mSelectedMediaList)
|
||||
} else {
|
||||
if (mChooseType == LocalMediaActivity.ChooseType.IMAGE.value) {
|
||||
ToastUtils.showToast("至多选择${maxChooseSize}张图片")
|
||||
} else {
|
||||
ToastUtils.showToast("至多选择${maxChooseSize}条视频")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entrance == "发帖子" || entrance == "发提问帖" || entrance == "发视频帖") {
|
||||
val publishContentType = if (entrance == "发帖子") "帖子" else if (entrance == "发提问帖") "提问帖" else "视频帖"
|
||||
val publishMediaType = if (mChooseType == LocalMediaActivity.ChooseType.IMAGE.value) "图片" else "视频"
|
||||
NewLogUtils.logChooseMedia("click_radio_button", publishContentType, publishMediaType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int, cursor: Cursor?): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun getSelectedMediaList(): ArrayList<Item> {
|
||||
return mSelectedMediaList
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVideoPreviewViewHolder(val binding: LocalVideoItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
|
||||
@ -1,191 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.gh.common.util.NewLogUtils
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.base.fragment.BaseFragment
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.common.utils.dip2px
|
||||
import com.gh.gamecenter.common.utils.toColor
|
||||
import com.gh.gamecenter.common.utils.tryWithDefaultCatch
|
||||
import com.gh.gamecenter.common.view.GridSpacingItemDecoration
|
||||
import com.gh.gamecenter.core.utils.MD5Utils
|
||||
import com.gh.gamecenter.databinding.FragmentLocalMediaBinding
|
||||
import com.gh.gamecenter.entity.LocalVideoEntity
|
||||
import com.zhihu.matisse.internal.entity.Album
|
||||
import com.zhihu.matisse.internal.entity.Item
|
||||
import com.zhihu.matisse.internal.model.AlbumMediaCollection
|
||||
import com.zhihu.matisse.internal.model.SelectedItemCollection
|
||||
import com.zhihu.matisse.internal.ui.BasePreviewActivity
|
||||
import com.zhihu.matisse.internal.ui.SelectedPreviewActivity
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
import com.zhihu.matisse.ui.MatisseActivity
|
||||
|
||||
class LocalMediaFragment : BaseFragment<Any>(), AlbumMediaCollection.AlbumMediaCallbacks {
|
||||
private lateinit var mBinding: FragmentLocalMediaBinding
|
||||
private lateinit var mAdapter: LocalMediaAdapter
|
||||
private var mAlbumMediaCollection: AlbumMediaCollection? = null
|
||||
private var mChooseType = ""
|
||||
|
||||
override fun getLayoutId(): Int = 0
|
||||
|
||||
override fun getInflatedLayout(): View {
|
||||
mBinding = FragmentLocalMediaBinding.inflate(LayoutInflater.from(requireContext()), null, false)
|
||||
return mBinding.root
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
mChooseType = arguments?.getString(EntranceConsts.KEY_TYPE) ?: ""
|
||||
// mBinding.reuseNoneData.reuseNoneDataTv.text = "暂无数据~"
|
||||
mBinding.listRv.layoutManager = GridLayoutManager(requireContext(), 3)
|
||||
mBinding.listRv.addItemDecoration(GridSpacingItemDecoration(3, 4F.dip2px(), false))
|
||||
val maxChooseCount = arguments?.getInt(EntranceConsts.KEY_CHOOSE_MAX_COUNT, 1)
|
||||
mAdapter = LocalMediaAdapter(
|
||||
requireContext(), mChooseType, maxChooseCount
|
||||
?: 1, mEntrance
|
||||
) {
|
||||
mBinding.previewTv.isEnabled = it.isNotEmpty()
|
||||
mBinding.confirmTv.isEnabled = it.isNotEmpty()
|
||||
if (it.isEmpty()) {
|
||||
mBinding.previewTv.setTextColor(R.color.text_instance.toColor(requireContext()))
|
||||
mBinding.confirmTv.alpha = 0.6f
|
||||
} else {
|
||||
mBinding.previewTv.setTextColor(R.color.text_secondary.toColor(requireContext()))
|
||||
mBinding.confirmTv.alpha = 1f
|
||||
}
|
||||
mBinding.numTv.text = "(${it.size}/${mAdapter.maxChooseSize})"
|
||||
}
|
||||
mBinding.numTv.text = "(0/${mAdapter.maxChooseSize})"
|
||||
mBinding.listRv.adapter = mAdapter
|
||||
mBinding.listRefresh.isEnabled = false
|
||||
|
||||
val publishContentType = if (mEntrance == "发帖子") "帖子" else if (mEntrance == "发提问帖") "提问帖" else "视频帖"
|
||||
val publishMediaType = if (mChooseType == LocalMediaActivity.ChooseType.IMAGE.value) "图片" else "视频"
|
||||
mBinding.previewTv.setOnClickListener {
|
||||
if (mChooseType == LocalMediaActivity.ChooseType.VIDEO.value) {
|
||||
val intent = PreviewVideoActivity.getIntent(requireContext(), mAdapter.getSelectedMediaList())
|
||||
requireActivity().startActivityForResult(intent, PREVIEW_VIDEO)
|
||||
NewLogUtils.logChooseMedia("click_preview", publishContentType, publishMediaType)
|
||||
} else {
|
||||
val intent = Intent(requireContext(), SelectedPreviewActivity::class.java)
|
||||
val bundle = bundleOf(
|
||||
SelectedItemCollection.STATE_SELECTION to mAdapter.getSelectedMediaList(),
|
||||
SelectedItemCollection.STATE_COLLECTION_TYPE to SelectedItemCollection.COLLECTION_IMAGE
|
||||
)
|
||||
intent.putExtra(BasePreviewActivity.EXTRA_DEFAULT_BUNDLE, bundle)
|
||||
startActivityForResult(intent, PREVIEW_IMAGE)
|
||||
}
|
||||
|
||||
}
|
||||
mBinding.confirmTv.setOnClickListener {
|
||||
NewLogUtils.logChooseMedia("click_confirm", publishContentType, publishMediaType)
|
||||
val intent = Intent()
|
||||
if (mChooseType == LocalMediaActivity.ChooseType.VIDEO.value) {
|
||||
val localVideoList = arrayListOf<LocalVideoEntity>()
|
||||
mAdapter.getSelectedMediaList().forEach {
|
||||
val path = PathUtils.getPath(requireContext(), it.contentUri)
|
||||
if (path == null) {
|
||||
toast("视频已不存在,请重新选择")
|
||||
return@forEach
|
||||
}
|
||||
val id = MD5Utils.getUrlMD5(path) + System.currentTimeMillis()
|
||||
val format = getFileFormat(it.mimeType)
|
||||
localVideoList.add(
|
||||
LocalVideoEntity(
|
||||
id,
|
||||
path,
|
||||
contentUri = it.contentUri,
|
||||
duration = it.duration,
|
||||
format = format,
|
||||
size = it.size
|
||||
)
|
||||
)
|
||||
}
|
||||
intent.putExtra(LocalVideoEntity::class.java.name, localVideoList)
|
||||
} else {
|
||||
val data = mAdapter.getSelectedMediaList().map { it.contentUri }.toList()
|
||||
val path = data.map { PathUtils.getPath(requireContext(), it) }.toList()
|
||||
intent.putParcelableArrayListExtra(MatisseActivity.EXTRA_RESULT_SELECTION, ArrayList<Uri>(data))
|
||||
intent.putStringArrayListExtra(MatisseActivity.EXTRA_RESULT_SELECTION_PATH, ArrayList<String>(path))
|
||||
}
|
||||
requireActivity().setResult(Activity.RESULT_OK, intent)
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFileFormat(mimeType: String?): String {
|
||||
var format = ""
|
||||
tryWithDefaultCatch {
|
||||
if (mimeType != null) {
|
||||
val split = mimeType.split("/")
|
||||
format = if (split.count() >= 2) {
|
||||
split[1]
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
}
|
||||
}
|
||||
return format
|
||||
}
|
||||
|
||||
override fun onAlbumMediaReset() {
|
||||
mAdapter.swapCursor(null)
|
||||
}
|
||||
|
||||
override fun onAlbumMediaLoad(cursor: Cursor?) {
|
||||
mAdapter.swapCursor(cursor)
|
||||
mBinding.reuseNoneData.reuseNoneData.visibility = View.GONE
|
||||
mBinding.reuseLlLoading.root.visibility = View.GONE
|
||||
mBinding.reuseNoConnection.root.visibility = View.GONE
|
||||
mBinding.listRefresh.isRefreshing = false
|
||||
}
|
||||
|
||||
fun loadVideos(album: Album) {
|
||||
mAlbumMediaCollection?.onDestroy()
|
||||
|
||||
mAlbumMediaCollection = AlbumMediaCollection()
|
||||
mAlbumMediaCollection?.onCreate(requireActivity(), this@LocalMediaFragment)
|
||||
|
||||
mAlbumMediaCollection?.load(album)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (data == null) return
|
||||
if (requestCode == PREVIEW_IMAGE) {
|
||||
val bundleExtra = data.getBundleExtra(BasePreviewActivity.EXTRA_RESULT_BUNDLE)
|
||||
val resultApply = data.getBooleanExtra(BasePreviewActivity.EXTRA_RESULT_APPLY, false)
|
||||
val items = bundleExtra?.getParcelableArrayList<Item>(SelectedItemCollection.STATE_SELECTION)
|
||||
if (resultApply && !items.isNullOrEmpty()) {
|
||||
mAdapter.getSelectedMediaList().clear()
|
||||
mAdapter.getSelectedMediaList().addAll(items)
|
||||
mAdapter.notifyDataSetChanged()
|
||||
mBinding.numTv.text = "(${items.size}/${mAdapter.maxChooseSize})"
|
||||
}
|
||||
|
||||
} else if (requestCode == PREVIEW_VIDEO) {
|
||||
requireActivity().setResult(Activity.RESULT_OK, data)
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
mAlbumMediaCollection?.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PREVIEW_VIDEO = 100
|
||||
const val PREVIEW_IMAGE = 101
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.gh.gamecenter.common.base.activity.BaseActivity
|
||||
import com.gh.gamecenter.core.utils.DisplayUtils
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.R
|
||||
import com.zhihu.matisse.internal.entity.Item
|
||||
|
||||
class PreviewVideoActivity : BaseActivity() {
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.activity_amway
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
DisplayUtils.transparentStatusBar(this)
|
||||
|
||||
val containerFragment = supportFragmentManager.findFragmentByTag(PreviewVideoFragment::class.java.name)
|
||||
?: PreviewVideoFragment().with(intent.extras)
|
||||
// 若 placeholder 外层为 RelativeLayout 的话,会出现莫名的偏移
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.placeholder, containerFragment, PreviewVideoFragment::class.java.name)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getIntent(context: Context, videos: ArrayList<Item>): Intent {
|
||||
val intent = Intent(context, PreviewVideoActivity::class.java)
|
||||
intent.putExtra(EntranceConsts.KEY_VIDEO_LIST, videos)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,229 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder
|
||||
import com.facebook.drawee.generic.RoundingParams
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.gh.gamecenter.common.base.fragment.BaseFragment
|
||||
import com.gh.gamecenter.common.base.fragment.WaitingDialogFragment
|
||||
import com.gh.gamecenter.common.view.GridSpacingItemColorDecoration
|
||||
import com.gh.gamecenter.CropImageActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.utils.*
|
||||
import com.gh.gamecenter.databinding.FragmentPreviewVideoBinding
|
||||
import com.gh.gamecenter.databinding.ItemVideoSelectorBinding
|
||||
import com.gh.gamecenter.entity.LocalVideoEntity
|
||||
import com.gh.gamecenter.video.poster.PosterEditActivity
|
||||
import com.gh.gamecenter.video.upload.view.UploadVideoActivity
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter
|
||||
import com.shuyu.gsyvideoplayer.GSYVideoManager
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder
|
||||
import com.zhihu.matisse.internal.entity.Item
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
|
||||
class PreviewVideoFragment : BaseFragment<Any>() {
|
||||
private lateinit var mBinding: FragmentPreviewVideoBinding
|
||||
private var mVideoItems: ArrayList<Item> = arrayListOf()
|
||||
private var mProcessingDialog: WaitingDialogFragment? = null
|
||||
private lateinit var mVideoSelectorAdapter: VideoSelectorAdapter
|
||||
private val mLocalVideoList = arrayListOf<LocalVideoEntity>()
|
||||
override fun getLayoutId(): Int = 0
|
||||
|
||||
override fun getInflatedLayout(): View {
|
||||
mBinding = FragmentPreviewVideoBinding.inflate(LayoutInflater.from(requireContext()), null, false)
|
||||
return mBinding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mVideoItems = arguments?.getParcelableArrayList<Item>(EntranceConsts.KEY_VIDEO_LIST)
|
||||
?: arrayListOf()
|
||||
if (mVideoItems.isNotEmpty()) {
|
||||
mVideoItems.forEach {
|
||||
val path = PathUtils.getPath(requireContext(), it.contentUri)
|
||||
val id = MD5Utils.getUrlMD5(path) + System.currentTimeMillis()
|
||||
val format = getFileFormat(it.mimeType)
|
||||
val localVideoEntity = LocalVideoEntity(
|
||||
id = id,
|
||||
filePath = path,
|
||||
contentUri = it.contentUri,
|
||||
duration = it.duration,
|
||||
format = format,
|
||||
size = it.size
|
||||
)
|
||||
mLocalVideoList.add(localVideoEntity)
|
||||
}
|
||||
initVideo(mLocalVideoList[0])
|
||||
}
|
||||
mBinding.numTv.text = "(1/${mVideoItems.size})"
|
||||
mVideoSelectorAdapter = VideoSelectorAdapter(requireContext(), mLocalVideoList) { entity, position ->
|
||||
mBinding.videoView.release()
|
||||
mBinding.numTv.text = "(${position + 1}/${mVideoItems.size})"
|
||||
initVideo(entity)
|
||||
}
|
||||
mBinding.videoSelectorRv.adapter = mVideoSelectorAdapter
|
||||
mBinding.videoSelectorRv.layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
|
||||
mBinding.videoSelectorRv.addItemDecoration(
|
||||
GridSpacingItemColorDecoration(
|
||||
requireContext(),
|
||||
4,
|
||||
0,
|
||||
R.color.transparent
|
||||
)
|
||||
)
|
||||
mBinding.confirmTv.setOnClickListener {
|
||||
val intent = Intent()
|
||||
intent.putExtra(LocalVideoEntity::class.java.name, mLocalVideoList)
|
||||
requireActivity().setResult(Activity.RESULT_OK, intent)
|
||||
requireActivity().finish()
|
||||
}
|
||||
|
||||
mBinding.changeCoverTv.setOnClickListener {
|
||||
val item = mVideoItems[mVideoSelectorAdapter.selectPosition]
|
||||
val intent =
|
||||
PosterEditActivity.getIntentByPath(requireContext(), PathUtils.getPath(requireContext(), item.uri))
|
||||
startActivityForResult(intent, UploadVideoActivity.REQUEST_CODE_IMAGE_CROP)
|
||||
}
|
||||
mBinding.backBtn.setOnClickListener { requireActivity().finish() }
|
||||
}
|
||||
|
||||
private fun getFileFormat(mimeType: String?): String {
|
||||
var format = ""
|
||||
tryWithDefaultCatch {
|
||||
if (mimeType != null) {
|
||||
val split = mimeType.split("/")
|
||||
format = if (split.count() >= 2) {
|
||||
split[1]
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
}
|
||||
}
|
||||
return format
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (data == null || resultCode != Activity.RESULT_OK) return
|
||||
if (requestCode == UploadVideoActivity.REQUEST_CODE_IMAGE_CROP) {
|
||||
val imagePath = data.getStringExtra(CropImageActivity.RESULT_CLIP_PATH) ?: ""
|
||||
if (imagePath.isNotEmpty()) {
|
||||
uploadImage(imagePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun uploadImage(imagePath: String) {
|
||||
mProcessingDialog = WaitingDialogFragment.newInstance("图片上传中...", false)
|
||||
mProcessingDialog?.show(requireActivity().supportFragmentManager, WaitingDialogFragment::class.java.name)
|
||||
UploadImageUtils.uploadImage(
|
||||
UploadImageUtils.UploadType.poster,
|
||||
imagePath,
|
||||
object : UploadImageUtils.OnUploadImageListener {
|
||||
override fun onSuccess(imageUrl: String) {
|
||||
mProcessingDialog?.dismiss()
|
||||
mLocalVideoList[mVideoSelectorAdapter.selectPosition].poster = imageUrl
|
||||
mBinding.videoView.updateThumb(imageUrl)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable?) {
|
||||
mProcessingDialog?.dismiss()
|
||||
ToastUtils.showToast("上传失败")
|
||||
}
|
||||
|
||||
override fun onProgress(total: Long, progress: Long) {}
|
||||
})
|
||||
}
|
||||
|
||||
private fun initVideo(entity: LocalVideoEntity) {
|
||||
GSYVideoOptionBuilder()
|
||||
.setIsTouchWiget(false)
|
||||
.setUrl(entity.filePath)
|
||||
.setRotateViewAuto(false)
|
||||
.setCacheWithPlay(false)
|
||||
.setRotateWithSystem(false)
|
||||
.setReleaseWhenLossAudio(true)
|
||||
.setLooping(false)
|
||||
.setShowFullAnimation(false)
|
||||
.build(mBinding.videoView)
|
||||
if (entity.poster.isNotEmpty()) {
|
||||
mBinding.videoView.updateThumb(entity.poster)
|
||||
} else {
|
||||
mBinding.videoView.updateThumb("file:///${PathUtils.getPath(requireContext(), entity.contentUri)}")
|
||||
}
|
||||
}
|
||||
|
||||
class VideoSelectorAdapter(
|
||||
context: Context,
|
||||
val localVideoList: ArrayList<LocalVideoEntity>,
|
||||
val callback: (LocalVideoEntity, Int) -> Unit
|
||||
) : BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {
|
||||
var selectPosition: Int = 0
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return VideoSelectorViewHolder(
|
||||
ItemVideoSelectorBinding.inflate(
|
||||
LayoutInflater.from(mContext),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = localVideoList.size
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is VideoSelectorViewHolder) {
|
||||
val item = localVideoList[position]
|
||||
holder.binding.previewBorder.goneIf(selectPosition != position)
|
||||
setPreviewBorder(holder.binding.preview, selectPosition == position)
|
||||
ImageUtils.display(holder.binding.preview, "file:///${PathUtils.getPath(mContext, item.contentUri)}")
|
||||
holder.binding.root.setOnClickListener {
|
||||
selectPosition = position
|
||||
callback.invoke(localVideoList[selectPosition], selectPosition)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setPreviewBorder(view: SimpleDraweeView, isSelected: Boolean) {
|
||||
val params = RoundingParams()
|
||||
params.setBorder(
|
||||
if (isSelected) R.color.black.toColor() else R.color.transparent.toColor(),
|
||||
if (isSelected) 1f.dip2px().toFloat() else 0f
|
||||
)
|
||||
params.setCornersRadius(4f.dip2px().toFloat())
|
||||
val build = GenericDraweeHierarchyBuilder.newInstance(mContext.resources)
|
||||
.setRoundingParams(params)
|
||||
.build()
|
||||
view.hierarchy = build
|
||||
}
|
||||
}
|
||||
|
||||
class VideoSelectorViewHolder(val binding: ItemVideoSelectorBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
GSYVideoManager.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
GSYVideoManager.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
GSYVideoManager.releaseAllVideos()
|
||||
}
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.gh.gamecenter.common.utils.ImageUtils
|
||||
import com.gh.gamecenter.R
|
||||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView
|
||||
|
||||
class PreviewVideoView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
StandardGSYVideoPlayer(context, attrs) {
|
||||
|
||||
var thumbImage: SimpleDraweeView = findViewById(R.id.thumbImage)
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.layout_preview_video
|
||||
}
|
||||
|
||||
override fun updateStartImage() {
|
||||
if (mStartButton is ImageView) {
|
||||
val imageView = mStartButton as ImageView
|
||||
when (mCurrentState) {
|
||||
GSYVideoView.CURRENT_STATE_PLAYING -> imageView.setImageResource(R.drawable.icon_preview_video_pause)
|
||||
GSYVideoView.CURRENT_STATE_ERROR -> imageView.setImageResource(R.drawable.icon_preview_video_play)
|
||||
else -> imageView.setImageResource(R.drawable.icon_preview_video_play)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClickUiToggle(e: MotionEvent?) {
|
||||
if (mCurrentState == CURRENT_STATE_PLAYING) {
|
||||
if (mStartButton.visibility == View.VISIBLE) {
|
||||
changeUiToPlayingClear()
|
||||
} else {
|
||||
changeUiToPlayingShow()
|
||||
}
|
||||
} else {
|
||||
super.onClickUiToggle(e)
|
||||
}
|
||||
}
|
||||
|
||||
/******************* 下方两个重载方法,在播放开始前不屏蔽封面,不需要可屏蔽 ********************/
|
||||
|
||||
override fun onSurfaceUpdated(surface: Surface) {
|
||||
super.onSurfaceUpdated(surface)
|
||||
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
|
||||
mThumbImageViewLayout.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
fun updateThumb(url: String) {
|
||||
ImageUtils.display(thumbImage, url)
|
||||
}
|
||||
|
||||
override fun setViewShowState(view: View?, visibility: Int) {
|
||||
if (view === mThumbImageViewLayout && visibility != View.VISIBLE) {
|
||||
return
|
||||
}
|
||||
super.setViewShowState(view, visibility)
|
||||
}
|
||||
|
||||
/********************************各类UI的状态显示*********************************************/
|
||||
|
||||
override fun touchSurfaceMoveFullLogic(absDeltaX: Float, absDeltaY: Float) {
|
||||
super.touchSurfaceMoveFullLogic(absDeltaX, absDeltaY)
|
||||
//不给触摸快进,如果需要,屏蔽下方代码即可
|
||||
mChangePosition = false
|
||||
//不给触摸音量,如果需要,屏蔽下方代码即可
|
||||
mChangeVolume = false
|
||||
//不给触摸亮度,如果需要,屏蔽下方代码即可
|
||||
mBrightness = false
|
||||
}
|
||||
|
||||
override fun isShowNetConfirm(): Boolean = false
|
||||
|
||||
override fun touchDoubleUp(e: MotionEvent?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onLossTransientAudio() {
|
||||
// transient audio lost 代表的是短暂的 audio focus lost,不暂停播放。不然视频很容易就处于暂停状态
|
||||
// onLossAudio 回调的时候再决定是否需要暂停
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CursorAdapter
|
||||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.gh.gamecenter.R
|
||||
import com.zhihu.matisse.internal.entity.Album
|
||||
|
||||
class VideoAlbumsAdapter(context: Context) : CursorAdapter(context, null) {
|
||||
|
||||
override fun newView(context: Context?, cursor: Cursor?, parent: ViewGroup?): View {
|
||||
val inflate = LayoutInflater.from(context)
|
||||
return inflate.inflate(R.layout.video_albums_item, parent, false)
|
||||
}
|
||||
|
||||
override fun bindView(view: View, context: Context, cursor: Cursor?) {
|
||||
val album = Album.valueOf(cursor)
|
||||
view.findViewById<TextView>(R.id.album_name).text = album.getDisplayName(context)
|
||||
view.findViewById<TextView>(R.id.album_media_count).text = album.count.toString()
|
||||
view.findViewById<SimpleDraweeView>(R.id.album_cover).setImageURI(album.coverUri)
|
||||
}
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.CursorAdapter
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.PopupWindow
|
||||
import androidx.appcompat.widget.ListPopupWindow
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.gh.gamecenter.common.utils.dip2px
|
||||
import com.gh.gamecenter.R
|
||||
|
||||
class VideoAlbumsSpanner(val context: Context) {
|
||||
|
||||
private var mListPopupWindow: ListPopupWindow = CustomListPopupWindow(context, R.style.PosterListPopupWindow)
|
||||
|
||||
private lateinit var mAdapter: CursorAdapter
|
||||
|
||||
var onItemSelectedListener: AdapterView.OnItemSelectedListener? = null
|
||||
|
||||
init {
|
||||
mListPopupWindow.isModal = true
|
||||
mListPopupWindow.setContentWidth(context.resources.displayMetrics.widthPixels)
|
||||
mListPopupWindow.setOnItemClickListener { parent, view, position, id ->
|
||||
mListPopupWindow.dismiss()
|
||||
onItemSelectedListener?.onItemSelected(parent, view, position, id)
|
||||
}
|
||||
mListPopupWindow.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(context, R.color.transparent)))
|
||||
}
|
||||
|
||||
fun setDismissListener(listener: PopupWindow.OnDismissListener) {
|
||||
mListPopupWindow.setOnDismissListener(listener)
|
||||
}
|
||||
|
||||
fun setAdapter(adapter: CursorAdapter) {
|
||||
mListPopupWindow.setAdapter(adapter)
|
||||
mAdapter = adapter
|
||||
}
|
||||
|
||||
fun setPopupAnchorView(view: View?) {
|
||||
mListPopupWindow.anchorView = view
|
||||
}
|
||||
|
||||
fun show(popupHeight: Int) {
|
||||
if (mListPopupWindow.isShowing) return
|
||||
if (popupHeight > 0) mListPopupWindow.height = popupHeight
|
||||
// 去掉ListPopupWindow默认动画
|
||||
mListPopupWindow.animationStyle = 0
|
||||
mListPopupWindow.show()
|
||||
val containerView = mListPopupWindow.listView as? ViewGroup
|
||||
val params = containerView?.layoutParams as ViewGroup.LayoutParams
|
||||
params.height = 280f.dip2px()
|
||||
containerView.background = ColorDrawable(ContextCompat.getColor(context, R.color.ui_surface))
|
||||
containerView.layoutParams = params
|
||||
val parentContainer = containerView.parent as FrameLayout
|
||||
|
||||
//添加半透明maskView
|
||||
val maskView = View(context)
|
||||
val maskViewParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, popupHeight)
|
||||
maskView.background = ColorDrawable(ContextCompat.getColor(context, R.color.black_alpha_40))
|
||||
maskView.layoutParams = maskViewParams
|
||||
parentContainer.addView(maskView, 0)
|
||||
maskView.setOnClickListener {
|
||||
mListPopupWindow.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CustomListPopupWindow(val context: Context, defStyleAttr: Int) : ListPopupWindow(context, null, defStyleAttr) {
|
||||
override fun dismiss() {
|
||||
val parentContainer = listView?.parent as? FrameLayout
|
||||
parentContainer?.getChildAt(0)?.alpha = 0f
|
||||
parentContainer?.postDelayed({ super.dismiss() }, 0)
|
||||
}
|
||||
}
|
||||
@ -24,8 +24,10 @@ import com.gh.gamecenter.common.base.fragment.ToolbarFragment
|
||||
import com.gh.gamecenter.common.base.fragment.WaitingDialogFragment
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.common.entity.CommunityEntity
|
||||
import com.gh.gamecenter.common.entity.LocalVideoEntity
|
||||
import com.gh.gamecenter.common.entity.NotificationUgc
|
||||
import com.gh.gamecenter.common.mvvm.Status
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.core.runOnUiThread
|
||||
@ -34,6 +36,7 @@ import com.gh.gamecenter.databinding.FragmentVideoPublishBinding
|
||||
import com.gh.gamecenter.entity.*
|
||||
import com.gh.gamecenter.feature.entity.ForumVideoEntity
|
||||
import com.gh.gamecenter.feature.entity.GameEntity
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.login.user.UserManager
|
||||
import com.gh.gamecenter.qa.BbsType
|
||||
import com.gh.gamecenter.qa.dialog.ChooseActivityDialogFragment
|
||||
@ -41,7 +44,6 @@ import com.gh.gamecenter.qa.dialog.ChooseForumActivity
|
||||
import com.gh.gamecenter.qa.dialog.ChooseSectionDialogFragment
|
||||
import com.gh.gamecenter.qa.dialog.InputUrlDialogFragment
|
||||
import com.gh.gamecenter.qa.editor.GameActivity
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.gh.gamecenter.video.poster.PosterEditActivity
|
||||
import com.gh.gamecenter.video.upload.OnUploadListener
|
||||
import com.gh.gamecenter.video.upload.UploadManager
|
||||
@ -117,7 +119,7 @@ class VideoPublishFragment : ToolbarFragment(), KeyboardHeightObserver {
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.VIDEO,
|
||||
ChooseType.VIDEO,
|
||||
1,
|
||||
"发视频帖"
|
||||
), BaseRichEditorActivity.INSERT_MEDIA_VIDEO_CODE
|
||||
@ -285,7 +287,7 @@ class VideoPublishFragment : ToolbarFragment(), KeyboardHeightObserver {
|
||||
startActivityForResult(
|
||||
LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
LocalMediaActivity.ChooseType.VIDEO,
|
||||
ChooseType.VIDEO,
|
||||
1,
|
||||
"发视频帖"
|
||||
), BaseRichEditorActivity.INSERT_MEDIA_VIDEO_CODE
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.halo.assistant.fragment.user
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
@ -13,7 +12,6 @@ import com.gh.gamecenter.common.base.fragment.WaitingDialogFragment
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.core.utils.EmptyCallback
|
||||
import com.gh.gamecenter.common.utils.PermissionHelper
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.common.utils.enlargeTouchArea
|
||||
@ -22,7 +20,11 @@ import com.gh.gamecenter.databinding.FragmentManuallyRealNameBinding
|
||||
import com.gh.gamecenter.login.entity.IdCardEntity
|
||||
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
|
||||
import com.gh.gamecenter.common.utils.UploadImageUtils
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.squareup.picasso.MemoryPolicy
|
||||
import com.zhihu.matisse.Matisse
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
class ManuallyRealNameFragment : ToolbarFragment() {
|
||||
@ -69,28 +71,10 @@ class ManuallyRealNameFragment : ToolbarFragment() {
|
||||
|
||||
if (data == null) return
|
||||
if (requestCode == REQUEST_IMAGE) {
|
||||
val selectedImage = data.data ?: return
|
||||
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
|
||||
val selectedPaths = Matisse.obtainResult(data) ?: return
|
||||
val picturePath = PathUtils.getPath(requireContext(), selectedPaths[0])
|
||||
|
||||
try {
|
||||
val cursor = requireContext().contentResolver.query(
|
||||
selectedImage,
|
||||
filePathColumn,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
) ?: return
|
||||
|
||||
cursor.moveToFirst()
|
||||
|
||||
val columnIndex = cursor.getColumnIndex(filePathColumn[0])
|
||||
val picturePath = cursor.getString(columnIndex)
|
||||
cursor.close()
|
||||
|
||||
uploadPicture(selectedImage, picturePath)
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.showToast(e.localizedMessage ?: "")
|
||||
}
|
||||
uploadPicture(selectedPaths[0], picturePath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,22 +134,13 @@ class ManuallyRealNameFragment : ToolbarFragment() {
|
||||
}
|
||||
|
||||
private fun selectImage() {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
startActivityForResult(intent, REQUEST_IMAGE)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
// https://stackoverflow.com/questions/45707678
|
||||
val getIntent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
getIntent.type = "image/*"
|
||||
|
||||
val pickIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
pickIntent.type = "image/*"
|
||||
|
||||
val chooserIntent = Intent.createChooser(getIntent, "Select Image")
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(pickIntent))
|
||||
|
||||
startActivityForResult(chooserIntent, REQUEST_IMAGE)
|
||||
}
|
||||
val intent = LocalMediaActivity.getIntent(
|
||||
requireContext(),
|
||||
ChooseType.IMAGE,
|
||||
1,
|
||||
"人工审核"
|
||||
)
|
||||
startActivityForResult(intent, REQUEST_IMAGE)
|
||||
}
|
||||
|
||||
private fun removeUploadedImage() {
|
||||
|
||||
@ -2,10 +2,8 @@ package com.halo.assistant.fragment.user.avatar
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
@ -18,15 +16,18 @@ import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.base.activity.BaseActivity
|
||||
import com.gh.gamecenter.common.base.fragment.BaseDialogFragment
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts
|
||||
import com.gh.gamecenter.feature.selector.LocalMediaActivity
|
||||
import com.gh.gamecenter.common.utils.PermissionHelper.checkStoragePermissionBeforeAction
|
||||
import com.gh.gamecenter.common.utils.viewModelProvider
|
||||
import com.gh.gamecenter.core.utils.SPUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.databinding.DialogChangeAvatarBinding
|
||||
import com.gh.gamecenter.feature.selector.ChooseType
|
||||
import com.gh.gamecenter.login.user.UserViewModel
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.halo.assistant.fragment.user.UserPortraitCropImageActivity
|
||||
import com.lightgame.utils.Utils
|
||||
import com.zhihu.matisse.Matisse
|
||||
import com.zhihu.matisse.internal.utils.PathUtils
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
@ -93,8 +94,8 @@ class ChangeAvatarDialog : BaseDialogFragment() {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
when (requestCode) {
|
||||
REQUEST_MEDIA_ICON -> {
|
||||
val selectedImage = data.data ?: return
|
||||
val picturePath = PathUtils.getPath(requireContext(), selectedImage)
|
||||
val selectedPaths = Matisse.obtainResult(data) ?: return
|
||||
val picturePath = PathUtils.getPath(requireContext(), selectedPaths[0])
|
||||
Utils.log("picturePath = $picturePath")
|
||||
// 上传头像
|
||||
val intent = UserPortraitCropImageActivity.getIntent(
|
||||
@ -144,12 +145,9 @@ class ChangeAvatarDialog : BaseDialogFragment() {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_MEDIA_ICON)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Utils.toast(requireContext(), "找不到图片选择器")
|
||||
}
|
||||
|
||||
val intent = LocalMediaActivity.getIntent(requireContext(), ChooseType.IMAGE, 1, "头像选择")
|
||||
startActivityForResult(intent, REQUEST_MEDIA_ICON)
|
||||
}
|
||||
|
||||
override fun onDarkModeChanged() {
|
||||
|
||||
Reference in New Issue
Block a user