Skip to content

Commit

Permalink
Merge pull request #5944 from seadowg/end-buttons
Browse files Browse the repository at this point in the history
Make sure form end buttons grow together
  • Loading branch information
grzesiek2010 committed Feb 1, 2024
2 parents 15d9e19 + 19667b9 commit 92ad4fc
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
Expand Up @@ -104,7 +104,7 @@ class AuditTest {
.pressBack(MainMenuPage())
.startBlankForm("One Question Audit")
.fillOut(FormEntryPage.QuestionAndAnswer("what is your age", "31"))
.killAndReopenApp(MainMenuPage())
.killAndReopenApp(rule, MainMenuPage())
.startBlankForm("One Question Audit")
.swipeToEndScreen()
.clickFinalize()
Expand Down
Expand Up @@ -113,7 +113,7 @@ class BulkFinalizationTest {

.clickDrafts()
.clickOnForm("One Question")
.killAndReopenApp(MainMenuPage())
.killAndReopenApp(rule, MainMenuPage())

.clickDrafts(false)
.clickFinalizeAll(1)
Expand Down
Expand Up @@ -7,13 +7,16 @@
import static org.hamcrest.core.AllOf.allOf;

import android.app.Activity;
import android.content.Intent;
import android.view.ContextThemeWrapper;
import android.view.View;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.platform.app.InstrumentationRegistry;

import org.hamcrest.Matcher;
import org.odk.collect.android.BuildConfig;

public final class ActivityHelpers {

Expand Down Expand Up @@ -48,4 +51,14 @@ public void perform(UiController uiController, View view) {
onView(allOf(withId(android.R.id.content), isDisplayed())).perform(getActivityViewAction);
return currentActivity[0];
}

public static Intent getLaunchIntent() {
Intent launchIntentForPackage = InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getPackageManager()
.getLaunchIntentForPackage(BuildConfig.APPLICATION_ID);

launchIntentForPackage.addCategory(Intent.CATEGORY_LAUNCHER);
return launchIntentForPackage;
}
}
@@ -1,5 +1,6 @@
package org.odk.collect.android.support.pages

import android.app.Activity
import android.app.Application
import android.content.pm.ActivityInfo
import android.view.View
Expand Down Expand Up @@ -47,12 +48,14 @@ import org.odk.collect.android.BuildConfig
import org.odk.collect.android.R
import org.odk.collect.android.application.Collect
import org.odk.collect.android.storage.StoragePathProvider
import org.odk.collect.android.support.ActivityHelpers.getLaunchIntent
import org.odk.collect.android.support.CollectHelpers
import org.odk.collect.android.support.WaitFor.wait250ms
import org.odk.collect.android.support.WaitFor.waitFor
import org.odk.collect.android.support.actions.RotateAction
import org.odk.collect.android.support.matchers.CustomMatchers.withIndex
import org.odk.collect.androidshared.ui.ToastUtils.popRecordedToasts
import org.odk.collect.androidtest.ActivityScenarioLauncherRule
import org.odk.collect.strings.localization.getLocalizedQuantityString
import org.odk.collect.strings.localization.getLocalizedString
import org.odk.collect.testshared.EspressoHelpers
Expand Down Expand Up @@ -492,7 +495,7 @@ abstract class Page<T : Page<T>> {
return destination!!.assertOnPage()
}

fun <D : Page<D>?> killAndReopenApp(destination: D): D {
fun <D : Page<D>> killAndReopenApp(rule: ActivityScenarioLauncherRule, destination: D): D {
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

// kill
Expand All @@ -504,11 +507,8 @@ abstract class Page<T : Page<T>> {
}

// reopen
InstrumentationRegistry.getInstrumentation().targetContext.apply {
val intent = packageManager.getLaunchIntentForPackage(BuildConfig.APPLICATION_ID)!!
startActivity(intent)
}
return destination!!.assertOnPage()
rule.launch<Activity>(getLaunchIntent())
return destination.assertOnPage()
}

fun assertNoOptionsMenu(): T {
Expand Down
Expand Up @@ -2,11 +2,9 @@ package org.odk.collect.android.support.rules

import android.app.Activity
import android.app.Instrumentation
import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import org.odk.collect.android.BuildConfig.APPLICATION_ID
import org.odk.collect.android.external.AndroidShortcutsActivity
import org.odk.collect.android.support.ActivityHelpers.getLaunchIntent
import org.odk.collect.android.support.StubOpenRosaServer
import org.odk.collect.android.support.pages.FirstLaunchPage
import org.odk.collect.android.support.pages.MainMenuPage
Expand Down Expand Up @@ -80,14 +78,4 @@ class CollectTestRule @JvmOverloads constructor(
actions.accept(destination)
return scenario.result
}

private fun getLaunchIntent(): Intent {
return ApplicationProvider
.getApplicationContext<Context>()
.packageManager
.getLaunchIntentForPackage(APPLICATION_ID)!!
.apply {
this.addCategory(Intent.CATEGORY_LAUNCHER)
}
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="@dimen/margin_standard" />
<size android:height="@dimen/margin_standard" />
</shape>
</item>
</layer-list>
30 changes: 11 additions & 19 deletions collect_app/src/main/res/layout/form_entry_end.xml
Expand Up @@ -77,46 +77,38 @@ the specific language governing permissions and limitations under the License.
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
app:layout_constraintWidth_max="640dp"
android:divider="@drawable/margin_standard_list_divider"
android:showDividers="middle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/form_edits_warning">
app:layout_constraintTop_toBottomOf="@+id/form_edits_warning"
app:layout_constraintWidth_max="@dimen/max_content_width">

<com.google.android.material.button.MaterialButton
android:id="@+id/save_as_draft"
style="?materialButtonOutlinedIconStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/save_as_draft"
android:layout_marginEnd="@dimen/margin_extra_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"
app:icon="@drawable/ic_save_menu_24"
app:iconGravity="textStart" />

<com.google.android.material.button.MaterialButton
android:id="@+id/finalize"
style="?materialButtonIconStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/finalize"
android:layout_marginStart="@dimen/margin_extra_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"
app:icon="@drawable/ic_send_24"
app:iconGravity="textStart" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

0 comments on commit 92ad4fc

Please sign in to comment.