package com.example.criminalintent

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import com.example.criminalintent.ui.theme.CriminalIntentTheme

abstract class SingleFragmentActivity : FragmentActivity() {  //abstract means I can inherit from it
    protected abstract fun createFragment ():Fragment

    //Private means only other objects of the same class can see this stuff
    //Public means all objects can see this stuff
    //Protected is in between
    //It means that objects of an inherited class from this
    //one can see this stuff

    //An abstract method is one in which I choose not to define
    //code.  Any class that inherits from this one will have
    //to provide code for that method

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView (R.layout.activity_fragment)
        val fm: FragmentManager? = supportFragmentManager
        var fragment: Fragment? = fm!!.findFragmentById (R.id.fragment_container)
        if (fragment==null) {
            fragment = createFragment()
            fm.beginTransaction().add(R.id.fragment_container,fragment).commit()
        }
}



}