diff --git a/app/src/main/java/org/oppia/app/home/HomeActivity.kt b/app/src/main/java/org/oppia/app/home/HomeActivity.kt index d5fe94ca133..c3a8d1f699f 100644 --- a/app/src/main/java/org/oppia/app/home/HomeActivity.kt +++ b/app/src/main/java/org/oppia/app/home/HomeActivity.kt @@ -6,11 +6,11 @@ import javax.inject.Inject /** The central activity for all users entering the app. */ class HomeActivity : InjectableAppCompatActivity() { - @Inject lateinit var homeActivityController: HomeActivityController + @Inject lateinit var homeActivityPresenter: HomeActivityPresenter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityComponent.inject(this) - homeActivityController.handleOnCreate() + homeActivityPresenter.handleOnCreate() } } diff --git a/app/src/main/java/org/oppia/app/home/HomeActivityController.kt b/app/src/main/java/org/oppia/app/home/HomeActivityController.kt deleted file mode 100644 index 9fd3b0e7f81..00000000000 --- a/app/src/main/java/org/oppia/app/home/HomeActivityController.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.oppia.app.home - -import androidx.appcompat.app.AppCompatActivity -import org.oppia.app.R -import org.oppia.app.activity.ActivityScope -import javax.inject.Inject - -/** The controller for [HomeActivity]. */ -@ActivityScope -class HomeActivityController @Inject constructor(private val activity: AppCompatActivity) { - fun handleOnCreate() { - activity.setContentView(R.layout.home_activity) - activity.supportFragmentManager.beginTransaction().add( - R.id.home_fragment_placeholder, - HomeFragment() - ).commitNow() - } -} diff --git a/app/src/main/java/org/oppia/app/home/HomeActivityPresenter.kt b/app/src/main/java/org/oppia/app/home/HomeActivityPresenter.kt new file mode 100644 index 00000000000..570d2bbd56c --- /dev/null +++ b/app/src/main/java/org/oppia/app/home/HomeActivityPresenter.kt @@ -0,0 +1,24 @@ +package org.oppia.app.home + +import androidx.appcompat.app.AppCompatActivity +import org.oppia.app.R +import org.oppia.app.activity.ActivityScope +import javax.inject.Inject + +/** The controller for [HomeActivity]. */ +@ActivityScope +class HomeActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { + fun handleOnCreate() { + activity.setContentView(R.layout.home_activity) + if (getHomeFragment() == null) { + activity.supportFragmentManager.beginTransaction().add( + R.id.home_fragment_placeholder, + HomeFragment() + ).commitNow() + } + } + + private fun getHomeFragment(): HomeFragment? { + return activity.supportFragmentManager.findFragmentById(R.id.home_fragment_placeholder) as HomeFragment? + } +} diff --git a/app/src/main/java/org/oppia/app/home/HomeFragment.kt b/app/src/main/java/org/oppia/app/home/HomeFragment.kt index e3bc454853f..6cb984812c7 100644 --- a/app/src/main/java/org/oppia/app/home/HomeFragment.kt +++ b/app/src/main/java/org/oppia/app/home/HomeFragment.kt @@ -10,7 +10,7 @@ import javax.inject.Inject /** Fragment that contains an introduction to the app. */ class HomeFragment : InjectableFragment() { - @Inject lateinit var homeFragmentController: HomeFragmentController + @Inject lateinit var homeFragmentPresenter: HomeFragmentPresenter override fun onAttach(context: Context?) { super.onAttach(context) @@ -18,6 +18,6 @@ class HomeFragment : InjectableFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return homeFragmentController.handleCreateView(inflater, container) + return homeFragmentPresenter.handleCreateView(inflater, container) } } diff --git a/app/src/main/java/org/oppia/app/home/HomeFragmentController.kt b/app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt similarity index 96% rename from app/src/main/java/org/oppia/app/home/HomeFragmentController.kt rename to app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt index d8f19de8685..688f86a1123 100644 --- a/app/src/main/java/org/oppia/app/home/HomeFragmentController.kt +++ b/app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt @@ -12,7 +12,7 @@ import javax.inject.Inject /** The controller for [HomeFragment]. */ @FragmentScope -class HomeFragmentController @Inject constructor( +class HomeFragmentPresenter @Inject constructor( private val fragment: Fragment, private val viewModelProvider: ViewModelProvider, private val userAppHistoryController: UserAppHistoryController