Skip to content

Commit

Permalink
mpv is default player, long press to change
Browse files Browse the repository at this point in the history
  • Loading branch information
itszechs committed Jun 14, 2023
1 parent da555f1 commit e9471a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
28 changes: 22 additions & 6 deletions app/src/main/java/zechs/drive/stream/ui/files/FilesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ class FilesFragment : BaseFragment() {
is Resource.Success -> response.data?.let { files ->
onSuccess(files)
}

is Resource.Error -> {
showSnackBar(response.message)
showError(response.message)
}

is Resource.Loading -> {
isLoading = true
if (!viewModel.hasLoaded || viewModel.hasFailed) {
Expand Down Expand Up @@ -197,12 +199,25 @@ class FilesFragment : BaseFragment() {
private val filesAdapter by lazy {
FilesAdapter(
onClickListener = { handleFileOnClick(it) },
onLongClickListener = { handleFileOnLongPress(it) },
onStarClickListener = { file, isStarred ->
viewModel.starFile(file, isStarred)
}
)
}

private fun handleFileOnLongPress(file: DriveFile) {
Log.d(TAG, file.toString())
if (file.isVideoFile) {
launchVideoPlayer(file)
} else if (file.isShortcut) {
if (file.isShortcutVideo) {
val videoShortcutFile = file.copy(id = file.shortcutDetails.targetId!!)
launchVideoPlayer(videoShortcutFile)
}
}
}

private fun handleFileOnClick(file: DriveFile) {
Log.d(TAG, file.toString())
if (file.isFolder && !file.isShortcut) {
Expand All @@ -212,26 +227,25 @@ class FilesFragment : BaseFragment() {
)
findNavController().navigate(action)
} else if (file.isVideoFile) {
launchVideoPlayer(file)
viewModel.fetchToken(file)
} else if (file.isShortcut) {
if (file.isShortcutFolder) {
val action = FilesFragmentDirections.actionFilesFragmentSelf(
name = file.name,
query = "'${file.shortcutDetails.targetId}' in parents and trashed=false"
)
findNavController().navigate(action)
}
else if (file.isShortcutVideo){
val videoShortcutFile = file.copy(id=file.shortcutDetails.targetId!!)
launchVideoPlayer(videoShortcutFile)
} else if (file.isShortcutVideo) {
val videoShortcutFile = file.copy(id = file.shortcutDetails.targetId!!)
viewModel.fetchToken(videoShortcutFile)
}
}

}

private fun launchVideoPlayer(file: DriveFile) {

val items = arrayOf("ExoPlayer", "MPV (Experimental)")
val items = arrayOf("ExoPlayer", "MPV")

MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.play_using))
Expand All @@ -251,9 +265,11 @@ class FilesFragment : BaseFragment() {
is Resource.Success -> {
launchMpv(res.data!!)
}

is Resource.Error -> {
showSnackBar(res.message!!)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import zechs.drive.stream.databinding.ItemLoadingBinding

class FilesAdapter(
val onClickListener: (DriveFile) -> Unit,
val onLongClickListener: (DriveFile) -> Unit,
val onStarClickListener: (DriveFile, Boolean) -> Unit
) : ListAdapter<FilesDataModel, FilesViewHolder>(FilesItemDiffCallback()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sealed class FilesViewHolder(
}
}
}

Starred.STARRED -> {
itemBinding.apply {
btnStar.isInvisible = false
Expand All @@ -44,12 +45,14 @@ sealed class FilesViewHolder(
}
}
}

Starred.LOADING -> {
itemBinding.apply {
btnStar.isInvisible = true
starLoading.isGone = false
}
}

Starred.UNKNOWN -> {
itemBinding.apply {
btnStar.isGone = true
Expand Down Expand Up @@ -87,6 +90,11 @@ sealed class FilesViewHolder(
filesAdapter.onClickListener.invoke(item)
}

root.setOnLongClickListener {
filesAdapter.onLongClickListener.invoke(item)
return@setOnLongClickListener true
}

setStarred(item, item.starred)
}
}
Expand Down

0 comments on commit e9471a8

Please sign in to comment.