diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-25 16:32:51 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2018-12-25 16:32:51 -0500 |
commit | 697e457da453568ca703c2b655a2dd490157b443 (patch) | |
tree | c066cc83ee96c83a05d2b35b609a924b5c87a241 /app/src/main/kotlin/com/pitchedapps/frost/fragments | |
parent | 25760fa2d066a23e7fc72747f59c964e76ed0889 (diff) | |
download | frost-697e457da453568ca703c2b655a2dd490157b443.tar.gz frost-697e457da453568ca703c2b655a2dd490157b443.tar.bz2 frost-697e457da453568ca703c2b655a2dd490157b443.zip |
Clean up image activity and prepare for tests
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt | 17 |
1 files changed, 16 insertions, 1 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 98e28bd3..2c46edbc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -41,6 +41,11 @@ import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM import com.pitchedapps.frost.utils.frostEvent import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import kotlin.coroutines.CoroutineContext /** * Created by Allan Wang on 2017-11-07. @@ -48,7 +53,7 @@ import io.reactivex.disposables.Disposable * All fragments pertaining to the main view * Must be attached to activities implementing [MainActivityContract] */ -abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { +abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, DynamicUiContract { companion object { private const val ARG_POSITION = "arg_position" @@ -71,6 +76,10 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { } } + open lateinit var job: Job + override val coroutineContext: CoroutineContext + get() = Dispatchers.Main + job + override val baseUrl: String by lazy { arguments!!.getString(ARG_URL) } override val baseEnum: FbItem by lazy { FbItem[arguments]!! } override val position: Int by lazy { arguments!!.getInt(ARG_POSITION) } @@ -98,6 +107,7 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + job = SupervisorJob() firstLoad = true if (context !is MainActivityContract) throw IllegalArgumentException("${this::class.java.simpleName} is not attached to a context implementing MainActivityContract") @@ -207,6 +217,11 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { super.onDestroyView() } + override fun onDestroy() { + job.cancel() + super.onDestroy() + } + override fun reloadTheme() { reloadThemeSelf() content?.reloadTextSize() |