Skip to content

Commit

Permalink
Fix #3410: Merged Switch click with TextViews in ProfileEditActivity (#…
Browse files Browse the repository at this point in the history
…3409)

* Merged switch click with TextViews in Profile Edit

* Added tests

* Added more tests

Co-authored-by: Rajat Talesra <[email protected]>
  • Loading branch information
rt4914 and Rajat Talesra committed Jul 5, 2021
1 parent 6716b6e commit fb84577
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ class ProfileEditFragmentPresenter @Inject constructor(
}
)

binding.profileEditAllowDownloadSwitch.setOnCheckedChangeListener { compoundButton, checked ->
if (compoundButton.isPressed) {
profileManagementController.updateAllowDownloadAccess(
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
checked
).toLiveData().observe(
activity,
Observer {
if (it.isFailure()) {
oppiaLogger.e(
"ProfileEditActivityPresenter",
"Failed to updated allow download access",
it.getErrorOrNull()!!
)
}
binding.profileEditAllowDownloadContainer.setOnClickListener {
binding.profileEditAllowDownloadSwitch.isChecked =
!binding.profileEditAllowDownloadSwitch.isChecked
profileManagementController.updateAllowDownloadAccess(
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
binding.profileEditAllowDownloadSwitch.isChecked
).toLiveData().observe(
activity,
Observer {
if (it.isFailure()) {
oppiaLogger.e(
"ProfileEditActivityPresenter",
"Failed to updated allow download access",
it.getErrorOrNull()!!
)
}
)
}
}
)
}
return binding.root
}
Expand Down
104 changes: 53 additions & 51 deletions app/src/main/res/layout-land/profile_edit_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,61 +135,63 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_reset_button" />

<View
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_edit_allow_download_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="wrap_content"
android:background="@color/white"
android:focusable="true"
android:importantForAccessibility="yes"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintBottom_toBottomOf="@+id/profile_edit_allow_download_sub"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view4" />

<TextView
android:id="@+id/profile_edit_allow_download_heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:text="@string/profile_edit_allow_download_heading"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view4" />

<TextView
android:id="@+id/profile_edit_allow_download_sub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@string/profile_edit_allow_download_sub"
android:textColor="@color/accessible_light_grey"
android:textSize="14sp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_heading" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/profile_edit_allow_download_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:minHeight="48dp"
android:paddingStart="12dp"
android:paddingTop="0dp"
android:paddingEnd="12dp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/profile_edit_allow_download_heading" />
app:layout_constraintTop_toBottomOf="@id/view4">

<TextView
android:id="@+id/profile_edit_allow_download_heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:text="@string/profile_edit_allow_download_heading"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/profile_edit_allow_download_sub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@string/profile_edit_allow_download_sub"
android:textColor="@color/accessible_light_grey"
android:textSize="14sp"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_heading" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/profile_edit_allow_download_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:minWidth="48dp"
android:minHeight="48dp"
android:paddingStart="12dp"
android:paddingTop="0dp"
android:paddingEnd="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/profile_edit_allow_download_heading" />
</androidx.constraintlayout.widget.ConstraintLayout>

<View
android:id="@+id/view6"
Expand All @@ -199,7 +201,7 @@
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_sub" />
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_container" />

<View
android:layout_width="match_parent"
Expand Down
104 changes: 53 additions & 51 deletions app/src/main/res/layout/profile_edit_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,61 +135,63 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_reset_button" />

<View
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_edit_allow_download_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="wrap_content"
android:background="@color/white"
android:focusable="true"
android:importantForAccessibility="yes"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintBottom_toBottomOf="@+id/profile_edit_allow_download_sub"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view4" />

<TextView
android:id="@+id/profile_edit_allow_download_heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:text="@string/profile_edit_allow_download_heading"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view4" />

<TextView
android:id="@+id/profile_edit_allow_download_sub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@string/profile_edit_allow_download_sub"
android:textColor="@color/accessible_light_grey"
android:textSize="14sp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_heading" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/profile_edit_allow_download_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:minHeight="48dp"
android:paddingStart="12dp"
android:paddingTop="0dp"
android:paddingEnd="12dp"
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/profile_edit_allow_download_heading" />
app:layout_constraintTop_toBottomOf="@id/view4">

<TextView
android:id="@+id/profile_edit_allow_download_heading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:text="@string/profile_edit_allow_download_heading"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/profile_edit_allow_download_sub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:paddingStart="16dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:text="@string/profile_edit_allow_download_sub"
android:textColor="@color/accessible_light_grey"
android:textSize="14sp"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_allow_download_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_heading" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/profile_edit_allow_download_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:minWidth="48dp"
android:minHeight="48dp"
android:paddingStart="12dp"
android:paddingTop="0dp"
android:paddingEnd="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/profile_edit_allow_download_heading" />
</androidx.constraintlayout.widget.ConstraintLayout>

<View
android:layout_width="match_parent"
Expand All @@ -198,7 +200,7 @@
android:visibility="@{viewModel.profile.isAdmin ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_sub" />
app:layout_constraintTop_toBottomOf="@+id/profile_edit_allow_download_container" />

<View
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit fb84577

Please sign in to comment.