From 6b8ffc0ed2a02256008f0b331915ff62fd482539 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 17 Apr 2021 19:20:27 -0700 Subject: Inject frost content view --- .../pitchedapps/frost/views/FrostContentView.kt | 60 ++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index 5700b54b..124a75df 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -42,13 +42,13 @@ import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L +import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.ConflatedBroadcastChannel import kotlinx.coroutines.channels.ReceiveChannel -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject +import javax.inject.Inject class FrostContentWeb @JvmOverloads constructor( context: Context, @@ -76,18 +76,48 @@ abstract class FrostContentView @JvmOverloads constructor( attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 -) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), - FrostContentParent, - KoinComponent where T : View, T : FrostContentCore { +) : FrostContentViewBase(context, attrs, defStyleAttr, defStyleRes), + FrostContentParent where T : View, T : FrostContentCore { - private val prefs: Prefs by inject() - private val themeProvider: ThemeProvider by inject() - private val refresh: SwipeRefreshLayout by bindView(R.id.content_refresh) - private val progress: ProgressBar by bindView(R.id.content_progress) val coreView: T by bindView(R.id.content_core) override val core: FrostContentCore get() = coreView +} + +/** + * Subsection of [FrostContentView] that is [AndroidEntryPoint] friendly (no generics) + */ +@UseExperimental(ExperimentalCoroutinesApi::class) +@AndroidEntryPoint +abstract class FrostContentViewBase( + context: Context, + attrs: AttributeSet?, + defStyleAttr: Int, + defStyleRes: Int +) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), + FrostContentParent { + + // No JvmOverloads due to hilt + constructor(context: Context) : this(context, null) + + constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this( + context, + attrs, + defStyleAttr, + 0 + ) + + @Inject + lateinit var prefs: Prefs + + @Inject + lateinit var themeProvider: ThemeProvider + + private val refresh: SwipeRefreshLayout by bindView(R.id.content_refresh) + private val progress: ProgressBar by bindView(R.id.content_progress) /** * While this can be conflated, there exist situations where we wish to watch refresh cycles. @@ -130,7 +160,7 @@ abstract class FrostContentView @JvmOverloads constructor( */ protected fun init() { inflate(context, layoutRes, this) - coreView.parent = this + core.parent = this reloadThemeSelf() } @@ -141,9 +171,7 @@ abstract class FrostContentView @JvmOverloads constructor( scope = container core.bind(container) refresh.setOnRefreshListener { - with(coreView) { - reload(true) - } + core.reload(true) } refreshChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { r -> @@ -161,11 +189,11 @@ abstract class FrostContentView @JvmOverloads constructor( override fun reloadTheme() { reloadThemeSelf() - coreView.reloadTheme() + core.reloadTheme() } override fun reloadTextSize() { - coreView.reloadTextSize() + core.reloadTextSize() } override fun reloadThemeSelf() { @@ -196,7 +224,7 @@ abstract class FrostContentView @JvmOverloads constructor( return false // still in progress; do not bother with load } L.v { "Registered transition" } - with(coreView) { + with(core) { refreshReceiver = refreshChannel.openSubscription().also { receiver -> scope.launchMain { var loading = false -- cgit v1.2.3