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

import android.os.Bundle
import androidx.fragment.app.Fragment
import io.realm.Realm

open class PokerAnalyticsFragment: Fragment() {

	private var realm: Realm? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
	    realm = Realm.getDefaultInstance()
    }

    override fun onDestroyView() {
        super.onDestroyView()
	    this.realm?.close()
    }

	/**
	 * Get the realm instance
 	 */
	fun getRealm(): Realm {
		this.realm?.let {
			return it
		} ?: run {
			val realm = Realm.getDefaultInstance()
			this.realm = realm
			return realm
		}
	}

	/**
	 * Method called when the activity override onBackPressed and send the information to the fragment
	 */
	open fun onBackPressed(){}

}