Skip to content

Instantly share code, notes, and snippets.

@NetoDevel

NetoDevel/sample.kt

Created Jul 10, 2018
Embed
What would you like to do?
class EventFragment {
companion object {
var fragmentEventsView : FragmentEventsView? = null
fun register(fragmentEventsView: FragmentEventsView) {
this.fragmentEventsView = fragmentEventsView
}
fun unRegister() {
this.fragmentEventsView = null
}
fun emitterUpdateUI(position: Int) {
if (this.fragmentEventsView != null) {
this.fragmentEventsView!!.onUpdateUI(position)
}
}
}
interface FragmentEventsView {
fun onUpdateUI(position: Int)
}
}
in fragment
class BlankFragment : Fragment() {
private lateinit var view : View
private val currentPosition = 2
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
view = inflater.inflate(R.layout.fragment_blank, container, false)
EventFragment.register(object : EventFragment.FragmentEventsView {
override fun onUpdateUI(position: Int) {
if (position == currentPosition) {
if(isVisible) {
presenter.findOne(App.token, App.credentialId)
}
}
}
})
return view
}
override fun onDestroy() {
super.onDestroy()
EventFragment.unRegister()
}
}
in viewpager
navigationTabBar.setOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
EventFragment.emitterUpdateUI(position)
}
override fun onPageScrollStateChanged(state: Int) {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.