-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially fixed #168: Introduced fragment components for profile choo…
…sing and adding (#254) * Introduced files for profile components * Added comments * Removed saved instance * Added extra line * Added periods to kdocs
- Loading branch information
Showing
16 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/oppia/app/profile/AddProfileFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/oppia/app/profile/AddProfileFragmentPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
app/src/main/java/org/oppia/app/profile/AdminAuthFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/oppia/app/profile/AdminAuthFragmentPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
app/src/main/java/org/oppia/app/profile/ProfileActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/org/oppia/app/profile/ProfileActivityPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
app/src/main/java/org/oppia/app/profile/ProfileChooserFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/org/oppia/app/profile/ProfileChooserFragmentPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
app/src/main/java/org/oppia/app/profile/ProfileChooserViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |