mirror of
https://github.com/element-hq/element-android
synced 2024-10-25 12:17:25 +03:00
Remove usage of GlobalScope
This commit is contained in:
parent
0711ecc7f4
commit
25b4c32fd0
2 changed files with 7 additions and 3 deletions
|
@ -19,6 +19,7 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import im.vector.app.core.extensions.cleanup
|
import im.vector.app.core.extensions.cleanup
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.databinding.EmojiChooserFragmentBinding
|
import im.vector.app.databinding.EmojiChooserFragmentBinding
|
||||||
|
@ -51,6 +52,8 @@ class EmojiChooserFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getCoroutineScope() = lifecycleScope
|
||||||
|
|
||||||
override fun firstVisibleSectionChange(section: Int) {
|
override fun firstVisibleSectionChange(section: Int) {
|
||||||
viewModel.setCurrentSection(section)
|
viewModel.setCurrentSection(section)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ import androidx.transition.AutoTransition
|
||||||
import androidx.transition.TransitionManager
|
import androidx.transition.TransitionManager
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.features.reactions.data.EmojiDataSource
|
import im.vector.app.features.reactions.data.EmojiDataSource
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
@ -278,6 +278,7 @@ class EmojiRecyclerAdapter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InteractionListener {
|
interface InteractionListener {
|
||||||
|
fun getCoroutineScope(): CoroutineScope
|
||||||
fun firstVisibleSectionChange(section: Int)
|
fun firstVisibleSectionChange(section: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,11 +324,11 @@ class EmojiRecyclerAdapter @Inject constructor(
|
||||||
// Log.i("SCROLL SPEED","scroll speed $dy")
|
// Log.i("SCROLL SPEED","scroll speed $dy")
|
||||||
isFastScroll = abs(dy) > 50
|
isFastScroll = abs(dy) > 50
|
||||||
val visible = (recyclerView.layoutManager as GridLayoutManager).findFirstCompletelyVisibleItemPosition()
|
val visible = (recyclerView.layoutManager as GridLayoutManager).findFirstCompletelyVisibleItemPosition()
|
||||||
GlobalScope.launch {
|
interactionListener?.getCoroutineScope()?.launch {
|
||||||
val section = getSectionForAbsoluteIndex(visible)
|
val section = getSectionForAbsoluteIndex(visible)
|
||||||
if (section != currentFirstVisibleSection) {
|
if (section != currentFirstVisibleSection) {
|
||||||
currentFirstVisibleSection = section
|
currentFirstVisibleSection = section
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
interactionListener?.getCoroutineScope()?.launch(Dispatchers.Main) {
|
||||||
interactionListener?.firstVisibleSectionChange(currentFirstVisibleSection)
|
interactionListener?.firstVisibleSectionChange(currentFirstVisibleSection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue