Skip to content

Commit

Permalink
Reverse library grid preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-saenko committed Nov 18, 2023
1 parent 5d80557 commit fd1e196
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UserPreferencesMapper @Inject constructor(
override fun map(input: UserPreferencesDo): UserPreferences {
return UserPreferences(
trackFilter = trackFilterMapper.map(input.trackFilter),
useGridForLibrary = input.useGridForLibrary
useColumnForLibrary = input.useColumnForLibrary
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class AdapterPreferencesRepository @Inject constructor(
)
}

override suspend fun setUseGridForLibrary(value: Boolean) {
preferencesRepositoryDo.setUseGridForLibrary(value)
override suspend fun setUseColumnForLibrary(value: Boolean) {
preferencesRepositoryDo.setUseColumnForLibrary(value)
}

override suspend fun setThemeMode(value: ThemeMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PreferencesMapper @Inject constructor(
requiredServices = requiredServicesMapper.map(input.requiredServices),
fallbackPolicy = fallbackPolicyMapper.map(input.fallbackPolicy),
hapticFeedback = hapticFeedbackMapper.map(input.hapticFeedback),
useGridForLibrary = input.useGridForLibrary,
useColumnForLibrary = input.useColumnForLibrary,
themeMode = themeModeMapper.map(input.themeMode),
usePureBlackForDarkTheme = input.usePureBlackForDarkTheme
)
Expand Down
3 changes: 2 additions & 1 deletion core/strings/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
<string name="theme_use_pure_black">Исп. черный фон</string>
<string name="music_services_links">Ссылки на музыкальные сервисы</string>
<string name="required_services_dialog">Выберите музыкальные сервисы, для которых вы хотите видеть веб-ссылки (если доступны):</string>
<string name="use_grid_for_library">Использовать сетку для библиотеки</string>
<string name="use_grid_for_library">Библиотека в виде сетки</string>
<string name="use_list_for_library">Библиотека в виде списка</string>
<string name="vibration_feedback">Вибрация</string>
<string name="vibration_feedback_dialog_title">Вибрация</string>
<string name="vibration_feedback_dialog_message">Настройте вибрацию для конкретных действий в приложении:</string>
Expand Down
1 change: 1 addition & 0 deletions core/strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<string name="music_services_links">Music service links</string>
<string name="required_services_dialog">Choose the music services for which you would like to see web links (if available):</string>
<string name="use_grid_for_library">Use grid layout for library</string>
<string name="use_list_for_library">Use list layout for library</string>
<string name="vibration_feedback">Vibration feedback</string>
<string name="vibration_feedback_dialog_title">Vibration feedback</string>
<string name="vibration_feedback_dialog_message">Configure vibration feedback for certain in-app actions:</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface PreferencesRepositoryDo {
suspend fun setLyricsFontStyle(value: UserPreferencesDo.LyricsFontStyleDo)
suspend fun setTrackFilter(value: UserPreferencesDo.TrackFilterDo)
suspend fun setHapticFeedback(value: UserPreferencesDo.HapticFeedbackDo)
suspend fun setUseGridForLibrary(value: Boolean)
suspend fun setUseColumnForLibrary(value: Boolean)
suspend fun setThemeMode(value: ThemeModeDo)
suspend fun setUsePureBlackForDarkTheme(value: Boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class PreferencesRepositoryImpl @Inject constructor(
}
}

override suspend fun setUseGridForLibrary(value: Boolean) {
safeWriter { setUseGridForLibrary(value) }
override suspend fun setUseColumnForLibrary(value: Boolean) {
safeWriter { setUseColumnForLibrary(value) }
}

override suspend fun setThemeMode(value: ThemeModeDo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class UserPreferencesDo(
val lyricsFontStyle: LyricsFontStyleDo,
val trackFilter: TrackFilterDo,
val hapticFeedback: HapticFeedbackDo,
val useGridForLibrary: Boolean,
val useColumnForLibrary: Boolean,
val themeMode: ThemeModeDo,
val usePureBlackForDarkTheme: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object UserPreferencesProtoSerializer : Serializer<UserPreferencesProto> {
.setOnboardingCompleted(false)
.setDynamicColorsEnabled(true)
.setArtworkBasedThemeEnabled(false)
.setUseGridForLibrary(true)
.setUseColumnForLibrary(false)
.setNotificationServiceEnabled(false)
.setDeveloperModeEnabled(true)
.setFallbackPolicy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UserPreferencesDoMapper @Inject constructor(
.setLyricsFontStyle(lyricsFontStyleMapper.reverseMap(input.lyricsFontStyle))
.setTrackFilter(trackFilterMapper.reverseMap(input.trackFilter))
.setHapticFeedback(hapticFeedbackMapper.reverseMap(input.hapticFeedback))
.setUseGridForLibrary(input.useGridForLibrary)
.setUseColumnForLibrary(input.useColumnForLibrary)
.setThemeMode(themeModeMapper.reverseMap(input.themeMode))
.setUsePureBlackForDarkTheme(input.usePureBlackForDarkTheme)
.build()
Expand All @@ -49,7 +49,7 @@ class UserPreferencesDoMapper @Inject constructor(
lyricsFontStyle = lyricsFontStyleMapper.map(input.lyricsFontStyle),
trackFilter = trackFilterMapper.map(input.trackFilter),
hapticFeedback = hapticFeedbackMapper.map(input.hapticFeedback),
useGridForLibrary = input.useGridForLibrary,
useColumnForLibrary = input.useColumnForLibrary,
themeMode = themeModeMapper.map(input.themeMode),
usePureBlackForDarkTheme = input.usePureBlackForDarkTheme
)
Expand Down
2 changes: 1 addition & 1 deletion data/src/main/proto/user_preferences_proto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ message UserPreferencesProto {
}

HapticFeedbackProto haptic_feedback = 31;
bool use_grid_for_library = 32;
bool use_column_for_library = 32;

enum ThemeModeProto {
FOLLOW_SYSTEM = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.mrsep.musicrecognizer.feature.library.domain.model

data class UserPreferences(
val trackFilter: TrackFilter,
val useGridForLibrary: Boolean
val useColumnForLibrary: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,37 @@ internal fun LibraryScreen(
)
var newFilterApplied by rememberSaveable { mutableStateOf(false) }

if (uiState.useGridLayout) {
val lazyGridState = rememberLazyGridState()
TrackLazyGrid(
if (uiState.useColumnLayout) {
val lazyListState = rememberLazyListState()
TrackLazyColumn(
trackList = uiState.trackList,
onTrackClick = onTrackClick,
lazyGridState = lazyGridState,
lazyListState = lazyListState,
multiSelectionState = multiSelectionState,
modifier = Modifier.nestedScroll(
topBarBehaviour.nestedScrollConnection
)
)
LaunchedEffect(uiState.trackFilter) {
if (newFilterApplied) {
lazyGridState.animateScrollToItem(0)
lazyListState.animateScrollToItem(0)
newFilterApplied = false
}
}
} else {
val lazyListState = rememberLazyListState()
TrackLazyColumn(
val lazyGridState = rememberLazyGridState()
TrackLazyGrid(
trackList = uiState.trackList,
onTrackClick = onTrackClick,
lazyListState = lazyListState,
lazyGridState = lazyGridState,
multiSelectionState = multiSelectionState,
modifier = Modifier.nestedScroll(
topBarBehaviour.nestedScrollConnection
)
)
LaunchedEffect(uiState.trackFilter) {
if (newFilterApplied) {
lazyListState.animateScrollToItem(0)
lazyGridState.animateScrollToItem(0)
newFilterApplied = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class LibraryViewModel @Inject constructor(
LibraryUiState.Success(
trackList = trackList.map { track -> track.toUi() }.toImmutableList(),
trackFilter = preferences.trackFilter,
useGridLayout = preferences.useGridForLibrary
useColumnLayout = preferences.useColumnForLibrary
)
}
}
Expand Down Expand Up @@ -66,7 +66,7 @@ internal sealed class LibraryUiState {
data class Success(
val trackList: ImmutableList<TrackUi>,
val trackFilter: TrackFilter,
val useGridLayout: Boolean
val useColumnLayout: Boolean
) : LibraryUiState()

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface PreferencesRepository {
suspend fun setRequiredServices(requiredServices: UserPreferences.RequiredServices)
suspend fun setFallbackPolicy(fallbackPolicy: UserPreferences.FallbackPolicy)
suspend fun setHapticFeedback(hapticFeedback: UserPreferences.HapticFeedback)
suspend fun setUseGridForLibrary(value: Boolean)
suspend fun setUseColumnForLibrary(value: Boolean)
suspend fun setThemeMode(value: ThemeMode)
suspend fun setUsePureBlackForDarkTheme(value: Boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class UserPreferences(
val developerModeEnabled: Boolean,
val fallbackPolicy: FallbackPolicy,
val hapticFeedback: HapticFeedback,
val useGridForLibrary: Boolean,
val useColumnForLibrary: Boolean,
val themeMode: ThemeMode,
val usePureBlackForDarkTheme: Boolean,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ internal fun PreferencesScreen(
)
}
PreferenceSwitchItem(
title = stringResource(StringsR.string.use_grid_for_library),
onCheckedChange = { viewModel.setUseGridForLibrary(it) },
checked = uiState.preferences.useGridForLibrary,
title = stringResource(StringsR.string.use_list_for_library),
onCheckedChange = { viewModel.setUseColumnForLibrary(it) },
checked = uiState.preferences.useColumnForLibrary,
modifier = Modifier.padding(top = 12.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ internal class PreferencesViewModel @Inject constructor(
}
}

fun setUseGridForLibrary(value: Boolean) {
fun setUseColumnForLibrary(value: Boolean) {
viewModelScope.launch {
preferencesRepository.setUseGridForLibrary(value)
preferencesRepository.setUseColumnForLibrary(value)
}
}

Expand Down

0 comments on commit fd1e196

Please sign in to comment.