diff --git a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoDisplayDateChildAdapter.kt b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoDisplayDateChildAdapter.kt index 8dd7577..b703131 100644 --- a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoDisplayDateChildAdapter.kt +++ b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoDisplayDateChildAdapter.kt @@ -142,24 +142,19 @@ class PhotoDisplayDateChildAdapter( item: ResultPhotosFiles, viewType: Int ) { - when (holder) { is TwoHolder -> holder.vb.run { initDateView(rootLayout, imageSelect, textSize, imageThumbnail, item, imageType) } - is ThreeHolder -> holder.vb.run { initDateView(rootLayout, imageSelect, textSize, imageThumbnail, item, imageType) } - is OneHolder -> { item.run { holder.vb.let { it.textName.text = name it.textDuration.text = Common.formatDuration(duration) it.textSize.text = sizeString - - viewModel.checkIsSelect(this).let { isSelected -> it.imageSelect.isSelected = isSelected addOrRemove(this, isSelected) @@ -170,6 +165,9 @@ class PhotoDisplayDateChildAdapter( addOrRemove(this, newStatus) } } + it.constraintLayout.setOnClickListener { + clickItem(this) + } } } diff --git a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoInfoActivity.kt b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoInfoActivity.kt index 9d25a72..96f46eb 100644 --- a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoInfoActivity.kt +++ b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoInfoActivity.kt @@ -2,10 +2,16 @@ package com.ux.video.file.filerecovery.photo import android.content.Intent import android.graphics.drawable.Drawable +import android.net.Uri import android.os.Build import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.ImageView import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope +import androidx.media3.common.MediaItem +import androidx.media3.common.Player +import androidx.media3.exoplayer.ExoPlayer import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException @@ -29,7 +35,9 @@ import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_documents import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_photo import com.ux.video.file.filerecovery.utils.Common.VALUE_SCAN_TYPE_video import com.ux.video.file.filerecovery.utils.ExtendFunctions.dpToPx +import com.ux.video.file.filerecovery.video.PlayMediaManager import com.ux.video.file.filerecovery.video.VideoPlayActivity +import java.io.File class PhotoInfoActivity : BaseActivity() { @@ -39,7 +47,7 @@ class PhotoInfoActivity : BaseActivity() { private var scanType: Int = VALUE_SCAN_TYPE_photo private var myData: ResultPhotosFiles? = null - + private lateinit var player: ExoPlayer override fun inflateBinding(inflater: LayoutInflater): ActivityPhotoInfoBinding = ActivityPhotoInfoBinding.inflate(inflater) @@ -65,37 +73,10 @@ class PhotoInfoActivity : BaseActivity() { tvName.text = resultPhotosFiles.name tvPath.text = resultPhotosFiles.path + tvSize.text = resultPhotosFiles.sizeString tvDate.text = Common.getFormatDate(resultPhotosFiles.lastModified) tvResolution.text = resultPhotosFiles.resolution tvDuration.text = Common.formatDuration(resultPhotosFiles.duration) - - Glide.with(this@PhotoInfoActivity) - .load(resultPhotosFiles.targetFile) - .apply(RequestOptions().transform(CenterCrop(), RoundedCorners(8.dpToPx(this@PhotoInfoActivity)))) - .listener(object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target, - isFirstResource: Boolean - ): Boolean { - return false - } - - override fun onResourceReady( - resource: Drawable, - model: Any, - target: Target?, - dataSource: DataSource, - isFirstResource: Boolean - ): Boolean { - - return false - } - - }) - .into(image) - layoutBottom.tvLeft.run { text = resources.getString(R.string.delete) setOnClickListener { @@ -109,7 +90,6 @@ class PhotoInfoActivity : BaseActivity() { } } } - layoutBottom.tvRight.run { text = resources.getString(R.string.recover) setOnClickListener { @@ -134,12 +114,17 @@ class PhotoInfoActivity : BaseActivity() { layoutPath.isVisible = true layoutResolution.isVisible = true layoutDate.isVisible = true + frameImage.setBackgroundResource(0) + + layoutSeekbar.isVisible = false layoutType.isVisible = false layoutSize.isVisible = false layoutDuration.isVisible = false imPlay.isVisible = false + + myData?.targetFile?.let { loadImage(image,it) } } VALUE_SCAN_TYPE_video, VALUE_SCAN_TYPE_deleted_video -> { @@ -148,12 +133,16 @@ class PhotoInfoActivity : BaseActivity() { layoutResolution.isVisible = true layoutDate.isVisible = true layoutDuration.isVisible = true + frameImage.setBackgroundResource(0) + + layoutSeekbar.isVisible = false layoutType.isVisible = false layoutSize.isVisible = false imPlay.isVisible = true myData?.let { data-> + data.targetFile?.let { loadImage(image,it) } frameImage.setOnClickListener { startActivity(Intent(this@PhotoInfoActivity, VideoPlayActivity::class.java).apply { putExtra(VideoPlayActivity.KEY_DATA, data) @@ -163,12 +152,25 @@ class PhotoInfoActivity : BaseActivity() { } VALUE_SCAN_TYPE_audio, VALUE_SCAN_TYPE_deleted_audio -> { + Common.showLog("----------音频") layoutName.isVisible = true layoutPath.isVisible = true layoutSize.isVisible = true layoutDate.isVisible = true layoutDuration.isVisible = true + layoutSeekbar.isVisible = true + imPlay.isVisible = true + frameImage.setBackgroundResource(R.drawable.bg_info_music_f2f2f7_8) + image.setImageResource(R.drawable.image_info_music) + val params = image.layoutParams ?: ViewGroup.LayoutParams( + 180.dpToPx(this@PhotoInfoActivity), + 180.dpToPx(this@PhotoInfoActivity) + ) + params.width = 180.dpToPx(this@PhotoInfoActivity) + params.height = 180.dpToPx(this@PhotoInfoActivity) + image.layoutParams = params + initPlayAudio() layoutResolution.isVisible = false layoutType.isVisible = false } @@ -189,6 +191,49 @@ class PhotoInfoActivity : BaseActivity() { } + private fun loadImage(image: ImageView,file: File){ + Glide.with(this@PhotoInfoActivity) + .load(file) + .apply(RequestOptions().transform(CenterCrop(), RoundedCorners(8.dpToPx(this@PhotoInfoActivity)))) + .listener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target, + isFirstResource: Boolean + ): Boolean { + return false + } + + override fun onResourceReady( + resource: Drawable, + model: Any, + target: Target?, + dataSource: DataSource, + isFirstResource: Boolean + ): Boolean { + + return false + } + + }) + .into(image) + } + + + private fun initPlayAudio(){ + myData?.targetFile?.let { + binding.run { + PlayMediaManager(context = this@PhotoInfoActivity, mediaFile = it, + seekBar = seekBar, playBtn = imPlay, onUpdateProgress = { current,total-> + textTimeCurrent.text = current + textTimeTotal.text = total + } ) + } + } + } + + private fun complete(number: Int, type: Int) { finish() startActivity(Intent(this@PhotoInfoActivity, RecoverySuccessActivity::class.java).apply { diff --git a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoSortingActivity.kt b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoSortingActivity.kt index c77a4ec..92e8254 100644 --- a/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoSortingActivity.kt +++ b/app/src/main/java/com/ux/video/file/filerecovery/photo/PhotoSortingActivity.kt @@ -89,7 +89,7 @@ class PhotoSortingActivity : BaseActivity() { private var filterDate = FILTER_DATE_ALL //筛选大小,默认全部-1 - private var filterSize: String = "All" + private var filterSize: String = "All" private var filterDatePopupWindows: DateFilterPopupWindows? = null private var filterStartDate: Date? = null @@ -170,7 +170,7 @@ class PhotoSortingActivity : BaseActivity() { this@PhotoSortingActivity, PhotoInfoActivity::class.java ).apply { - putExtra(KEY_SCAN_TYPE,scanType) + putExtra(KEY_SCAN_TYPE, scanType) putExtra(PhotoInfoActivity.KEY_CLICK_ITEM, item) }) @@ -189,7 +189,7 @@ class PhotoSortingActivity : BaseActivity() { this@PhotoSortingActivity, PhotoInfoActivity::class.java ).apply { - putExtra(KEY_SCAN_TYPE,scanType) + putExtra(KEY_SCAN_TYPE, scanType) putExtra(PhotoInfoActivity.KEY_CLICK_ITEM, item) }) }.apply { @@ -477,10 +477,20 @@ class PhotoSortingActivity : BaseActivity() { private fun setSizeAdapter() { binding.recyclerView.run { val aPx = 16.dpToPx(context) - val bPx = 6.dpToPx(context) - setPadding(aPx, 0, bPx, 70.dpToPx(context)) - clipToPadding = false - layoutManager = GridLayoutManager(context, columns) + val bottom = 70.dpToPx(context) + when (scanType) { + VALUE_SCAN_TYPE_audio, VALUE_SCAN_TYPE_deleted_audio -> { + layoutManager = LinearLayoutManager(context) + setPadding(aPx, 0, 0, bottom) + } + + else -> { + val bPx = 6.dpToPx(context) + setPadding(aPx, 0, bPx, bottom) + clipToPadding = false + layoutManager = GridLayoutManager(context, columns) + } + } adapter = sizeSortAdapter } @@ -685,6 +695,7 @@ class PhotoSortingActivity : BaseActivity() { VALUE_SCAN_TYPE_photo, VALUE_SCAN_TYPE_deleted_photo, VALUE_SCAN_TYPE_documents, VALUE_SCAN_TYPE_deleted_documents -> { filterBySizeList(filterSizeCovert.first, filterSizeCovert.second) } + else -> { filterByDurationList(filterSizeCovert.first, filterSizeCovert.second) } diff --git a/app/src/main/java/com/ux/video/file/filerecovery/video/PlayMediaManager.kt b/app/src/main/java/com/ux/video/file/filerecovery/video/PlayMediaManager.kt new file mode 100644 index 0000000..f6283df --- /dev/null +++ b/app/src/main/java/com/ux/video/file/filerecovery/video/PlayMediaManager.kt @@ -0,0 +1,110 @@ +package com.ux.video.file.filerecovery.video + +import android.content.Context +import android.net.Uri +import android.os.Handler +import android.os.Looper +import android.widget.ImageView +import android.widget.SeekBar +import androidx.media3.common.MediaItem +import androidx.media3.common.Player +import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.ui.PlayerView +import com.ux.video.file.filerecovery.utils.Common +import java.io.File + +class PlayMediaManager(var context: Context, var mediaFile: File, var playView: PlayerView? = null, var seekBar: SeekBar, var playBtn: ImageView, var onUpdateProgress:(currentStr: String, totalStr: String)-> Unit) { + + private lateinit var player: ExoPlayer + private val updateHandler = Handler(Looper.getMainLooper()) + + init { + initPlayer() + playBtn.setOnClickListener { + if (player.playbackState == Player.STATE_ENDED) { + player.seekTo(0) + } + if (!player.isPlaying) { + player.play() + it.isSelected = true + } else { + player.pause() + it.isSelected = false + } + } + + seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged( + seekBar: SeekBar?, + progress: Int, + fromUser: Boolean + ) { + if (fromUser) { + val newPosition = progress * player.duration / 100 + player.seekTo(newPosition) + } + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + + } + + }) + + } + private fun initPlayer() { + player = ExoPlayer.Builder(context).build() + playView?.player = player + val mediaItem = MediaItem.fromUri(Uri.fromFile(mediaFile)) + player.addListener(object : Player.Listener { + override fun onPlaybackStateChanged(playbackState: Int) { + super.onPlaybackStateChanged(playbackState) + when (playbackState) { + Player.STATE_IDLE -> { + + } + + Player.STATE_BUFFERING -> { + + } + + Player.STATE_READY -> { + + } + + Player.STATE_ENDED -> { + playBtn.isSelected = false +// onPlayEnd() + } + } + + } + }) + player.setMediaItem(mediaItem) + player.prepare() + + startProgressUpdater() + } + + private fun startProgressUpdater() { + updateHandler.post(object : Runnable { + override fun run() { + if (player.isPlaying || player.isLoading) { + val pos = player.currentPosition + val dur = player.duration.takeIf { it > 0 } ?: 1L + val progress = (pos * 100 / dur).toInt() + onUpdateProgress(Common.formatDuration(pos),Common.formatDuration(dur)) + seekBar.progress = progress +// +// binding.textTimeCurrent.text = Common.formatDuration(pos) +// binding.textTimeTotal.text = Common.formatDuration(dur) + } + updateHandler.postDelayed(this, 500) + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/ux/video/file/filerecovery/video/VideoPlayActivity.kt b/app/src/main/java/com/ux/video/file/filerecovery/video/VideoPlayActivity.kt index 7231b0f..1cf9ebc 100644 --- a/app/src/main/java/com/ux/video/file/filerecovery/video/VideoPlayActivity.kt +++ b/app/src/main/java/com/ux/video/file/filerecovery/video/VideoPlayActivity.kt @@ -53,44 +53,52 @@ class VideoPlayActivity : BaseActivity() { @Suppress("DEPRECATION") intent.getParcelableExtra(KEY_DATA) } - initPlayer() +// initPlayer() binding.run { myData?.let { resultPhotosFiles-> imageBack.setOnClickListener { finish() } - playImage.setOnClickListener { - if (player.playbackState == Player.STATE_ENDED) { - player.seekTo(0) - } - if (!player.isPlaying) { - player.play() - it.isSelected = true - } else { - player.pause() - it.isSelected = false - } + resultPhotosFiles.targetFile?.let { + PlayMediaManager(context = this@VideoPlayActivity, mediaFile = it, playView = playerView, + seekBar = seekBar, playBtn = playImage, onUpdateProgress = { current,total-> + textTimeCurrent.text = current + textTimeTotal.text = total + } ) } - seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged( - seekBar: SeekBar?, - progress: Int, - fromUser: Boolean - ) { - if (fromUser) { - val newPosition = progress * player.duration / 100 - player.seekTo(newPosition) - } - } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - - } - - override fun onStopTrackingTouch(seekBar: SeekBar?) { - - } - - }) - startProgressUpdater() +// playImage.setOnClickListener { +// if (player.playbackState == Player.STATE_ENDED) { +// player.seekTo(0) +// } +// if (!player.isPlaying) { +// player.play() +// it.isSelected = true +// } else { +// player.pause() +// it.isSelected = false +// } +// } +// seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { +// override fun onProgressChanged( +// seekBar: SeekBar?, +// progress: Int, +// fromUser: Boolean +// ) { +// if (fromUser) { +// val newPosition = progress * player.duration / 100 +// player.seekTo(newPosition) +// } +// } +// +// override fun onStartTrackingTouch(seekBar: SeekBar?) { +// +// } +// +// override fun onStopTrackingTouch(seekBar: SeekBar?) { +// +// } +// +// }) +// startProgressUpdater() layoutBottom.tvLeft.run { text = resources.getString(R.string.delete) setOnClickListener { diff --git a/app/src/main/res/drawable/bg_info_music_f2f2f7_8.xml b/app/src/main/res/drawable/bg_info_music_f2f2f7_8.xml new file mode 100644 index 0000000..1b9fb01 --- /dev/null +++ b/app/src/main/res/drawable/bg_info_music_f2f2f7_8.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/icon_search.png b/app/src/main/res/drawable/icon_search.png new file mode 100644 index 0000000..d437887 Binary files /dev/null and b/app/src/main/res/drawable/icon_search.png differ diff --git a/app/src/main/res/drawable/image_info_music.png b/app/src/main/res/drawable/image_info_music.png new file mode 100644 index 0000000..8ec945c Binary files /dev/null and b/app/src/main/res/drawable/image_info_music.png differ diff --git a/app/src/main/res/layout/activity_photo_info.xml b/app/src/main/res/layout/activity_photo_info.xml index f94842a..85094a3 100644 --- a/app/src/main/res/layout/activity_photo_info.xml +++ b/app/src/main/res/layout/activity_photo_info.xml @@ -56,17 +56,57 @@ + android:layout_height="match_parent" /> + android:src="@drawable/selector_play_button" /> + + + + + + + + diff --git a/app/src/main/res/layout/activity_photo_sorting.xml b/app/src/main/res/layout/activity_photo_sorting.xml index 5e54de9..6d8dec3 100644 --- a/app/src/main/res/layout/activity_photo_sorting.xml +++ b/app/src/main/res/layout/activity_photo_sorting.xml @@ -123,9 +123,8 @@ android:layout_marginStart="8dp" android:src="@drawable/selector_arrow_up_down" /> - + - + android:text="00:00" /> @@ -64,7 +64,7 @@ android:textColor="@color/white" android:textSize="10sp" app:fontType="bold" - tools:text="00:00" /> + android:text="00:00"/>