package net.pokeranalytics.android.ui.fragment.components

import android.os.Bundle
import io.realm.RealmResults
import net.pokeranalytics.android.model.realm.ComputableResult

open class SessionObserverFragment : PokerAnalyticsFragment() {

    private lateinit var endedSessions: RealmResults<ComputableResult>

	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		this.endedSessions = getRealm().where(ComputableResult::class.java).findAll() // ComputableResult are existing only if sessions are ended
		this.endedSessions.addChangeListener { _, _ ->
			this.sessionsChanged()
		}
	}

	override fun onDestroyView() {
		super.onDestroyView()
		endedSessions.removeAllChangeListeners()
	}

    open fun sessionsChanged() {
        // to override
    }

}