Skip to content
Open
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 @@ -112,9 +112,11 @@ class AppSettingsScreenTest {
setContent(appSettings = appSettings)

val debugTitle = composeTestRule.activity.getString(R.string.debug_category_pref_title)
scrollToText(text = debugTitle)
composeTestRule.onNodeWithText(debugTitle).assertIsDisplayed()

val dumpSmsTitle = composeTestRule.activity.getString(R.string.dump_sms_pref_title)
scrollToText(text = dumpSmsTitle)
composeTestRule.onNodeWithText(dumpSmsTitle).assertIsDisplayed()

val dumpMmsTitle = composeTestRule.activity.getString(R.string.dump_mms_pref_title)
Expand All @@ -132,6 +134,7 @@ class AppSettingsScreenTest {
setContent(appSettings = appSettings)

val title = composeTestRule.activity.getString(R.string.dump_sms_pref_title)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

verify(exactly = 1) {
Expand Down Expand Up @@ -162,6 +165,7 @@ class AppSettingsScreenTest {
setContent()

val title = composeTestRule.activity.getString(R.string.menu_license)
scrollToText(text = title)
composeTestRule.onNodeWithText(title).performClick()

verify(exactly = 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.content.res.Resources
import com.android.messaging.Factory
import com.android.messaging.R
import com.android.messaging.data.appsettings.model.AppBooleanPref
import com.android.messaging.data.appsettings.model.ConversationSwipeOption
import com.android.messaging.data.appsettings.model.ConversationSwipePref
import com.android.messaging.data.appsettings.model.ConversationSwipeSettings
import com.android.messaging.data.appsettings.repository.AppSettingsRepositoryImpl
import com.android.messaging.data.debug.DebugFeaturesProvider
import com.android.messaging.datamodel.data.ParticipantData
Expand Down Expand Up @@ -70,6 +73,12 @@ internal class AppSettingsRepositoryImplTest {
every {
context.getString(R.string.youtube_link_previews_pref_key)
} returns YOUTUBE_LINK_PREVIEWS_PREF_KEY
every {
context.getString(R.string.conversation_swipe_start_to_end_pref_key)
} returns SWIPE_START_TO_END_PREF_KEY
every {
context.getString(R.string.conversation_swipe_end_to_start_pref_key)
} returns SWIPE_END_TO_START_PREF_KEY
every {
resources.getBoolean(R.bool.youtube_link_previews_pref_default)
} returns YOUTUBE_LINK_PREVIEWS_DEFAULT
Expand Down Expand Up @@ -108,6 +117,8 @@ internal class AppSettingsRepositoryImplTest {
YOUTUBE_LINK_PREVIEWS_DEFAULT,
)
} returns true
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns "Delete"
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns null

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
Expand All @@ -118,6 +129,13 @@ internal class AppSettingsRepositoryImplTest {
assertFalse(result.sendSoundEnabled)
assertTrue(result.inConversationSoundEnabled)
assertTrue(result.youTubeLinkPreviewsEnabled)
assertEquals(
ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Delete,
endToStart = ConversationSwipeOption.Archive,
),
result.conversationSwipeSettings,
)
assertTrue(result.isDebugEnabled)
assertTrue(result.dumpSmsEnabled)
assertFalse(result.dumpMmsEnabled)
Expand Down Expand Up @@ -191,6 +209,64 @@ internal class AppSettingsRepositoryImplTest {
}
}

@Test
fun setConversationSwipeOptions_writesExpectedStringToEachPreferenceKey() {
runTest {
every { appPrefs.putString(any(), any()) } just runs
val repository = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
)

repository.setConversationSwipeOption(
pref = ConversationSwipePref.START_TO_END,
option = ConversationSwipeOption.Archive,
)
repository.setConversationSwipeOption(
pref = ConversationSwipePref.END_TO_START,
option = ConversationSwipeOption.ToggleRead,
)

verify(exactly = 1) {
appPrefs.putString(SWIPE_START_TO_END_PREF_KEY, "Archive")
appPrefs.putString(SWIPE_END_TO_START_PREF_KEY, "ToggleRead")
}
}
}

@Test
fun getConversationSwipeSettings_readsStoredOptions() {
runTest {
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns "Archive"
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns "Delete"

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
).getConversationSwipeSettings()

assertEquals(
ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Archive,
endToStart = ConversationSwipeOption.Delete,
),
result,
)
}
}

@Test
fun getConversationSwipeSettings_fallsBackToDefaultsWhenMissingOrUnknown() {
runTest {
every { appPrefs.getString(SWIPE_START_TO_END_PREF_KEY, null) } returns null
every { appPrefs.getString(SWIPE_END_TO_START_PREF_KEY, null) } returns "UnknownValue"

val result = createRepository(
ioDispatcher = UnconfinedTestDispatcher(testScheduler),
).getConversationSwipeSettings()

assertEquals(ConversationSwipeSettings.Default, result)
}
}

@Test
fun isYouTubeLinkPreviewsEnabled_readsPreferenceWithResourceDefault() {
runTest {
Expand Down Expand Up @@ -242,6 +318,8 @@ internal class AppSettingsRepositoryImplTest {
private const val IN_CONVERSATION_SOUND_PREF_KEY = "in_conversation_sound"
private const val SEND_SOUND_DEFAULT = true
private const val SEND_SOUND_PREF_KEY = "send_sound"
private const val SWIPE_END_TO_START_PREF_KEY = "conversation_swipe_end_to_start"
private const val SWIPE_START_TO_END_PREF_KEY = "conversation_swipe_start_to_end"
private const val YOUTUBE_LINK_PREVIEWS_DEFAULT = false
private const val YOUTUBE_LINK_PREVIEWS_PREF_KEY = "youtube_link_previews"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.android.messaging.ui.appsettings.general.mapper.appsettingsuistatema
import android.content.Context
import com.android.messaging.R
import com.android.messaging.data.appsettings.model.AppSettings
import com.android.messaging.data.appsettings.model.ConversationSwipeOption
import com.android.messaging.data.appsettings.model.ConversationSwipeSettings
import com.android.messaging.ui.appsettings.general.mapper.AppSettingsUiStateMapperImpl
import com.android.messaging.ui.appsettings.general.model.AppSettingsUiState
import io.mockk.every
Expand Down Expand Up @@ -30,6 +32,10 @@ internal class AppSettingsUiStateMapperImplTest {
sendSoundEnabled = false,
inConversationSoundEnabled = true,
youTubeLinkPreviewsEnabled = true,
conversationSwipeSettings = ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Delete,
endToStart = ConversationSwipeOption.ToggleRead,
),
isDebugEnabled = true,
dumpSmsEnabled = true,
dumpMmsEnabled = false,
Expand All @@ -43,6 +49,10 @@ internal class AppSettingsUiStateMapperImplTest {
sendSoundEnabled = false,
inConversationSoundEnabled = true,
youTubeLinkPreviewsEnabled = true,
conversationSwipeSettings = ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.Delete,
endToStart = ConversationSwipeOption.ToggleRead,
),
isDebugEnabled = true,
dumpSmsEnabled = true,
dumpMmsEnabled = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.android.common.test.helpers.targetContext
import com.android.messaging.FactoryTestAccess
import com.android.messaging.data.appsettings.repository.AppSettingsRepository
import com.android.messaging.data.conversation.event.ConversationArchiveEventsImpl
import com.android.messaging.data.conversation.model.ConversationId
import com.android.messaging.data.conversationlist.repository.ConversationListRepository
Expand Down Expand Up @@ -51,7 +52,8 @@ internal class ConversationListNewestConversationVisibilityTest {
@get:Rule
val composeTestRule = createComposeRule()

private val repository = mockk<ConversationListRepository>(relaxed = true)
private val conversationListRepository = mockk<ConversationListRepository>(relaxed = true)
private val appSettingsRepository = mockk<AppSettingsRepository>(relaxed = true)
private val visibilityUpdates = mutableListOf<Boolean>()

private lateinit var lifecycleOwner: TestLifecycleOwner
Expand All @@ -60,7 +62,7 @@ internal class ConversationListNewestConversationVisibilityTest {
@Before
fun setUp() {
installTestFactory(context = targetContext)
every { repository.setNewestConversationVisible(any()) } answers {
every { conversationListRepository.setNewestConversationVisible(any()) } answers {
visibilityUpdates += firstArg<Boolean>()
}
}
Expand Down Expand Up @@ -180,7 +182,8 @@ internal class ConversationListNewestConversationVisibilityTest {
every { selectionDelegate.selectedIds } returns MutableStateFlow(persistentListOf())

return ConversationListViewModel(
repository = repository,
conversationListRepository = conversationListRepository,
appSettingsRepository = appSettingsRepository,
uiStateMapper = uiStateMapper,
selectionDelegate = selectionDelegate,
actionsDelegate = mockk(relaxed = true),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.android.messaging.ui.conversationlist.chats

import app.cash.turbine.test
import com.android.messaging.data.appsettings.model.ConversationSwipeSettings
import com.android.messaging.data.appsettings.repository.AppSettingsRepository
import com.android.messaging.data.conversation.event.ConversationArchiveEventsImpl
import com.android.messaging.data.conversation.model.ConversationId
import com.android.messaging.data.conversationlist.model.ConversationListSnapshot
Expand Down Expand Up @@ -43,7 +45,8 @@ class ConversationListViewModelTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()

private val repository = mockk<ConversationListRepository>()
private val conversationListRepository = mockk<ConversationListRepository>()
private val appSettingsRepository = mockk<AppSettingsRepository>()
private val uiStateMapper = mockk<ConversationListUiStateMapper>()
private val selectionDelegate = mockk<ConversationListSelectionDelegate>()
private val actionsDelegate = mockk<ConversationListActionsDelegate>()
Expand Down Expand Up @@ -271,8 +274,8 @@ class ConversationListViewModelTest {
}

private fun createViewModel(): ConversationListViewModel {
every { repository.refresh() } just runs
every { repository.setNewestConversationVisible(any()) } just runs
every { conversationListRepository.refresh() } just runs
every { conversationListRepository.setNewestConversationVisible(any()) } just runs

every { optimisticSnapshotDelegate.snapshot } returns snapshotFlow
every { optimisticSnapshotDelegate.bind(any(), any()) } just runs
Expand All @@ -299,15 +302,18 @@ class ConversationListViewModelTest {
every { debugFeaturesProvider.isEnabled() } returns false
every { resolveContactAction(any(), any(), any()) } returns
ResolveContactActionResult.Unavailable
coEvery { appSettingsRepository.getConversationSwipeSettings() } returns
ConversationSwipeSettings.Default

return ConversationListViewModel(
repository = repository,
conversationListRepository = conversationListRepository,
appSettingsRepository = appSettingsRepository,
uiStateMapper = uiStateMapper,
selectionDelegate = selectionDelegate,
actionsDelegate = actionsDelegate,
optimisticSnapshotDelegate = optimisticSnapshotDelegate,
debugFeaturesProvider = debugFeaturesProvider,
resolveContactAction = resolveContactAction,
debugFeaturesProvider = debugFeaturesProvider,
conversationArchiveEvents = conversationArchiveEvents,
defaultDispatcher = mainDispatcherRule.testDispatcher,
mainDispatcher = mainDispatcherRule.testDispatcher,
Expand Down
2 changes: 2 additions & 0 deletions res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<bool name="in_conversation_sound_pref_default" translatable="false">false</bool>
<string name="youtube_link_previews_pref_key" translatable="false">youtube_link_previews</string>
<bool name="youtube_link_previews_pref_default" translatable="false">false</bool>
<string name="conversation_swipe_start_to_end_pref_key" translatable="false">conversation_swipe_start_to_end</string>
<string name="conversation_swipe_end_to_start_pref_key" translatable="false">conversation_swipe_end_to_start</string>

<!-- Subscription-specific settings. The values of these pref keys must be prefixed with
"buglesub_" to allow for runtime checks -->
Expand Down
8 changes: 8 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@
<string name="mms_messaging_category_pref_title">MMS</string>
<!-- Preference category: Advanced -->
<string name="advanced_category_pref_title">Advanced</string>
<!-- Preference category: Conversation Swipe Options -->
<string name="swipe_category_pref_title">Conversation Swipe Actions</string>
<!-- Title for the preference choosing what swiping a conversation towards the end edge does -->
<string name="swipe_start_to_end_pref_title">Swipe right</string>
<!-- Title for the preference choosing what swiping a conversation towards the start edge does -->
<string name="swipe_end_to_start_pref_title">Swipe left</string>
<!-- Swipe action option that marks a conversation read if unread, or unread if read -->
<string name="swipe_action_toggle_read">Mark as read/unread</string>
<!-- Preference category: Debug -->
<string name="debug_category_pref_title">Debug</string>
<!-- Title for the preference for whether or not to request/show delivery reports for SMS -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ internal data class AppSettings(
val sendSoundEnabled: Boolean,
val inConversationSoundEnabled: Boolean,
val youTubeLinkPreviewsEnabled: Boolean,
val conversationSwipeSettings: ConversationSwipeSettings,
val isDebugEnabled: Boolean,
val dumpSmsEnabled: Boolean,
val dumpMmsEnabled: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.android.messaging.data.appsettings.model

internal enum class ConversationSwipeOption {
ToggleRead,
Archive,
Delete,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.android.messaging.data.appsettings.model

import androidx.annotation.StringRes
import com.android.messaging.R

internal enum class ConversationSwipePref(
@param:StringRes val keyResId: Int,
) {
START_TO_END(R.string.conversation_swipe_start_to_end_pref_key),
END_TO_START(R.string.conversation_swipe_end_to_start_pref_key),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.android.messaging.data.appsettings.model

internal data class ConversationSwipeSettings(
val startToEnd: ConversationSwipeOption,
val endToStart: ConversationSwipeOption,
) {
companion object {
val Default = ConversationSwipeSettings(
startToEnd = ConversationSwipeOption.ToggleRead,
endToStart = ConversationSwipeOption.Archive,
)
}
}
Loading
Loading