aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-04-17 19:20:27 -0700
committerAllan Wang <me@allanwang.ca>2021-04-17 19:20:27 -0700
commit6b8ffc0ed2a02256008f0b331915ff62fd482539 (patch)
treec859be1b37c6dedbf3e56b0c53a54ba633171ef3 /app/src/main/kotlin
parenta56dbf0f61e80225f0d86af43ea0f1d6efa5e66a (diff)
downloadfrost-6b8ffc0ed2a02256008f0b331915ff62fd482539.tar.gz
frost-6b8ffc0ed2a02256008f0b331915ff62fd482539.tar.bz2
frost-6b8ffc0ed2a02256008f0b331915ff62fd482539.zip
Inject frost content view
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt37
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt60
2 files changed, 65 insertions, 32 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
index f68ce6d8..27263789 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
@@ -31,8 +31,6 @@ import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.injectors.ThemeProvider
import com.pitchedapps.frost.prefs.Prefs
import com.pitchedapps.frost.utils.launchWebOverlay
-import org.koin.core.component.KoinComponent
-import org.koin.core.component.inject
/**
* Created by Allan Wang on 30/12/17.
@@ -74,14 +72,18 @@ interface ClickableIItemContract {
*/
open class HeaderIItem(
val text: String?,
- itemId: Int = R.layout.iitem_header
-) : KauIItem<HeaderIItem.ViewHolder>(R.layout.iitem_header, ::ViewHolder, itemId) {
-
- class ViewHolder(itemView: View) :
- FastAdapter.ViewHolder<HeaderIItem>(itemView),
- KoinComponent {
-
- private val themeProvider: ThemeProvider by inject()
+ itemId: Int = R.layout.iitem_header,
+ private val themeProvider: ThemeProvider
+) : KauIItem<HeaderIItem.ViewHolder>(
+ R.layout.iitem_header,
+ { ViewHolder(it, themeProvider) },
+ itemId
+) {
+
+ class ViewHolder(
+ itemView: View,
+ private val themeProvider: ThemeProvider
+ ) : FastAdapter.ViewHolder<HeaderIItem>(itemView) {
val text: TextView by bindView(R.id.item_header_text)
@@ -104,20 +106,23 @@ open class HeaderIItem(
open class TextIItem(
val text: String?,
override val url: String?,
- itemId: Int = R.layout.iitem_text
-) : KauIItem<TextIItem.ViewHolder>(R.layout.iitem_text, ::ViewHolder, itemId),
+ itemId: Int = R.layout.iitem_text,
+ private val themeProvider: ThemeProvider
+) : KauIItem<TextIItem.ViewHolder>(R.layout.iitem_text, { ViewHolder(it, themeProvider) }, itemId),
ClickableIItemContract {
- class ViewHolder(itemView: View) : FastAdapter.ViewHolder<TextIItem>(itemView), KoinComponent {
-
- private val themeProvider: ThemeProvider by inject()
+ class ViewHolder(
+ itemView: View,
+ private val themeProvider: ThemeProvider
+ ) : FastAdapter.ViewHolder<TextIItem>(itemView) {
val text: TextView by bindView(R.id.item_text_view)
override fun bindView(item: TextIItem, payloads: List<Any>) {
text.setTextColor(themeProvider.textColor)
text.text = item.text
- text.background = createSimpleRippleDrawable(themeProvider.bgColor, themeProvider.nativeBgColor)
+ text.background =
+ createSimpleRippleDrawable(themeProvider.bgColor, themeProvider.nativeBgColor)
}
override fun unbindView(item: TextIItem) {
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<out T> @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<out T> @JvmOverloads constructor(
*/
protected fun init() {
inflate(context, layoutRes, this)
- coreView.parent = this
+ core.parent = this
reloadThemeSelf()
}
@@ -141,9 +171,7 @@ abstract class FrostContentView<out T> @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<out T> @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<out T> @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