Skip to content

Commit

Permalink
handle disposable properly
Browse files Browse the repository at this point in the history
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
  • Loading branch information
sowjanyakch committed Nov 11, 2024
1 parent e4e5ac1 commit a94b95f
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class SetStatusDialogFragment :

val predefinedStatusesList = ArrayList<PredefinedStatus>()

private val disposables: MutableList<Disposable> = ArrayList()

private lateinit var adapter: PredefinedStatusListAdapter
private var clearAt: Long? = null
private lateinit var popup: EmojiPopup
Expand Down Expand Up @@ -130,7 +132,9 @@ class SetStatusDialogFragment :
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<ResponseBody> {
override fun onSubscribe(d: Disposable) {}
override fun onSubscribe(d: Disposable) {
disposables.add(d)
}

@SuppressLint("NotifyDataSetChanged")
override fun onNext(responseBody: ResponseBody) {
Expand All @@ -152,7 +156,9 @@ class SetStatusDialogFragment :
Log.e(TAG, "Error while fetching predefined statuses", e)
}

override fun onComplete() {}
override fun onComplete() {
// unused atm
}
})
}

Expand All @@ -163,6 +169,7 @@ class SetStatusDialogFragment :
.subscribe(object : Observer<StatusOverall> {

override fun onSubscribe(d: Disposable) {
disposables.add(d)
}

@SuppressLint("NotifyDataSetChanged")
Expand All @@ -188,6 +195,7 @@ class SetStatusDialogFragment :
}

override fun onComplete() {
// unused atm
}
})
}
Expand Down Expand Up @@ -294,6 +302,7 @@ class SetStatusDialogFragment :
.subscribe(object : Observer<GenericOverall> {

override fun onSubscribe(d: Disposable) {
disposables.add(d)
}

@SuppressLint("NotifyDataSetChanged")
Expand All @@ -314,6 +323,7 @@ class SetStatusDialogFragment :
}

override fun onComplete() {
// unused atm
}
})
}
Expand Down Expand Up @@ -432,7 +442,7 @@ class SetStatusDialogFragment :
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
disposables.add(d)
}

override fun onNext(statusOverall: GenericOverall) {
Expand All @@ -459,7 +469,7 @@ class SetStatusDialogFragment :
)
.observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
disposables.add(d)
}

override fun onNext(statusOverall: GenericOverall) {
Expand Down Expand Up @@ -562,7 +572,9 @@ class SetStatusDialogFragment :
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) = Unit
override fun onSubscribe(d: Disposable) {
disposables.add(d)
}

override fun onNext(t: GenericOverall) {
Log.d(TAG, "PredefinedStatusMessage successfully set")
Expand All @@ -573,7 +585,8 @@ class SetStatusDialogFragment :
Log.e(TAG, "failed to set PredefinedStatusMessage", e)
}

override fun onComplete() = Unit
override fun onComplete() {
}
})
}
}
Expand Down Expand Up @@ -619,6 +632,19 @@ class SetStatusDialogFragment :
}
}

private fun dispose() {
for (i in disposables.indices) {
if (!disposables[i].isDisposed) {
disposables[i].dispose()
}
}
}

override fun onDestroy() {
dispose()
super.onDestroy()
}

/**
* Fragment creator
*/
Expand Down

0 comments on commit a94b95f

Please sign in to comment.