forked from oppia/oppia-android
-
Notifications
You must be signed in to change notification settings - Fork 0
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' of https://github.com/oppia/oppia-android into o…
…ppia#4419 � Conflicts: � utility/src/main/java/org/oppia/android/util/logging/KenyaAlphaEventTypeToHumanReadableNameConverterImpl.kt � utility/src/test/java/org/oppia/android/util/logging/KenyaAlphaEventBundleCreatorTest.kt
- Loading branch information
Showing
77 changed files
with
6,012 additions
and
86 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
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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/oppia/android/app/hintsandsolution/ViewHintListener.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,10 @@ | ||
package org.oppia.android.app.hintsandsolution | ||
|
||
/** Callback listener for when the user wishes to view a hint. */ | ||
interface ViewHintListener { | ||
/** | ||
* Called when the user indicates they want to view the hint corresponding to the specified | ||
* index. | ||
*/ | ||
fun viewHint(hintIndex: Int) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/oppia/android/app/hintsandsolution/ViewSolutionInterface.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,9 @@ | ||
package org.oppia.android.app.hintsandsolution | ||
|
||
/** Interface to check the preference regarding alert for [HintsAndSolutionDialogFragment]. */ | ||
interface ViewSolutionInterface { | ||
/** | ||
* Called when the user indicates they want to view the solution. | ||
*/ | ||
fun viewSolution() | ||
} |
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) | ||
} |
Oops, something went wrong.