diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 38f59252976..00af8fdd303 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,7 +39,6 @@ android:screenOrientation="portrait" /> by lazy { + getProfileData() + } + + private fun getProfileData(): LiveData { + return Transformations.map(profileManagementController.getProfile(profileId), ::processGetProfileResult) + } + + private fun subscribeToProfileLiveData() { + profileLiveData.observe(activity, Observer { result -> + profileName = result.name + setProfileName() + }) + } + + private fun processGetProfileResult(profileResult: AsyncResult): Profile { + if (profileResult.isFailure()) { + logger.e("HomeFragment", "Failed to retrieve profile", profileResult.getErrorOrNull()!!) + } + return profileResult.getOrDefault(Profile.getDefaultInstance()) + } + private val topicListSummaryResultLiveData: LiveData> by lazy { topicListController.getTopicList() } @@ -108,6 +142,7 @@ class HomeFragmentPresenter @Inject constructor( getUserAppHistory().observe(fragment, Observer { result -> userAppHistoryViewModel = UserAppHistoryViewModel() userAppHistoryViewModel.setAlreadyAppOpened(result.alreadyOpenedApp) + setProfileName() itemList[0] = userAppHistoryViewModel topicListAdapter.notifyItemChanged(0) }) @@ -125,6 +160,12 @@ class HomeFragmentPresenter @Inject constructor( return appHistoryResult.getOrDefault(UserAppHistory.getDefaultInstance()) } + private fun setProfileName() { + if (::userAppHistoryViewModel.isInitialized && ::profileName.isInitialized) { + userAppHistoryViewModel.profileName = "$profileName!" + } + } + private val ongoingStoryListSummaryResultLiveData: LiveData> by lazy { topicListController.getOngoingStoryList() } diff --git a/app/src/main/java/org/oppia/app/home/UserAppHistoryViewModel.kt b/app/src/main/java/org/oppia/app/home/UserAppHistoryViewModel.kt index 6b43dd7787f..b4012f329dc 100644 --- a/app/src/main/java/org/oppia/app/home/UserAppHistoryViewModel.kt +++ b/app/src/main/java/org/oppia/app/home/UserAppHistoryViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel /** [ViewModel] for user app usage history. */ class UserAppHistoryViewModel : HomeItemViewModel() { var isAppAlreadyOpened = ObservableField(false) + var profileName : String = "" fun setAlreadyAppOpened(alreadyOpenedApp: Boolean) = isAppAlreadyOpened.set(alreadyOpenedApp) } diff --git a/app/src/main/java/org/oppia/app/profile/AdminAuthActivity.kt b/app/src/main/java/org/oppia/app/profile/AdminAuthActivity.kt index 454f94df4f6..0cfa91cf33b 100644 --- a/app/src/main/java/org/oppia/app/profile/AdminAuthActivity.kt +++ b/app/src/main/java/org/oppia/app/profile/AdminAuthActivity.kt @@ -29,6 +29,16 @@ class AdminAuthActivity : InjectableAppCompatActivity() { adminAuthFragmentPresenter.handleOnCreate() } + override fun onSaveInstanceState(outState: Bundle) { + adminAuthFragmentPresenter.handleOnSavedInstanceState(outState) + super.onSaveInstanceState(outState) + } + + override fun onRestoreInstanceState(savedInstanceState: Bundle?) { + super.onRestoreInstanceState(savedInstanceState) + adminAuthFragmentPresenter.handleOnRestoreInstanceState(savedInstanceState!!) + } + override fun onSupportNavigateUp(): Boolean { finish() return false diff --git a/app/src/main/java/org/oppia/app/profile/AdminAuthActivityPresenter.kt b/app/src/main/java/org/oppia/app/profile/AdminAuthActivityPresenter.kt index 072febdc71e..2a65a371125 100644 --- a/app/src/main/java/org/oppia/app/profile/AdminAuthActivityPresenter.kt +++ b/app/src/main/java/org/oppia/app/profile/AdminAuthActivityPresenter.kt @@ -1,6 +1,7 @@ package org.oppia.app.profile import android.content.Context +import android.os.Bundle import android.text.Editable import android.text.TextWatcher import androidx.appcompat.app.AppCompatActivity @@ -11,6 +12,8 @@ import org.oppia.app.databinding.AdminAuthActivityBinding import org.oppia.app.viewmodel.ViewModelProvider import javax.inject.Inject +const val KEY_ADMIN_AUTH_INPUT_ERROR_MESSAGE = "ADMIN_AUTH_INPUT_ERROR_MESSAGE" + /** The presenter for [AdminAuthActivity]. */ @ActivityScope class AdminAuthActivityPresenter @Inject constructor( @@ -61,6 +64,17 @@ class AdminAuthActivityPresenter @Inject constructor( } } + fun handleOnSavedInstanceState(bundle: Bundle) { + bundle.putString(KEY_ADMIN_AUTH_INPUT_ERROR_MESSAGE, authViewModel.errorMessage.get()) + } + + fun handleOnRestoreInstanceState(bundle: Bundle) { + val errorMessage = bundle.getString(KEY_ADMIN_AUTH_INPUT_ERROR_MESSAGE) + if (errorMessage != null && errorMessage.isNotEmpty()) { + authViewModel.errorMessage.set(errorMessage) + } + } + private fun getAdminAuthViewModel(): AdminAuthViewModel { return viewModelProvider.getForActivity(activity, AdminAuthViewModel::class.java) } diff --git a/app/src/main/java/org/oppia/app/profile/PinPasswordActivityPresenter.kt b/app/src/main/java/org/oppia/app/profile/PinPasswordActivityPresenter.kt index d230cf6bf70..1564d58112d 100644 --- a/app/src/main/java/org/oppia/app/profile/PinPasswordActivityPresenter.kt +++ b/app/src/main/java/org/oppia/app/profile/PinPasswordActivityPresenter.kt @@ -64,7 +64,7 @@ class PinPasswordActivityPresenter @Inject constructor( profileManagementController.loginToProfile(ProfileId.newBuilder().setInternalId(profileId).build()) .observe(activity, Observer { if (it.isSuccess()) { - activity.startActivity(Intent(activity, HomeActivity::class.java)) + activity.startActivity((HomeActivity.createHomeActivity(activity, profileId))) } }) } else { diff --git a/app/src/main/java/org/oppia/app/profile/ProfileChooserFragmentPresenter.kt b/app/src/main/java/org/oppia/app/profile/ProfileChooserFragmentPresenter.kt index 926a6738eb5..31c1ab0dc56 100644 --- a/app/src/main/java/org/oppia/app/profile/ProfileChooserFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/profile/ProfileChooserFragmentPresenter.kt @@ -1,7 +1,6 @@ package org.oppia.app.profile import android.content.Context -import android.content.Intent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -112,7 +111,7 @@ class ProfileChooserFragmentPresenter @Inject constructor( if (model.profile.pin.isEmpty()) { profileManagementController.loginToProfile(model.profile.id).observe(fragment, Observer { if (it.isSuccess()) { - activity.startActivity(Intent(fragment.context, HomeActivity::class.java)) + activity.startActivity((HomeActivity.createHomeActivity(activity, model.profile.id.internalId))) } }) } else { diff --git a/app/src/main/res/layout-land/admin_auth_activity.xml b/app/src/main/res/layout-land/admin_auth_activity.xml new file mode 100644 index 00000000000..d8850174c26 --- /dev/null +++ b/app/src/main/res/layout-land/admin_auth_activity.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +