From 93fe31f014a4383f5b9172fc637b914306300e0a Mon Sep 17 00:00:00 2001 From: LagradOst Date: Wed, 16 Jun 2021 02:15:07 +0200 Subject: [PATCH] minicast color --- .../cloudstream3/ui/MiniControllerFragment.kt | 23 ++++++++++++++++++- .../cloudstream3/ui/result/ResultFragment.kt | 15 +++++++++++- app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/layout/fragment_result.xml | 7 ++++-- app/src/main/res/values/attrs.xml | 9 ++++++++ app/src/main/res/values/styles.xml | 2 +- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/MiniControllerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/MiniControllerFragment.kt index 32134c72..4e983f64 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/MiniControllerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/MiniControllerFragment.kt @@ -1,18 +1,34 @@ package com.lagradost.cloudstream3.ui +import android.content.Context import android.os.Bundle +import android.util.AttributeSet import android.view.View -import android.widget.ImageView import android.widget.LinearLayout import android.widget.ProgressBar import android.widget.RelativeLayout +import androidx.core.content.ContextCompat import com.google.android.gms.cast.framework.media.widget.MiniControllerFragment import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.UIHelper.adjustAlpha import com.lagradost.cloudstream3.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.UIHelper.toPx + class MyMiniControllerFragment : MiniControllerFragment() { + var currentColor: Int = 0 + + // I KNOW, KINDA SPAGHETTI SOLUTION, BUT IT WORKS + override fun onInflate(context: Context, attributeSet: AttributeSet, bundle: Bundle?) { + val obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.CustomCast, 0, 0) + if (obtainStyledAttributes.hasValue(R.styleable.CustomCast_customCastBackgroundColor)) { + currentColor = obtainStyledAttributes.getColor(R.styleable.CustomCast_customCastBackgroundColor, 0) + } + + super.onInflate(context, attributeSet, bundle) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -20,12 +36,17 @@ class MyMiniControllerFragment : MiniControllerFragment() { try { val progressBar: ProgressBar? = view.findViewById(R.id.progressBar) val containerAll: LinearLayout? = view.findViewById(R.id.container_all) + val containerCurrent: RelativeLayout? = view.findViewById(R.id.container_current) context?.let { ctx -> progressBar?.setBackgroundColor(adjustAlpha(ctx.colorFromAttribute(R.attr.colorPrimary), 0.35f)) val params = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 2.toPx) progressBar?.layoutParams = params + + if (currentColor != 0) { + containerCurrent?.setBackgroundColor(currentColor) + } } val child = containerAll?.getChildAt(0) child?.alpha = 0f // REMOVE GRADIENT diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 4591a5ad..7c3e0674 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -26,6 +26,7 @@ import com.google.android.gms.cast.framework.CastContext import com.google.android.gms.cast.framework.CastState import com.google.android.material.button.MaterialButton import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.UIHelper.isCastApiAvailable import com.lagradost.cloudstream3.UIHelper.popupMenu @@ -122,6 +123,18 @@ class ResultFragment : Fragment() { override fun onDestroy() { //requireActivity().viewModelStore.clear() // REMEMBER THE CLEAR super.onDestroy() + activity?.let { + it.window?.navigationBarColor = + it.colorFromAttribute(R.attr.darkBackground) + } + } + + override fun onResume() { + super.onResume() + activity?.let { + it.window?.navigationBarColor = + it.colorFromAttribute(R.attr.bitDarkerGrayBackground) + } } private var currentPoster: String? = null @@ -245,7 +258,7 @@ class ResultFragment : Fragment() { it.popupMenuNoIcons( items = WatchType.values() .map { watchType -> Pair(watchType.internalId, watchType.stringRes) }, - //.map { watchType -> Triple(watchType.internalId, watchType.iconRes, watchType.stringRes) }, + //.map { watchType -> Triple(watchType.internalId, watchType.iconRes, watchType.stringRes) }, ) { context?.let { localContext -> viewModel.updateWatchStatus(localContext, WatchType.fromInternalId(this.itemId)) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 72cc9101..4d18d1c0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -44,6 +44,7 @@ > - + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 21a10220..bcf71e6a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -147,7 +147,7 @@ @style/TextAppearance.AppCompat.Subhead @style/TextAppearance.AppCompat.Caption - ?attr/darkBackground + @color/transparent ?attr/colorPrimary @drawable/cast_ic_mini_controller_stop' @drawable/cast_ic_mini_controller_stop_large