diff options
author | Allan Wang <me@allanwang.ca> | 2020-02-23 17:50:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 17:50:22 -0800 |
commit | 654cc6b943177120dc1a0a22a0d68d5cbfde2b5e (patch) | |
tree | 3bba2feb0cf99ae222693a4d564d9acf624322e2 /app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt | |
parent | 4d5aaf541dbfa7d521ebbc5f011a642c83c4b9c5 (diff) | |
parent | 1686de0d71d687990ca6f0d4b621bc4d52dee146 (diff) | |
download | frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.tar.gz frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.tar.bz2 frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.zip |
Merge pull request #1647 from AllanWang/kpref
Remove stateful singletons
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt | 14 |
1 files changed, 10 insertions, 4 deletions
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..257611e8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -32,6 +32,7 @@ import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.contracts.MainActivityContract import com.pitchedapps.frost.contracts.MainFabContract import com.pitchedapps.frost.enums.FeedSort +import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.utils.ARG_URL import com.pitchedapps.frost.utils.L @@ -47,6 +48,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +import org.koin.android.ext.android.inject /** * 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, 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,8 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna } } + protected val fbCookie: FbCookie by inject() + protected val prefs: Prefs by inject() open lateinit var job: Job override val coroutineContext: CoroutineContext get() = ContextHelper.dispatcher + job @@ -195,10 +201,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() } |