146 lines
6.5 KiB
Kotlin
146 lines
6.5 KiB
Kotlin
package com.adlerosn.brasilfurfest.helper
|
|
|
|
import android.app.Activity
|
|
import androidx.core.content.ContextCompat
|
|
import android.view.Gravity
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import com.adlerosn.brasilfurfest.R
|
|
import com.adlerosn.brasilfurfest.schedule.abstractDataTypes.dataholder.PeekableEvent
|
|
//import com.peekandpop.shalskar.peekandpop.PeekAndPop
|
|
import com.tooltip.Tooltip
|
|
import kotlinx.android.synthetic.main.peek_event_item.view.*
|
|
import java.text.SimpleDateFormat
|
|
fun bindPeekAndPop(
|
|
activity: Activity,
|
|
viewGroup: ViewGroup,
|
|
view: View,
|
|
starStatus: Boolean?,
|
|
starAction: ()->Unit,
|
|
fullscreenAction: ()->Unit,
|
|
peekableEvent: PeekableEvent
|
|
) = {
|
|
val dowFormatter = SimpleDateFormat("E", view.context.runtimeLanguage.locale)
|
|
val hourMinuteFormatter = SimpleDateFormat("HH:mm", view.context.runtimeLanguage.locale)
|
|
var tooltip: Tooltip? = null
|
|
PeekAndPop.Builder(activity)
|
|
.peekLayout(R.layout.peek_event_item)
|
|
.longClickViews(view)
|
|
.blurBackground(false)
|
|
.parentViewGroupToDisallowTouchEvents(viewGroup)
|
|
.onGeneralActionListener(object : PeekAndPop.OnGeneralActionListener {
|
|
override fun onPeek(longClickView: View, position: Int) {
|
|
// vibrate(longClickView.context, 10)
|
|
activity.hideKeyboard()
|
|
}
|
|
|
|
override fun onPop(longClickView: View, position: Int) {
|
|
tooltip?.dismiss()
|
|
tooltip = null
|
|
}
|
|
})
|
|
.onHoldAndReleaseListener(object : PeekAndPop.OnHoldAndReleaseListener {
|
|
override fun onHold(view: View, position: Int) {
|
|
vibrate(view.context, 10)
|
|
tooltip?.dismiss()
|
|
tooltip = when (view.id) {
|
|
R.id.starIt -> starStatus?.let {
|
|
Tooltip.Builder(view)
|
|
.setText(view.context.getString(
|
|
if (it)
|
|
R.string.tooltip_remove_favorite
|
|
else
|
|
R.string.tooltip_add_favorite
|
|
))
|
|
}
|
|
R.id.goFullscreen ->
|
|
Tooltip.Builder(view)
|
|
.setText(view.context.getString(R.string.tooltip_show_details))
|
|
else -> null
|
|
}
|
|
?.setBackgroundColor(view.context.getColorCompat(R.color.colorBase03))
|
|
?.setTextColor(view.context.getColorCompat(R.color.colorBase18))
|
|
?.setGravity(Gravity.TOP)
|
|
?.show()
|
|
}
|
|
|
|
override fun onLeave(view: View, position: Int) {
|
|
tooltip?.dismiss()
|
|
tooltip = null
|
|
}
|
|
override fun onRelease(view: View, position: Int) {
|
|
tooltip?.dismiss()
|
|
tooltip = null
|
|
when (view.id) {
|
|
R.id.starIt -> starAction()
|
|
R.id.goFullscreen -> fullscreenAction()
|
|
}
|
|
}
|
|
})
|
|
.build()
|
|
// .apply {
|
|
// val scheduleManager = ScheduleManagerGetter[activity]
|
|
// var obs = Observer { _: Observable, _: Any? -> }
|
|
// obs = Observer { observable: Observable, _: Any? ->
|
|
// observable.deleteObserver(obs)
|
|
// destroy()
|
|
// val lht = PeekAndPop::class.java.getDeclaredField("longHoldTimer").let{
|
|
// it.isAccessible = true
|
|
// it.get(this) as Timer
|
|
// }
|
|
// lht.purge()
|
|
// lht.cancel()
|
|
// }
|
|
// scheduleManager.addObserver(obs)
|
|
// }
|
|
.apply {
|
|
if (starStatus == null)
|
|
peekView.starIt.visibility = View.GONE
|
|
else
|
|
peekView.starIt.setImageResource(
|
|
if (!starStatus)
|
|
R.drawable.ic_star_black_24dp
|
|
else
|
|
R.drawable.ic_star_border_black_24dp
|
|
)
|
|
addHoldAndReleaseView(R.id.starIt)
|
|
addHoldAndReleaseView(R.id.goFullscreen)
|
|
peekView.timeRange.text = "" +
|
|
dowFormatter.format(peekableEvent.timeRange.start.timeInMillis).capitalize() +
|
|
", " +
|
|
hourMinuteFormatter.format(peekableEvent.timeRange.start.timeInMillis) +
|
|
" - " +
|
|
hourMinuteFormatter.format(peekableEvent.timeRange.finish.timeInMillis)
|
|
peekView.title.text = peekableEvent.title.solved
|
|
if(peekableEvent.language==null){
|
|
peekView.language.visibility = View.GONE
|
|
}else {
|
|
("" + view.context.getString(R.string.preposition_in) + " " + view.context.getString(peekableEvent.language.language).toLowerCase())
|
|
.let {
|
|
peekView.language.text = it
|
|
}
|
|
}
|
|
if(peekableEvent.subtitles==null || peekableEvent.subtitles.solved.isNullOrBlank()){
|
|
peekView.speaker.visibility = View.GONE
|
|
}else{
|
|
peekView.speaker.text = peekableEvent.subtitles.solved
|
|
}
|
|
if(peekableEvent.places==null || peekableEvent.places.isEmpty()){
|
|
peekView.place.visibility = View.GONE
|
|
}else{
|
|
peekableEvent.places.map {
|
|
it.names.solved!!
|
|
}.let {
|
|
peekView.place.text = it.textuallyJoined
|
|
}
|
|
}
|
|
if(peekableEvent.descriptions==null || peekableEvent.descriptions.solved.isNullOrBlank()){
|
|
peekView.description.visibility = View.GONE
|
|
}else{
|
|
peekableEvent.descriptions.solved.let {
|
|
peekView.description.text = it
|
|
}
|
|
}
|
|
}
|
|
// */
|
|
}() |