Skip to content

Commit

Permalink
功能优化: 优化扫描目录添加
Browse files Browse the repository at this point in the history
  • Loading branch information
xyoye committed Feb 4, 2024
1 parent cabd39b commit fa3b9de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FileManagerDialog(
activity: Activity,
private val action: FileManagerAction,
private var defaultFolderPath: String? = null,
private val dismissWhenClickPositive: Boolean = true,
private val listener: (resultPath: String) -> Unit
) : BaseBottomDialog<DialogFileManagerBinding>(activity) {

Expand Down Expand Up @@ -79,9 +80,11 @@ class FileManagerDialog(
setNegativeListener { dismiss() }

setPositiveListener {
dismiss()
AppConfig.putLastOpenFolder(currentDirPath)
listener.invoke(currentDirPath)
if (dismissWhenClickPositive) {
dismiss()
}
}

binding.rootPathTv.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ import com.xyoye.data_component.entity.ExtendFolderEntity
import com.xyoye.data_component.enums.FileManagerAction
import com.xyoye.user_component.BR
import com.xyoye.user_component.R
import com.xyoye.user_component.databinding.*
import com.xyoye.user_component.databinding.FragmentScanExtendBinding
import com.xyoye.user_component.databinding.ItemExtendFolderAddBinding
import com.xyoye.user_component.databinding.ItemExtendFolderBinding

class ScanExtendFragment : BaseFragment<ScanExtendFragmentViewModel, FragmentScanExtendBinding>() {

companion object {
fun newInstance() = ScanExtendFragment()
}

private var fileManagerDialog: FileManagerDialog? = null

override fun initViewModel() =
ViewModelInit(
BR.viewModel,
Expand Down Expand Up @@ -69,13 +73,24 @@ class ScanExtendFragment : BaseFragment<ScanExtendFragmentViewModel, FragmentSca
dataBinding.extendFolderRv.setData(it)
}

viewModel.extendAppendedLiveData.observe(this) {
fileManagerDialog?.dismiss()
}

viewModel.getExtendFolder()
}

private fun showExtendFolderDialog() {
FileManagerDialog(requireActivity(), FileManagerAction.ACTION_SELECT_DIRECTORY) {
fileManagerDialog?.dismiss()
fileManagerDialog = FileManagerDialog(
mAttachActivity,
FileManagerAction.ACTION_SELECT_DIRECTORY,
dismissWhenClickPositive = false
) {
viewModel.addExtendFolder(it)
}.show()
}.also {
it.show()
}
}

private fun showConfirmRemoveDialog(entity: ExtendFolderEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.coroutines.launch
class ScanExtendFragmentViewModel : BaseViewModel() {

val extendFolderLiveData = MutableLiveData<MutableList<Any>>()
val extendAppendedLiveData = MutableLiveData<Any>()

fun getExtendFolder() {
viewModelScope.launch {
Expand All @@ -37,18 +38,18 @@ class ScanExtendFragmentViewModel : BaseViewModel() {
fun addExtendFolder(folderPath: String) {
viewModelScope.launch(Dispatchers.IO) {
showLoading()

val extendVideos = MediaUtils.scanVideoFile(folderPath)
if (extendVideos.size == 0){
ToastCenter.showError("失败,未识别到任何视频")
hideLoading()
hideLoading()

if (extendVideos.size == 0) {
ToastCenter.showError("失败,当前文件夹内未识别到任何视频")
return@launch
}

val entity = ExtendFolderEntity(folderPath, extendVideos.size)
DatabaseManager.instance.getExtendFolderDao().insert(entity)
getExtendFolder()
hideLoading()
extendAppendedLiveData.postValue(Any())
}
}
}

0 comments on commit fa3b9de

Please sign in to comment.