Skip to content

Commit

Permalink
Fix #951: Lowfi ProfileChooser (#952)
Browse files Browse the repository at this point in the history
* Updated implemented - unfinished

* Lowfi landscape correct

* Updated final implementation

* lowfi-profile-chooser-part-1

* Added few textviews

* Updated UI

* Nit change

* Nit changes

* Nit change

Co-authored-by: Rajat Talesra <talesra@talesra-macbookpro.roam.corp.google.com>
  • Loading branch information
rt4914 and Rajat Talesra authored Apr 8, 2020
1 parent a7d302e commit fd97958
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package org.oppia.app.profile

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.databinding.ObservableField
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import org.oppia.app.R
import org.oppia.app.databinding.ProfileChooserAddViewBinding
import org.oppia.app.databinding.ProfileChooserFragmentBinding
Expand All @@ -18,6 +25,8 @@ import org.oppia.app.model.ProfileChooserUiModel
import org.oppia.app.recyclerview.BindableAdapter
import org.oppia.app.viewmodel.ViewModelProvider
import org.oppia.domain.profile.ProfileManagementController
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
import javax.inject.Inject

private val COLORS_LIST = listOf(
Expand Down Expand Up @@ -53,10 +62,14 @@ class ProfileChooserFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val activity: AppCompatActivity,
private val context: Context,
private val logger: Logger,
private val viewModelProvider: ViewModelProvider<ProfileChooserViewModel>,
private val profileManagementController: ProfileManagementController
) {
private lateinit var binding: ProfileChooserFragmentBinding
private val orientation = Resources.getSystem().configuration.orientation

val wasProfileEverBeenAddedValue = ObservableField<Boolean>(true)

private val chooserViewModel: ProfileChooserViewModel by lazy {
getProfileChooserViewModel()
Expand All @@ -70,12 +83,52 @@ class ProfileChooserFragmentPresenter @Inject constructor(
lifecycleOwner = fragment
}
binding.profileRecyclerView.isNestedScrollingEnabled = false
subscribeToWasProfileEverBeenAdded()
binding.profileRecyclerView.apply {
adapter = createRecyclerViewAdapter()
}
return binding.root
}

private fun subscribeToWasProfileEverBeenAdded() {
wasProfileEverBeenAdded.observe(activity, Observer<Boolean> {
wasProfileEverBeenAddedValue.set(it)
val layoutManager = if (it) {
val spanCount = if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.resources.getInteger(R.integer.profile_chooser_span_count)
} else {
/* spanCount= */ 2
}
GridLayoutManager(activity, spanCount)
} else {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager(activity, /* spanCount= */ 2)
} else {
LinearLayoutManager(activity)
}
}
binding.profileRecyclerView.layoutManager = layoutManager
})
}

private val wasProfileEverBeenAdded: LiveData<Boolean> by lazy {
Transformations.map(
profileManagementController.getWasProfileEverAdded(),
::processWasProfileEverBeenAddedResult
)
}

private fun processWasProfileEverBeenAddedResult(wasProfileEverBeenAddedResult: AsyncResult<Boolean>): Boolean {
if (wasProfileEverBeenAddedResult.isFailure()) {
logger.e(
"ProfileChooserFragment",
"Failed to retrieve the information on wasProfileEverBeenAdded",
wasProfileEverBeenAddedResult.getErrorOrNull()!!
)
}
return wasProfileEverBeenAddedResult.getOrDefault(/* defaultValue= */ false)
}

