Skip to content

Commit

Permalink
Merge pull request #5589 from grzesiek2010/COLLECT-5581
Browse files Browse the repository at this point in the history
When a control in "Access control" settings is unchecked, hide that control
  • Loading branch information
grzesiek2010 committed May 17, 2023
2 parents 609fad6 + 5061116 commit 0b96d5e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
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
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

0 comments on commit 0b96d5e

Please sign in to comment.