Skip to content

Commit

Permalink
#82 [Feat] - 음악 cell 탭했을 때, Miniplayer 보여주기
Browse files Browse the repository at this point in the history
  • Loading branch information
JIWON1923 committed Apr 20, 2024
1 parent 046d08c commit 692aa99
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/com/soi/moya/models/UserPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,7 @@ class UserPreferences(private val context: Context) {
private val Context.dataStore: DataStore<Preferences> 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<String?> = context.dataStore.data
Expand All @@ -27,6 +29,11 @@ class UserPreferences(private val context: Context) {
preferences[APP_VERSION] ?: BuildConfig.VERSION_NAME
}

val showMiniPlayer: Flow<Boolean> = context.dataStore.data
.map { preference ->
preference[SHOW_MINI_PLAYER] ?: true
}

suspend fun saveSelectedTeam(team: Team) {
context.dataStore.edit { preferences ->
preferences[SELECTED_TEAM] = team.name
Expand All @@ -40,4 +47,10 @@ class UserPreferences(private val context: Context) {
}
}
}

suspend fun showingMiniPlayer() {
context.dataStore.edit { preference ->
preference[SHOW_MINI_PLAYER] = true
}
}
}
13 changes: 8 additions & 5 deletions app/src/main/java/com/soi/moya/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,6 +34,7 @@ class MainActivity : BaseComposeActivity() {
val navController = rememberNavController()
var selectedTeam by remember { mutableStateOf<String?>(null) }
var isLoaded by remember { mutableStateOf(false) }
val showingMiniPlayer = userPreferences.showMiniPlayer.collectAsState(initial = false)

LaunchedEffect(key1 = userPreferences) {
userPreferences.getSelectedTeam.collect { team ->
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/soi/moya/ui/music_list/MusicListScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ fun MusicListScreen(
music = music,
team = team,
image = albumImageResourceId,
navController = navController
navController = navController,
viewModel = viewModel
)
}

Expand Down Expand Up @@ -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) }
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class MusicListViewModel(
observeSelectedTeam()
}

fun onSongSelected() {
viewModelScope.launch {
_userPreferences.showingMiniPlayer()
}
}

private fun observeUserPreference() {
viewModelScope.launch {
_userPreferences.getSelectedTeam.collect { team ->
Expand Down

0 comments on commit 692aa99

Please sign in to comment.