From bed926c31797475fcae38070307e9953f032c0f7 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Mon, 1 Jul 2019 15:23:41 -0700 Subject: [PATCH] For #3834 - Initialize job in init --- .../org/mozilla/fenix/utils/AdapterWithJob.kt | 18 ++++-------------- app/src/main/res/navigation/nav_graph.xml | 1 - 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/utils/AdapterWithJob.kt b/app/src/main/java/org/mozilla/fenix/utils/AdapterWithJob.kt index 6417ade33a80..ae91db6a71e7 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/AdapterWithJob.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/AdapterWithJob.kt @@ -11,15 +11,10 @@ import kotlinx.coroutines.Job /** * [RecyclerView.Adapter] with a [Job] for coroutines. - * The adapterJob is setup when the adapter is attached to a RecyclerView and canceled when detached. + * The adapterJob is setup when the adapter is initialized to a RecyclerView and canceled when detached. */ abstract class AdapterWithJob : RecyclerView.Adapter() { - protected lateinit var adapterJob: Job - - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - super.onAttachedToRecyclerView(recyclerView) - adapterJob = Job() - } + protected var adapterJob: Job = Job() override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { super.onDetachedFromRecyclerView(recyclerView) @@ -29,17 +24,12 @@ abstract class AdapterWithJob : RecyclerView.Adapt /** * [ListAdapter] with a [Job] for coroutines. - * The adapterJob is setup when the adapter is attached to a RecyclerView and canceled when detached. + * The adapterJob is setup when the adapter is initialized to a RecyclerView and canceled when detached. */ abstract class ListAdapterWithJob( diffCallback: DiffUtil.ItemCallback ) : ListAdapter(diffCallback) { - protected lateinit var adapterJob: Job - - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - super.onAttachedToRecyclerView(recyclerView) - adapterJob = Job() - } + protected var adapterJob: Job = Job() override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { super.onDetachedFromRecyclerView(recyclerView) diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 0214e623fba9..b49a8e739dd9 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -405,7 +405,6 @@