/** Randomly selects a color for the new profile that is not already in use. */
private fun selectUniqueRandomColor(): Int {
return COLORS_LIST.map {
Expand Down Expand Up @@ -108,6 +161,7 @@ class ProfileChooserFragmentPresenter @Inject constructor(
model: ProfileChooserUiModel
) {
binding.viewModel = model
binding.presenter = this
binding.root.setOnClickListener {
if (model.profile.pin.isEmpty()) {
profileManagementController.loginToProfile(model.profile.id).observe(fragment, Observer {
Expand All @@ -132,6 +186,7 @@ class ProfileChooserFragmentPresenter @Inject constructor(
}

private fun bindAddView(binding: ProfileChooserAddViewBinding, @Suppress("UNUSED_PARAMETER") model: ProfileChooserUiModel) {
binding.presenter = this
binding.root.setOnClickListener {
if (chooserViewModel.adminPin.isEmpty()) {
activity.startActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class ProfileChooserFragmentTestActivityPresenter @Inject constructor(
appLanguage = AppLanguage.ENGLISH_APP_LANGUAGE,
audioLanguage = AudioLanguage.ENGLISH_AUDIO_LANGUAGE
)
profileManagementController.addProfile(
name = "Ben",
pin = "123",
avatarImagePath = null,
allowDownloadAccess = false,
colorRgb = -10710042,
isAdmin = false,
storyTextSize = StoryTextSize.MEDIUM_TEXT_SIZE,
appLanguage = AppLanguage.HINDI_APP_LANGUAGE,
audioLanguage = AudioLanguage.ENGLISH_AUDIO_LANGUAGE
)
activity.setContentView(R.layout.profile_test_activity)
if (getProfileChooserFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/profile_chooser_divider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="1dp" />
<solid android:color="@color/oppiaProfileChooserDivider" />
</shape>
71 changes: 71 additions & 0 deletions app/src/main/res/layout-land/profile_chooser_add_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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">

<data>

<import type="android.view.View" />

<variable
name="presenter"
type="org.oppia.app.profile.ProfileChooserFragmentPresenter" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<View
android:id="@+id/add_profile_divider_view"
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="@color/oppiaProfileChooserDivider"
android:visibility="@{presenter.wasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:gravity="center_horizontal"
android:orientation="vertical">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_add_button"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginBottom="12dp"
android:src="@drawable/ic_add_profile"
app:civ_border_color="@color/avatarBorder"
app:civ_border_width="1dp" />

<TextView
android:id="@+id/add_profile_text"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="@{presenter.wasProfileEverBeenAddedValue ? @string/profile_chooser_add : @string/set_up_multiple_profiles}"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textColor="@color/white"
android:textSize="14sp" />

<TextView
android:id="@+id/add_profile_description_text"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:gravity="center"
android:text="@string/set_up_multiple_profiles_description"
android:textColor="@color/white"
android:textSize="14sp"
android:visibility="@{presenter.wasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}" />
</LinearLayout>
</LinearLayout>
</layout>
55 changes: 30 additions & 25 deletions app/src/main/res/layout-land/profile_chooser_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@
android:scrollbars="none"
android:tag="profile_recycler_view"
app:data="@{viewModel.profiles}"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/profile_select_text"
app:spanCount="@integer/profile_chooser_span_count" />
app:layout_constraintTop_toBottomOf="@id/profile_select_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

Expand All @@ -97,31 +95,38 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
<LinearLayout
android:id="@+id/administrator_controls_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:minHeight="48dp"
android:text="@string/profile_chooser_administrator_controls"
android:textColor="@color/profileChooserGreyTextColor"
android:textSize="16sp"
android:onClick="@{(v) -> viewModel.onAdministratorControlsButtonClicked()}"
android:background="@drawable/profile_chooser_gradient"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/profile_chooser_setting_icon" />
app:layout_constraintEnd_toEndOf="parent">

<ImageView
android:id="@+id/profile_chooser_setting_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="24dp"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="16dp"
android:paddingBottom="12dp"
android:src="@drawable/ic_settings_grey_48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:minHeight="48dp"
android:text="@string/profile_chooser_administrator_controls"
android:textColor="@color/profileChooserGreyTextColor"
android:textSize="16sp" />

<ImageView
android:id="@+id/profile_chooser_setting_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="24dp"
android:paddingStart="8dp"
android:paddingTop="12dp"
android:paddingEnd="16dp"
android:paddingBottom="12dp"
android:src="@drawable/ic_settings_grey_48dp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
77 changes: 77 additions & 0 deletions app/src/main/res/layout-land/profile_chooser_profile_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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:profile="http://schemas.android.com/tools">

<data>

<import type="android.view.View" />

<variable
name="presenter"
type="org.oppia.app.profile.ProfileChooserFragmentPresenter" />

<variable
name="viewModel"
type="org.oppia.app.model.ProfileChooserUiModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_avatar_img"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginBottom="8dp"
app:civ_border_color="@color/avatarBorder"
app:civ_border_width="1dp"
profile:src="@{viewModel.profile.avatar}" />

<TextView
android:id="@+id/profile_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:maxLines="2"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:singleLine="false"
android:text="@{viewModel.profile.name}"
android:textColor="@color/white"
android:textSize="14sp" />

<TextView
android:id="@+id/profile_is_admin_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/profile_chooser_admin"
android:textColor="@color/white"
android:textSize="12sp"
android:textStyle="italic"
android:visibility="@{viewModel.profile.isAdmin ? View.VISIBLE : View.GONE}" />
</LinearLayout>

<View
android:id="@+id/add_profile_divider_view"
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:visibility="@{presenter.wasProfileEverBeenAddedValue ? View.GONE : View.VISIBLE}"
android:background="@color/oppiaProfileChooserDivider" />
</LinearLayout>
</layout>
Loading

0 comments on commit fd97958

Please sign in to comment.