diff --git a/app/BUILD.bazel b/app/BUILD.bazel index 9cc7ada4641..1e4620c4821 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -694,7 +694,6 @@ kt_android_library( "//app/src/main/java/org/oppia/android/app/utility/math:math_expression_accessibility_util", "//app/src/main/java/org/oppia/android/app/viewmodel:observable_array_list", "//app/src/main/java/org/oppia/android/app/viewmodel:observable_view_model", - "//app/src/main/java/org/oppia/android/app/viewmodel:view_model_provider", "//domain", "//domain/src/main/java/org/oppia/android/domain/audio:audio_player_controller", "//domain/src/main/java/org/oppia/android/domain/clipboard:clipboard_controller", diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt index 74e0f97ae89..f357a02a2ae 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivity.kt @@ -138,6 +138,7 @@ class AdministratorControlsActivity : if (fragment is ProfileEditFragment) { administratorControlsActivityPresenter.handleOnBackPressed() } else { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. super.onBackPressed() } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt index 0dfe9b50b9c..c152e484dad 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/AdministratorControlsActivityPresenter.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.administratorcontrols import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.Toolbar import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope @@ -62,14 +61,11 @@ class AdministratorControlsActivityPresenter @Inject constructor( if (isMultipane) { val adminControlsActivity = activity as AdministratorControlsActivity when (lastLoadedFragment) { - PROFILE_LIST_FRAGMENT -> (activity as AdministratorControlsActivity).loadProfileList() - APP_VERSION_FRAGMENT -> (activity as AdministratorControlsActivity).loadAppVersion() + PROFILE_LIST_FRAGMENT -> activity.loadProfileList() + APP_VERSION_FRAGMENT -> activity.loadAppVersion() PROFILE_EDIT_FRAGMENT -> selectedProfileId.let { profileId -> if (extraControlsTitle != null) { - (activity as AdministratorControlsActivity).loadProfileEdit( - profileId = profileId, - profileName = extraControlsTitle - ) + activity.loadProfileEdit(profileId = profileId, profileName = extraControlsTitle) if (isProfileDeletionDialogVisible && profileId != 0) { val fragment = activity.supportFragmentManager.findFragmentById( R.id.administrator_controls_fragment_multipane_placeholder @@ -88,7 +84,7 @@ class AdministratorControlsActivityPresenter @Inject constructor( /** Sets up the navigation drawer. */ private fun setUpNavigationDrawer() { - val toolbar = binding.administratorControlsActivityToolbar as Toolbar + val toolbar = binding.administratorControlsActivityToolbar activity.setSupportActionBar(toolbar) activity.supportActionBar!!.setDisplayShowHomeEnabled(true) navigationDrawerFragment = activity @@ -206,9 +202,9 @@ class AdministratorControlsActivityPresenter @Inject constructor( outState.putString(SELECTED_CONTROLS_TITLE_SAVED_KEY, titleTextView.text.toString()) } outState.putString(LAST_LOADED_FRAGMENT_EXTRA_KEY, lastLoadedFragment) - isProfileDeletionDialogVisible?.let { + isProfileDeletionDialogVisible.let { outState.putBoolean(IS_PROFILE_DELETION_DIALOG_VISIBLE_KEY, it) } - selectedProfileId?.let { outState.putInt(SELECTED_PROFILE_ID_SAVED_KEY, it) } + selectedProfileId.let { outState.putInt(SELECTED_PROFILE_ID_SAVED_KEY, it) } } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt index ec5dce2c206..e41600bb929 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionActivity.kt @@ -23,6 +23,7 @@ class AppVersionActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. onBackPressed() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionFragmentPresenter.kt index 984296b4f88..125841f8f9f 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/appversion/AppVersionFragmentPresenter.kt @@ -5,7 +5,6 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import org.oppia.android.app.fragment.FragmentScope -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AppVersionFragmentBinding import javax.inject.Inject @@ -13,7 +12,7 @@ import javax.inject.Inject @FragmentScope class AppVersionFragmentPresenter @Inject constructor( private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider + private val appVersionViewModel: AppVersionViewModel ) { private lateinit var binding: AppVersionFragmentBinding @@ -26,12 +25,8 @@ class AppVersionFragmentPresenter @Inject constructor( ) binding.let { it.lifecycleOwner = fragment - it.viewModel = getAppVersionViewModel() + it.viewModel = appVersionViewModel } return binding.root } - - private fun getAppVersionViewModel(): AppVersionViewModel { - return viewModelProvider.getForFragment(fragment, AppVersionViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt index b890f3ebbb9..cf6fb025db6 100644 --- a/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt +++ b/app/src/main/java/org/oppia/android/app/administratorcontrols/learneranalytics/ProfileAndDeviceIdActivity.kt @@ -28,6 +28,7 @@ class ProfileAndDeviceIdActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. onBackPressed() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt index 91e43599cd0..ed1a566d4de 100644 --- a/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListFragmentPresenter.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import org.oppia.android.R import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.CompletedStoryItemBinding import org.oppia.android.databinding.CompletedStoryListFragmentBinding import javax.inject.Inject @@ -17,7 +16,7 @@ import javax.inject.Inject class CompletedStoryListFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val viewModel: CompletedStoryListViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { @@ -29,7 +28,6 @@ class CompletedStoryListFragmentPresenter @Inject constructor( container: ViewGroup?, internalProfileId: Int ): View? { - val viewModel = getCompletedStoryListViewModel() viewModel.setProfileId(internalProfileId) binding = CompletedStoryListFragmentBinding @@ -61,8 +59,4 @@ class CompletedStoryListFragmentPresenter @Inject constructor( ) .build() } - - private fun getCompletedStoryListViewModel(): CompletedStoryListViewModel { - return viewModelProvider.getForFragment(fragment, CompletedStoryListViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/databinding/AppCompatCheckBoxBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/AppCompatCheckBoxBindingAdapters.java index 4e7f59b0bb3..fb7b85b19cf 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/AppCompatCheckBoxBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/AppCompatCheckBoxBindingAdapters.java @@ -12,7 +12,7 @@ */ public final class AppCompatCheckBoxBindingAdapters { /** Sets the button tint for the specified checkbox, via data-binding. */ - @BindingAdapter("app:buttonTint") + @BindingAdapter("buttonTint") public static void setButtonTint(@NonNull AppCompatCheckBox checkBox, @ColorInt int colorRgb) { CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(colorRgb)); } diff --git a/app/src/main/java/org/oppia/android/app/databinding/CircularProgressIndicatorAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/CircularProgressIndicatorAdapters.java index 2df902df0f1..ca6c0d61f58 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/CircularProgressIndicatorAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/CircularProgressIndicatorAdapters.java @@ -18,7 +18,7 @@ public final class CircularProgressIndicatorAdapters { * @param progress the numerical progress to set on the indicator (which will be displayed based * on the indicator's customized minimum and maximum progress values) */ - @BindingAdapter("app:animatedProgress") + @BindingAdapter("animatedProgress") public static void setAnimatedProgress(CircularProgressIndicator indicator, int progress) { if (progress > 0) { indicator.setProgressCompat(progress, /* animated = */ true); diff --git a/app/src/main/java/org/oppia/android/app/databinding/ConstraintLayoutAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/ConstraintLayoutAdapters.java index 734c29ea37e..657c811bf43 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/ConstraintLayoutAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/ConstraintLayoutAdapters.java @@ -10,7 +10,7 @@ public final class ConstraintLayoutAdapters { /** Binding adapter for setting a layout_constraintEnd_toEndOf to a view. */ - @BindingAdapter("app:layout_constraintEnd_toEndOf") + @BindingAdapter("layout_constraintEnd_toEndOf") public static void setConstraintEndToEndOf(@NonNull View view, int constraintToId) { ConstraintLayout constraintLayout = (ConstraintLayout) view.getParent(); ConstraintSet constraintSet = new ConstraintSet(); @@ -20,7 +20,7 @@ public static void setConstraintEndToEndOf(@NonNull View view, int constraintToI } /** Binding adapter for setting layout_constraintHorizontal_bias to a view. */ - @BindingAdapter("app:layout_constraintHorizontal_bias") + @BindingAdapter("layout_constraintHorizontal_bias") public static void setHorizontalBias(@NonNull View view, float value) { ConstraintLayout constraintLayout = (ConstraintLayout) view.getParent(); ConstraintSet constraintSet = new ConstraintSet(); diff --git a/app/src/main/java/org/oppia/android/app/databinding/DrawableBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/DrawableBindingAdapters.java index c256532ded2..8890dd4fbec 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/DrawableBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/DrawableBindingAdapters.java @@ -20,7 +20,7 @@ public static void setBackgroundColor(@NonNull View view, @ColorInt int colorRgb } /** Used to set a rounded-rect background drawable with a data-bound color. */ - @BindingAdapter("app:roundedRectDrawableWithColor") + @BindingAdapter("roundedRectDrawableWithColor") public static void setBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { view.setBackgroundResource(R.drawable.rounded_rect_background); // The input color needs to have alpha channel prepended to it. @@ -29,7 +29,7 @@ public static void setBackgroundDrawable(@NonNull View view, @ColorInt int color } /** Used to set a top rounded-rect background drawable with a data-bound color. */ - @BindingAdapter("app:topRoundedRectDrawableWithColor") + @BindingAdapter("topRoundedRectDrawableWithColor") public static void setTopBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { view.setBackgroundResource(R.drawable.top_rounded_rect_background); // The input color needs to have alpha channel prepended to it. diff --git a/app/src/main/java/org/oppia/android/app/databinding/EditTextBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/EditTextBindingAdapters.java index dad9dc8c84a..824af3b7e78 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/EditTextBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/EditTextBindingAdapters.java @@ -9,7 +9,7 @@ public final class EditTextBindingAdapters { /** Binding adapter for setting a [TextWatcher] as a change listener for an [EditText]. */ - @BindingAdapter("app:textChangedListener") + @BindingAdapter("textChangedListener") public static void bindTextWatcher(@NonNull EditText editText, TextWatcher textWatcher) { editText.addTextChangedListener(textWatcher); } diff --git a/app/src/main/java/org/oppia/android/app/databinding/GuidelineBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/GuidelineBindingAdapters.java index cc8f29fe95f..05b805d563c 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/GuidelineBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/GuidelineBindingAdapters.java @@ -9,7 +9,7 @@ public final class GuidelineBindingAdapters { /** Binding adapter for setting the `guidePercent` for a [Guideline]. */ - @BindingAdapter("app:layout_constraintGuide_percent") + @BindingAdapter("layout_constraintGuide_percent") public static void setGuidelinePercentage(@NonNull Guideline guideline, float percentage) { ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) guideline.getLayoutParams(); @@ -18,7 +18,7 @@ public static void setGuidelinePercentage(@NonNull Guideline guideline, float pe } /** Binding adapter for setting the `guideEnd` for a [Guideline]. */ - @BindingAdapter("app:layout_constraintGuide_end") + @BindingAdapter("layout_constraintGuide_end") public static void setConstraintGuidelineEnd(@NonNull Guideline guideline, float guideEndPx) { ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) guideline.getLayoutParams(); diff --git a/app/src/main/java/org/oppia/android/app/databinding/ImageViewBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/ImageViewBindingAdapters.java index 5f5df424537..7606551bae1 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/ImageViewBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/ImageViewBindingAdapters.java @@ -17,7 +17,7 @@ /** Holds all custom binding adapters that bind to [ImageView]. */ public final class ImageViewBindingAdapters { - @BindingAdapter("app:srcCompat") + @BindingAdapter("srcCompat") public static void setImageDrawableCompat( @NonNull ImageView imageView, @DrawableRes int drawableResourceId @@ -25,7 +25,7 @@ public static void setImageDrawableCompat( imageView.setImageResource(drawableResourceId); } - @BindingAdapter("app:srcCompat") + @BindingAdapter("srcCompat") public static void setImageDrawableCompat( @NonNull ImageView imageView, Drawable drawable @@ -40,7 +40,7 @@ public static void setImageDrawableCompat( * @param imageView view where the profile avatar will be loaded into * @param profileAvatar represents either a colorId or local image uri */ - @BindingAdapter("profile:src") + @BindingAdapter("profileImageSource") public static void setProfileImage(ImageView imageView, ProfileAvatar profileAvatar) { if (profileAvatar != null) { if (profileAvatar.getAvatarTypeCase() == ProfileAvatar.AvatarTypeCase.AVATAR_COLOR_RGB) { @@ -86,7 +86,7 @@ public boolean onResourceReady( *

* Reference: https://stackoverflow.com/a/35809319/3689782. */ - @BindingAdapter("playState:image") + @BindingAdapter("playStateImage") public static void setPlayStateDrawable( @NonNull ImageView imageView, ChapterPlayState chapterPlayState diff --git a/app/src/main/java/org/oppia/android/app/databinding/MarginBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/MarginBindingAdapters.java index 69dd1f379c4..2c7cd8be971 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/MarginBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/MarginBindingAdapters.java @@ -10,7 +10,7 @@ public final class MarginBindingAdapters { /** Sets the start margin for a view, accounting for RTL scenarios. */ - @BindingAdapter("app:layoutMarginStart") + @BindingAdapter("layoutMarginStart") public static void setLayoutMarginStart(@NonNull View view, float marginStart) { if (view.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); @@ -20,7 +20,7 @@ public static void setLayoutMarginStart(@NonNull View view, float marginStart) { } /** Sets the end margin for a view, accounting for RTL scenarios. */ - @BindingAdapter("app:layoutMarginEnd") + @BindingAdapter("layoutMarginEnd") public static void setLayoutMarginEnd(@NonNull View view, float marginEnd) { if (view.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); @@ -30,7 +30,7 @@ public static void setLayoutMarginEnd(@NonNull View view, float marginEnd) { } /** Used to set a margin-top for views. */ - @BindingAdapter("app:layoutMarginTop") + @BindingAdapter("layoutMarginTop") public static void setLayoutMarginTop(@NonNull View view, float marginTop) { if (view.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); @@ -41,7 +41,7 @@ public static void setLayoutMarginTop(@NonNull View view, float marginTop) { } /** Used to set a margin-bottom for views. */ - @BindingAdapter("app:layoutMarginBottom") + @BindingAdapter("layoutMarginBottom") public static void setLayoutMarginBottom(@NonNull View view, float marginBottom) { if (view.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); @@ -52,7 +52,7 @@ public static void setLayoutMarginBottom(@NonNull View view, float marginBottom) } /** Used to set a margin for views. */ - @BindingAdapter("app:layoutMargin") + @BindingAdapter("layoutMargin") public static void setLayoutMargin(@NonNull View view, float margin) { if (view.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); diff --git a/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerMarginBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerMarginBindingAdapters.java index 77bab0f3555..a5dd6a15c39 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerMarginBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerMarginBindingAdapters.java @@ -14,11 +14,11 @@ public final class StateAssemblerMarginBindingAdapters { /** Used to set a margin for exploration split-view. */ @BindingAdapter( value = { - "app:explorationSplitViewMarginApplicable", - "app:explorationSplitViewMarginStart", - "app:explorationSplitViewMarginTop", - "app:explorationSplitViewMarginEnd", - "app:explorationSplitViewMarginBottom", + "explorationSplitViewMarginApplicable", + "explorationSplitViewMarginStart", + "explorationSplitViewMarginTop", + "explorationSplitViewMarginEnd", + "explorationSplitViewMarginBottom", }, requireAll = false ) @@ -36,11 +36,11 @@ public static void setExplorationSplitViewMargin( /** Used to set a margin for exploration view. */ @BindingAdapter( value = { - "app:explorationViewMarginApplicable", - "app:explorationViewMarginStart", - "app:explorationViewMarginTop", - "app:explorationViewMarginEnd", - "app:explorationViewMarginBottom", + "explorationViewMarginApplicable", + "explorationViewMarginStart", + "explorationViewMarginTop", + "explorationViewMarginEnd", + "explorationViewMarginBottom", }, requireAll = false ) @@ -58,11 +58,11 @@ public static void setExplorationViewMargin( /** Used to set a margin for question view. */ @BindingAdapter( value = { - "app:questionViewMarginApplicable", - "app:questionViewMarginStart", - "app:questionViewMarginTop", - "app:questionViewMarginEnd", - "app:questionViewMarginBottom", + "questionViewMarginApplicable", + "questionViewMarginStart", + "questionViewMarginTop", + "questionViewMarginEnd", + "questionViewMarginBottom", }, requireAll = false ) @@ -80,11 +80,11 @@ public static void setQuestionViewMargin( /** Used to set a margin for question split-view. */ @BindingAdapter( value = { - "app:questionSplitViewMarginApplicable", - "app:questionSplitViewMarginStart", - "app:questionSplitViewMarginTop", - "app:questionSplitViewMarginEnd", - "app:questionSplitViewMarginBottom", + "questionSplitViewMarginApplicable", + "questionSplitViewMarginStart", + "questionSplitViewMarginTop", + "questionSplitViewMarginEnd", + "questionSplitViewMarginBottom", }, requireAll = false ) diff --git a/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerPaddingBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerPaddingBindingAdapters.java index c1ab6d73911..44cdbe19e45 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerPaddingBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/StateAssemblerPaddingBindingAdapters.java @@ -13,11 +13,11 @@ public final class StateAssemblerPaddingBindingAdapters { /** Used to set a padding for exploration split-view. */ @BindingAdapter( value = { - "app:explorationSplitViewPaddingApplicable", - "app:explorationSplitViewPaddingStart", - "app:explorationSplitViewPaddingTop", - "app:explorationSplitViewPaddingEnd", - "app:explorationSplitViewPaddingBottom", + "explorationSplitViewPaddingApplicable", + "explorationSplitViewPaddingStart", + "explorationSplitViewPaddingTop", + "explorationSplitViewPaddingEnd", + "explorationSplitViewPaddingBottom", }, requireAll = false ) @@ -35,11 +35,11 @@ public static void setExplorationSplitViewPadding( /** Used to set a padding for exploration view. */ @BindingAdapter( value = { - "app:explorationViewPaddingApplicable", - "app:explorationViewPaddingStart", - "app:explorationViewPaddingTop", - "app:explorationViewPaddingEnd", - "app:explorationViewPaddingBottom", + "explorationViewPaddingApplicable", + "explorationViewPaddingStart", + "explorationViewPaddingTop", + "explorationViewPaddingEnd", + "explorationViewPaddingBottom", }, requireAll = false ) @@ -57,11 +57,11 @@ public static void setExplorationViewPadding( /** Used to set a padding for question view. */ @BindingAdapter( value = { - "app:questionViewPaddingApplicable", - "app:questionViewPaddingStart", - "app:questionViewPaddingTop", - "app:questionViewPaddingEnd", - "app:questionViewPaddingBottom", + "questionViewPaddingApplicable", + "questionViewPaddingStart", + "questionViewPaddingTop", + "questionViewPaddingEnd", + "questionViewPaddingBottom", }, requireAll = false ) @@ -79,11 +79,11 @@ public static void setQuestionViewPadding( /** Used to set a padding for question split-view. */ @BindingAdapter( value = { - "app:questionSplitViewPaddingApplicable", - "app:questionSplitViewPaddingStart", - "app:questionSplitViewPaddingTop", - "app:questionSplitViewPaddingEnd", - "app:questionSplitViewPaddingBottom", + "questionSplitViewPaddingApplicable", + "questionSplitViewPaddingStart", + "questionSplitViewPaddingTop", + "questionSplitViewPaddingEnd", + "questionSplitViewPaddingBottom", }, requireAll = false ) diff --git a/app/src/main/java/org/oppia/android/app/databinding/TextInputLayoutBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/TextInputLayoutBindingAdapters.java index 9ec97b475ad..d0dd35c2a77 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/TextInputLayoutBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/TextInputLayoutBindingAdapters.java @@ -8,7 +8,7 @@ public final class TextInputLayoutBindingAdapters { /** Binding adapter for setting an error message. */ - @BindingAdapter("app:errorMessage") + @BindingAdapter("errorMessage") public static void setErrorMessage( @NonNull TextInputLayout textInputLayout, String errorMessage diff --git a/app/src/main/java/org/oppia/android/app/databinding/TextViewBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/TextViewBindingAdapters.java index 591e8c88738..e4584d7cad1 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/TextViewBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/TextViewBindingAdapters.java @@ -20,7 +20,7 @@ public final class TextViewBindingAdapters { /** Binds date text with relative time. */ - @BindingAdapter("profile:created") + @BindingAdapter("profileCreatedTime") public static void setProfileDataText(@NonNull TextView textView, long timestamp) { AppLanguageResourceHandler resourceHandler = getResourceHandler(textView); String time = resourceHandler.computeDateString(timestamp); @@ -31,7 +31,7 @@ public static void setProfileDataText(@NonNull TextView textView, long timestamp } /** Binds last used with relative timestamp. */ - @BindingAdapter("profile:lastVisited") + @BindingAdapter("profileLastVisitedTime") public static void setProfileLastVisitedText(@NonNull TextView textView, long timestamp) { AppLanguageResourceHandler resourceHandler = getResourceHandler(textView); String profileLastUsed = resourceHandler.getStringInLocale(R.string.profile_last_used); @@ -46,7 +46,7 @@ public static void setProfileLastVisitedText(@NonNull TextView textView, long ti // TODO(#4345): Add test for this method. /** Binds an AndroidX KitKat-compatible drawable top to the specified text view. */ - @BindingAdapter("app:drawableTopCompat") + @BindingAdapter("drawableTopCompat") public static void setDrawableTopCompat( @NonNull TextView imageView, Drawable drawable @@ -57,7 +57,7 @@ public static void setDrawableTopCompat( } /** Binds an AndroidX KitKat-compatible drawable end to the specified text view. */ - @BindingAdapter("app:drawableEndCompat") + @BindingAdapter("drawableEndCompat") public static void setDrawableEndCompat( @NonNull TextView imageView, Drawable drawable diff --git a/app/src/main/java/org/oppia/android/app/databinding/ViewBindingAdapters.java b/app/src/main/java/org/oppia/android/app/databinding/ViewBindingAdapters.java index fbe1b859e6f..6b0dea8b2b6 100644 --- a/app/src/main/java/org/oppia/android/app/databinding/ViewBindingAdapters.java +++ b/app/src/main/java/org/oppia/android/app/databinding/ViewBindingAdapters.java @@ -37,8 +37,8 @@ public static void setLayoutWidth(@NonNull View view, float width) { /** Adapter to animate-rotate a view by the specified angle in the specified direction. */ @BindingAdapter( value = { - "app:isRotationAnimationClockwise", - "app:rotationAnimationAngle" + "isRotationAnimationClockwise", + "rotationAnimationAngle" }, requireAll = true ) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt index edd4e952711..9caf3ee3bfb 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt @@ -1,7 +1,6 @@ package org.oppia.android.app.devoptions import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.Toolbar import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope @@ -33,7 +32,7 @@ class DeveloperOptionsActivityPresenter @Inject constructor( } private fun setUpNavigationDrawer() { - val toolbar = binding.developerOptionsActivityToolbar as Toolbar + val toolbar = binding.developerOptionsActivityToolbar activity.setSupportActionBar(toolbar) activity.supportActionBar!!.setDisplayShowHomeEnabled(true) navigationDrawerFragment = activity diff --git a/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeFragmentPresenter.kt index 1b09b469bb4..54db449bc89 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/forcenetworktype/ForceNetworkTypeFragmentPresenter.kt @@ -9,7 +9,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.common.base.Optional import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ForceNetworkTypeFragmentBinding import org.oppia.android.databinding.ForceNetworkTypeNetworkItemViewBinding import org.oppia.android.util.networking.NetworkConnectionDebugUtil @@ -21,7 +20,7 @@ class ForceNetworkTypeFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, private val networkConnectionUtil: Optional, - private val viewModelProvider: ViewModelProvider, + private val forceNetworkTypeViewModel: ForceNetworkTypeViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { @@ -46,7 +45,7 @@ class ForceNetworkTypeFragmentPresenter @Inject constructor( binding.apply { this.lifecycleOwner = fragment - this.viewModel = getForceNetworkTypeViewModel() + this.viewModel = forceNetworkTypeViewModel } linearLayoutManager = LinearLayoutManager(activity.applicationContext) @@ -83,8 +82,4 @@ class ForceNetworkTypeFragmentPresenter @Inject constructor( } } } - - private fun getForceNetworkTypeViewModel(): ForceNetworkTypeViewModel { - return viewModelProvider.getForFragment(fragment, ForceNetworkTypeViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt index 4509dedb942..0c93279a099 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markchapterscompleted/MarkChaptersCompletedActivity.kt @@ -33,6 +33,7 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity() override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. onBackPressed() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt index 4e3b2f92a12..5c26e1408a4 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/markstoriescompleted/MarkStoriesCompletedActivity.kt @@ -33,6 +33,7 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity() override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. onBackPressed() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt index 5274a993e7b..6801d2fcea0 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/marktopicscompleted/MarkTopicsCompletedActivity.kt @@ -34,6 +34,7 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. onBackPressed() } return super.onOptionsItemSelected(item) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragmentPresenter.kt index 9fe0b2849f8..78635f02db3 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsFragmentPresenter.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ViewEventLogsEventLogItemViewBinding import org.oppia.android.databinding.ViewEventLogsFragmentBinding import javax.inject.Inject @@ -18,7 +17,7 @@ import javax.inject.Inject class ViewEventLogsFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val viewEventLogsViewModel: ViewEventLogsViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { @@ -42,7 +41,7 @@ class ViewEventLogsFragmentPresenter @Inject constructor( binding.apply { this.lifecycleOwner = fragment - this.viewModel = getViewEventLogsViewModel() + this.viewModel = viewEventLogsViewModel } linearLayoutManager = LinearLayoutManager(activity.applicationContext) @@ -64,8 +63,4 @@ class ViewEventLogsFragmentPresenter @Inject constructor( ) .build() } - - private fun getViewEventLogsViewModel(): ViewEventLogsViewModel { - return viewModelProvider.getForFragment(fragment, ViewEventLogsViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt index 44fb2ec9945..f76c4cf919e 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerFragmentPresenter.kt @@ -11,7 +11,6 @@ import androidx.core.view.forEach import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.Fragment import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer import androidx.lifecycle.Transformations import com.google.android.material.navigation.NavigationView import com.google.common.base.Optional @@ -31,7 +30,6 @@ import org.oppia.android.app.mydownloads.MyDownloadsActivity import org.oppia.android.app.options.OptionsActivity import org.oppia.android.app.profileprogress.ProfileProgressActivity import org.oppia.android.app.topic.TopicActivity -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.DrawerFragmentBinding import org.oppia.android.databinding.NavHeaderNavigationDrawerBinding import org.oppia.android.domain.oppialogger.OppiaLogger @@ -54,8 +52,8 @@ class NavigationDrawerFragmentPresenter @Inject constructor( private val profileManagementController: ProfileManagementController, private val topicController: TopicController, private val oppiaLogger: OppiaLogger, - private val headerViewModelProvider: ViewModelProvider, - private val footerViewModelProvider: ViewModelProvider, + private val headerViewModel: NavigationDrawerHeaderViewModel, + private val footerViewModel: NavigationDrawerFooterViewModel, private val developerOptionsStarter: Optional ) : NavigationView.OnNavigationItemSelectedListener { private lateinit var drawerToggle: ActionBarDrawerToggle @@ -80,13 +78,13 @@ class NavigationDrawerFragmentPresenter @Inject constructor( container, /* attachToRoot= */ false ) - headerBinding.viewModel = getHeaderViewModel() + headerBinding.viewModel = headerViewModel subscribeToProfileLiveData() subscribeToCompletedStoryListLiveData() subscribeToOngoingTopicListLiveData() binding.fragmentDrawerNavView.addHeaderView(headerBinding.root) - binding.footerViewModel = getFooterViewModel() + binding.footerViewModel = footerViewModel binding.executePendingBindings() // TODO(#3382): Remove debug only code from prod build (also check imports, constructor and drawer_fragment.xml) @@ -98,15 +96,15 @@ class NavigationDrawerFragmentPresenter @Inject constructor( // TODO(#3382): Remove debug only code from prod build (also check imports, constructor and drawer_fragment.xml) private fun setIfDeveloperOptionsMenuItemListener() { developerOptionsStarter.asSet().forEach { starter -> - getFooterViewModel().isDebugMode.set(true) + footerViewModel.isDebugMode.set(true) binding.developerOptionsLinearLayout.setOnClickListener { - if (getFooterViewModel().isDeveloperOptionsSelected.get() == true) { + if (footerViewModel.isDeveloperOptionsSelected.get() == true) { drawerLayout.closeDrawers() return@setOnClickListener } uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() drawerLayout.closeDrawers() - getFooterViewModel().isDeveloperOptionsSelected.set(true) + footerViewModel.isDeveloperOptionsSelected.set(true) val intent = starter.createIntent(activity, internalProfileId) fragment.activity!!.startActivity(intent) if (previousMenuItemId == 0) fragment.activity!!.finish() @@ -129,38 +127,35 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } private fun subscribeToProfileLiveData() { - getProfileData().observe( - fragment, - Observer { - getHeaderViewModel().profile.set(it) - getFooterViewModel().isAdmin.set(it.isAdmin) - binding.administratorControlsLinearLayout.setOnClickListener { - if (getFooterViewModel().isAdministratorControlsSelected.get() == true) { - drawerLayout.closeDrawers() - return@setOnClickListener - } + getProfileData().observe(fragment) { + headerViewModel.profile.set(it) + footerViewModel.isAdmin.set(it.isAdmin) + binding.administratorControlsLinearLayout.setOnClickListener { + if (footerViewModel.isAdministratorControlsSelected.get() == true) { + drawerLayout.closeDrawers() + return@setOnClickListener + } - uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() + uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() - drawerLayout.closeDrawers() - getFooterViewModel().isAdministratorControlsSelected.set(true) - val intent = - AdministratorControlsActivity.createAdministratorControlsActivityIntent( - activity, - internalProfileId - ) - fragment.activity!!.startActivity(intent) - if (previousMenuItemId == -1) fragment.activity!!.finish() - else if (previousMenuItemId != null && - NavigationDrawerItem.valueFromNavId(previousMenuItemId!!) != - NavigationDrawerItem.HOME - ) { - fragment.activity!!.finish() - } - drawerLayout.closeDrawers() + drawerLayout.closeDrawers() + footerViewModel.isAdministratorControlsSelected.set(true) + val intent = + AdministratorControlsActivity.createAdministratorControlsActivityIntent( + activity, + internalProfileId + ) + fragment.activity!!.startActivity(intent) + if (previousMenuItemId == -1) fragment.activity!!.finish() + else if (previousMenuItemId != null && + NavigationDrawerItem.valueFromNavId(previousMenuItemId!!) != + NavigationDrawerItem.HOME + ) { + fragment.activity!!.finish() } + drawerLayout.closeDrawers() } - ) + } } private fun processGetProfileResult(profileResult: AsyncResult): Profile { @@ -182,12 +177,9 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } private fun subscribeToCompletedStoryListLiveData() { - getCompletedStoryListCount().observe( - fragment, - { - getHeaderViewModel().setCompletedStoryProgress(it.completedStoryCount) - } - ) + getCompletedStoryListCount().observe(fragment) { + headerViewModel.setCompletedStoryProgress(it.completedStoryCount) + } } private fun processGetCompletedStoryListResult( @@ -215,12 +207,9 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } private fun subscribeToOngoingTopicListLiveData() { - getOngoingTopicListCount().observe( - fragment, - { - getHeaderViewModel().setOngoingTopicProgress(it.topicCount) - } - ) + getOngoingTopicListCount().observe(fragment) { + headerViewModel.setOngoingTopicProgress(it.topicCount) + } } private fun processGetOngoingTopicListResult( @@ -286,12 +275,12 @@ class NavigationDrawerFragmentPresenter @Inject constructor( fragment.childFragmentManager.beginTransaction().remove(previousFragment).commitNow() } val exitProfileDialogArguments = - if (getFooterViewModel().isAdministratorControlsSelected.get() == true) { + if (footerViewModel.isAdministratorControlsSelected.get() == true) { ExitProfileDialogArguments .newBuilder() .setHighlightItem(HighlightItem.ADMINISTRATOR_CONTROLS_ITEM) .build() - } else if (getFooterViewModel().isDeveloperOptionsSelected.get() == true) { + } else if (footerViewModel.isDeveloperOptionsSelected.get() == true) { ExitProfileDialogArguments .newBuilder() .setHighlightItem(HighlightItem.DEVELOPER_OPTIONS_ITEM) @@ -302,8 +291,8 @@ class NavigationDrawerFragmentPresenter @Inject constructor( .setHighlightItem(HighlightItem.LAST_CHECKED_MENU_ITEM) .build() } - getFooterViewModel().isAdministratorControlsSelected.set(false) - getFooterViewModel().isDeveloperOptionsSelected.set(false) + footerViewModel.isAdministratorControlsSelected.set(false) + footerViewModel.isDeveloperOptionsSelected.set(false) binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.SWITCH_PROFILE.ordinal ).isChecked = @@ -342,13 +331,13 @@ class NavigationDrawerFragmentPresenter @Inject constructor( } fun highlightAdministratorControlsItem() { - getFooterViewModel().isAdministratorControlsSelected.set(true) + footerViewModel.isAdministratorControlsSelected.set(true) uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() drawerLayout.closeDrawers() } fun highlightDeveloperOptionsItem() { - getFooterViewModel().isDeveloperOptionsSelected.set(true) + footerViewModel.isDeveloperOptionsSelected.set(true) uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() drawerLayout.closeDrawers() } @@ -373,8 +362,8 @@ class NavigationDrawerFragmentPresenter @Inject constructor( fun setUpDrawer(drawerLayout: DrawerLayout, toolbar: Toolbar, menuItemId: Int) { previousMenuItemId = if (activity is TopicActivity) null else menuItemId if (menuItemId != 0 && menuItemId != -1) { - getFooterViewModel().isAdministratorControlsSelected.set(false) - getFooterViewModel().isDeveloperOptionsSelected.set(false) + footerViewModel.isAdministratorControlsSelected.set(false) + footerViewModel.isDeveloperOptionsSelected.set(false) when (NavigationDrawerItem.valueFromNavId(menuItemId)) { NavigationDrawerItem.HOME -> { binding.fragmentDrawerNavView.menu.getItem( @@ -437,14 +426,14 @@ class NavigationDrawerFragmentPresenter @Inject constructor( ) } } - drawerLayout.setDrawerListener(drawerToggle) + drawerLayout.addDrawerListener(drawerToggle) /* Synchronize the state of the drawer indicator/affordance with the linked [drawerLayout]. */ drawerLayout.post { drawerToggle.syncState() } } else { // For showing navigation drawer in AdministratorControlsActivity - if (menuItemId == 0) getFooterViewModel().isAdministratorControlsSelected.set(true) + if (menuItemId == 0) footerViewModel.isAdministratorControlsSelected.set(true) // For showing navigation drawer in DeveloperOptionsActivity - else if (menuItemId == -1) getFooterViewModel().isDeveloperOptionsSelected.set(true) + else if (menuItemId == -1) footerViewModel.isDeveloperOptionsSelected.set(true) uncheckAllMenuItemsWhenAdministratorControlsOrDeveloperOptionsIsSelected() this.drawerLayout = drawerLayout drawerToggle = object : ActionBarDrawerToggle( @@ -474,7 +463,7 @@ class NavigationDrawerFragmentPresenter @Inject constructor( ) } } - drawerLayout.setDrawerListener(drawerToggle) + drawerLayout.addDrawerListener(drawerToggle) /* Synchronize the state of the drawer indicator/affordance with the linked [drawerLayout]. */ drawerLayout.post { drawerToggle.syncState() } if (previousMenuItemId != NavigationDrawerItem.HOME.ordinal && previousMenuItemId != -1) { @@ -503,18 +492,4 @@ class NavigationDrawerFragmentPresenter @Inject constructor( openActivityByMenuItemId(menuItem.itemId) return true } - - private fun getHeaderViewModel(): NavigationDrawerHeaderViewModel { - return headerViewModelProvider.getForFragment( - fragment, - NavigationDrawerHeaderViewModel::class.java - ) - } - - private fun getFooterViewModel(): NavigationDrawerFooterViewModel { - return footerViewModelProvider.getForFragment( - fragment, - NavigationDrawerFooterViewModel::class.java - ) - } } diff --git a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerItem.kt b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerItem.kt index b8ee7cf62e4..bcd4a46b15a 100644 --- a/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerItem.kt +++ b/app/src/main/java/org/oppia/android/app/drawer/NavigationDrawerItem.kt @@ -17,7 +17,7 @@ enum class NavigationDrawerItem(val value: Int) { for (item: NavigationDrawerItem in values()) { if (item.value == id) return item } - return throw IllegalArgumentException("NavigationDrawerItem not found by $id") + throw IllegalArgumentException("NavigationDrawerItem not found by $id") } } } diff --git a/app/src/main/java/org/oppia/android/app/help/HelpFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/help/HelpFragmentPresenter.kt index 2748b323c4f..06af338f41b 100644 --- a/app/src/main/java/org/oppia/android/app/help/HelpFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/help/HelpFragmentPresenter.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.HelpFragmentBinding import org.oppia.android.databinding.HelpItemBinding import javax.inject.Inject @@ -18,7 +17,7 @@ import javax.inject.Inject class HelpFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val helpListViewModel: HelpListViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { private lateinit var binding: HelpFragmentBinding @@ -28,7 +27,7 @@ class HelpFragmentPresenter @Inject constructor( container: ViewGroup?, isMultipane: Boolean ): View? { - val viewModel = getHelpListViewModel() + val viewModel = helpListViewModel viewModel.isMultipane.set(isMultipane) binding = HelpFragmentBinding.inflate( @@ -55,8 +54,4 @@ class HelpFragmentPresenter @Inject constructor( setViewModel = HelpItemBinding::setViewModel ).build() } - - private fun getHelpListViewModel(): HelpListViewModel { - return viewModelProvider.getForFragment(fragment, HelpListViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/help/faq/FAQListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/help/faq/FAQListFragmentPresenter.kt index ca0288a22bd..63db13ff594 100644 --- a/app/src/main/java/org/oppia/android/app/help/faq/FAQListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/help/faq/FAQListFragmentPresenter.kt @@ -11,7 +11,6 @@ import org.oppia.android.app.help.faq.faqItemViewModel.FAQContentViewModel import org.oppia.android.app.help.faq.faqItemViewModel.FAQHeaderViewModel import org.oppia.android.app.help.faq.faqItemViewModel.FAQItemViewModel import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.FaqContentBinding import org.oppia.android.databinding.FaqItemHeaderBinding import org.oppia.android.databinding.FaqListFragmentBinding @@ -22,14 +21,12 @@ import javax.inject.Inject class FAQListFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val faqListViewModel: FAQListViewModel, private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory ) { private lateinit var binding: FaqListFragmentBinding fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { - val viewModel = getFAQListViewModel() - binding = FaqListFragmentBinding.inflate( inflater, container, @@ -43,7 +40,7 @@ class FAQListFragmentPresenter @Inject constructor( binding.let { it.lifecycleOwner = fragment - it.viewModel = viewModel + it.viewModel = faqListViewModel } return binding.root } @@ -71,10 +68,6 @@ class FAQListFragmentPresenter @Inject constructor( .build() } - private fun getFAQListViewModel(): FAQListViewModel { - return viewModelProvider.getForFragment(fragment, FAQListViewModel::class.java) - } - private enum class ViewType { VIEW_TYPE_HEADER, VIEW_TYPE_CONTENT diff --git a/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListFragmentPresenter.kt index 50fa6374c40..cdc7151afb5 100644 --- a/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/help/thirdparty/ThirdPartyDependencyListFragmentPresenter.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ThirdPartyDependencyItemBinding import org.oppia.android.databinding.ThirdPartyDependencyListFragmentBinding import javax.inject.Inject @@ -18,7 +17,7 @@ import javax.inject.Inject class ThirdPartyDependencyListFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val thirdPartyDependencyListViewModel: ThirdPartyDependencyListViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { private lateinit var binding: ThirdPartyDependencyListFragmentBinding @@ -29,8 +28,7 @@ class ThirdPartyDependencyListFragmentPresenter @Inject constructor( container: ViewGroup?, isMultipane: Boolean ): View { - val viewModel = getThirdPartyDependencyListViewModel() - viewModel.isMultipane.set(isMultipane) + thirdPartyDependencyListViewModel.isMultipane.set(isMultipane) binding = ThirdPartyDependencyListFragmentBinding.inflate( inflater, container, @@ -45,7 +43,7 @@ class ThirdPartyDependencyListFragmentPresenter @Inject constructor( binding.let { it.lifecycleOwner = fragment - it.viewModel = viewModel + it.viewModel = thirdPartyDependencyListViewModel } return binding.root } @@ -58,8 +56,4 @@ class ThirdPartyDependencyListFragmentPresenter @Inject constructor( ) .build() } - - private fun getThirdPartyDependencyListViewModel(): ThirdPartyDependencyListViewModel { - return viewModelProvider.getForFragment(fragment, ThirdPartyDependencyListViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/hintsandsolution/HintsAndSolutionDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/hintsandsolution/HintsAndSolutionDialogFragmentPresenter.kt index 670afb8c3c5..46d7c3fd9c7 100644 --- a/app/src/main/java/org/oppia/android/app/hintsandsolution/HintsAndSolutionDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/hintsandsolution/HintsAndSolutionDialogFragmentPresenter.kt @@ -52,7 +52,7 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( private lateinit var profileId: ProfileId private lateinit var bindingAdapter: BindableAdapter private lateinit var explorationId: String - private lateinit var viewModel: HintsAndSolutionViewModel + private lateinit var hintsViewModel: HintsAndSolutionViewModel /** * Sets up data binding and toolbar. @@ -86,7 +86,8 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( this.explorationId = explorationId // Check if hints are available for this state. - viewModel = hintsAndSolutionViewModelFactory.create(state, helpIndex, writtenTranslationContext) + hintsViewModel = + hintsAndSolutionViewModelFactory.create(state, helpIndex, writtenTranslationContext) val binding = HintsAndSolutionFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false) @@ -98,7 +99,7 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( (fragment.requireActivity() as? HintsAndSolutionListener)?.dismiss() } binding.let { - it.viewModel = this.viewModel + it.viewModel = hintsViewModel it.lifecycleOwner = fragment } @@ -147,7 +148,7 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( private fun bindHintViewModel(binding: HintSummaryBinding, hintViewModel: HintViewModel) { binding.viewModel = hintViewModel - val position: Int = viewModel.itemList.indexOf(hintViewModel) + val position: Int = hintsViewModel.itemList.indexOf(hintViewModel) binding.isListExpanded = position in expandedItemIndexes @@ -217,7 +218,7 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( ) { binding.viewModel = solutionViewModel - val position: Int = viewModel.itemList.indexOf(solutionViewModel) + val position: Int = hintsViewModel.itemList.indexOf(solutionViewModel) binding.isListExpanded = expandedItemIndexes.contains(position) solutionIndex?.let { solutionIndex -> @@ -300,13 +301,13 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor( } fun handleRevealSolution() { - viewModel.isSolutionRevealed.set(true) + hintsViewModel.isSolutionRevealed.set(true) expandedHintListIndexListener.onRevealSolutionClicked( - solutionIndex = viewModel.solutionIndex, + solutionIndex = hintsViewModel.solutionIndex, isSolutionRevealed = true ) (fragment.requireActivity() as? RevealSolutionInterface)?.revealSolution() - expandOrCollapseItem(position = viewModel.solutionIndex) + expandOrCollapseItem(position = hintsViewModel.solutionIndex) } fun onRevealHintClicked(index: Int?, isHintRevealed: Boolean?) { diff --git a/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt index c58c3bdbbd5..b62c266612d 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeFragmentPresenter.kt @@ -115,7 +115,7 @@ class HomeFragmentPresenter @Inject constructor( object : Observer> { override fun onChanged(startUpStateResult: AsyncResult?) { when (startUpStateResult) { - is AsyncResult.Pending -> { + null, is AsyncResult.Pending -> { // Do nothing } is AsyncResult.Success -> { diff --git a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenter.kt index 1551e6c4199..c9a37d9b391 100644 --- a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenter.kt @@ -14,7 +14,6 @@ import org.oppia.android.app.model.PolicyPage import org.oppia.android.app.policies.RouteToPoliciesListener import org.oppia.android.app.recyclerview.BindableAdapter import org.oppia.android.app.translation.AppLanguageResourceHandler -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.OnboardingFragmentBinding import org.oppia.android.databinding.OnboardingSlideBinding import org.oppia.android.databinding.OnboardingSlideFinalBinding @@ -28,8 +27,8 @@ import javax.inject.Inject class OnboardingFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, - private val viewModelProviderFinalSlide: ViewModelProvider, + private val onboardingViewModel: OnboardingViewModel, + private val onboardingSlideFinalViewModel: OnboardingSlideFinalViewModel, private val resourceHandler: AppLanguageResourceHandler, private val htmlParserFactory: HtmlParser.Factory, private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory @@ -48,7 +47,7 @@ class OnboardingFragmentPresenter @Inject constructor( binding.let { it.lifecycleOwner = fragment it.presenter = this - it.viewModel = getOnboardingViewModel() + it.viewModel = onboardingViewModel } setUpViewPager() addDots() @@ -68,7 +67,7 @@ class OnboardingFragmentPresenter @Inject constructor( OnboardingSlideViewModel( context = activity, viewPagerSlide = ViewPagerSlide.SLIDE_2, resourceHandler ), - getOnboardingSlideFinalViewModel() + onboardingSlideFinalViewModel ) ) binding.onboardingSlideViewPager.adapter = onboardingViewPagerBindableAdapter @@ -87,12 +86,9 @@ class OnboardingFragmentPresenter @Inject constructor( override fun onPageSelected(position: Int) { if (position == TOTAL_NUMBER_OF_SLIDES - 1) { binding.onboardingSlideViewPager.currentItem = TOTAL_NUMBER_OF_SLIDES - 1 - getOnboardingViewModel().slideChanged(TOTAL_NUMBER_OF_SLIDES - 1) + onboardingViewModel.slideChanged(TOTAL_NUMBER_OF_SLIDES - 1) } else { - getOnboardingViewModel().slideChanged( - ViewPagerSlide.getSlideForPosition(position) - .ordinal - ) + onboardingViewModel.slideChanged(ViewPagerSlide.getSlideForPosition(position).ordinal) } selectDot(position) onboardingStatusBarColorUpdate(position) @@ -154,13 +150,6 @@ class OnboardingFragmentPresenter @Inject constructor( } } - private fun getOnboardingSlideFinalViewModel(): OnboardingSlideFinalViewModel { - return viewModelProviderFinalSlide.getForFragment( - fragment, - OnboardingSlideFinalViewModel::class.java - ) - } - private enum class ViewType { ONBOARDING_MIDDLE_SLIDE, ONBOARDING_FINAL_SLIDE @@ -204,17 +193,13 @@ class OnboardingFragmentPresenter @Inject constructor( val position: Int = binding.onboardingSlideViewPager.currentItem + 1 binding.onboardingSlideViewPager.currentItem = position if (position != TOTAL_NUMBER_OF_SLIDES - 1) { - getOnboardingViewModel().slideChanged(ViewPagerSlide.getSlideForPosition(position).ordinal) + onboardingViewModel.slideChanged(ViewPagerSlide.getSlideForPosition(position).ordinal) } else { - getOnboardingViewModel().slideChanged(TOTAL_NUMBER_OF_SLIDES - 1) + onboardingViewModel.slideChanged(TOTAL_NUMBER_OF_SLIDES - 1) } selectDot(position) } - private fun getOnboardingViewModel(): OnboardingViewModel { - return viewModelProvider.getForFragment(fragment, OnboardingViewModel::class.java) - } - private fun addDots() { val dotsLayout = binding.slideDotsContainer val dotIdList = ArrayList() diff --git a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt index 09968096fad..2f46bdab3fb 100644 --- a/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/ongoingtopiclist/OngoingTopicListFragmentPresenter.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import org.oppia.android.R import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.OngoingTopicItemBinding import org.oppia.android.databinding.OngoingTopicListFragmentBinding import javax.inject.Inject @@ -17,7 +16,7 @@ import javax.inject.Inject class OngoingTopicListFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val ongoingTopicListViewModel: OngoingTopicListViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { @@ -28,14 +27,13 @@ class OngoingTopicListFragmentPresenter @Inject constructor( container: ViewGroup?, internalProfileId: Int ): View? { - val viewModel = getOngoingTopicListViewModel() binding = OngoingTopicListFragmentBinding.inflate( inflater, container, /* attachToRoot= */ false ) - viewModel.setProfileId(internalProfileId) + ongoingTopicListViewModel.setProfileId(internalProfileId) binding.ongoingTopicListToolbar.setNavigationOnClickListener { (activity as OngoingTopicListActivity).finish() @@ -47,11 +45,11 @@ class OngoingTopicListFragmentPresenter @Inject constructor( layoutManager = GridLayoutManager(context, spanCount) } - // NB: Both the view model and lifecycle owner must be set in order to correctly bind LiveData elements to - // data-bound view models. + // NB: Both the view model and lifecycle owner must be set in order to correctly bind LiveData + // elements to data-bound view models. binding.let { it.lifecycleOwner = fragment - it.viewModel = viewModel + it.viewModel = ongoingTopicListViewModel } return binding.root } @@ -64,8 +62,4 @@ class OngoingTopicListFragmentPresenter @Inject constructor( ) .build() } - - private fun getOngoingTopicListViewModel(): OngoingTopicListViewModel { - return viewModelProvider.getForFragment(fragment, OngoingTopicListViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt index cad56a8bd96..34e25221b52 100644 --- a/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt +++ b/app/src/main/java/org/oppia/android/app/options/AppLanguageFragment.kt @@ -62,7 +62,6 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val oppiaLanguage = checkNotNull( savedInstanceState?.retrieveLanguageFromSavedState() @@ -73,7 +72,7 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener return appLanguageFragmentPresenter.handleOnCreateView( inflater, container, - oppiaLanguage!!, + oppiaLanguage, profileId!! ) } @@ -86,7 +85,7 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener outState.putProto(FRAGMENT_SAVED_STATE_KEY, state) } - override fun onLanguageSelected(selectedLanguage: OppiaLanguage) { - appLanguageFragmentPresenter.onLanguageSelected(selectedLanguage) + override fun onLanguageSelected(appLanguage: OppiaLanguage) { + appLanguageFragmentPresenter.onLanguageSelected(appLanguage) } } diff --git a/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt b/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt index 50484e5ff1e..ccbcea40b7b 100644 --- a/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt +++ b/app/src/main/java/org/oppia/android/app/options/OptionsActivity.kt @@ -83,6 +83,7 @@ class OptionsActivity : selectedFragment = if (savedInstanceState == null) { READING_TEXT_SIZE_FRAGMENT } else { + @Suppress("DEPRECATION") // TODO(#5405): Ensure the correct type is being retrieved. savedInstanceState.get(SELECTED_FRAGMENT_SAVED_KEY) as String } val extraOptionsTitle = @@ -151,12 +152,12 @@ class OptionsActivity : optionActivityPresenter.loadReadingTextSizeFragment(textSize) } - override fun loadAppLanguageFragment(appLanguage: OppiaLanguage) { + override fun loadAppLanguageFragment(oppiaLanguage: OppiaLanguage) { selectedFragment = APP_LANGUAGE_FRAGMENT optionActivityPresenter.setExtraOptionTitle( resourceHandler.getStringInLocale(R.string.app_language) ) - optionActivityPresenter.loadAppLanguageFragment(appLanguage) + optionActivityPresenter.loadAppLanguageFragment(oppiaLanguage) } override fun loadAudioLanguageFragment(audioLanguage: AudioLanguage) { diff --git a/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt index 0e11f227c1e..462b67c8b13 100644 --- a/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/OptionsFragmentPresenter.kt @@ -5,7 +5,6 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import androidx.recyclerview.widget.RecyclerView import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY import org.oppia.android.app.fragment.FragmentScope @@ -15,7 +14,6 @@ import org.oppia.android.app.model.OppiaLanguage import org.oppia.android.app.model.ProfileId import org.oppia.android.app.model.ReadingTextSize import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.OptionAppLanguageBinding import org.oppia.android.databinding.OptionAudioLanguageBinding import org.oppia.android.databinding.OptionStoryTextSizeBinding @@ -44,7 +42,7 @@ class OptionsFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, private val profileManagementController: ProfileManagementController, - private val viewModelProvider: ViewModelProvider, + private val optionControlsViewModel: OptionControlsViewModel, private val oppiaLogger: OppiaLogger, private val multiTypeBuilderFactory: BindableAdapter.MultiTypeBuilder.Factory, private val translationController: TranslationController @@ -55,7 +53,6 @@ class OptionsFragmentPresenter @Inject constructor( private lateinit var profileId: ProfileId private var appLanguage = OppiaLanguage.ENGLISH private var audioLanguage = AudioLanguage.NO_AUDIO - private val viewModel = getOptionControlsItemViewModel() /** Initializes and creates the views for [OptionsFragment]. */ fun handleCreateView( @@ -65,8 +62,8 @@ class OptionsFragmentPresenter @Inject constructor( isFirstOpen: Boolean, selectedFragment: String ): View? { - viewModel.isUIInitialized(false) - viewModel.isMultipane.set(isMultipane) + optionControlsViewModel.isUIInitialized(false) + optionControlsViewModel.isMultipane.set(isMultipane) binding = OptionsFragmentBinding.inflate( inflater, container, @@ -75,7 +72,7 @@ class OptionsFragmentPresenter @Inject constructor( internalProfileId = activity.intent.getIntExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, -1) profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build() - viewModel.setProfileId(profileId) + optionControlsViewModel.setProfileId(profileId) val optionsRecyclerViewAdapter = createRecyclerViewAdapter(isMultipane) binding.optionsRecyclerview.apply { @@ -84,13 +81,13 @@ class OptionsFragmentPresenter @Inject constructor( recyclerViewAdapter = optionsRecyclerViewAdapter binding.let { it.lifecycleOwner = fragment - it.viewModel = viewModel + it.viewModel = optionControlsViewModel } setSelectedFragment(selectedFragment) - viewModel.isUIInitialized(true) + optionControlsViewModel.isUIInitialized(true) var hasDefaultInitializedFragment = false - viewModel.optionsListLiveData.observe(fragment) { viewModels -> + optionControlsViewModel.optionsListLiveData.observe(fragment) { viewModels -> if (!hasDefaultInitializedFragment) { viewModels.filterIsInstance().singleOrNull()?.let { if (isMultipane && isFirstOpen) { @@ -146,7 +143,7 @@ class OptionsFragmentPresenter @Inject constructor( binding: OptionStoryTextSizeBinding, model: OptionsReadingTextSizeViewModel ) { - binding.commonViewModel = viewModel + binding.commonViewModel = optionControlsViewModel binding.viewModel = model } @@ -154,7 +151,7 @@ class OptionsFragmentPresenter @Inject constructor( binding: OptionAppLanguageBinding, model: OptionsAppLanguageViewModel ) { - binding.commonViewModel = viewModel + binding.commonViewModel = optionControlsViewModel binding.viewModel = model } @@ -162,13 +159,13 @@ class OptionsFragmentPresenter @Inject constructor( binding: OptionAudioLanguageBinding, model: OptionsAudioLanguageViewModel ) { - binding.commonViewModel = viewModel + binding.commonViewModel = optionControlsViewModel binding.viewModel = model } /** Sets the selected fragment index in [OptionsControlViewModel]. */ fun setSelectedFragment(selectedFragment: String) { - viewModel.selectedFragmentIndex.set( + optionControlsViewModel.selectedFragmentIndex.set( getSelectedFragmentIndex( selectedFragment ) @@ -184,10 +181,6 @@ class OptionsFragmentPresenter @Inject constructor( } } - private fun getOptionControlsItemViewModel(): OptionControlsViewModel { - return viewModelProvider.getForFragment(fragment, OptionControlsViewModel::class.java) - } - private enum class ViewType { /** Represents view type for displaying [ReadingTextSize]. */ VIEW_TYPE_READING_TEXT_SIZE, @@ -204,19 +197,17 @@ class OptionsFragmentPresenter @Inject constructor( * @param textSize new textSize to be set as current */ fun updateReadingTextSize(textSize: ReadingTextSize) { - profileManagementController.updateReadingTextSize(profileId, textSize).toLiveData().observe( - fragment, - { - when (it) { - is AsyncResult.Failure -> { - oppiaLogger.e( - READING_TEXT_SIZE_TAG, "$READING_TEXT_SIZE_ERROR: updating to $textSize", it.error - ) - } - else -> {} // Nothing needs to be done unless the update failed. + val sizeUpdateResult = profileManagementController.updateReadingTextSize(profileId, textSize) + sizeUpdateResult.toLiveData().observe(fragment) { + when (it) { + is AsyncResult.Failure -> { + oppiaLogger.e( + READING_TEXT_SIZE_TAG, "$READING_TEXT_SIZE_ERROR: updating to $textSize", it.error + ) } + else -> {} // Nothing needs to be done unless the update failed. } - ) + } recyclerViewAdapter.notifyItemChanged(0) } @@ -272,13 +263,10 @@ class OptionsFragmentPresenter @Inject constructor( * @param action what to execute after the UI is initialized. */ fun runAfterUIInitialization(action: () -> Unit) { - viewModel.uiLiveData.observe( - fragment, - Observer { - if (it) { - action.invoke() - } + optionControlsViewModel.uiLiveData.observe(fragment) { + if (it) { + action.invoke() } - ) + } } } diff --git a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt index 3ab661a3ced..85eedd9d379 100644 --- a/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/options/ReadingTextSizeActivityPresenter.kt @@ -28,6 +28,7 @@ class ReadingTextSizeActivityPresenter @Inject constructor( private fun setToolbar() { val readingTextSizeToolbar: Toolbar = activity.findViewById(R.id.reading_text_size_toolbar) readingTextSizeToolbar.setNavigationOnClickListener { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } } diff --git a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt index 02bcc3deb32..69b433d8aa9 100644 --- a/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/AudioFragmentPresenter.kt @@ -26,7 +26,6 @@ import org.oppia.android.app.spotlight.SpotlightManager import org.oppia.android.app.spotlight.SpotlightShape import org.oppia.android.app.spotlight.SpotlightTarget import org.oppia.android.app.translation.AppLanguageResourceHandler -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AudioFragmentBinding import org.oppia.android.domain.audio.CellularAudioDialogController import org.oppia.android.domain.oppialogger.OppiaLogger @@ -51,7 +50,7 @@ class AudioFragmentPresenter @Inject constructor( private val cellularAudioDialogController: CellularAudioDialogController, private val profileManagementController: ProfileManagementController, private val networkConnectionUtil: NetworkConnectionUtil, - private val viewModelProvider: ViewModelProvider, + private val audioViewModel: AudioViewModel, private val oppiaLogger: OppiaLogger, private val resourceHandler: AppLanguageResourceHandler, @EnableSpotlightUi private val enableSpotlightUi: PlatformParameterValue @@ -63,9 +62,6 @@ class AudioFragmentPresenter @Inject constructor( private var showCellularDataDialog = true private var useCellularData = false private var prepared = false - private val viewModel by lazy { - getAudioViewModel() - } private var isPauseAudioRequestPending = false private lateinit var binding: AudioFragmentBinding @@ -102,11 +98,11 @@ class AudioFragmentPresenter @Inject constructor( } override fun onStopTrackingTouch(seekBar: SeekBar?) { - viewModel.handleSeekTo(userProgress) + audioViewModel.handleSeekTo(userProgress) userIsSeeking = false } }) - viewModel.playStatusLiveData.observe( + audioViewModel.playStatusLiveData.observe( fragment, Observer { prepared = it != UiAudioPlayStatus.LOADING && it != UiAudioPlayStatus.FAILED @@ -124,7 +120,7 @@ class AudioFragmentPresenter @Inject constructor( ) binding.let { - it.viewModel = viewModel + it.viewModel = audioViewModel it.audioFragment = fragment as AudioFragment it.lifecycleOwner = fragment } @@ -162,8 +158,8 @@ class AudioFragmentPresenter @Inject constructor( getProfileData().observe( activity, Observer { result -> - viewModel.selectedLanguageCode = result - viewModel.loadMainContentAudio(allowAutoPlay = false, reloadingContent = false) + audioViewModel.selectedLanguageCode = result + audioViewModel.loadMainContentAudio(allowAutoPlay = false, reloadingContent = false) } ) } @@ -196,8 +192,8 @@ class AudioFragmentPresenter @Inject constructor( /** Sets selected language code in presenter and ViewModel. */ fun languageSelected(language: String) { - if (viewModel.selectedLanguageCode != language) { - viewModel.setAudioLanguageCode(language) + if (audioViewModel.selectedLanguageCode != language) { + audioViewModel.setAudioLanguageCode(language) } } @@ -208,8 +204,8 @@ class AudioFragmentPresenter @Inject constructor( fragment.childFragmentManager.beginTransaction().remove(previousFragment).commitNow() } val dialogFragment = LanguageDialogFragment.newInstance( - ArrayList(viewModel.languages), - viewModel.selectedLanguageCode + ArrayList(audioViewModel.languages), + audioViewModel.selectedLanguageCode ) dialogFragment.showNow(fragment.childFragmentManager, TAG_LANGUAGE_DIALOG) } @@ -217,30 +213,30 @@ class AudioFragmentPresenter @Inject constructor( /** Pauses audio if in prepared state. */ fun handleOnStop() { if (!activity.isChangingConfigurations && prepared) { - viewModel.pauseAudio() + audioViewModel.pauseAudio() } } /** Releases audio player resources. */ fun handleOnDestroy() { if (!activity.isChangingConfigurations) { - viewModel.handleRelease() + audioViewModel.handleRelease() } } fun setStateAndExplorationId(newState: State, explorationId: String) = - viewModel.setStateAndExplorationId(newState, explorationId) + audioViewModel.setStateAndExplorationId(newState, explorationId) fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) = - viewModel.loadMainContentAudio(allowAutoPlay, reloadingContent) + audioViewModel.loadMainContentAudio(allowAutoPlay, reloadingContent) fun loadFeedbackAudio(contentId: String, allowAutoPlay: Boolean) = - viewModel.loadFeedbackAudio(contentId, allowAutoPlay) + audioViewModel.loadFeedbackAudio(contentId, allowAutoPlay) fun pauseAudio() { isPauseAudioRequestPending = true if (prepared && isPauseAudioRequestPending) { - viewModel.pauseAudio() + audioViewModel.pauseAudio() isPauseAudioRequestPending = false } } @@ -343,8 +339,4 @@ class AudioFragmentPresenter @Inject constructor( dialog.dismiss() }.create().show() } - - private fun getAudioViewModel(): AudioViewModel { - return viewModelProvider.getForFragment(fragment, AudioViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/player/audio/LanguageDialogFragment.kt b/app/src/main/java/org/oppia/android/app/player/audio/LanguageDialogFragment.kt index 275705a0ed9..8480ce2a454 100644 --- a/app/src/main/java/org/oppia/android/app/player/audio/LanguageDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/player/audio/LanguageDialogFragment.kt @@ -86,7 +86,7 @@ class LanguageDialogFragment : InjectableDialogFragment() { return AlertDialog .Builder(ContextThemeWrapper(activity as Context, R.style.OppiaDialogFragmentTheme)) .setTitle(R.string.audio_language_select_dialog_title) - .setSingleChoiceItems(options, selectedIndex) { dialog, which -> + .setSingleChoiceItems(options, selectedIndex) { _, which -> selectedIndex = which } .setPositiveButton(R.string.audio_language_select_dialog_okay_button) { _, _ -> diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt index b20609b8e4d..c657a4a35fb 100755 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivity.kt @@ -155,13 +155,10 @@ class ExplorationActivity : ) as HintsAndSolutionDialogFragment? } - override fun routeToHintsAndSolution( - explorationId: String, - helpIndex: HelpIndex - ) { + override fun routeToHintsAndSolution(id: String, helpIndex: HelpIndex) { if (getHintsAndSolution() == null) { val hintsAndSolutionDialogFragment = HintsAndSolutionDialogFragment.newInstance( - explorationId, + id, state, helpIndex, writtenTranslationContext diff --git a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt index a5464c34459..54cde19b341 100644 --- a/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/exploration/ExplorationActivityPresenter.kt @@ -33,7 +33,6 @@ import org.oppia.android.app.survey.TAG_SURVEY_WELCOME_DIALOG import org.oppia.android.app.topic.TopicActivity import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.FontScaleConfigurationUtil -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ExplorationActivityBinding import org.oppia.android.domain.exploration.ExplorationDataController import org.oppia.android.domain.oppialogger.OppiaLogger @@ -57,7 +56,7 @@ const val TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER = "HINTS_AND_SOLUTION_EXPLO class ExplorationActivityPresenter @Inject constructor( private val activity: AppCompatActivity, private val explorationDataController: ExplorationDataController, - private val viewModelProvider: ViewModelProvider, + private val exploreViewModel: ExplorationViewModel, private val fontScaleConfigurationUtil: FontScaleConfigurationUtil, private val translationController: TranslationController, private val oppiaLogger: OppiaLogger, @@ -83,10 +82,6 @@ class ExplorationActivityPresenter @Inject constructor( private lateinit var oldestCheckpointExplorationTitle: String private lateinit var binding: ExplorationActivityBinding - private val exploreViewModel by lazy { - getExplorationViewModel() - } - fun handleOnCreate( context: Context, profileId: ProfileId, @@ -116,6 +111,7 @@ class ExplorationActivityPresenter @Inject constructor( } binding.explorationToolbar.setNavigationOnClickListener { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } @@ -357,10 +353,6 @@ class ExplorationActivityPresenter @Inject constructor( } } - private fun getExplorationViewModel(): ExplorationViewModel { - return viewModelProvider.getForActivity(activity, ExplorationViewModel::class.java) - } - /** Helper for subscribeToExploration. */ private fun getEphemeralExploration( exploration: LiveData> @@ -535,7 +527,7 @@ class ExplorationActivityPresenter @Inject constructor( object : Observer> { override fun onChanged(gatingResult: AsyncResult?) { when (gatingResult) { - is AsyncResult.Pending -> { + null, is AsyncResult.Pending -> { oppiaLogger.d("ExplorationActivity", "A gating decision is pending") } is AsyncResult.Failure -> { diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt index f1c00a6569a..aea996137c5 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt @@ -78,7 +78,7 @@ class StateFragmentPresenter @Inject constructor( private val assemblerBuilderFactory: StatePlayerRecyclerViewAssembler.Builder.Factory, private val splitScreenManager: SplitScreenManager, private val oppiaClock: OppiaClock, - private val viewModel: StateViewModel, + private val stateViewModel: StateViewModel, private val accessibilityService: AccessibilityService, private val resourceHandler: AppLanguageResourceHandler, private val surveyGatingController: SurveyGatingController @@ -117,7 +117,7 @@ class StateFragmentPresenter @Inject constructor( this.topicId = topicId this.storyId = storyId this.explorationId = explorationId - viewModel.initializeProfile(profileId) + stateViewModel.initializeProfile(profileId) binding = StateFragmentBinding.inflate( inflater, @@ -142,7 +142,7 @@ class StateFragmentPresenter @Inject constructor( recyclerViewAdapter = stateRecyclerViewAdapter binding.let { it.lifecycleOwner = fragment - it.viewModel = this.viewModel + it.viewModel = stateViewModel } binding.stateRecyclerView.addOnLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom -> @@ -175,7 +175,7 @@ class StateFragmentPresenter @Inject constructor( } fun onContinueButtonClicked() { - viewModel.setHintBulbVisibility(false) + stateViewModel.setHintBulbVisibility(false) hideKeyboard() moveToNextState() } @@ -201,14 +201,14 @@ class StateFragmentPresenter @Inject constructor( fun onSubmitButtonClicked() { hideKeyboard() - val answer = viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) + val answer = stateViewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) if (answer != null) { handleSubmitAnswer(answer) } } fun onResponsesHeaderClicked() { - recyclerViewAssembler.togglePreviousAnswers(viewModel.itemList) + recyclerViewAssembler.togglePreviousAnswers(stateViewModel.itemList) recyclerViewAssembler.adapter.notifyDataSetChanged() } @@ -216,8 +216,8 @@ class StateFragmentPresenter @Inject constructor( fun handleKeyboardAction() { hideKeyboard() - if (viewModel.getCanSubmitAnswer().get() == true) { - val answer = viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) + if (stateViewModel.getCanSubmitAnswer().get() == true) { + val answer = stateViewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) if (answer != null) { handleSubmitAnswer(answer) } @@ -240,7 +240,7 @@ class StateFragmentPresenter @Inject constructor( .hasConversationView(hasConversationView) .addContentSupport() .addFeedbackSupport() - .addInteractionSupport(viewModel.getCanSubmitAnswer()) + .addInteractionSupport(stateViewModel.getCanSubmitAnswer()) .addPastAnswersSupport() .addWrongAnswerCollapsingSupport() .addBackwardNavigationSupport() @@ -257,7 +257,7 @@ class StateFragmentPresenter @Inject constructor( ) .addHintsAndSolutionsSupport() .addAudioVoiceoverSupport( - explorationId, viewModel.currentStateName, viewModel.isAudioBarVisible, + explorationId, stateViewModel.currentStateName, stateViewModel.isAudioBarVisible, this::getAudioUiManager ) .addConceptCardSupport() @@ -307,11 +307,11 @@ class StateFragmentPresenter @Inject constructor( explorationCheckpointState = ephemeralState.checkpointState val shouldSplit = splitScreenManager.shouldSplitScreen(ephemeralState.state.interaction.id) if (shouldSplit) { - viewModel.isSplitView.set(true) - viewModel.centerGuidelinePercentage.set(0.5f) + stateViewModel.isSplitView.set(true) + stateViewModel.centerGuidelinePercentage.set(0.5f) } else { - viewModel.isSplitView.set(false) - viewModel.centerGuidelinePercentage.set(1f) + stateViewModel.isSplitView.set(false) + stateViewModel.centerGuidelinePercentage.set(1f) } val isInNewState = @@ -328,10 +328,10 @@ class StateFragmentPresenter @Inject constructor( shouldSplit ) - viewModel.itemList.clear() - viewModel.itemList += dataPair.first - viewModel.rightItemList.clear() - viewModel.rightItemList += dataPair.second + stateViewModel.itemList.clear() + stateViewModel.itemList += dataPair.first + stateViewModel.rightItemList.clear() + stateViewModel.rightItemList += dataPair.second if (isInNewState) { (binding.stateRecyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( @@ -377,7 +377,7 @@ class StateFragmentPresenter @Inject constructor( if (result.labelledAsCorrectAnswer) { recyclerViewAssembler.showCelebrationOnCorrectAnswer(result.feedback) } else { - viewModel.setCanSubmitAnswer(canSubmitAnswer = false) + stateViewModel.setCanSubmitAnswer(canSubmitAnswer = false) } recyclerViewAssembler.readOutAnswerFeedback(result.feedback) } @@ -417,7 +417,7 @@ class StateFragmentPresenter @Inject constructor( } private fun moveToNextState() { - viewModel.setCanSubmitAnswer(canSubmitAnswer = false) + stateViewModel.setCanSubmitAnswer(canSubmitAnswer = false) explorationProgressController.moveToNextState().toLiveData().observe( fragment, Observer { @@ -431,11 +431,12 @@ class StateFragmentPresenter @Inject constructor( activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.hideSoftInputFromWindow( fragment.view!!.windowToken, + @Suppress("DEPRECATION") // TODO(#5406): Use the correct constant value here. InputMethodManager.SHOW_FORCED ) } - fun setAudioBarVisibility(visibility: Boolean) = viewModel.setAudioBarVisibility(visibility) + fun setAudioBarVisibility(visibility: Boolean) = stateViewModel.setAudioBarVisibility(visibility) fun scrollToTop() { binding.stateRecyclerView.smoothScrollToPosition(0) @@ -444,9 +445,9 @@ class StateFragmentPresenter @Inject constructor( /** Updates submit button UI as active if pendingAnswerError null else inactive. */ fun updateSubmitButton(pendingAnswerError: String?, inputAnswerAvailable: Boolean) { if (inputAnswerAvailable) { - viewModel.setCanSubmitAnswer(pendingAnswerError == null) + stateViewModel.setCanSubmitAnswer(pendingAnswerError == null) } else { - viewModel.setCanSubmitAnswer(canSubmitAnswer = false) + stateViewModel.setCanSubmitAnswer(canSubmitAnswer = false) } } @@ -472,35 +473,35 @@ class StateFragmentPresenter @Inject constructor( if (!isCurrentStatePendingState) { // If current state is not the pending top state, hide the hint bulb. setHintOpenedAndUnRevealed(false) - viewModel.setHintBulbVisibility(false) + stateViewModel.setHintBulbVisibility(false) } else { when (helpIndex.indexTypeCase) { HelpIndex.IndexTypeCase.NEXT_AVAILABLE_HINT_INDEX -> { - viewModel.setHintBulbVisibility(true) + stateViewModel.setHintBulbVisibility(true) setHintOpenedAndUnRevealed(true) } HelpIndex.IndexTypeCase.LATEST_REVEALED_HINT_INDEX -> { - viewModel.setHintBulbVisibility(true) + stateViewModel.setHintBulbVisibility(true) setHintOpenedAndUnRevealed(false) } HelpIndex.IndexTypeCase.SHOW_SOLUTION -> { - viewModel.setHintBulbVisibility(true) + stateViewModel.setHintBulbVisibility(true) setHintOpenedAndUnRevealed(true) } HelpIndex.IndexTypeCase.EVERYTHING_REVEALED -> { setHintOpenedAndUnRevealed(false) - viewModel.setHintBulbVisibility(true) + stateViewModel.setHintBulbVisibility(true) } else -> { setHintOpenedAndUnRevealed(false) - viewModel.setHintBulbVisibility(false) + stateViewModel.setHintBulbVisibility(false) } } } } private fun setHintOpenedAndUnRevealed(isHintUnrevealed: Boolean) { - viewModel.setHintOpenedAndUnRevealedVisibility(isHintUnrevealed) + stateViewModel.setHintOpenedAndUnRevealedVisibility(isHintUnrevealed) if (isHintUnrevealed) { val hintBulbAnimation = AnimationUtils.loadAnimation( @@ -512,7 +513,7 @@ class StateFragmentPresenter @Inject constructor( // cases like configuration changes, or returning from a saved checkpoint. lifecycleSafeTimerFactory.run { activity.runPeriodically(delayMillis = 5_000, periodMillis = 30_000) { - return@runPeriodically viewModel.isHintOpenedAndUnRevealed.get()!!.also { playAnim -> + return@runPeriodically stateViewModel.isHintOpenedAndUnRevealed.get()!!.also { playAnim -> if (playAnim) binding.hintBulb.startAnimation(hintBulbAnimation) // Make a forced announcement when the hint bar becomes visible so that the non sighted // users know about the availability of hints. Instead of suddenly changing the focus of diff --git a/app/src/main/java/org/oppia/android/app/player/state/listener/RouteToHintsAndSolutionListener.kt b/app/src/main/java/org/oppia/android/app/player/state/listener/RouteToHintsAndSolutionListener.kt index 351e37b35c1..f0468d6c13a 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/listener/RouteToHintsAndSolutionListener.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/listener/RouteToHintsAndSolutionListener.kt @@ -4,8 +4,5 @@ import org.oppia.android.app.model.HelpIndex /** Listener for when an [ExplorationActivity] should route to a [HintsAndSolution]. */ interface RouteToHintsAndSolutionListener { - fun routeToHintsAndSolution( - id: String, - helpIndex: HelpIndex - ) + fun routeToHintsAndSolution(id: String, helpIndex: HelpIndex) } diff --git a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt index 07e0c179795..032849bd9d4 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivity.kt @@ -108,14 +108,11 @@ class StateFragmentTestActivity : override fun dismiss() {} - override fun routeToHintsAndSolution( - explorationId: String, - helpIndex: HelpIndex - ) { + override fun routeToHintsAndSolution(id: String, helpIndex: HelpIndex) { if (getHintsAndSolution() == null) { val hintsAndSolutionFragment = HintsAndSolutionDialogFragment.newInstance( - explorationId, + id, state, helpIndex, writtenTranslationContext diff --git a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt index 482451ae6b7..dd1dbc96a80 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/testing/StateFragmentTestActivityPresenter.kt @@ -9,7 +9,6 @@ import org.oppia.android.app.model.ProfileId import org.oppia.android.app.player.exploration.HintsAndSolutionExplorationManagerFragment import org.oppia.android.app.player.exploration.TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER import org.oppia.android.app.player.state.StateFragment -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.StateFragmentTestActivityBinding import org.oppia.android.domain.exploration.ExplorationDataController import org.oppia.android.domain.oppialogger.OppiaLogger @@ -28,7 +27,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( private val activity: AppCompatActivity, private val explorationDataController: ExplorationDataController, private val oppiaLogger: OppiaLogger, - private val viewModelProvider: ViewModelProvider + private val stateFragmentTestViewModel: StateFragmentTestViewModel ) { private var profileId: Int = 1 @@ -44,7 +43,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( ) binding.apply { lifecycleOwner = activity - viewModel = getStateFragmentTestViewModel() + viewModel = stateFragmentTestViewModel } profileId = activity.intent.getIntExtra(TEST_ACTIVITY_PROFILE_ID_EXTRA_KEY, 1) @@ -121,7 +120,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( storyId: String, explorationId: String ) { - getStateFragmentTestViewModel().hasExplorationStarted.set(true) + stateFragmentTestViewModel.hasExplorationStarted.set(true) val stateFragment = StateFragment.newInstance(profileId, topicId, storyId, explorationId) activity.supportFragmentManager.beginTransaction().add( @@ -145,7 +144,7 @@ class StateFragmentTestActivityPresenter @Inject constructor( activity.supportFragmentManager.beginTransaction().remove(fragment).commitNow() } - getStateFragmentTestViewModel().hasExplorationStarted.set(false) + stateFragmentTestViewModel.hasExplorationStarted.set(false) } private fun getStateFragment(): StateFragment? { @@ -159,8 +158,4 @@ class StateFragmentTestActivityPresenter @Inject constructor( TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER ) as HintsAndSolutionExplorationManagerFragment? } - - private fun getStateFragmentTestViewModel(): StateFragmentTestViewModel { - return viewModelProvider.getForActivity(activity, StateFragmentTestViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/profile/AdminAuthActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/AdminAuthActivityPresenter.kt index 2651603478d..a4ff853487f 100644 --- a/app/src/main/java/org/oppia/android/app/profile/AdminAuthActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/AdminAuthActivityPresenter.kt @@ -10,7 +10,6 @@ import org.oppia.android.app.activity.ActivityScope import org.oppia.android.app.administratorcontrols.AdministratorControlsActivity import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AdminAuthActivityBinding import javax.inject.Inject @@ -19,13 +18,10 @@ import javax.inject.Inject class AdminAuthActivityPresenter @Inject constructor( private val context: Context, private val activity: AppCompatActivity, - private val viewModelProvider: ViewModelProvider, + private val authViewModel: AdminAuthViewModel, private val resourceHandler: AppLanguageResourceHandler ) { private lateinit var binding: AdminAuthActivityBinding - private val authViewModel by lazy { - getAdminAuthViewModel() - } /** Binds ViewModel and sets up text and button listeners. */ fun handleOnCreate() { @@ -126,8 +122,4 @@ class AdminAuthActivityPresenter @Inject constructor( } } } - - private fun getAdminAuthViewModel(): AdminAuthViewModel { - return viewModelProvider.getForActivity(activity, AdminAuthViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/profile/AdminPinActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/AdminPinActivityPresenter.kt index 5ab5624b99f..ba9f04ea197 100644 --- a/app/src/main/java/org/oppia/android/app/profile/AdminPinActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/AdminPinActivityPresenter.kt @@ -12,7 +12,6 @@ import org.oppia.android.app.administratorcontrols.AdministratorControlsActivity import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AdminPinActivityBinding import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.util.data.AsyncResult @@ -25,17 +24,13 @@ class AdminPinActivityPresenter @Inject constructor( private val context: Context, private val activity: AppCompatActivity, private val profileManagementController: ProfileManagementController, - private val viewModelProvider: ViewModelProvider, + private val adminViewModel: AdminPinViewModel, private val resourceHandler: AppLanguageResourceHandler ) { private var inputtedPin = false private var inputtedConfirmPin = false - private val adminViewModel by lazy { - getAdminPinViewModel() - } - /** Binds ViewModel and sets up text and button listeners. */ fun handleOnCreate() { @@ -165,14 +160,6 @@ class AdminPinActivityPresenter @Inject constructor( } private fun setValidPin() { - if (inputtedPin && inputtedConfirmPin) { - getAdminPinViewModel().isButtonActive.set(true) - } else { - getAdminPinViewModel().isButtonActive.set(false) - } - } - - private fun getAdminPinViewModel(): AdminPinViewModel { - return viewModelProvider.getForActivity(activity, AdminPinViewModel::class.java) + adminViewModel.isButtonActive.set(inputtedPin && inputtedConfirmPin) } } diff --git a/app/src/main/java/org/oppia/android/app/profile/AdminSettingsDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/AdminSettingsDialogFragmentPresenter.kt index c0faded0563..e8509cbda09 100644 --- a/app/src/main/java/org/oppia/android/app/profile/AdminSettingsDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/AdminSettingsDialogFragmentPresenter.kt @@ -11,7 +11,6 @@ import org.oppia.android.R import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.AdminSettingsDialogBinding import javax.inject.Inject @@ -20,13 +19,9 @@ import javax.inject.Inject class AdminSettingsDialogFragmentPresenter @Inject constructor( private val fragment: Fragment, private val activity: AppCompatActivity, - private val viewModelProvider: ViewModelProvider, + private val adminViewModel: AdminSettingsViewModel, private val resourceHandler: AppLanguageResourceHandler ) { - private val adminViewModel by lazy { - getAdminSettingsViewModel() - } - fun handleOnCreateDialog( routeDialogInterface: ProfileRouteDialogInterface, adminPin: String? @@ -100,8 +95,4 @@ class AdminSettingsDialogFragmentPresenter @Inject constructor( } return dialog } - - private fun getAdminSettingsViewModel(): AdminSettingsViewModel { - return viewModelProvider.getForFragment(fragment, AdminSettingsViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/profile/PinPasswordActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/PinPasswordActivityPresenter.kt index 57c999e2586..2e5928fb4ac 100644 --- a/app/src/main/java/org/oppia/android/app/profile/PinPasswordActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/PinPasswordActivityPresenter.kt @@ -12,7 +12,6 @@ import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged import org.oppia.android.app.utility.lifecycle.LifecycleSafeTimerFactory -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.PinPasswordActivityBinding import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.util.accessibility.AccessibilityService @@ -29,13 +28,10 @@ class PinPasswordActivityPresenter @Inject constructor( private val activity: AppCompatActivity, private val profileManagementController: ProfileManagementController, private val lifecycleSafeTimerFactory: LifecycleSafeTimerFactory, - private val viewModelProvider: ViewModelProvider, - private val resourceHandler: AppLanguageResourceHandler + private val pinViewModel: PinPasswordViewModel, + private val resourceHandler: AppLanguageResourceHandler, + private val accessibilityService: AccessibilityService ) { - @Inject lateinit var accessibilityService: AccessibilityService - private val pinViewModel by lazy { - getPinPasswordViewModel() - } private var profileId = -1 private lateinit var alertDialog: AlertDialog private var confirmedDeletion = false @@ -168,10 +164,6 @@ class PinPasswordActivityPresenter @Inject constructor( showSuccessDialog() } - private fun getPinPasswordViewModel(): PinPasswordViewModel { - return viewModelProvider.getForActivity(activity, PinPasswordViewModel::class.java) - } - private fun showAdminForgotPin() { val appName = resourceHandler.getStringInLocale(R.string.app_name) pinViewModel.showAdminPinForgotPasswordPopUp.set(true) @@ -214,15 +206,12 @@ class PinPasswordActivityPresenter @Inject constructor( pinViewModel.showAdminPinForgotPasswordPopUp.set(false) dialog.dismiss() } - .setPositiveButton(R.string.admin_confirm_app_wipe_positive_button_text) { dialog, _ -> - profileManagementController.deleteAllProfiles().toLiveData().observe( - activity, - { - // Regardless of the result of the operation, always restart the app. - confirmedDeletion = true - activity.finishAffinity() - } - ) + .setPositiveButton(R.string.admin_confirm_app_wipe_positive_button_text) { _, _ -> + profileManagementController.deleteAllProfiles().toLiveData().observe(activity) { + // Regardless of the result of the operation, always restart the app. + confirmedDeletion = true + activity.finishAffinity() + } }.create() alertDialog.setCanceledOnTouchOutside(false) alertDialog.show() diff --git a/app/src/main/java/org/oppia/android/app/profile/ProfileChooserFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/ProfileChooserFragmentPresenter.kt index c9753662083..9ccd175ea45 100644 --- a/app/src/main/java/org/oppia/android/app/profile/ProfileChooserFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/ProfileChooserFragmentPresenter.kt @@ -19,7 +19,6 @@ import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.model.Profile import org.oppia.android.app.model.ProfileChooserUiModel import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ProfileChooserAddViewBinding import org.oppia.android.databinding.ProfileChooserFragmentBinding import org.oppia.android.databinding.ProfileChooserProfileViewBinding @@ -64,7 +63,7 @@ class ProfileChooserFragmentPresenter @Inject constructor( private val fragment: Fragment, private val activity: AppCompatActivity, private val context: Context, - private val viewModelProvider: ViewModelProvider, + private val chooserViewModel: ProfileChooserViewModel, private val profileManagementController: ProfileManagementController, private val oppiaLogger: OppiaLogger, private val analyticsController: AnalyticsController, @@ -73,10 +72,6 @@ class ProfileChooserFragmentPresenter @Inject constructor( private lateinit var binding: ProfileChooserFragmentBinding val hasProfileEverBeenAddedValue = ObservableField(true) - private val chooserViewModel: ProfileChooserViewModel by lazy { - getProfileChooserViewModel() - } - /** Binds ViewModel and sets up RecyclerView Adapter. */ fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { StatusBarColor.statusBarColorUpdate( @@ -148,10 +143,6 @@ class ProfileChooserFragmentPresenter @Inject constructor( }.minus(chooserViewModel.usedColors).random() } - private fun getProfileChooserViewModel(): ProfileChooserViewModel { - return viewModelProvider.getForFragment(fragment, ProfileChooserViewModel::class.java) - } - private fun createRecyclerViewAdapter(): BindableAdapter { return multiTypeBuilderFactory.create( diff --git a/app/src/main/java/org/oppia/android/app/profile/ResetPinDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/ResetPinDialogFragmentPresenter.kt index bf81773b519..a4105ee19e4 100644 --- a/app/src/main/java/org/oppia/android/app/profile/ResetPinDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/ResetPinDialogFragmentPresenter.kt @@ -13,7 +13,6 @@ import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ResetPinDialogBinding import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.util.data.AsyncResult @@ -26,13 +25,9 @@ class ResetPinDialogFragmentPresenter @Inject constructor( private val fragment: Fragment, private val activity: AppCompatActivity, private val profileManagementController: ProfileManagementController, - private val viewModelProvider: ViewModelProvider, + private val resetViewModel: ResetPinViewModel, private val resourceHandler: AppLanguageResourceHandler ) { - private val resetViewModel by lazy { - getResetPinViewModel() - } - fun handleOnCreateDialog( routeDialogInterface: ProfileRouteDialogInterface, profileId: Int, @@ -116,8 +111,4 @@ class ResetPinDialogFragmentPresenter @Inject constructor( } return dialog } - - private fun getResetPinViewModel(): ResetPinViewModel { - return viewModelProvider.getForFragment(fragment, ResetPinViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt index f0425144d3b..e6cbc39c507 100644 --- a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonActivityPresenter.kt @@ -33,6 +33,7 @@ class ResumeLessonActivityPresenter @Inject constructor( activity.setSupportActionBar(resumeLessonToolbar) resumeLessonToolbar.setNavigationOnClickListener { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } diff --git a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonFragmentPresenter.kt index 89173f4c236..b3775e5607f 100644 --- a/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/resumelesson/ResumeLessonFragmentPresenter.kt @@ -13,7 +13,6 @@ import org.oppia.android.app.model.ExplorationActivityParams import org.oppia.android.app.model.ExplorationCheckpoint import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ResumeLessonFragmentBinding import org.oppia.android.domain.exploration.ExplorationDataController import org.oppia.android.domain.oppialogger.OppiaLogger @@ -29,7 +28,7 @@ import javax.inject.Inject class ResumeLessonFragmentPresenter @Inject constructor( activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val resumeLessonViewModel: ResumeLessonViewModel, private val topicController: TopicController, private val explorationDataController: ExplorationDataController, private val htmlParserFactory: HtmlParser.Factory, @@ -42,7 +41,6 @@ class ResumeLessonFragmentPresenter @Inject constructor( private val routeToExplorationListener = activity as RouteToExplorationListener private lateinit var binding: ResumeLessonFragmentBinding - private val resumeLessonViewModel = getResumeLessonViewModel() private lateinit var profileId: ProfileId private lateinit var topicId: String private lateinit var storyId: String @@ -148,10 +146,6 @@ class ResumeLessonFragmentPresenter @Inject constructor( } } - private fun getResumeLessonViewModel(): ResumeLessonViewModel { - return viewModelProvider.getForFragment(fragment, ResumeLessonViewModel::class.java) - } - private fun getChapterSummary(): LiveData { return Transformations.map(chapterSummaryResultLiveData, ::processChapterSummaryResult) } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt index b8cf2dcd2d5..2e42ba5bbff 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivity.kt @@ -48,6 +48,7 @@ class ProfileEditActivity : InjectableAutoLocalizedAppCompatActivity() { override fun onBackPressed() { val isMultipane = intent.extras!!.getBoolean(IS_MULTIPANE_EXTRA_KEY, false) if (isMultipane) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. super.onBackPressed() } else { val intent = Intent(this, ProfileListActivity::class.java) diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt index 05ad56e6a46..dd6b0f39e78 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditActivityPresenter.kt @@ -26,6 +26,7 @@ class ProfileEditActivityPresenter @Inject constructor( toolbar.setNavigationOnClickListener { if (isMultipane) { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } else { val intent = Intent(activity, ProfileListActivity::class.java) diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditDeletionDialogFragment.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditDeletionDialogFragment.kt index 27b1914a650..aea5b10011d 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditDeletionDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditDeletionDialogFragment.kt @@ -53,7 +53,7 @@ class ProfileEditDeletionDialogFragment : InjectableDialogFragment() { .setNegativeButton(R.string.profile_edit_delete_dialog_negative) { dialog, _ -> dialog.dismiss() } - .setPositiveButton(R.string.profile_edit_delete_dialog_positive) { dialog, _ -> + .setPositiveButton(R.string.profile_edit_delete_dialog_positive) { _, _ -> profileEditDialogInterface.deleteProfileByInternalProfileId(internalProfileId) } .create() diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragmentPresenter.kt index f1fb73492b1..c5df7aa5439 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileEditFragmentPresenter.kt @@ -75,7 +75,7 @@ class ProfileEditFragmentPresenter @Inject constructor( ) } - binding.profileMarkChaptersForCompletionButton?.setOnClickListener { + binding.profileMarkChaptersForCompletionButton.setOnClickListener { activity.startActivity( MarkChaptersCompletedActivity.createMarkChaptersCompletedIntent( activity, internalProfileId, showConfirmationNotice = true diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt index 41846084168..91fd34399d1 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileListFragmentPresenter.kt @@ -9,7 +9,6 @@ import org.oppia.android.app.administratorcontrols.LoadProfileEditListener import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.Profile import org.oppia.android.app.recyclerview.BindableAdapter -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ProfileListFragmentBinding import org.oppia.android.databinding.ProfileListProfileViewBinding import javax.inject.Inject @@ -19,7 +18,7 @@ import javax.inject.Inject class ProfileListFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val profileListViewModel: ProfileListViewModel, private val singleTypeBuilderFactory: BindableAdapter.SingleTypeBuilder.Factory ) { @@ -42,7 +41,7 @@ class ProfileListFragmentPresenter @Inject constructor( (activity as ProfileListActivity).finish() } binding.apply { - viewModel = getProfileListViewModel() + viewModel = profileListViewModel lifecycleOwner = fragment } @@ -77,8 +76,4 @@ class ProfileListFragmentPresenter @Inject constructor( } } } - - private fun getProfileListViewModel(): ProfileListViewModel { - return viewModelProvider.getForFragment(fragment, ProfileListViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt index b32adbbba6c..10898a226c7 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameActivityPresenter.kt @@ -4,16 +4,12 @@ import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ProfileRenameActivityBinding import javax.inject.Inject /** The presenter for [ProfileRenameActivity]. */ @ActivityScope -class ProfileRenameActivityPresenter @Inject constructor( - private val activity: AppCompatActivity, - private val viewModelProvider: ViewModelProvider, -) { +class ProfileRenameActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { /** Handles onCreate() of [ProfileRenameActivity]. */ fun handleOnCreate(profileId: Int) { @@ -46,8 +42,4 @@ class ProfileRenameActivityPresenter @Inject constructor( R.id.profile_rename_fragment_placeholder ) as ProfileRenameFragment? } - - private fun getProfileRenameViewModel(): ProfileRenameViewModel { - return viewModelProvider.getForActivity(activity, ProfileRenameViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameFragmentPresenter.kt index 6350c2e4581..3ad5bcd4f68 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileRenameFragmentPresenter.kt @@ -13,7 +13,6 @@ import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ProfileRenameFragmentBinding import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.util.data.AsyncResult @@ -26,13 +25,9 @@ class ProfileRenameFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, private val profileManagementController: ProfileManagementController, - private val viewModelProvider: ViewModelProvider, + private val renameViewModel: ProfileRenameViewModel, private val resourceHandler: AppLanguageResourceHandler ) { - private val renameViewModel: ProfileRenameViewModel by lazy { - getProfileRenameViewModel() - } - private lateinit var binding: ProfileRenameFragmentBinding /** Handles onCreateView() method of [ProfileRenameFragment]. */ @@ -122,8 +117,4 @@ class ProfileRenameFragmentPresenter @Inject constructor( } } } - - private fun getProfileRenameViewModel(): ProfileRenameViewModel { - return viewModelProvider.getForFragment(fragment, ProfileRenameViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileResetPinFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileResetPinFragmentPresenter.kt index b4afe1d73e1..fb4e499fafd 100644 --- a/app/src/main/java/org/oppia/android/app/settings/profile/ProfileResetPinFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/settings/profile/ProfileResetPinFragmentPresenter.kt @@ -13,7 +13,6 @@ import org.oppia.android.R import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler import org.oppia.android.app.utility.TextInputEditTextHelper.Companion.onTextChanged -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ProfileResetPinFragmentBinding import org.oppia.android.domain.profile.ProfileManagementController import org.oppia.android.util.data.AsyncResult @@ -24,13 +23,10 @@ import javax.inject.Inject class ProfileResetPinFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val profileResetPinViewModel: ProfileResetPinViewModel, private val profileManagementController: ProfileManagementController, private val resourceHandler: AppLanguageResourceHandler ) { - private val viewModel: ProfileResetPinViewModel by lazy { - getProfileResetPinViewModel() - } private lateinit var binding: ProfileResetPinFragmentBinding private var inputtedPin = false private var inputtedConfirmPin = false @@ -44,24 +40,24 @@ class ProfileResetPinFragmentPresenter @Inject constructor( ): View? { binding = ProfileResetPinFragmentBinding.inflate(inflater, container, false) - viewModel.isAdmin.set(isAdmin) + profileResetPinViewModel.isAdmin.set(isAdmin) binding.let { it.lifecycleOwner = fragment - it.viewModel = viewModel + it.viewModel = profileResetPinViewModel } // [onTextChanged] is a extension function defined at [TextInputEditTextHelper] binding.profileResetInputPinEditText.onTextChanged { pin -> pin?.let { if ( - viewModel.pinErrorMsg.get()?.isNotEmpty()!! && - viewModel.inputPin.get() == it + profileResetPinViewModel.pinErrorMsg.get()?.isNotEmpty()!! && + profileResetPinViewModel.inputPin.get() == it ) { - viewModel.inputPin.set(it) + profileResetPinViewModel.inputPin.set(it) inputtedPin = pin.isNotEmpty() } else { - viewModel.inputPin.set(it) - viewModel.pinErrorMsg.set("") + profileResetPinViewModel.inputPin.set(it) + profileResetPinViewModel.pinErrorMsg.set("") inputtedPin = pin.isNotEmpty() setValidPin() } @@ -72,14 +68,14 @@ class ProfileResetPinFragmentPresenter @Inject constructor( binding.profileResetInputConfirmPinEditText.onTextChanged { confirmPin -> confirmPin?.let { if ( - viewModel.confirmErrorMsg.get()?.isNotEmpty()!! && - viewModel.inputConfirmPin.get() == it + profileResetPinViewModel.confirmErrorMsg.get()?.isNotEmpty()!! && + profileResetPinViewModel.inputConfirmPin.get() == it ) { - viewModel.inputConfirmPin.set(it) + profileResetPinViewModel.inputConfirmPin.set(it) inputtedConfirmPin = confirmPin.isNotEmpty() } else { - viewModel.inputConfirmPin.set(it) - viewModel.confirmErrorMsg.set("") + profileResetPinViewModel.inputConfirmPin.set(it) + profileResetPinViewModel.confirmErrorMsg.set("") inputtedConfirmPin = confirmPin.isNotEmpty() setValidPin() } @@ -101,7 +97,7 @@ class ProfileResetPinFragmentPresenter @Inject constructor( var failed = false if (isAdmin) { if (pin.length < 5) { - viewModel.pinErrorMsg.set( + profileResetPinViewModel.pinErrorMsg.set( resourceHandler.getStringInLocale( R.string.profile_reset_pin_error_admin_pin_length ) @@ -110,7 +106,7 @@ class ProfileResetPinFragmentPresenter @Inject constructor( } } else { if (pin.length < 3) { - viewModel.pinErrorMsg.set( + profileResetPinViewModel.pinErrorMsg.set( resourceHandler.getStringInLocale( R.string.profile_reset_pin_error_user_pin_length ) @@ -119,7 +115,7 @@ class ProfileResetPinFragmentPresenter @Inject constructor( } } if (pin != confirmPin) { - viewModel.confirmErrorMsg.set( + profileResetPinViewModel.confirmErrorMsg.set( resourceHandler.getStringInLocale( R.string.add_profile_error_pin_confirm_wrong ) @@ -147,13 +143,9 @@ class ProfileResetPinFragmentPresenter @Inject constructor( private fun setValidPin() { if (inputtedPin && inputtedConfirmPin) { - viewModel.isButtonActive.set(true) + profileResetPinViewModel.isButtonActive.set(true) } else { - viewModel.isButtonActive.set(false) + profileResetPinViewModel.isButtonActive.set(false) } } - - private fun getProfileResetPinViewModel(): ProfileResetPinViewModel { - return viewModelProvider.getForFragment(fragment, ProfileResetPinViewModel::class.java) - } } diff --git a/app/src/main/java/org/oppia/android/app/spotlight/SpotlightFragment.kt b/app/src/main/java/org/oppia/android/app/spotlight/SpotlightFragment.kt index 0c2203d4ae2..603f7b53a82 100644 --- a/app/src/main/java/org/oppia/android/app/spotlight/SpotlightFragment.kt +++ b/app/src/main/java/org/oppia/android/app/spotlight/SpotlightFragment.kt @@ -359,6 +359,8 @@ class SpotlightFragment : InjectableFragment(), SpotlightNavigationListener, Spo private fun calculateScreenSize() { val displayMetrics = DisplayMetrics() + // TODO(#3616): Migrate to the proper SDK 30+ APIs. + @Suppress("DEPRECATION") // The code is correct for targeted versions of Android. activity.windowManager.defaultDisplay.getMetrics(displayMetrics) screenHeight = displayMetrics.heightPixels diff --git a/app/src/main/java/org/oppia/android/app/survey/ExitSurveyConfirmationDialogFragment.kt b/app/src/main/java/org/oppia/android/app/survey/ExitSurveyConfirmationDialogFragment.kt index f111bafbec6..884ab15ed1e 100644 --- a/app/src/main/java/org/oppia/android/app/survey/ExitSurveyConfirmationDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/survey/ExitSurveyConfirmationDialogFragment.kt @@ -9,7 +9,6 @@ import org.oppia.android.R import org.oppia.android.app.fragment.FragmentComponentImpl import org.oppia.android.app.fragment.InjectableDialogFragment import org.oppia.android.app.model.ProfileId -import org.oppia.android.util.extensions.getProto import org.oppia.android.util.extensions.putProto import javax.inject.Inject @@ -54,20 +53,9 @@ class ExitSurveyConfirmationDialogFragment : InjectableDialogFragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View { - val args = - checkNotNull( - arguments - ) { "Expected arguments to be passed to ExitSurveyConfirmationDialogFragment" } - - val profileId = args.getProto(PROFILE_ID_KEY, ProfileId.getDefaultInstance()) - dialog?.setCanceledOnTouchOutside(false) dialog?.setCancelable(false) - - return exitSurveyConfirmationDialogFragmentPresenter.handleCreateView( - inflater, - container - ) + return exitSurveyConfirmationDialogFragmentPresenter.handleCreateView(inflater, container) } override fun onStart() { diff --git a/app/src/main/java/org/oppia/android/app/survey/SurveyFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/survey/SurveyFragmentPresenter.kt index 88789ee130d..062a4d3864e 100644 --- a/app/src/main/java/org/oppia/android/app/survey/SurveyFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/survey/SurveyFragmentPresenter.kt @@ -334,6 +334,7 @@ class SurveyFragmentPresenter @Inject constructor( activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.hideSoftInputFromWindow( fragment.view!!.windowToken, + @Suppress("DEPRECATION") // TODO(#5406): Use the correct constant value here. InputMethodManager.SHOW_FORCED ) } diff --git a/app/src/main/java/org/oppia/android/app/testing/FractionInputInteractionViewTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/FractionInputInteractionViewTestActivity.kt index bb812a550a9..1e0a95cb7d9 100644 --- a/app/src/main/java/org/oppia/android/app/testing/FractionInputInteractionViewTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/FractionInputInteractionViewTestActivity.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.testing import android.content.Context import android.content.Intent import android.os.Bundle -import android.view.View import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -60,11 +59,9 @@ class FractionInputInteractionViewTestActivity : ) writtenTranslationContext = params.writtenTranslationContext binding.fractionInteractionViewModel = fractionInteractionViewModel - } - - /** Checks submit-time errors. */ - fun getPendingAnswerErrorOnSubmitClick(v: View) { - fractionInteractionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + binding.getPendingAnswerErrorOnSubmitClick = Runnable { + fractionInteractionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + } } override fun onPendingAnswerErrorOrAvailabilityCheck( diff --git a/app/src/main/java/org/oppia/android/app/testing/InputInteractionViewTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/InputInteractionViewTestActivity.kt index 20706aa12a3..bda539ed689 100644 --- a/app/src/main/java/org/oppia/android/app/testing/InputInteractionViewTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/InputInteractionViewTestActivity.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.testing import android.content.Context import android.content.Intent import android.os.Bundle -import android.view.View import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -58,10 +57,9 @@ class InputInteractionViewTestActivity : writtenTranslationContext = params.writtenTranslationContext binding.numericInputViewModel = numericInputViewModel - } - - fun getPendingAnswerErrorOnSubmitClick(v: View) { - numericInputViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + binding.getPendingAnswerErrorOnSubmitClick = Runnable { + numericInputViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + } } override fun onPendingAnswerErrorOrAvailabilityCheck( diff --git a/app/src/main/java/org/oppia/android/app/testing/MathExpressionInteractionsViewTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/MathExpressionInteractionsViewTestActivity.kt index 55219840ea9..aaa119915e3 100644 --- a/app/src/main/java/org/oppia/android/app/testing/MathExpressionInteractionsViewTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/MathExpressionInteractionsViewTestActivity.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.testing import android.content.Context import android.content.Intent import android.os.Bundle -import android.view.View import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -93,11 +92,9 @@ class MathExpressionInteractionsViewTestActivity : } binding.mathExpressionInteractionsViewModel = mathExpressionViewModel - } - - /** Checks submit-time errors. */ - fun getPendingAnswerErrorOnSubmitClick(v: View) { - mathExpressionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + binding.getPendingAnswerErrorOnSubmitClick = Runnable { + mathExpressionViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + } } override fun onPendingAnswerErrorOrAvailabilityCheck( diff --git a/app/src/main/java/org/oppia/android/app/testing/RatioInputInteractionViewTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/RatioInputInteractionViewTestActivity.kt index a16d8e7c12c..f307c69d318 100644 --- a/app/src/main/java/org/oppia/android/app/testing/RatioInputInteractionViewTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/RatioInputInteractionViewTestActivity.kt @@ -3,7 +3,6 @@ package org.oppia.android.app.testing import android.content.Context import android.content.Intent import android.os.Bundle -import android.view.View import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -71,14 +70,10 @@ class RatioInputInteractionViewTestActivity : writtenTranslationContext = params.writtenTranslationContext binding.ratioInteractionInputViewModel = ratioExpressionInputInteractionViewModel - } - - /** - * Checks for submit time errors. - */ - fun getPendingAnswerErrorOnSubmitClick(v: View) { - ratioExpressionInputInteractionViewModel - .checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + binding.getPendingAnswerErrorOnSubmitClick = Runnable { + ratioExpressionInputInteractionViewModel + .checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + } } override fun onAnswerReadyForSubmission(answer: UserAnswer) { } diff --git a/app/src/main/java/org/oppia/android/app/testing/TestFontScaleConfigurationUtilActivity.kt b/app/src/main/java/org/oppia/android/app/testing/TestFontScaleConfigurationUtilActivity.kt index b8aa02dcd3d..03e8d29d3dd 100644 --- a/app/src/main/java/org/oppia/android/app/testing/TestFontScaleConfigurationUtilActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/TestFontScaleConfigurationUtilActivity.kt @@ -17,6 +17,7 @@ class TestFontScaleConfigurationUtilActivity : InjectableAutoLocalizedAppCompatA override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activityComponent as ActivityComponentImpl).inject(this) + @Suppress("DEPRECATION") // TODO(#5405): Ensure the correct type is being retrieved. val readingTextSize = checkNotNull( intent.getSerializableExtra(FONT_SCALE_EXTRA_KEY) as? ReadingTextSize ) { "Expected $FONT_SCALE_EXTRA_KEY to be in intent extras." } diff --git a/app/src/main/java/org/oppia/android/app/testing/TextInputInteractionViewTestActivity.kt b/app/src/main/java/org/oppia/android/app/testing/TextInputInteractionViewTestActivity.kt index 5308bac3f8e..2a175fb9429 100644 --- a/app/src/main/java/org/oppia/android/app/testing/TextInputInteractionViewTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/testing/TextInputInteractionViewTestActivity.kt @@ -1,7 +1,6 @@ package org.oppia.android.app.testing import android.os.Bundle -import android.view.View import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponentImpl @@ -51,11 +50,9 @@ class TextInputInteractionViewTestActivity : writtenTranslationContext = WrittenTranslationContext.getDefaultInstance() binding.textInputViewModel = textInputViewModel - } - - /** Checks submit-time errors. */ - fun getPendingAnswerErrorOnSubmitClick(v: View) { - textInputViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + binding.getPendingAnswerErrorOnSubmitClick = Runnable { + textInputViewModel.checkPendingAnswerError(AnswerErrorCategory.SUBMIT_TIME) + } } override fun onPendingAnswerErrorOrAvailabilityCheck( diff --git a/app/src/main/java/org/oppia/android/app/topic/TopicFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/topic/TopicFragmentPresenter.kt index b7bb9548635..76a43e98978 100644 --- a/app/src/main/java/org/oppia/android/app/topic/TopicFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/topic/TopicFragmentPresenter.kt @@ -86,7 +86,7 @@ class TopicFragmentPresenter @Inject constructor( viewModel.numberOfChaptersCompletedLiveData.observe(fragment) { numberOfChaptersCompleted -> if (numberOfChaptersCompleted != null) { val lessonsTabView = tabLayout.getTabAt(computeTabPosition(TopicTab.LESSONS))?.view - lessonsTabView?.let { lessonsTabView -> + lessonsTabView?.let { val lessonsTabSpotlightTarget = SpotlightTarget( lessonsTabView, resourceHandler.getStringInLocale(R.string.topic_lessons_tab_spotlight_hint), diff --git a/app/src/main/java/org/oppia/android/app/topic/conceptcard/ConceptCardFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/topic/conceptcard/ConceptCardFragmentPresenter.kt index b33e85cba61..72862362b66 100644 --- a/app/src/main/java/org/oppia/android/app/topic/conceptcard/ConceptCardFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/topic/conceptcard/ConceptCardFragmentPresenter.kt @@ -8,7 +8,6 @@ import org.oppia.android.R import org.oppia.android.app.fragment.FragmentScope import org.oppia.android.app.model.ProfileId import org.oppia.android.app.translation.AppLanguageResourceHandler -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.ConceptCardFragmentBinding import org.oppia.android.domain.oppialogger.OppiaLogger import org.oppia.android.domain.oppialogger.analytics.AnalyticsController @@ -27,7 +26,7 @@ class ConceptCardFragmentPresenter @Inject constructor( private val htmlParserFactory: HtmlParser.Factory, @ConceptCardHtmlParserEntityType private val entityType: String, @DefaultResourceBucketName private val resourceBucketName: String, - private val viewModelProvider: ViewModelProvider, + private val conceptCardViewModel: ConceptCardViewModel, private val translationController: TranslationController, private val appLanguageResourceHandler: AppLanguageResourceHandler ) : HtmlParser.CustomOppiaTagActionListener { @@ -50,9 +49,8 @@ class ConceptCardFragmentPresenter @Inject constructor( /* attachToRoot= */ false ) val view = binding.conceptCardExplanationText - val viewModel = getConceptCardViewModel() - viewModel.initialize(skillId, profileId) + conceptCardViewModel.initialize(skillId, profileId) logConceptCardEvent(skillId) binding.conceptCardToolbar.setNavigationIcon(R.drawable.ic_close_white_24dp) @@ -64,11 +62,11 @@ class ConceptCardFragmentPresenter @Inject constructor( } binding.let { - it.viewModel = viewModel + it.viewModel = conceptCardViewModel it.lifecycleOwner = fragment } - viewModel.conceptCardLiveData.observe( + conceptCardViewModel.conceptCardLiveData.observe( fragment ) { ephemeralConceptCard -> val explanationHtml = @@ -95,10 +93,6 @@ class ConceptCardFragmentPresenter @Inject constructor( return binding.root } - private fun getConceptCardViewModel(): ConceptCardViewModel { - return viewModelProvider.getForFragment(fragment, ConceptCardViewModel::class.java) - } - private fun logConceptCardEvent(skillId: String) { analyticsController.logImportantEvent( oppiaLogger.createOpenConceptCardContext(skillId), profileId diff --git a/app/src/main/java/org/oppia/android/app/topic/practice/TopicPracticeFragment.kt b/app/src/main/java/org/oppia/android/app/topic/practice/TopicPracticeFragment.kt index 839ba92af07..d5cc29fc1d8 100644 --- a/app/src/main/java/org/oppia/android/app/topic/practice/TopicPracticeFragment.kt +++ b/app/src/main/java/org/oppia/android/app/topic/practice/TopicPracticeFragment.kt @@ -46,6 +46,9 @@ class TopicPracticeFragment : InjectableFragment() { var selectedSkillId = HashMap>() if (savedInstanceState != null) { selectedIdList = savedInstanceState.getIntegerArrayList(SUBTOPIC_ID_LIST_ARGUMENT_KEY)!! + // TODO(#4986): Convert this to a type-safe proto. + @Suppress("DEPRECATION") // TODO(#5405): Ensure the correct type is being retrieved. + @Suppress("UNCHECKED_CAST") // Not quite safe. selectedSkillId = savedInstanceState .getSerializable(SKILL_ID_LIST_ARGUMENT_KEY)!! as HashMap> } diff --git a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt index ee821d56b86..a97d28ce138 100644 --- a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerActivityPresenter.kt @@ -47,6 +47,7 @@ class QuestionPlayerActivityPresenter @Inject constructor( activity.setSupportActionBar(binding.questionPlayerToolbar) binding.questionPlayerToolbar.setNavigationOnClickListener { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } diff --git a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerFragmentPresenter.kt index 703dbbc95ed..78a978ba51c 100644 --- a/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/topic/questionplayer/QuestionPlayerFragmentPresenter.kt @@ -27,7 +27,6 @@ import org.oppia.android.app.player.stopplaying.RestartPlayingSessionListener import org.oppia.android.app.player.stopplaying.StopStatePlayingSessionListener import org.oppia.android.app.topic.conceptcard.ConceptCardFragment import org.oppia.android.app.utility.SplitScreenManager -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.databinding.QuestionPlayerFragmentBinding import org.oppia.android.domain.oppialogger.OppiaLogger import org.oppia.android.domain.oppialogger.analytics.AnalyticsController @@ -43,7 +42,7 @@ import javax.inject.Inject class QuestionPlayerFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val fragment: Fragment, - private val viewModelProvider: ViewModelProvider, + private val questionViewModel: QuestionPlayerViewModel, private val questionAssessmentProgressController: QuestionAssessmentProgressController, private val oppiaLogger: OppiaLogger, private val analyticsController: AnalyticsController, @@ -56,7 +55,6 @@ class QuestionPlayerFragmentPresenter @Inject constructor( private val routeToHintsAndSolutionListener = activity as RouteToHintsAndSolutionListener private val hasConversationView = false - private val questionViewModel by lazy { getQuestionPlayerViewModel() } private val ephemeralQuestionLiveData: LiveData> by lazy { questionAssessmentProgressController.getCurrentQuestion().toLiveData() } @@ -317,6 +315,7 @@ class QuestionPlayerFragmentPresenter @Inject constructor( activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.hideSoftInputFromWindow( fragment.view!!.windowToken, + @Suppress("DEPRECATION") // TODO(#5406): Use the correct constant value here. InputMethodManager.SHOW_FORCED ) } @@ -347,10 +346,6 @@ class QuestionPlayerFragmentPresenter @Inject constructor( .build() } - private fun getQuestionPlayerViewModel(): QuestionPlayerViewModel { - return viewModelProvider.getForFragment(fragment, QuestionPlayerViewModel::class.java) - } - private fun logQuestionPlayerEvent(questionId: String, skillIds: List) { analyticsController.logImportantEvent( oppiaLogger.createOpenQuestionPlayerContext(questionId, skillIds), diff --git a/app/src/main/java/org/oppia/android/app/utility/ClickableAreasImage.kt b/app/src/main/java/org/oppia/android/app/utility/ClickableAreasImage.kt index 5093290768b..1a0081db7ee 100644 --- a/app/src/main/java/org/oppia/android/app/utility/ClickableAreasImage.kt +++ b/app/src/main/java/org/oppia/android/app/utility/ClickableAreasImage.kt @@ -9,7 +9,7 @@ import androidx.core.view.children import androidx.core.view.forEachIndexed import androidx.core.view.isVisible import org.oppia.android.R -import org.oppia.android.app.model.ImageWithRegions +import org.oppia.android.app.model.ImageWithRegions.LabeledRegion import org.oppia.android.app.player.state.ImageRegionSelectionInteractionView import org.oppia.android.app.shim.ViewBindingShim import kotlin.math.roundToInt @@ -21,19 +21,11 @@ class ClickableAreasImage( private val listener: OnClickableAreaClickedListener, bindingInterface: ViewBindingShim, private val isAccessibilityEnabled: Boolean, - private val clickableAreas: List + private val clickableAreas: List ) { private val defaultRegionView by lazy { bindingInterface.getDefaultRegion(parentView) } - init { - imageView.setOnTouchListener { view, motionEvent -> - if (motionEvent.action == MotionEvent.ACTION_DOWN) { - onPhotoTap(motionEvent.x, motionEvent.y) - } - view.performClick() - return@setOnTouchListener false - } - } + init { imageView.initializeShowRegionTouchListener() } /** * Called when an image is clicked. @@ -111,13 +103,7 @@ class ClickableAreasImage( newView.isFocusable = true newView.isFocusableInTouchMode = true newView.tag = clickableArea.label - newView.setOnTouchListener { view, event -> - if (event.action == MotionEvent.ACTION_DOWN) { - showOrHideRegion(newView, clickableArea) - } - view.performClick() - return@setOnTouchListener true - } + newView.initializeToggleRegionTouchListener(clickableArea) if (isAccessibilityEnabled) { // Make default region visibility gone when talkback enabled to avoid any accidental touch. defaultRegionView.isVisible = false @@ -144,7 +130,7 @@ class ClickableAreasImage( } } - private fun showOrHideRegion(newView: View, clickableArea: ImageWithRegions.LabeledRegion) { + private fun showOrHideRegion(newView: View, clickableArea: LabeledRegion) { resetRegionSelectionViews() listener.onClickableAreaTouched( NamedRegionClickedEvent( @@ -154,4 +140,24 @@ class ClickableAreasImage( ) newView.setBackgroundResource(R.drawable.selected_region_background) } + + private fun View.initializeShowRegionTouchListener() { + setOnTouchListener { view, motionEvent -> + if (motionEvent.action == MotionEvent.ACTION_DOWN) { + onPhotoTap(motionEvent.x, motionEvent.y) + } + view.performClick() + return@setOnTouchListener false + } + } + + private fun View.initializeToggleRegionTouchListener(clickableArea: LabeledRegion) { + setOnTouchListener { view, event -> + if (event.action == MotionEvent.ACTION_DOWN) { + showOrHideRegion(this@initializeToggleRegionTouchListener, clickableArea) + } + view.performClick() + return@setOnTouchListener true + } + } } diff --git a/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt b/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt index 78731ab1ce5..80603b9fb95 100644 --- a/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt +++ b/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt @@ -18,6 +18,8 @@ class FontScaleConfigurationUtil @Inject constructor() { configuration.fontScale = getReadingTextSizeConfigurationUtil(readingTextSize) val metrics: DisplayMetrics = context.resources.displayMetrics val windowManager = context.getSystemService(WINDOW_SERVICE) as? WindowManager + // TODO(#3616): Migrate to the proper SDK 30+ APIs. + @Suppress("DEPRECATION") // The code is correct for targeted versions of Android. windowManager!!.defaultDisplay.getMetrics(metrics) metrics.scaledDensity = configuration.fontScale * metrics.density context.createConfigurationContext(configuration) diff --git a/app/src/main/java/org/oppia/android/app/viewmodel/BUILD.bazel b/app/src/main/java/org/oppia/android/app/viewmodel/BUILD.bazel index d89b4acf356..eafd028c412 100644 --- a/app/src/main/java/org/oppia/android/app/viewmodel/BUILD.bazel +++ b/app/src/main/java/org/oppia/android/app/viewmodel/BUILD.bazel @@ -26,17 +26,3 @@ kt_android_library( "//third_party:androidx_lifecycle_lifecycle-extensions", ], ) - -kt_android_library( - name = "view_model_provider", - srcs = [ - "ViewModelBridgeFactory.kt", - "ViewModelProvider.kt", - ], - visibility = ["//visibility:public"], - deps = [ - "//third_party:androidx_appcompat_appcompat", - "//third_party:androidx_lifecycle_lifecycle-extensions", - "//third_party:javax_inject_javax_inject", - ], -) diff --git a/app/src/main/java/org/oppia/android/app/viewmodel/ObservableViewModel.kt b/app/src/main/java/org/oppia/android/app/viewmodel/ObservableViewModel.kt index 558bb071d15..de168e7b3cd 100644 --- a/app/src/main/java/org/oppia/android/app/viewmodel/ObservableViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/viewmodel/ObservableViewModel.kt @@ -2,10 +2,9 @@ package org.oppia.android.app.viewmodel import androidx.databinding.Observable import androidx.databinding.PropertyChangeRegistry -import androidx.lifecycle.ViewModel -/** A [ViewModel] that behaves the same as [androidx.databinding.BaseObservable]. */ -open class ObservableViewModel : ViewModel(), Observable { +/** A view model that behaves the same as [androidx.databinding.BaseObservable]. */ +open class ObservableViewModel : Observable { private val callbacks by lazy { PropertyChangeRegistry() } diff --git a/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelBridgeFactory.kt b/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelBridgeFactory.kt deleted file mode 100644 index eec42377602..00000000000 --- a/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelBridgeFactory.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.oppia.android.app.viewmodel - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import javax.inject.Inject -import javax.inject.Provider - -/** - * Provides a Dagger bridge to facilitate [ViewModel]s supporting @Inject constructors. Adapted from: - * https://proandroiddev.com/dagger-2-on-android-the-simple-way-f706a2c597e9 and - * https://github.com/tfcporciuncula/dagger-simple-way. - */ -class ViewModelBridgeFactory @Inject constructor( - private val viewModelProvider: Provider -) : ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - val viewModel = viewModelProvider.get() - // Check whether the user accidentally switched the types during provider retrieval. ViewModelProvider is meant to - // guard against this from happening by ensuring the two types remain the same. - check(modelClass.isAssignableFrom(viewModel.javaClass)) { - "Cannot convert between injected generic type and " + - "runtime assumed generic type for bridge factory." - } - // Ensure the compiler that the type casting is correct and intentional here. A cast failure should result in a - // runtime crash. - return modelClass.cast(viewModel)!! - } -} diff --git a/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelProvider.kt b/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelProvider.kt deleted file mode 100644 index 76d6ec4871d..00000000000 --- a/app/src/main/java/org/oppia/android/app/viewmodel/ViewModelProvider.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.oppia.android.app.viewmodel - -import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProviders -import javax.inject.Inject - -/** - * Provider for a specific type of [ViewModel] that supports @Inject construction. This class is automatically bound to - * the narrowest scope and component in which it's used. - */ -class ViewModelProvider @Inject constructor( - private val bridgeFactory: ViewModelBridgeFactory -) { - /** Retrieves a new instance of the [ViewModel] of type [V] scoped to the specified fragment. */ - fun getForFragment(fragment: Fragment, clazz: Class): V { - return ViewModelProviders.of(fragment, bridgeFactory).get(clazz) - } - - /** Retrieves a new instance of the [ViewModel] of type [V] scoped to the specified activity. */ - fun getForActivity(activity: AppCompatActivity, clazz: Class): V { - return ViewModelProviders.of(activity, bridgeFactory).get(clazz) - } -} diff --git a/app/src/main/java/org/oppia/android/app/walkthrough/WalkthroughActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/walkthrough/WalkthroughActivityPresenter.kt index 9f7733df2fc..f1682fb4de2 100644 --- a/app/src/main/java/org/oppia/android/app/walkthrough/WalkthroughActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/walkthrough/WalkthroughActivityPresenter.kt @@ -4,7 +4,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import org.oppia.android.R import org.oppia.android.app.activity.ActivityScope -import org.oppia.android.app.viewmodel.ViewModelProvider import org.oppia.android.app.walkthrough.end.WalkthroughFinalFragment import org.oppia.android.app.walkthrough.topiclist.WalkthroughTopicListFragment import org.oppia.android.app.walkthrough.welcome.WalkthroughWelcomeFragment @@ -16,7 +15,7 @@ import javax.inject.Inject @ActivityScope class WalkthroughActivityPresenter @Inject constructor( private val activity: AppCompatActivity, - private val viewModelProvider: ViewModelProvider + private val walkthroughViewModel: WalkthroughViewModel ) : WalkthroughActivityListener { private lateinit var topicId: String private lateinit var binding: WalkthroughActivityBinding @@ -25,7 +24,7 @@ class WalkthroughActivityPresenter @Inject constructor( binding = DataBindingUtil.setContentView(activity, R.layout.walkthrough_activity) binding.apply { - viewModel = getWalkthroughViewModel() + viewModel = walkthroughViewModel presenter = this@WalkthroughActivityPresenter lifecycleOwner = activity } @@ -34,14 +33,14 @@ class WalkthroughActivityPresenter @Inject constructor( activity, true ) - val currentFragmentIndex = getWalkthroughViewModel().currentProgress.get()?.minus(1) + val currentFragmentIndex = walkthroughViewModel.currentProgress.get()?.minus(1) if (currentFragmentIndex == -1 && getWalkthroughWelcomeFragment() == null) { activity.supportFragmentManager.beginTransaction().add( R.id.walkthrough_fragment_placeholder, WalkthroughWelcomeFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(1) + walkthroughViewModel.currentProgress.set(1) } } else if (currentFragmentIndex != null) { when (currentFragmentIndex) { @@ -50,21 +49,21 @@ class WalkthroughActivityPresenter @Inject constructor( R.id.walkthrough_fragment_placeholder, getWalkthroughWelcomeFragment() ?: WalkthroughWelcomeFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(1) + walkthroughViewModel.currentProgress.set(1) } 1 -> activity.supportFragmentManager.beginTransaction().replace( R.id.walkthrough_fragment_placeholder, getWalkthroughTopicListFragment() ?: WalkthroughTopicListFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(2) + walkthroughViewModel.currentProgress.set(2) } 2 -> activity.supportFragmentManager.beginTransaction().replace( R.id.walkthrough_fragment_placeholder, getWalkthroughFinalFragment() ?: WalkthroughFinalFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(3) + walkthroughViewModel.currentProgress.set(3) } } } @@ -78,10 +77,6 @@ class WalkthroughActivityPresenter @Inject constructor( } } - private fun getWalkthroughViewModel(): WalkthroughViewModel { - return viewModelProvider.getForActivity(activity, WalkthroughViewModel::class.java) - } - private fun getWalkthroughWelcomeFragment(): WalkthroughWelcomeFragment? { return activity .supportFragmentManager @@ -113,7 +108,7 @@ class WalkthroughActivityPresenter @Inject constructor( R.id.walkthrough_fragment_placeholder, WalkthroughWelcomeFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(1) + walkthroughViewModel.currentProgress.set(1) } } WalkthroughPages.TOPIC_LIST.value -> { @@ -121,7 +116,7 @@ class WalkthroughActivityPresenter @Inject constructor( R.id.walkthrough_fragment_placeholder, WalkthroughTopicListFragment() ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(2) + walkthroughViewModel.currentProgress.set(2) } } WalkthroughPages.FINAL.value -> { @@ -129,14 +124,14 @@ class WalkthroughActivityPresenter @Inject constructor( R.id.walkthrough_fragment_placeholder, WalkthroughFinalFragment.newInstance(topicId) ).commitNow().also { - getWalkthroughViewModel().currentProgress.set(3) + walkthroughViewModel.currentProgress.set(3) } } } } fun handleSystemBack() { - moveToPreviousPage(getWalkthroughViewModel().currentProgress.get() ?: 1) + moveToPreviousPage(walkthroughViewModel.currentProgress.get() ?: 1) } fun setTopicId(topicId: String) { diff --git a/app/src/main/java/org/oppia/android/app/walkthrough/end/WalkthroughFinalFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/walkthrough/end/WalkthroughFinalFragmentPresenter.kt index 1b2658ba0ff..f3f44e0875f 100644 --- a/app/src/main/java/org/oppia/android/app/walkthrough/end/WalkthroughFinalFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/walkthrough/end/WalkthroughFinalFragmentPresenter.kt @@ -106,6 +106,7 @@ class WalkthroughFinalFragmentPresenter @Inject constructor( } override fun goBack() { + @Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher. activity.onBackPressed() } } diff --git a/app/src/main/res/layout-land/profile_chooser_profile_view.xml b/app/src/main/res/layout-land/profile_chooser_profile_view.xml index d150c4cfd0f..637bae7983d 100644 --- a/app/src/main/res/layout-land/profile_chooser_profile_view.xml +++ b/app/src/main/res/layout-land/profile_chooser_profile_view.xml @@ -1,7 +1,6 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> @@ -44,7 +43,7 @@ app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedShape" app:strokeColor="@color/component_color_shared_divider_color" app:strokeWidth="1dp" - profile:src="@{viewModel.profile.avatar}" /> + app:profileImageSource="@{viewModel.profile.avatar}" /> + app:profileLastVisitedTime="@{viewModel.profile.lastLoggedInTimestampMs}" /> + xmlns:app="http://schemas.android.com/apk/res-auto"> @@ -44,7 +43,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedShape" - profile:src="@{viewModel.profile.avatar}" /> + app:profileImageSource="@{viewModel.profile.avatar}" /> + app:profileCreatedTime="@{viewModel.profile.dateCreatedTimestampMs}" />