-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed SearchView look, added long click thumb action, updated depen…
…dencies Signed-off-by: AndreaCioccarelli <[email protected]>
- Loading branch information
1 parent
5714104
commit b53138c
Showing
8 changed files
with
86 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/src/main/kotlin/com/andreacioccarelli/musicdownloader/util/YoutubeUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<YouTubePlayerView>(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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters