Skip to content

Commit

Permalink
Fix part #575: Low fi Home Page display Profile name (#633)
Browse files Browse the repository at this point in the history
* Display profile name

* changed greeting message

* Update strings.xml

* Update HomeFragmentPresenter.kt

* working on testcase

* fetching correct id

* working on testcase

* Update HomeFragmentPresenter.kt

* Update HomeActivityTest.kt

* updated testcase

* Update HomeActivityTest.kt

* updated test cases

* Update HomeActivity.kt

* nit change

* Update ProfileManagementController.kt

* fixed issues

* Update HomeActivityTest.kt

* made util class for date time

* Fixed testcases.

* Update strings.xml

* Create DateTimeUtilTest.kt

* working on mocking calender

* created oppia clock

* working on testcase

* updated testcase

* Update HomeActivityTest.kt

* Update HomeFragmentPresenter.kt

* nit change

* fixed testcase using homeInjectionActivity

* fixed nit changes

* fixed issues

* Update DateTimeUtilTest.kt

* Update DateTimeUtilTest.kt

* Update DateTimeUtilTest.kt

* nit change

* Update OppiaClock.kt

* update to circle ci time zone

* changed time condition

* added log

* update gradle

* Update DateTimeUtilTest.kt

* removed logging

* removed greetng related code.

* Update HomeFragmentPresenter.kt

* Update HomeActivityTest.kt
  • Loading branch information
veena14cs authored Jan 30, 2020
1 parent 3cf1964 commit 631def4
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 32 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/org/oppia/app/home/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.app.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
Expand All @@ -9,10 +10,20 @@ import org.oppia.app.profile.ProfileActivity
import org.oppia.app.topic.TopicActivity
import javax.inject.Inject

const val KEY_HOME_PROFILE_ID = "KEY_HOME_PROFILE_ID"

