diff --git a/app/build.gradle b/app/build.gradle index be2889f..eb6c429 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "com.andreacioccarelli.musicdownloader" minSdkVersion 21 targetSdkVersion 28 - versionCode 18 - versionName "1.3.8" + versionCode 19 + versionName "1.3.9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } @@ -75,9 +75,10 @@ dependencies { implementation "com.afollestad:assent:2.2.3" implementation "com.github.AndreaCioccarelli:CryptoPrefs:1.3.2.5" implementation "com.github.AndreaCioccarelli:LogKit:1.2.0" - implementation "com.afollestad.material-dialogs:core:2.8.1" - implementation "com.afollestad.material-dialogs:input:2.8.1" - implementation "com.tapadoo.android:alerter:4.0.2" + implementation "com.afollestad.material-dialogs:core:3.0.0-beta2" + implementation "com.afollestad.material-dialogs:input:3.0.0-beta2" + implementation 'com.afollestad.material-dialogs:bottomsheets:3.0.0-beta2' + implementation "com.tapadoo.android:alerter:4.0.3" implementation "com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3" implementation "com.github.GrenderG:Toasty:1.4.1" implementation 'uk.co.chrisjenx:calligraphy:2.3.0' diff --git a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/activities/MainActivity.kt b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/activities/MainActivity.kt index 8b2be54..b056c02 100755 --- a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/activities/MainActivity.kt @@ -284,7 +284,6 @@ class MainActivity : BaseActivity() { checklistDialog = MaterialDialog(this).show { customView(R.layout.empty_view_checklist) } - } else { val checklistAdapter = ChecklistAdapter(this@MainActivity) val extensions = listOf("MP3", "MP4") @@ -319,4 +318,4 @@ class MainActivity : BaseActivity() { else -> super.onOptionsItemSelected(item) } -} +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/adapters/SearchResultAdapter.kt b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/adapters/SearchResultAdapter.kt index 8c4e848..444a428 100644 --- a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/adapters/SearchResultAdapter.kt +++ b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/adapters/SearchResultAdapter.kt @@ -18,6 +18,7 @@ import com.andreacioccarelli.musicdownloader.ui.fragments.BottomDialogFragment import com.andreacioccarelli.musicdownloader.ui.holders.ResultCardViewHolder import com.andreacioccarelli.musicdownloader.ui.toast.ToastUtil import com.andreacioccarelli.musicdownloader.util.VibrationUtil +import com.andreacioccarelli.musicdownloader.util.YoutubeUtil import com.bumptech.glide.Glide /** @@ -52,6 +53,12 @@ class SearchResultAdapter( with(holder) { title.text = data[i].snippet.title.escapeHtml() + + icon.setOnLongClickListener { + YoutubeUtil.getVideoViewerDialog(activity, data[i].id.videoId).show() + true + } + card.setOnClickListener { val bottomSheetFragment = BottomDialogFragment(data[i]) bottomSheetFragment.show(fragmentManager, bottomSheetFragment.tag) @@ -61,9 +68,11 @@ class SearchResultAdapter( VibrationUtil.medium() if (checklist.contains(data[i].id.videoId)) { ToastUtil.error("Removed from checklist", R.drawable.remove_outline, duration = 0) + checklist.remove(data[i].id.videoId) } else { ToastUtil.success("Added to checklist", R.drawable.add_outline, duration = 0) + checklist.add( ChecklistEntry( data[i].id.videoId, diff --git a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/fragments/BottomDialogFragment.kt b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/fragments/BottomDialogFragment.kt index 4874f67..04b6583 100755 --- a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/fragments/BottomDialogFragment.kt +++ b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/ui/fragments/BottomDialogFragment.kt @@ -14,8 +14,6 @@ import androidx.cardview.widget.CardView import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.WhichButton import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.customview.customView -import com.afollestad.materialdialogs.customview.getCustomView import com.afollestad.materialdialogs.input.getInputField import com.afollestad.materialdialogs.input.input import com.andreacioccarelli.musicdownloader.App.Companion.checklist @@ -31,19 +29,14 @@ import com.andreacioccarelli.musicdownloader.data.model.DownloadInfo import com.andreacioccarelli.musicdownloader.data.serializers.Result import com.andreacioccarelli.musicdownloader.extensions.escapeHtml import com.andreacioccarelli.musicdownloader.extensions.toUri -import com.andreacioccarelli.musicdownloader.ui.gradients.GradientGenerator import com.andreacioccarelli.musicdownloader.ui.toast.ToastUtil import com.andreacioccarelli.musicdownloader.util.VibrationUtil +import com.andreacioccarelli.musicdownloader.util.YoutubeUtil import com.bumptech.glide.Glide import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants -import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer -import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.YouTubePlayerListener -import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView import org.jetbrains.anko.find - /** * Created by La mejor on 2018/Aug. * Part of the package andreacioccarelli.musicdownloader.ui.fragment @@ -139,45 +132,7 @@ class BottomDialogFragment(val remoteResult: Result) : BottomSheetDialogFragment } private fun openVideoInDialog() { - val dialog = MaterialDialog(requireContext()) - .customView(R.layout.video_player_dialog, scrollable = false) - - dialog.window!!.setBackgroundDrawable(GradientGenerator.make(26F, R.color.Grey_1000, R.color.Grey_1000)) - - val youtubePlayer = dialog.getCustomView().find(R.id.player) - - youtubePlayer.enableAutomaticInitialization = false - youtubePlayer.initialize(object: YouTubePlayerListener { - override fun onReady(youTubePlayer: YouTubePlayer) { - youTubePlayer.loadVideo(remoteResult.id.videoId, 0f) - } - - override fun onError(youTubePlayer: YouTubePlayer, error: PlayerConstants.PlayerError) { - when (error) { - PlayerConstants.PlayerError.UNKNOWN -> ToastUtil.error("An unknown error has occurred while playing video") - PlayerConstants.PlayerError.INVALID_PARAMETER_IN_REQUEST -> ToastUtil.error("An internal error has occurred while playing video") - PlayerConstants.PlayerError.HTML_5_PLAYER -> ToastUtil.error("Internal HTML player error") - PlayerConstants.PlayerError.VIDEO_NOT_FOUND -> ToastUtil.warn("Video not found") - PlayerConstants.PlayerError.VIDEO_NOT_PLAYABLE_IN_EMBEDDED_PLAYER -> ToastUtil.warn("MusicDownloader can't play this type of video") - } - } - - override fun onStateChange(youTubePlayer: YouTubePlayer, state: PlayerConstants.PlayerState) {} - override fun onVideoDuration(youTubePlayer: YouTubePlayer, duration: Float) {} - override fun onVideoId(youTubePlayer: YouTubePlayer, videoId: String) {} - override fun onVideoLoadedFraction(youTubePlayer: YouTubePlayer, loadedFraction: Float) {} - override fun onApiChange(youTubePlayer: YouTubePlayer) {} - override fun onCurrentSecond(youTubePlayer: YouTubePlayer, second: Float) {} - override fun onPlaybackQualityChange(youTubePlayer: YouTubePlayer, playbackQuality: PlayerConstants.PlaybackQuality) {} - override fun onPlaybackRateChange(youTubePlayer: YouTubePlayer, playbackRate: PlayerConstants.PlaybackRate) {} - }, true) - - with(dialog) { - show() - setOnDismissListener { - youtubePlayer.release() - } - } + YoutubeUtil.getVideoViewerDialog(requireContext(), remoteResult.id.videoId).show() } private fun getFullLink() = "$YOUTUBE_WATCH_URL${remoteResult.id.videoId}" diff --git a/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/util/YoutubeUtil.kt b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/util/YoutubeUtil.kt new file mode 100644 index 0000000..1b40b90 --- /dev/null +++ b/app/src/main/kotlin/com/andreacioccarelli/musicdownloader/util/YoutubeUtil.kt @@ -0,0 +1,64 @@ +package com.andreacioccarelli.musicdownloader.util + +import android.content.Context +import androidx.annotation.CheckResult +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.customview.customView +import com.afollestad.materialdialogs.customview.getCustomView +import com.andreacioccarelli.musicdownloader.R +import com.andreacioccarelli.musicdownloader.ui.gradients.GradientGenerator +import com.andreacioccarelli.musicdownloader.ui.toast.ToastUtil +import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants +import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer +import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.YouTubePlayerListener +import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView +import org.jetbrains.anko.find + +object YoutubeUtil { + + @CheckResult + fun getVideoViewerDialog( + context: Context, + id: String + ): MaterialDialog { + val dialog = MaterialDialog(context) + .customView(R.layout.video_player_dialog, scrollable = false) + + val background = GradientGenerator.make(26F, R.color.Grey_1000, R.color.Grey_1000) + dialog.window!!.setBackgroundDrawable(background) + + val youtubePlayer = dialog.getCustomView().find(R.id.player) + + youtubePlayer.enableAutomaticInitialization = false + youtubePlayer.initialize(object: YouTubePlayerListener { + override fun onReady(youTubePlayer: YouTubePlayer) { + youTubePlayer.loadVideo(id, 0f) + } + + override fun onError(youTubePlayer: YouTubePlayer, error: PlayerConstants.PlayerError) { + when (error) { + PlayerConstants.PlayerError.UNKNOWN -> ToastUtil.error("An unknown error has occurred while playing video") + PlayerConstants.PlayerError.INVALID_PARAMETER_IN_REQUEST -> ToastUtil.error("An internal error has occurred while playing video") + PlayerConstants.PlayerError.HTML_5_PLAYER -> ToastUtil.error("Internal HTML player error") + PlayerConstants.PlayerError.VIDEO_NOT_FOUND -> ToastUtil.warn("Video not found") + PlayerConstants.PlayerError.VIDEO_NOT_PLAYABLE_IN_EMBEDDED_PLAYER -> ToastUtil.warn("MusicDownloader can't play this type of video") + } + } + + override fun onStateChange(youTubePlayer: YouTubePlayer, state: PlayerConstants.PlayerState) {} + override fun onVideoDuration(youTubePlayer: YouTubePlayer, duration: Float) {} + override fun onVideoId(youTubePlayer: YouTubePlayer, videoId: String) {} + override fun onVideoLoadedFraction(youTubePlayer: YouTubePlayer, loadedFraction: Float) {} + override fun onApiChange(youTubePlayer: YouTubePlayer) {} + override fun onCurrentSecond(youTubePlayer: YouTubePlayer, second: Float) {} + override fun onPlaybackQualityChange(youTubePlayer: YouTubePlayer, playbackQuality: PlayerConstants.PlaybackQuality) {} + override fun onPlaybackRateChange(youTubePlayer: YouTubePlayer, playbackRate: PlayerConstants.PlaybackRate) {} + }, true) + + dialog.setOnDismissListener { + youtubePlayer.release() + } + + return dialog + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_content.xml b/app/src/main/res/layout/activity_content.xml index 3692008..fb17cf0 100755 --- a/app/src/main/res/layout/activity_content.xml +++ b/app/src/main/res/layout/activity_content.xml @@ -11,6 +11,7 @@ tools:showIn="@layout/activity_layout">