From c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Feb 2020 16:06:45 -0800 Subject: Move prefs to service locator --- .../com/pitchedapps/frost/fragments/FragmentBase.kt | 15 ++++++++++----- .../com/pitchedapps/frost/fragments/WebFragments.kt | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index a2399d7c..316e05c7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -39,7 +39,6 @@ import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.REQUEST_REFRESH import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM import com.pitchedapps.frost.utils.frostEvent -import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job @@ -47,6 +46,9 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +import org.koin.core.KoinComponent +import org.koin.core.inject +import kotlin.coroutines.CoroutineContext /** * Created by Allan Wang on 2017-11-07. @@ -55,7 +57,8 @@ import kotlinx.coroutines.launch * Must be attached to activities implementing [MainActivityContract] */ @UseExperimental(ExperimentalCoroutinesApi::class) -abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, DynamicUiContract { +abstract class BaseFragment : Fragment(), CoroutineScope, KoinComponent, FragmentContract, + DynamicUiContract { companion object { private const val ARG_POSITION = "arg_position" @@ -63,12 +66,13 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna internal operator fun invoke( base: () -> BaseFragment, + prefs: Prefs, useFallback: Boolean, data: FbItem, position: Int ): BaseFragment { val fragment = if (useFallback) WebFragment() else base() - val d = if (data == FbItem.FEED) FeedSort(Prefs.feedSort).item else data + val d = if (data == FbItem.FEED) FeedSort(prefs.feedSort).item else data fragment.withArguments( ARG_URL to d.url, ARG_POSITION to position @@ -78,6 +82,7 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna } } + protected val prefs: Prefs by inject() open lateinit var job: Job override val coroutineContext: CoroutineContext get() = ContextHelper.dispatcher + job @@ -195,10 +200,10 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna protected fun FloatingActionButton.update(iicon: IIcon, click: () -> Unit) { if (isShown) { fadeScaleTransition { - setIcon(iicon, Prefs.iconColor) + setIcon(iicon, prefs.iconColor) } } else { - setIcon(iicon, Prefs.iconColor) + setIcon(iicon, prefs.iconColor) show() } setOnClickListener { click() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt index a6b4eae7..4235ef49 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt @@ -52,9 +52,9 @@ class WebFragment : BaseFragment() { L.e { "Webview not found in fragment $baseEnum" } return super.updateFab(contract) } - if (baseEnum.isFeed && Prefs.showCreateFab) { + if (baseEnum.isFeed && prefs.showCreateFab) { contract.showFab(GoogleMaterial.Icon.gmd_edit) { - JsActions.CREATE_POST.inject(web) + JsActions.CREATE_POST.inject(web, prefs) } return } -- cgit v1.2.3