/** The central activity for all users entering the app. */
class HomeActivity : InjectableAppCompatActivity(), RouteToTopicListener {
@Inject lateinit var homeActivityPresenter: HomeActivityPresenter

companion object {
fun createHomeActivity(context: Context, profileId: Int?): Intent {
val intent = Intent(context, HomeActivity::class.java)
intent.putExtra(KEY_HOME_PROFILE_ID, profileId)
return intent
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.oppia.app.activity.ActivityScope
import org.oppia.app.drawer.NavigationDrawerFragment
import javax.inject.Inject

const val TAG_HOME_FRAGMENT = "HOME_FRAGMENT"

/** The presenter for [HomeActivity]. */
@ActivityScope
class HomeActivityPresenter @Inject constructor(private val activity: AppCompatActivity) {
Expand All @@ -20,7 +22,8 @@ class HomeActivityPresenter @Inject constructor(private val activity: AppCompatA
if (getHomeFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
R.id.home_fragment_placeholder,
HomeFragment()
HomeFragment(),
TAG_HOME_FRAGMENT
).commitNow()
}
}
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import org.oppia.app.home.topiclist.TopicListAdapter
import org.oppia.app.home.topiclist.TopicSummaryClickListener
import org.oppia.app.home.topiclist.TopicSummaryViewModel
import org.oppia.app.model.OngoingStoryList
import org.oppia.app.model.Profile
import org.oppia.app.model.ProfileId
import org.oppia.app.model.TopicList
import org.oppia.app.model.TopicSummary
import org.oppia.app.model.UserAppHistory
import org.oppia.domain.UserAppHistoryController
import org.oppia.domain.profile.ProfileManagementController
import org.oppia.domain.topic.TopicListController
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
Expand All @@ -32,6 +35,7 @@ import javax.inject.Inject
class HomeFragmentPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val profileManagementController: ProfileManagementController,
private val userAppHistoryController: UserAppHistoryController,
private val topicListController: TopicListController,
private val logger: Logger
Expand All @@ -44,6 +48,10 @@ class HomeFragmentPresenter @Inject constructor(
private lateinit var allTopicsViewModel: AllTopicsViewModel
private lateinit var topicListAdapter: TopicListAdapter
private lateinit var binding: HomeFragmentBinding
private var internalProfileId: Int = -1
private lateinit var profileId: ProfileId
private lateinit var profileName: String

fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
binding = HomeFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
// NB: Both the view model and lifecycle owner must be set in order to correctly bind LiveData elements to
Expand All @@ -57,6 +65,9 @@ class HomeFragmentPresenter @Inject constructor(
itemList.add(allTopicsViewModel)
topicListAdapter = TopicListAdapter(activity, itemList, promotedStoryList)

internalProfileId = activity.intent.getIntExtra(KEY_HOME_PROFILE_ID, -1)
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()

val homeLayoutManager = GridLayoutManager(activity.applicationContext, 2)
homeLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
Expand All @@ -79,12 +90,35 @@ class HomeFragmentPresenter @Inject constructor(
}

userAppHistoryController.markUserOpenedApp()
subscribeToProfileLiveData()
subscribeToUserAppHistory()
subscribeToOngoingStoryList()
subscribeToTopicList()
return binding.root
}

private val profileLiveData: LiveData<Profile> by lazy {
getProfileData()
}

private fun getProfileData(): LiveData<Profile> {
return Transformations.map(profileManagementController.getProfile(profileId), ::processGetProfileResult)
}

private fun subscribeToProfileLiveData() {
profileLiveData.observe(activity, Observer<Profile> { result ->
profileName = result.name
setProfileName()
})
}

private fun processGetProfileResult(profileResult: AsyncResult<Profile>): Profile {
if (profileResult.isFailure()) {
logger.e("HomeFragment", "Failed to retrieve profile", profileResult.getErrorOrNull()!!)
}
return profileResult.getOrDefault(Profile.getDefaultInstance())
}

private val topicListSummaryResultLiveData: LiveData<AsyncResult<TopicList>> by lazy {
topicListController.getTopicList()
}
Expand All @@ -108,6 +142,7 @@ class HomeFragmentPresenter @Inject constructor(
getUserAppHistory().observe(fragment, Observer<UserAppHistory> { result ->
userAppHistoryViewModel = UserAppHistoryViewModel()
userAppHistoryViewModel.setAlreadyAppOpened(result.alreadyOpenedApp)
setProfileName()
itemList[0] = userAppHistoryViewModel
topicListAdapter.notifyItemChanged(0)
})
Expand All @@ -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<AsyncResult<OngoingStoryList>> by lazy {
topicListController.getOngoingStoryList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
/** [ViewModel] for user app usage history. */
class UserAppHistoryViewModel : HomeItemViewModel() {
var isAppAlreadyOpened = ObservableField<Boolean>(false)
var profileName : String = ""

fun setAlreadyAppOpened(alreadyOpenedApp: Boolean) = isAppAlreadyOpened.set(alreadyOpenedApp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 19 additions & 9 deletions app/src/main/res/layout/welcome.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:profile="http://schemas.android.com/tools">

<data>

Expand All @@ -18,24 +19,33 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:textColor="@color/oppiaPrimaryText"
android:textSize="24sp"
android:text="@{viewModel.isAppAlreadyOpened().get() ? @string/welcome_back_text : @string/welcome_text}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/profile_name_textview"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="28dp"
android:fontFamily="sans-serif"
android:text="@{viewModel.profileName}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/welcome_text_view"
app:layout_constraintTop_toTopOf="parent" />

<View
android:layout_width="172dp"
android:layout_width="0dp"
android:layout_height="6dp"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:background="@color/oppiaLightBrown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="@+id/welcome_text_view"
app:layout_constraintStart_toStartOf="@+id/welcome_text_view"
app:layout_constraintTop_toBottomOf="@+id/welcome_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading

0 comments on commit 631def4

Please sign in to comment.