diff --git a/app/src/main/java/com/soi/moya/models/UserPreferences.kt b/app/src/main/java/com/soi/moya/models/UserPreferences.kt index 6b9a0c3..9252613 100644 --- a/app/src/main/java/com/soi/moya/models/UserPreferences.kt +++ b/app/src/main/java/com/soi/moya/models/UserPreferences.kt @@ -3,6 +3,7 @@ package com.soi.moya.models import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore @@ -15,6 +16,7 @@ class UserPreferences(private val context: Context) { private val Context.dataStore: DataStore by preferencesDataStore("selected_team") val SELECTED_TEAM = stringPreferencesKey("selected_team") val APP_VERSION = stringPreferencesKey("app_version") + val SHOW_MINI_PLAYER = booleanPreferencesKey("show_mini_player") } val getSelectedTeam: Flow = context.dataStore.data @@ -27,6 +29,11 @@ class UserPreferences(private val context: Context) { preferences[APP_VERSION] ?: BuildConfig.VERSION_NAME } + val showMiniPlayer: Flow = context.dataStore.data + .map { preference -> + preference[SHOW_MINI_PLAYER] ?: true + } + suspend fun saveSelectedTeam(team: Team) { context.dataStore.edit { preferences -> preferences[SELECTED_TEAM] = team.name @@ -40,4 +47,10 @@ class UserPreferences(private val context: Context) { } } } + + suspend fun showingMiniPlayer() { + context.dataStore.edit { preference -> + preference[SHOW_MINI_PLAYER] = true + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/soi/moya/ui/MainActivity.kt b/app/src/main/java/com/soi/moya/ui/MainActivity.kt index e526fcc..01b4391 100644 --- a/app/src/main/java/com/soi/moya/ui/MainActivity.kt +++ b/app/src/main/java/com/soi/moya/ui/MainActivity.kt @@ -1,11 +1,10 @@ package com.soi.moya.ui -import android.util.DisplayMetrics import android.widget.Toast import androidx.activity.OnBackPressedCallback -import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -35,6 +34,7 @@ class MainActivity : BaseComposeActivity() { val navController = rememberNavController() var selectedTeam by remember { mutableStateOf(null) } var isLoaded by remember { mutableStateOf(false) } + val showingMiniPlayer = userPreferences.showMiniPlayer.collectAsState(initial = false) LaunchedEffect(key1 = userPreferences) { userPreferences.getSelectedTeam.collect { team -> @@ -47,9 +47,12 @@ class MainActivity : BaseComposeActivity() { if (selectedTeam != null) { MoyaTheme(team = Team.valueOf(selectedTeam ?: "doosan")) { BottomNavScreen() - MiniPlayerScreen( - maxHeight = computeWindowSizeClasses(), - navController = navController) + if (showingMiniPlayer.value) { + MiniPlayerScreen( + maxHeight = computeWindowSizeClasses(), + navController = navController + ) + } } } else { SelectTeamScreen(navController = navController) diff --git a/app/src/main/java/com/soi/moya/ui/bottom_nav/BottomNavScreen.kt b/app/src/main/java/com/soi/moya/ui/bottom_nav/BottomNavScreen.kt index 04dd6e3..326064b 100644 --- a/app/src/main/java/com/soi/moya/ui/bottom_nav/BottomNavScreen.kt +++ b/app/src/main/java/com/soi/moya/ui/bottom_nav/BottomNavScreen.kt @@ -19,12 +19,10 @@ import androidx.compose.material.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.remember import androidx.compose.ui.unit.sp import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -45,7 +43,6 @@ import com.soi.moya.ui.MUSIC_STORAGE import com.soi.moya.ui.SEARCH import com.soi.moya.ui.music_list.MusicListScreen import com.soi.moya.ui.SELECT_TEAM -import com.soi.moya.ui.mini_player.MiniPlayerScreen import com.soi.moya.ui.music_player.MusicPlayerScreen import com.soi.moya.ui.music_storage.MusicStorageScreen import com.soi.moya.ui.notice.NoticeBottomSheetViewModel diff --git a/app/src/main/java/com/soi/moya/ui/music_list/MusicListScreen.kt b/app/src/main/java/com/soi/moya/ui/music_list/MusicListScreen.kt index 1d90ae7..e08394e 100644 --- a/app/src/main/java/com/soi/moya/ui/music_list/MusicListScreen.kt +++ b/app/src/main/java/com/soi/moya/ui/music_list/MusicListScreen.kt @@ -117,7 +117,8 @@ fun MusicListScreen( music = music, team = team, image = albumImageResourceId, - navController = navController + navController = navController, + viewModel = viewModel ) } @@ -227,7 +228,13 @@ fun MusicListHeaderView( @OptIn(ExperimentalMaterial3Api::class) @Composable -fun MusicListItemView(music: Music, team: Team, image: Int, navController: NavHostController) { +fun MusicListItemView( + music: Music, + team: Team, + image: Int, + navController: NavHostController, + viewModel: MusicListViewModel +) { val sheetState = rememberModalBottomSheetState() val scope = rememberCoroutineScope() var showBottomSheet by remember { mutableStateOf(false) } @@ -238,7 +245,7 @@ fun MusicListItemView(music: Music, team: Team, image: Int, navController: NavHo cellType = CellType.List, image = image, onClickCell = { - navController.navigate("MUSIC_PLAYER/${team.name}/${music.id}") + viewModel.onSongSelected() }, onClickExtraButton = { Log.d("clicked", "extra button") diff --git a/app/src/main/java/com/soi/moya/ui/music_list/MusicListViewModel.kt b/app/src/main/java/com/soi/moya/ui/music_list/MusicListViewModel.kt index 7a3805c..7b408b1 100644 --- a/app/src/main/java/com/soi/moya/ui/music_list/MusicListViewModel.kt +++ b/app/src/main/java/com/soi/moya/ui/music_list/MusicListViewModel.kt @@ -33,6 +33,12 @@ class MusicListViewModel( observeSelectedTeam() } + fun onSongSelected() { + viewModelScope.launch { + _userPreferences.showingMiniPlayer() + } + } + private fun observeUserPreference() { viewModelScope.launch { _userPreferences.getSelectedTeam.collect { team ->