From c8f4741ab01b90797fc8b72145c415cbceed865f Mon Sep 17 00:00:00 2001 From: Jordan Longstaff Date: Thu, 28 Nov 2024 15:25:09 -0500 Subject: [PATCH] Move public scan setting back to connection settings --- .../settings/ClientSettingsFragmentTest.kt | 28 +++++------------ .../ConnectionSettingsFragmentTest.kt | 22 +++++++++++++ .../setup/settings/ClientSettingsFragment.kt | 17 ++-------- .../settings/ConnectionSettingsFragment.kt | 13 ++++++++ .../agent/setup/settings/SettingsFragment.kt | 2 +- .../main/res/layout-land/settings_client.xml | 31 +------------------ app/src/main/res/layout/settings_client.xml | 31 +------------------ .../main/res/layout/settings_connection.xml | 29 +++++++++++++++++ app/src/main/res/values/strings.xml | 2 +- 9 files changed, 77 insertions(+), 98 deletions(-) diff --git a/app/src/androidTest/kotlin/artemis/agent/setup/settings/ClientSettingsFragmentTest.kt b/app/src/androidTest/kotlin/artemis/agent/setup/settings/ClientSettingsFragmentTest.kt index 16b25f2e..07dd217b 100644 --- a/app/src/androidTest/kotlin/artemis/agent/setup/settings/ClientSettingsFragmentTest.kt +++ b/app/src/androidTest/kotlin/artemis/agent/setup/settings/ClientSettingsFragmentTest.kt @@ -29,7 +29,6 @@ class ClientSettingsFragmentTest { val expectedUpdateInterval = AtomicInteger() val externalVesselDataCount = AtomicInteger() val showingInfo = AtomicBoolean() - val alwaysPublic = AtomicBoolean() activityScenarioRule.scenario.onActivity { activity -> val viewModel = activity.viewModels().value @@ -37,7 +36,6 @@ class ClientSettingsFragmentTest { expectedUpdateInterval.lazySet(viewModel.updateObjectsInterval) externalVesselDataCount.lazySet(viewModel.storageDirectories.size) showingInfo.lazySet(viewModel.showingNetworkInfo) - alwaysPublic.lazySet(viewModel.alwaysScanPublicBroadcasts) } SettingsFragmentTest.openSettingsMenu() @@ -47,7 +45,6 @@ class ClientSettingsFragmentTest { expectedPort.toString(), expectedUpdateInterval.toString(), showingInfo.get(), - alwaysPublic.get(), ) SettingsFragmentTest.closeSettingsSubMenu() @@ -55,19 +52,11 @@ class ClientSettingsFragmentTest { } private companion object { - val clientSingleToggleSettings = arrayOf( - SingleToggleButtonSetting( - R.id.showNetworkInfoDivider, - R.id.showNetworkInfoTitle, - R.string.show_network_info, - R.id.showNetworkInfoButton, - ), - SingleToggleButtonSetting( - R.id.alwaysScanPublicDivider, - R.id.alwaysScanPublicTitle, - R.string.always_scan_publicly, - R.id.alwaysScanPublicButton, - ) + val showNetworkInfoToggleSetting = SingleToggleButtonSetting( + R.id.showNetworkInfoDivider, + R.id.showNetworkInfoTitle, + R.string.show_network_info, + R.id.showNetworkInfoButton, ) fun testClientSubMenuOpen( @@ -75,7 +64,6 @@ class ClientSettingsFragmentTest { expectedPort: String, expectedUpdateInterval: String, showingInfo: Boolean, - alwaysPublic: Boolean, ) { scrollTo(R.id.vesselDataDivider) assertDisplayed(R.id.vesselDataTitle, R.string.vessel_data_xml_location) @@ -93,9 +81,7 @@ class ClientSettingsFragmentTest { } } - clientSingleToggleSettings.zip( - listOf(showingInfo, alwaysPublic), - ).forEach { (setting, isChecked) -> setting.testSingleToggle(isChecked) } + showNetworkInfoToggleSetting.testSingleToggle(showingInfo) scrollTo(R.id.serverPortDivider) assertDisplayed(R.id.serverPortTitle, R.string.server_port) @@ -121,7 +107,7 @@ class ClientSettingsFragmentTest { assertNotExist(R.id.serverPortTitle) assertNotExist(R.id.serverPortField) assertNotExist(R.id.serverPortDivider) - clientSingleToggleSettings.forEach { it.testNotExist() } + showNetworkInfoToggleSetting.testNotExist() assertNotExist(R.id.addressLimitTitle) assertNotExist(R.id.addressLimitEnableButton) assertNotExist(R.id.addressLimitInfinity) diff --git a/app/src/androidTest/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragmentTest.kt b/app/src/androidTest/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragmentTest.kt index c2b6189c..fe1b7a3a 100644 --- a/app/src/androidTest/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragmentTest.kt +++ b/app/src/androidTest/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragmentTest.kt @@ -1,8 +1,10 @@ package artemis.agent.setup.settings +import androidx.activity.viewModels import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest +import artemis.agent.AgentViewModel import artemis.agent.MainActivity import artemis.agent.R import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions.assertDisplayed @@ -11,6 +13,7 @@ import com.adevinta.android.barista.interaction.BaristaScrollInteractions.scroll import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import java.util.concurrent.atomic.AtomicBoolean @RunWith(AndroidJUnit4::class) @LargeTest @@ -20,6 +23,13 @@ class ConnectionSettingsFragmentTest { @Test fun connectionSettingsTest() { + val alwaysPublic = AtomicBoolean() + + activityScenarioRule.scenario.onActivity { activity -> + val viewModel = activity.viewModels().value + alwaysPublic.lazySet(viewModel.alwaysScanPublicBroadcasts) + } + SettingsFragmentTest.openSettingsMenu() SettingsFragmentTest.openSettingsSubMenu(1) @@ -38,6 +48,8 @@ class ConnectionSettingsFragmentTest { assertDisplayed(R.id.scanTimeoutTimeInput) assertDisplayed(R.id.scanTimeoutSecondsLabel, R.string.seconds) + alwaysScanPublicToggleSetting.testSingleToggle(alwaysPublic.get()) + SettingsFragmentTest.closeSettingsSubMenu() assertNotExist(R.id.connectionTimeoutTitle) assertNotExist(R.id.connectionTimeoutTimeInput) @@ -51,5 +63,15 @@ class ConnectionSettingsFragmentTest { assertNotExist(R.id.scanTimeoutTimeInput) assertNotExist(R.id.scanTimeoutSecondsLabel) assertNotExist(R.id.scanTimeoutDivider) + alwaysScanPublicToggleSetting.testNotExist() + } + + private companion object { + val alwaysScanPublicToggleSetting = SingleToggleButtonSetting( + R.id.alwaysScanPublicDivider, + R.id.alwaysScanPublicTitle, + R.string.always_scan_publicly, + R.id.alwaysScanPublicButton, + ) } } diff --git a/app/src/main/kotlin/artemis/agent/setup/settings/ClientSettingsFragment.kt b/app/src/main/kotlin/artemis/agent/setup/settings/ClientSettingsFragment.kt index 0fb37fbe..45bb68fe 100644 --- a/app/src/main/kotlin/artemis/agent/setup/settings/ClientSettingsFragment.kt +++ b/app/src/main/kotlin/artemis/agent/setup/settings/ClientSettingsFragment.kt @@ -44,7 +44,6 @@ class ClientSettingsFragment : Fragment(R.layout.settings_client) { vesselDataOptionButtons[it.vesselDataLocationValue].isChecked = true binding.showNetworkInfoButton.isChecked = it.showNetworkInfo - binding.alwaysScanPublicButton.isChecked = it.alwaysScanPublic val addressLimitEnabled = it.recentAddressLimitEnabled binding.addressLimitEnableButton.isChecked = addressLimitEnabled @@ -64,7 +63,7 @@ class ClientSettingsFragment : Fragment(R.layout.settings_client) { } prepareServerPortSettingField() - prepareScanSettingToggles() + prepareShowNetworkInfoSettingToggle() prepareAddressLimitSettingField() binding.updateIntervalField.setOnFocusChangeListener { _, hasFocus -> @@ -148,7 +147,7 @@ class ClientSettingsFragment : Fragment(R.layout.settings_client) { } } - private fun prepareScanSettingToggles() { + private fun prepareShowNetworkInfoSettingToggle() { binding.showNetworkInfoButton.setOnClickListener { viewModel.playSound(SoundEffect.BEEP_2) } @@ -160,18 +159,6 @@ class ClientSettingsFragment : Fragment(R.layout.settings_client) { } } } - - binding.alwaysScanPublicButton.setOnClickListener { - viewModel.playSound(SoundEffect.BEEP_2) - } - - binding.alwaysScanPublicButton.setOnCheckedChangeListener { _, isChecked -> - viewModel.viewModelScope.launch { - binding.root.context.userSettings.updateData { - it.copy { alwaysScanPublic = isChecked } - } - } - } } private fun prepareAddressLimitSettingField() { diff --git a/app/src/main/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragment.kt b/app/src/main/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragment.kt index bd84b90f..45f952e2 100644 --- a/app/src/main/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragment.kt +++ b/app/src/main/kotlin/artemis/agent/setup/settings/ConnectionSettingsFragment.kt @@ -65,6 +65,19 @@ class ConnectionSettingsFragment : Fragment(R.layout.settings_connection) { connectionTimeoutBinder.timeInSeconds = it.connectionTimeoutSeconds heartbeatTimeoutBinder.timeInSeconds = it.serverTimeoutSeconds scanTimeoutBinder.timeInSeconds = it.scanTimeoutSeconds + binding.alwaysScanPublicButton.isChecked = it.alwaysScanPublic + } + + binding.alwaysScanPublicButton.setOnClickListener { + viewModel.playSound(SoundEffect.BEEP_2) + } + + binding.alwaysScanPublicButton.setOnCheckedChangeListener { _, isChecked -> + viewModel.viewModelScope.launch { + binding.root.context.userSettings.updateData { + it.copy { alwaysScanPublic = isChecked } + } + } } } diff --git a/app/src/main/kotlin/artemis/agent/setup/settings/SettingsFragment.kt b/app/src/main/kotlin/artemis/agent/setup/settings/SettingsFragment.kt index 33c76547..9c4694c0 100644 --- a/app/src/main/kotlin/artemis/agent/setup/settings/SettingsFragment.kt +++ b/app/src/main/kotlin/artemis/agent/setup/settings/SettingsFragment.kt @@ -44,7 +44,6 @@ class SettingsFragment : Fragment(R.layout.settings_fragment) { vesselDataLocation = UserSettings.VesselDataLocation.VESSEL_DATA_LOCATION_DEFAULT serverPort = UserSettingsSerializer.DEFAULT_SERVER_PORT showNetworkInfo = true - alwaysScanPublic = false recentAddressLimit = UserSettingsSerializer.DEFAULT_ADDRESS_LIMIT recentAddressLimitEnabled = false updateInterval = UserSettingsSerializer.DEFAULT_UPDATE_INTERVAL @@ -58,6 +57,7 @@ class SettingsFragment : Fragment(R.layout.settings_fragment) { connectionTimeoutSeconds = UserSettingsSerializer.DEFAULT_CONNECTION_TIMEOUT serverTimeoutSeconds = UserSettingsSerializer.DEFAULT_HEARTBEAT_TIMEOUT scanTimeoutSeconds = UserSettingsSerializer.DEFAULT_SCAN_TIMEOUT + alwaysScanPublic = false } }, MISSION( diff --git a/app/src/main/res/layout-land/settings_client.xml b/app/src/main/res/layout-land/settings_client.xml index 2fe9bd4c..221e3ca2 100644 --- a/app/src/main/res/layout-land/settings_client.xml +++ b/app/src/main/res/layout-land/settings_client.xml @@ -109,35 +109,6 @@ android:layout_height="1dp" android:background="?android:attr/listDivider" app:layout_constraintTop_toBottomOf="@id/showNetworkInfoButton" /> - - - + app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" /> - - - + app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" /> + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ac77004..701ddb17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -305,7 +305,7 @@ will be listed below. When you select one of the listed servers, the app will attempt to connect to that server. By default, the app only scans for servers on the local network. If you are having trouble finding servers, you can scan publicly by activating the - \"Always scan publicly\" option in the client settings.\n + \"Always scan publicly\" option in the connection settings.\n \nAfter the app has connected to the server, you must select a ship. The Ships page