cloudstream/app/src/main/java/com/lagradost/cloudstream3/ui/MiniControllerFragment.kt

83 lines
3 KiB
Kotlin
Raw Normal View History

2021-06-14 00:00:29 +00:00
package com.lagradost.cloudstream3.ui
2021-06-16 00:15:07 +00:00
import android.content.Context
2021-06-14 00:00:29 +00:00
import android.os.Bundle
2021-06-16 00:15:07 +00:00
import android.util.AttributeSet
2021-06-14 00:00:29 +00:00
import android.view.View
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.RelativeLayout
import com.google.android.gms.cast.framework.media.widget.MiniControllerFragment
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.UIHelper.adjustAlpha
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import java.lang.ref.WeakReference
2021-06-14 00:00:29 +00:00
2021-06-16 00:15:07 +00:00
2021-06-14 00:00:29 +00:00
class MyMiniControllerFragment : MiniControllerFragment() {
2021-06-16 00:15:07 +00:00
var currentColor: Int = 0
override fun onDestroy() {
currentColor = 0
super.onDestroy()
}
2021-06-16 00:15:07 +00:00
// I KNOW, KINDA SPAGHETTI SOLUTION, BUT IT WORKS
override fun onInflate(context: Context, attributeSet: AttributeSet, bundle: Bundle?) {
super.onInflate(context, attributeSet, bundle)
// somehow this leaks and I really dont know why, it seams like if you go back to a fragment with this, it leaks????
if (currentColor == 0) {
WeakReference(
context.obtainStyledAttributes(
attributeSet,
R.styleable.CustomCast
)
).apply {
if (get()
?.hasValue(R.styleable.CustomCast_customCastBackgroundColor) == true
) {
currentColor =
get()
?.getColor(R.styleable.CustomCast_customCastBackgroundColor, 0) ?: 0
}
get()?.recycle()
}.clear()
}
}
2021-06-16 00:15:07 +00:00
2021-06-14 00:00:29 +00:00
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// SEE https://github.com/dandar3/android-google-play-services-cast-framework/blob/master/res/layout/cast_mini_controller.xml
try {
val progressBar: ProgressBar? = view.findViewById(R.id.progressBar)
val containerAll: LinearLayout? = view.findViewById(R.id.container_all)
2021-06-16 00:15:07 +00:00
val containerCurrent: RelativeLayout? = view.findViewById(R.id.container_current)
2021-06-14 00:00:29 +00:00
context?.let { ctx ->
progressBar?.setBackgroundColor(
adjustAlpha(
ctx.colorFromAttribute(R.attr.colorPrimary),
0.35f
)
)
val params = RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
2.toPx
)
2021-06-14 00:00:29 +00:00
progressBar?.layoutParams = params
val color = currentColor
if (color != 0)
containerCurrent?.setBackgroundColor(color)
2021-06-14 00:00:29 +00:00
}
val child = containerAll?.getChildAt(0)
child?.alpha = 0f // REMOVE GRADIENT
} catch (e: Exception) {
// JUST IN CASE
}
}
}