Skip to content

Commit

Permalink
Move public scan setting back to connection settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanLongstaff committed Nov 28, 2024
1 parent 9813aee commit c8f4741
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ class ClientSettingsFragmentTest {
val expectedUpdateInterval = AtomicInteger()
val externalVesselDataCount = AtomicInteger()
val showingInfo = AtomicBoolean()
val alwaysPublic = AtomicBoolean()

activityScenarioRule.scenario.onActivity { activity ->
val viewModel = activity.viewModels<AgentViewModel>().value
expectedPort.lazySet(viewModel.port)
expectedUpdateInterval.lazySet(viewModel.updateObjectsInterval)
externalVesselDataCount.lazySet(viewModel.storageDirectories.size)
showingInfo.lazySet(viewModel.showingNetworkInfo)
alwaysPublic.lazySet(viewModel.alwaysScanPublicBroadcasts)
}

SettingsFragmentTest.openSettingsMenu()
Expand All @@ -47,35 +45,25 @@ class ClientSettingsFragmentTest {
expectedPort.toString(),
expectedUpdateInterval.toString(),
showingInfo.get(),
alwaysPublic.get(),
)

SettingsFragmentTest.closeSettingsSubMenu()
testClientSubMenuClosed()
}

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(
externalVesselDataCount: Int,
expectedPort: String,
expectedUpdateInterval: String,
showingInfo: Boolean,
alwaysPublic: Boolean,
) {
scrollTo(R.id.vesselDataDivider)
assertDisplayed(R.id.vesselDataTitle, R.string.vessel_data_xml_location)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -20,6 +23,13 @@ class ConnectionSettingsFragmentTest {

@Test
fun connectionSettingsTest() {
val alwaysPublic = AtomicBoolean()

activityScenarioRule.scenario.onActivity { activity ->
val viewModel = activity.viewModels<AgentViewModel>().value
alwaysPublic.lazySet(viewModel.alwaysScanPublicBroadcasts)
}

SettingsFragmentTest.openSettingsMenu()
SettingsFragmentTest.openSettingsSubMenu(1)

Expand All @@ -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)
Expand All @@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,7 +63,7 @@ class ClientSettingsFragment : Fragment(R.layout.settings_client) {
}

prepareServerPortSettingField()
prepareScanSettingToggles()
prepareShowNetworkInfoSettingToggle()
prepareAddressLimitSettingField()

binding.updateIntervalField.setOnFocusChangeListener { _, hasFocus ->
Expand Down Expand Up @@ -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)
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
31 changes: 1 addition & 30 deletions app/src/main/res/layout-land/settings_client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,6 @@
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoButton" />
<TextView
android:id="@+id/alwaysScanPublicTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/always_scan_publicly"
android:textSize="@dimen/mediumTextSize"
app:autoSizeTextType="uniform"
app:autoSizeStepGranularity="2sp"
app:layout_constraintBottom_toBottomOf="@id/alwaysScanPublicButton"
app:layout_constraintEnd_toStartOf="@id/alwaysScanPublicButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/alwaysScanPublicButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/alwaysScanPublicButton" />
<ToggleButton
android:id="@+id/alwaysScanPublicButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textOff="@string/off"
android:textOn="@string/on"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" />
<View
android:id="@+id/alwaysScanPublicDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/alwaysScanPublicButton" />
<TextView
android:id="@+id/addressLimitTitle"
android:layout_width="0dp"
Expand Down Expand Up @@ -171,7 +142,7 @@
android:textOn="@string/on"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/alwaysScanPublicDivider" />
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" />
<TextView
android:id="@+id/addressLimitInfinity"
android:layout_width="0dp"
Expand Down
31 changes: 1 addition & 30 deletions app/src/main/res/layout/settings_client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,6 @@
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoButton" />
<TextView
android:id="@+id/alwaysScanPublicTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/always_scan_publicly"
android:textSize="@dimen/mediumTextSize"
app:autoSizeTextType="uniform"
app:autoSizeStepGranularity="2sp"
app:layout_constraintBottom_toBottomOf="@id/alwaysScanPublicButton"
app:layout_constraintEnd_toStartOf="@id/alwaysScanPublicButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/alwaysScanPublicButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/alwaysScanPublicButton" />
<ToggleButton
android:id="@+id/alwaysScanPublicButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textOff="@string/off"
android:textOn="@string/on"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" />
<View
android:id="@+id/alwaysScanPublicDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/alwaysScanPublicButton" />
<TextView
android:id="@+id/addressLimitTitle"
android:layout_width="0dp"
Expand Down Expand Up @@ -166,7 +137,7 @@
android:textOn="@string/on"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/alwaysScanPublicDivider" />
app:layout_constraintTop_toBottomOf="@id/showNetworkInfoDivider" />
<TextView
android:id="@+id/addressLimitInfinity"
android:layout_width="0dp"
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/settings_connection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,33 @@
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/scanTimeoutTimeInput" />
<TextView
android:id="@+id/alwaysScanPublicTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/always_scan_publicly"
android:textSize="@dimen/mediumTextSize"
app:autoSizeTextType="uniform"
app:autoSizeStepGranularity="2sp"
app:layout_constraintBottom_toBottomOf="@id/alwaysScanPublicButton"
app:layout_constraintEnd_toStartOf="@id/alwaysScanPublicButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/alwaysScanPublicButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/alwaysScanPublicButton" />
<ToggleButton
android:id="@+id/alwaysScanPublicButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textOff="@string/off"
android:textOn="@string/on"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/scanTimeoutDivider" />
<View
android:id="@+id/alwaysScanPublicDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
app:layout_constraintTop_toBottomOf="@id/alwaysScanPublicButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
</item>
<item>
\nAfter the app has connected to the server, you must select a ship. The Ships page
Expand Down

0 comments on commit c8f4741

Please sign in to comment.