Skip to content

Commit

Permalink
Changed SearchView look, added long click thumb action, updated depen…
Browse files Browse the repository at this point in the history
…dencies

Signed-off-by: AndreaCioccarelli <[email protected]>
  • Loading branch information
cioccarellia committed May 25, 2019
1 parent 5714104 commit b53138c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 57 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -319,4 +318,4 @@ class MainActivity : BaseActivity() {

else -> super.onOptionsItemSelected(item)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<YouTubePlayerView>(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}"
Expand Down
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
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
tools:showIn="@layout/activity_layout">

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/searchLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Binary file modified bin/music-downloader.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions bin/update.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"versionCode": 18,
"versionName": "1.3.8",
"changelog": "Performances & usability improvements, bug fixes",
"versionCode": 19,
"versionName": "1.3.9",
"changelog": "Changed SearchView look, added long-click actions for results, fixes",

"downloadInfo": {
"useBundledUpdateLink": true,
Expand Down

0 comments on commit b53138c

Please sign in to comment.