package net.pokeranalytics.android.ui.activity.components

import android.os.Bundle
import android.os.PersistableBundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import io.realm.Realm

open class PokerAnalyticsActivity : AppCompatActivity() {

	private val realm = Realm.getDefaultInstance()

	override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
		super.onCreate(savedInstanceState, persistentState)
	}

	override fun onOptionsItemSelected(item: MenuItem?): Boolean {
		item?.let {
			if (it.itemId == android.R.id.home) {
				finish()
			}
		}
		return super.onOptionsItemSelected(item)
	}

	override fun onDestroy() {
		super.onDestroy()
		realm.close()
	}

	/**
	 * Return the realm instance
	 */
	fun getRealm(): Realm {
		return realm
	}

}