Skip to content

Commit

Permalink
Nit changes to HomeActivity/Fragment (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
rt4914 authored Oct 9, 2019
1 parent a501b23 commit 3bb093e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/oppia/app/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
18 changes: 0 additions & 18 deletions app/src/main/java/org/oppia/app/home/HomeActivityController.kt

This file was deleted.

24 changes: 24 additions & 0 deletions app/src/main/java/org/oppia/app/home/HomeActivityPresenter.kt
Original file line number Diff line number Diff line change
@@ -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?
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/org/oppia/app/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return homeFragmentController.handleCreateView(inflater, container)
return homeFragmentPresenter.handleCreateView(inflater, container)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserAppHistoryViewModel>,
private val userAppHistoryController: UserAppHistoryController
Expand Down

0 comments on commit 3bb093e

Please sign in to comment.