Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #3834 - Initialize job in init
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Jul 1, 2019
1 parent 50052c9 commit bed926c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
18 changes: 4 additions & 14 deletions app/src/main/java/org/mozilla/fenix/utils/AdapterWithJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
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)
Expand All @@ -29,17 +24,12 @@ abstract class AdapterWithJob<VH : RecyclerView.ViewHolder> : 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<T, VH : RecyclerView.ViewHolder>(
diffCallback: DiffUtil.ItemCallback<T>
) : ListAdapter<T, VH>(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)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@
<dialog
android:id="@+id/shareFragment"
android:name="org.mozilla.fenix.share.ShareFragment"
android:label="fragment_share"
tools:layout="@layout/fragment_share" >
<argument
android:name="url"
Expand Down

0 comments on commit bed926c

Please sign in to comment.