Skip to content

Commit

Permalink
Partially fixed #168: Introduced fragment components for profile choo…
Browse files Browse the repository at this point in the history
…sing and adding (#254)

* Introduced files for profile components

* Added comments

* Removed saved instance

* Added extra line

* Added periods to kdocs
  • Loading branch information
jamesxu0 authored Oct 22, 2019
1 parent 8d8357b commit e167176
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<activity android:name=".topic.TopicActivity" />
<activity android:name=".player.audio.testing.AudioFragmentTestActivity" />
<activity android:name=".activity.InputInteractionViewTestActivity" />
<activity android:name=".profile.ProfileActivity" />
<activity android:name="org.oppia.app.home.HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/oppia/app/activity/ActivityComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.oppia.app.player.audio.testing.AudioFragmentTestActivity
import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.topic.conceptcard.testing.ConceptCardFragmentTestActivity
import org.oppia.app.player.state.testing.StateFragmentTestActivity
import org.oppia.app.profile.ProfileActivity
import org.oppia.app.testing.BindableAdapterTestActivity
import org.oppia.app.topic.TopicActivity
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
Expand All @@ -34,4 +35,5 @@ interface ActivityComponent {
fun inject(topicActivity: TopicActivity)
fun inject(audioFragmentTestActivity: AudioFragmentTestActivity)
fun inject(stateFragmentTestActivity: StateFragmentTestActivity)
fun inject(profileActivity: ProfileActivity)
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/oppia/app/fragment/FragmentComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import org.oppia.app.home.HomeFragment
import org.oppia.app.player.exploration.ExplorationFragment
import org.oppia.app.player.state.StateFragment
import org.oppia.app.player.audio.AudioFragment
import org.oppia.app.profile.AddProfileFragment
import org.oppia.app.profile.AdminAuthFragment
import org.oppia.app.profile.ProfileChooserFragment
import org.oppia.app.testing.BindableAdapterTestFragment
import org.oppia.app.topic.TopicFragment
import org.oppia.app.topic.conceptcard.ConceptCardFragment
Expand Down Expand Up @@ -38,4 +41,7 @@ interface FragmentComponent {
fun inject(topicPlayFragment: TopicPlayFragment)
fun inject(topicReviewFragment: TopicReviewFragment)
fun inject(topicTrainFragment: TopicTrainFragment)
fun inject(profileChooserFragment: ProfileChooserFragment)
fun inject(adminAuthFragment: AdminAuthFragment)
fun inject(addProfileFragment: AddProfileFragment)
}
23 changes: 23 additions & 0 deletions app/src/main/java/org/oppia/app/profile/AddProfileFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.oppia.app.profile

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.oppia.app.fragment.InjectableFragment
import javax.inject.Inject

/** Fragment that allows users to create new profiles. */
class AddProfileFragment : InjectableFragment() {
@Inject lateinit var addProfileFragmentPresenter: AddProfileFragmentPresenter

override fun onAttach(context: Context?) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return addProfileFragmentPresenter.handleCreateView(inflater, container)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.oppia.app.profile

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.oppia.app.databinding.AddProfileFragmentBinding
import org.oppia.app.fragment.FragmentScope
import javax.inject.Inject

/** The presenter for [AddProfileFragment]. */
@FragmentScope
class AddProfileFragmentPresenter @Inject constructor(
private val fragment: Fragment
) {
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
val binding = AddProfileFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
return binding.root
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/org/oppia/app/profile/AdminAuthFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.oppia.app.profile

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.oppia.app.fragment.InjectableFragment
import javax.inject.Inject

/** Fragment that authenticates by checking for admin's PIN. */
class AdminAuthFragment : InjectableFragment() {
@Inject lateinit var adminAuthFragmentPresenter: AdminAuthFragmentPresenter

override fun onAttach(context: Context?) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return adminAuthFragmentPresenter.handleCreateView(inflater, container)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.oppia.app.profile

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.oppia.app.databinding.AdminAuthFragmentBinding
import org.oppia.app.fragment.FragmentScope
import javax.inject.Inject

/** The presenter for [AdminAuthFragment]. */
@FragmentScope
class AdminAuthFragmentPresenter @Inject constructor(
private val fragment: Fragment
) {
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
val binding = AdminAuthFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
return binding.root
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/org/oppia/app/profile/ProfileActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.oppia.app.profile

import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import javax.inject.Inject

/** Activity that controls profile creation and selection. */
class ProfileActivity : InjectableAppCompatActivity() {
@Inject lateinit var profileActivityPresenter: ProfileActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
profileActivityPresenter.handleOnCreate()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.oppia.app.profile

import androidx.appcompat.app.AppCompatActivity
import org.oppia.app.R
import org.oppia.app.activity.ActivityScope
import javax.inject.Inject

/** The presenter for [ProfileActivity]. */
@ActivityScope
class ProfileActivityPresenter @Inject constructor(private val activity: AppCompatActivity){
fun handleOnCreate() {
activity.setContentView(R.layout.profile_activity)
if (getProfileChooserFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
R.id.profile_chooser_fragment_placeholder,
ProfileChooserFragment()
).commitNow()
}
}

private fun getProfileChooserFragment(): ProfileChooserFragment? {
return activity.supportFragmentManager.findFragmentById(R.id.profile_chooser_fragment_placeholder) as ProfileChooserFragment?
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/org/oppia/app/profile/ProfileChooserFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.oppia.app.profile

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.oppia.app.fragment.InjectableFragment
import javax.inject.Inject

/** Fragment that allows user to select a profile or create new ones. */
class ProfileChooserFragment : InjectableFragment() {
@Inject lateinit var profileChooserFragmentPresenter: ProfileChooserFragmentPresenter

override fun onAttach(context: Context?) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return profileChooserFragmentPresenter.handleCreateView(inflater, container)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.oppia.app.profile

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.oppia.app.databinding.ProfileChooserFragmentBinding
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.viewmodel.ViewModelProvider
import javax.inject.Inject

/** The presenter for [ProfileChooserFragment]. */
@FragmentScope
class ProfileChooserFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<ProfileChooserViewModel>
) {
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
val binding = ProfileChooserFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.apply {
viewModel = getProfileChooserViewModel()
}
return binding.root
}

private fun getProfileChooserViewModel(): ProfileChooserViewModel {
return viewModelProvider.getForFragment(fragment, ProfileChooserViewModel::class.java)
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/oppia/app/profile/ProfileChooserViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.oppia.app.profile

import androidx.lifecycle.ViewModel
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.viewmodel.ObservableViewModel
import javax.inject.Inject

/** The ViewModel for [ProfileChooserFragment]. */
@FragmentScope
class ProfileChooserViewModel @Inject constructor(): ObservableViewModel() {
}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/add_profile_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/admin_auth_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/profile_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_chooser_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".profile.ProfileActivity" />
14 changes: 14 additions & 0 deletions app/src/main/res/layout/profile_chooser_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="org.oppia.app.profile.ProfileChooserViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit e167176

Please sign in to comment.