diff options
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 | 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() |