-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into centralize-hasprotoextra
- Loading branch information
Showing
60 changed files
with
5,404 additions
and
6 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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/org/oppia/android/app/onboarding/CreateProfileActivity.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,32 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import org.oppia.android.app.activity.ActivityComponentImpl | ||
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity | ||
import org.oppia.android.app.model.ScreenName.CREATE_PROFILE_ACTIVITY | ||
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName | ||
import javax.inject.Inject | ||
|
||
/** Activity for displaying a new learner profile creation flow. */ | ||
class CreateProfileActivity : InjectableAutoLocalizedAppCompatActivity() { | ||
@Inject | ||
lateinit var learnerProfileActivityPresenter: CreateProfileActivityPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
(activityComponent as ActivityComponentImpl).inject(this) | ||
|
||
learnerProfileActivityPresenter.handleOnCreate() | ||
} | ||
|
||
companion object { | ||
/** Returns a new [Intent] open a [CreateProfileActivity] with the specified params. */ | ||
fun createProfileActivityIntent(context: Context): Intent { | ||
return Intent(context, CreateProfileActivity::class.java).apply { | ||
decorateWithScreenName(CREATE_PROFILE_ACTIVITY) | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/oppia/android/app/onboarding/CreateProfileActivityPresenter.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,39 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import org.oppia.android.R | ||
import org.oppia.android.databinding.CreateProfileActivityBinding | ||
import javax.inject.Inject | ||
|
||
private const val TAG_CREATE_PROFILE_ACTIVITY_FRAGMENT = "TAG_CREATE_PROFILE_ACTIVITY_FRAGMENT" | ||
|
||
/** Presenter for [CreateProfileActivity]. */ | ||
class CreateProfileActivityPresenter @Inject constructor( | ||
private val activity: AppCompatActivity | ||
) { | ||
private lateinit var binding: CreateProfileActivityBinding | ||
|
||
/** Handle creation and binding of the CreateProfileActivity layout. */ | ||
fun handleOnCreate() { | ||
binding = DataBindingUtil.setContentView(activity, R.layout.create_profile_activity) | ||
binding.apply { | ||
lifecycleOwner = activity | ||
} | ||
|
||
if (getNewLearnerProfileFragment() == null) { | ||
val createLearnerProfileFragment = CreateProfileFragment() | ||
activity.supportFragmentManager.beginTransaction().add( | ||
R.id.profile_fragment_placeholder, | ||
createLearnerProfileFragment, | ||
TAG_CREATE_PROFILE_ACTIVITY_FRAGMENT | ||
).commitNow() | ||
} | ||
} | ||
|
||
private fun getNewLearnerProfileFragment(): CreateProfileFragment? { | ||
return activity.supportFragmentManager.findFragmentByTag( | ||
TAG_CREATE_PROFILE_ACTIVITY_FRAGMENT | ||
) as? CreateProfileFragment | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/org/oppia/android/app/onboarding/CreateProfileFragment.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,38 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import org.oppia.android.app.fragment.FragmentComponentImpl | ||
import org.oppia.android.app.fragment.InjectableFragment | ||
import javax.inject.Inject | ||
|
||
/** Fragment for displaying a new learner profile creation flow. */ | ||
class CreateProfileFragment : InjectableFragment() { | ||
@Inject | ||
lateinit var createProfileFragmentPresenter: CreateProfileFragmentPresenter | ||
|
||
override fun onAttach(context: Context) { | ||
super.onAttach(context) | ||
(fragmentComponent as FragmentComponentImpl).inject(this) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
createProfileFragmentPresenter.activityResultLauncher = registerForActivityResult( | ||
ActivityResultContracts.StartActivityForResult() | ||
) { result -> | ||
if (result.resultCode == Activity.RESULT_OK) { | ||
createProfileFragmentPresenter.handleOnActivityResult(result.data) | ||
} | ||
} | ||
return createProfileFragmentPresenter.handleCreateView(inflater, container) | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
app/src/main/java/org/oppia/android/app/onboarding/CreateProfileFragmentPresenter.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,125 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import android.content.Intent | ||
import android.graphics.PorterDuff | ||
import android.provider.MediaStore | ||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.res.ResourcesCompat | ||
import androidx.fragment.app.Fragment | ||
import org.oppia.android.R | ||
import org.oppia.android.app.fragment.FragmentScope | ||
import org.oppia.android.databinding.CreateProfileFragmentBinding | ||
import org.oppia.android.util.parser.image.ImageLoader | ||
import org.oppia.android.util.parser.image.ImageViewTarget | ||
import javax.inject.Inject | ||
|
||
/** Presenter for [CreateProfileFragment]. */ | ||
@FragmentScope | ||
class CreateProfileFragmentPresenter @Inject constructor( | ||
private val fragment: Fragment, | ||
private val activity: AppCompatActivity, | ||
private val createProfileViewModel: CreateProfileViewModel, | ||
private val imageLoader: ImageLoader | ||
) { | ||
private lateinit var binding: CreateProfileFragmentBinding | ||
private lateinit var uploadImageView: ImageView | ||
private lateinit var selectedImage: String | ||
|
||
/** Launcher for picking an image from device gallery. */ | ||
lateinit var activityResultLauncher: ActivityResultLauncher<Intent> | ||
|
||
/** Initialize layout bindings. */ | ||
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View { | ||
binding = CreateProfileFragmentBinding.inflate( | ||
inflater, | ||
container, | ||
/* attachToRoot= */ false | ||
) | ||
binding.let { | ||
it.lifecycleOwner = fragment | ||
it.viewModel = createProfileViewModel | ||
} | ||
|
||
uploadImageView = binding.createProfileUserImageView | ||
|
||
uploadImageView.apply { | ||
setColorFilter( | ||
ResourcesCompat.getColor( | ||
activity.resources, | ||
R.color.component_color_avatar_background_25_color, | ||
null | ||
), | ||
PorterDuff.Mode.DST_OVER | ||
) | ||
|
||
imageLoader.loadDrawable( | ||
R.drawable.ic_profile_icon, | ||
ImageViewTarget(this) | ||
) | ||
} | ||
|
||
binding.onboardingNavigationContinue.setOnClickListener { | ||
val nickname = binding.createProfileNicknameEdittext.text.toString().trim() | ||
|
||
createProfileViewModel.hasErrorMessage.set(nickname.isBlank()) | ||
|
||
if (createProfileViewModel.hasErrorMessage.get() != true) { | ||
val intent = IntroActivity.createIntroActivity(activity, nickname) | ||
fragment.startActivity(intent) | ||
} | ||
} | ||
|
||
binding.createProfileNicknameEdittext.addTextChangedListener(object : TextWatcher { | ||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} | ||
override fun afterTextChanged(s: Editable?) {} | ||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | ||
createProfileViewModel.hasErrorMessage.set(false) | ||
} | ||
}) | ||
|
||
addViewOnClickListeners(binding) | ||
|
||
return binding.root | ||
} | ||
|
||
/** Receive the result of image upload and load it into the image view. */ | ||
fun handleOnActivityResult(intent: Intent?) { | ||
intent?.let { | ||
binding.createProfilePicturePrompt.visibility = View.GONE | ||
selectedImage = | ||
checkNotNull(intent.data.toString()) { "Could not find the selected image." } | ||
imageLoader.loadBitmap( | ||
selectedImage, | ||
ImageViewTarget(uploadImageView) | ||
) | ||
} | ||
} | ||
|
||
private fun addViewOnClickListeners(binding: CreateProfileFragmentBinding) { | ||
val galleryIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) | ||
|
||
binding.onboardingNavigationBack.setOnClickListener { activity.finish() } | ||
binding.createProfileEditPictureIcon.setOnClickListener { | ||
activityResultLauncher.launch( | ||
galleryIntent | ||
) | ||
} | ||
binding.createProfilePicturePrompt.setOnClickListener { | ||
activityResultLauncher.launch( | ||
galleryIntent | ||
) | ||
} | ||
binding.createProfileUserImageView.setOnClickListener { | ||
activityResultLauncher.launch( | ||
galleryIntent | ||
) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/org/oppia/android/app/onboarding/CreateProfileViewModel.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,14 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import androidx.databinding.ObservableField | ||
import org.oppia.android.app.fragment.FragmentScope | ||
import org.oppia.android.app.viewmodel.ObservableViewModel | ||
import javax.inject.Inject | ||
|
||
/** The ViewModel for [CreateProfileFragment]. */ | ||
@FragmentScope | ||
class CreateProfileViewModel @Inject constructor() : ObservableViewModel() { | ||
|
||
/** ObservableField that tracks whether creating a nickname has triggered an error condition. */ | ||
val hasErrorMessage = ObservableField(false) | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/org/oppia/android/app/onboarding/IntroActivity.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,59 @@ | ||
package org.oppia.android.app.onboarding | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import org.oppia.android.app.activity.ActivityComponentImpl | ||
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity | ||
import org.oppia.android.app.model.IntroActivityParams | ||
import org.oppia.android.app.model.ScreenName.INTRO_ACTIVITY | ||
import org.oppia.android.util.extensions.getProtoExtra | ||
import org.oppia.android.util.extensions.putProtoExtra | ||
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName | ||
import javax.inject.Inject | ||
|
||
/** The activity for showing the learner welcome screen. */ | ||
class IntroActivity : InjectableAutoLocalizedAppCompatActivity() { | ||
@Inject | ||
lateinit var onboardingLearnerIntroActivityPresenter: IntroActivityPresenter | ||
|
||
private lateinit var profileNickname: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
(activityComponent as ActivityComponentImpl).inject(this) | ||
|
||
val params = intent.extractParams() | ||
this.profileNickname = params.profileNickname | ||
|
||
onboardingLearnerIntroActivityPresenter.handleOnCreate(profileNickname) | ||
} | ||
|
||
companion object { | ||
private const val PARAMS_KEY = "OnboardingIntroActivity.params" | ||
|
||
/** | ||
* A convenience function for creating a new [OnboardingLearnerIntroActivity] intent by prefilling | ||
* common params needed by the activity. | ||
*/ | ||
fun createIntroActivity(context: Context, profileNickname: String): Intent { | ||
val params = IntroActivityParams.newBuilder() | ||
.setProfileNickname(profileNickname) | ||
.build() | ||
return createOnboardingLearnerIntroActivity(context, params) | ||
} | ||
|
||
private fun createOnboardingLearnerIntroActivity( | ||
context: Context, | ||
params: IntroActivityParams | ||
): Intent { | ||
return Intent(context, IntroActivity::class.java).apply { | ||
putProtoExtra(PARAMS_KEY, params) | ||
decorateWithScreenName(INTRO_ACTIVITY) | ||
} | ||
} | ||
|
||
private fun Intent.extractParams() = | ||
getProtoExtra(PARAMS_KEY, IntroActivityParams.getDefaultInstance()) | ||
} | ||
} |
Oops, something went wrong.