Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a control in "Access control" settings is unchecked, hide that control #5589

Merged
merged 5 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FormFinalizingTest {
.copyForm(FORM)
.startBlankForm("One Question")
.swipeToEndScreen()
.assertDisabled(R.string.save_as_draft)
.assertTextDoesNotExist(R.string.save_as_draft)
}

@Test
Expand All @@ -88,7 +88,7 @@ class FormFinalizingTest {
.copyForm(FORM)
.startBlankForm("One Question")
.swipeToEndScreen()
.assertDisabled(R.string.finalize)
.assertTextDoesNotExist(R.string.finalize)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.odk.collect.android.formentry

import android.content.Context
import android.view.LayoutInflater
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import org.odk.collect.android.R
import org.odk.collect.android.databinding.FormEntryEndBinding
Expand All @@ -18,12 +19,12 @@ class FormEndView(
init {
binding.description.text = context.getString(R.string.save_enter_data_description, formTitle)

binding.saveAsDraft.isEnabled = formEndViewModel.isSaveDraftEnabled()
binding.saveAsDraft.isVisible = formEndViewModel.isSaveDraftEnabled()
binding.saveAsDraft.setOnClickListener {
listener.onSaveClicked(false)
}

binding.finalize.isEnabled = formEndViewModel.isFinalizeEnabled()
binding.finalize.isVisible = formEndViewModel.isFinalizeEnabled()
binding.finalize.setOnClickListener {
listener.onSaveClicked(true)
}
Expand Down
52 changes: 31 additions & 21 deletions collect_app/src/main/res/layout/form_entry_end.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ the specific language governing permissions and limitations under the License.
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
app:cardBackgroundColor="?colorSurfaceContainerHighest"
app:layout_constraintBottom_toTopOf="@+id/save_as_draft"
app:layout_constraintBottom_toTopOf="@+id/buttons_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description"
app:layout_constraintWidth_max="640dp"
tools:visibility="visible">
app:layout_constraintWidth_max="640dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -76,30 +75,41 @@ the specific language governing permissions and limitations under the License.
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

<com.google.android.material.button.MaterialButton
android:id="@+id/save_as_draft"
style="@style/Widget.Material3.Button.OutlinedButton"
<androidx.constraintlayout.widget.ConstraintLayout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there must be a way to do this without nested ConstraintLayouts (maybe using Barrier), but it's really awkward to work out. Happy to go with this for now.

android:id="@+id/buttons_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:layout_marginEnd="@dimen/margin_small"
android:text="@string/save_as_draft"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/finalize"
app:layout_constraintEnd_toEndOf="@id/form_edits_warning"
app:layout_constraintStart_toStartOf="@id/form_edits_warning"
app:layout_constraintTop_toBottomOf="@+id/form_edits_warning" />
app:layout_constraintTop_toBottomOf="@+id/form_edits_warning">

<com.google.android.material.button.MaterialButton
android:id="@+id/finalize"
style="@style/Widget.Material3.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_small"
android:text="@string/finalize"
app:layout_constraintBottom_toBottomOf="@id/save_as_draft"
app:layout_constraintEnd_toEndOf="@id/form_edits_warning"
app:layout_constraintStart_toEndOf="@id/save_as_draft"
app:layout_constraintTop_toTopOf="@id/save_as_draft" />
<com.google.android.material.button.MaterialButton
android:id="@+id/save_as_draft"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/save_as_draft"
android:layout_marginEnd="@dimen/margin_small"
app:layout_goneMarginEnd="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/finalize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/finalize"
style="@style/Widget.Material3.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/finalize"
android:layout_marginStart="@dimen/margin_small"
app:layout_goneMarginStart="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/save_as_draft"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.odk.collect.android.formentry

import android.app.Application
import android.view.View
import android.widget.TextView
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -30,17 +31,17 @@ class FormEndViewTest {
}

@Test
fun `when saving drafts is enabled in settings should 'Save as draft' button be enabled`() {
fun `when saving drafts is enabled in settings should 'Save as draft' button be visible`() {
whenever(formEndViewModel.isSaveDraftEnabled()).thenReturn(true)
val view = FormEndView(context, "blah", formEndViewModel, listener)
assertThat(view.findViewById<MaterialButton>(R.id.save_as_draft).isEnabled, equalTo(true))
assertThat(view.findViewById<MaterialButton>(R.id.save_as_draft).visibility, equalTo(View.VISIBLE))
}

@Test
fun `when saving drafts is disabled in settings should 'Save as draft' button be disabled`() {
fun `when saving drafts is disabled in settings should 'Save as draft' button be hidden`() {
whenever(formEndViewModel.isSaveDraftEnabled()).thenReturn(false)
val view = FormEndView(context, "blah", formEndViewModel, listener)
assertThat(view.findViewById<MaterialButton>(R.id.save_as_draft).isEnabled, equalTo(false))
assertThat(view.findViewById<MaterialButton>(R.id.save_as_draft).visibility, equalTo(View.GONE))
}

@Test
Expand All @@ -52,17 +53,17 @@ class FormEndViewTest {
}

@Test
fun `when finalizing forms is enabled in settings should 'Finalize' button be enabled`() {
fun `when finalizing forms is enabled in settings should 'Finalize' button be visible`() {
whenever(formEndViewModel.isFinalizeEnabled()).thenReturn(true)
val view = FormEndView(context, "blah", formEndViewModel, listener)
assertThat(view.findViewById<MaterialButton>(R.id.finalize).isEnabled, equalTo(true))
assertThat(view.findViewById<MaterialButton>(R.id.finalize).visibility, equalTo(View.VISIBLE))
}

@Test
fun `when finalizing forms is disabled in settings should 'Finalize' button be disabled`() {
fun `when finalizing forms is disabled in settings should 'Finalize' button be hidden`() {
whenever(formEndViewModel.isFinalizeEnabled()).thenReturn(false)
val view = FormEndView(context, "blah", formEndViewModel, listener)
assertThat(view.findViewById<MaterialButton>(R.id.finalize).isEnabled, equalTo(false))
assertThat(view.findViewById<MaterialButton>(R.id.finalize).visibility, equalTo(View.GONE))
}

@Test
Expand Down