Skip to content

Commit

Permalink
Removing Now Playing in favor of music player
Browse files Browse the repository at this point in the history
  • Loading branch information
cristhianescobar committed Oct 31, 2023
1 parent 552388e commit 4bd758d
Show file tree
Hide file tree
Showing 63 changed files with 482 additions and 939 deletions.
1 change: 0 additions & 1 deletion android/app-newm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ dependencies {
implementation(project(Modules.coreTheme))
implementation(project(Modules.coreResources))
implementation(project(Modules.coreUiUtils))
implementation(project(Modules.nowPlaying))
implementation(project(Modules.login))
implementation(project(Modules.musicPlayer))
implementation(project(Modules.barcodeScanner))
Expand Down
5 changes: 0 additions & 5 deletions android/app-newm/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
android:launchMode="singleTop"
android:screenOrientation="portrait" />

<activity
android:name=".feature.now.playing.DemoPlayerActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" />

<activity
android:name=".feature.musicplayer.MusicPlayerActivity"
android:launchMode="singleTop"
Expand Down
35 changes: 21 additions & 14 deletions android/app-newm/src/main/java/io/newm/NewmAppComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,29 @@ internal fun NewmBottomNavigation(
onClick = { onNavigationSelected(Screen.NFTLibraryRoot) },
)
HomeBottomNavigationItem(
selected = currentRootScreen == Screen.HomeRoot,
iconResId = R.drawable.ic_home,
labelResId = R.string.home,
selectedIconBrush = HomeIconGradient,
selectedLabelColor = DarkViolet,
onClick = { onNavigationSelected(Screen.HomeRoot) },
)
HomeBottomNavigationItem(
selected = currentRootScreen == Screen.LibraryRoot,
iconResId = R.drawable.ic_library,
labelResId = R.string.library,
selected = currentRootScreen == Screen.ProfileViewRoot,
iconResId = R.drawable.ic_profile,
labelResId = R.string.profile,
selectedIconBrush = LibraryIconGradient,
selectedLabelColor = DarkPink,
onClick = { onNavigationSelected(Screen.LibraryRoot) },
onClick = { onNavigationSelected(Screen.ProfileViewRoot) },
)

// HomeBottomNavigationItem(
// selected = currentRootScreen == Screen.HomeRoot,
// iconResId = R.drawable.ic_home,
// labelResId = R.string.home,
// selectedIconBrush = HomeIconGradient,
// selectedLabelColor = DarkViolet,
// onClick = { onNavigationSelected(Screen.HomeRoot) },
// )
// HomeBottomNavigationItem(
// selected = currentRootScreen == Screen.LibraryRoot,
// iconResId = R.drawable.ic_library,
// labelResId = R.string.library,
// selectedIconBrush = LibraryIconGradient,
// selectedLabelColor = DarkPink,
// onClick = { onNavigationSelected(Screen.LibraryRoot) },
// )
}
}
}
Expand Down Expand Up @@ -224,6 +231,6 @@ val allScreens: List<Screen>

val routesWithoutBottomNavBar: List<String> by lazy {
listOf(
Screen.NowPlayingScreen.route
Screen.Profile.route
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import io.newm.feature.login.screen.welcome.WelcomeScreenPresenter
import io.newm.feature.musicplayer.repository.MockMusicRepository
import io.newm.feature.musicplayer.repository.MusicRepository
import io.newm.feature.musicplayer.viewmodel.MusicPlayerViewModel
import io.newm.feature.now.playing.DemoPlayerViewModel
import io.newm.screens.home.categories.MusicalCategoriesViewModel
import io.newm.screens.library.NFTLibraryViewModel
import io.newm.screens.profile.ProfileViewModel
import io.newm.screens.profile.view.ProfileReadOnlyViewModel
import io.newm.screens.profile.edit.ProfileEditViewModel
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
Expand All @@ -34,10 +34,10 @@ val viewModule = module {
viewModelOf(::MusicalCategoriesViewModel)
viewModelOf(::CreateAccountViewModel)
viewModelOf(::LoginViewModel)
viewModelOf(::ProfileViewModel)
viewModelOf(::DemoPlayerViewModel)
viewModelOf(::ProfileReadOnlyViewModel)
viewModelOf(::ProfileEditViewModel)
viewModelOf(::NFTLibraryViewModel)
viewModel { params -> MusicPlayerViewModel(params.get(), params.get(), get()) }
viewModel { params -> MusicPlayerViewModel(params.get(), params.get(), get(), get()) }

factory { params -> CreateAccountScreenPresenter(params.get(), get()) }
single<GoogleSignInLauncher> {
Expand Down
42 changes: 29 additions & 13 deletions android/app-newm/src/main/java/io/newm/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.newm.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
Expand All @@ -12,29 +11,31 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import io.newm.feature.barcode.scanner.BarcodeScannerActivity
import io.newm.feature.musicplayer.MusicPlayerActivity
import io.newm.feature.now.playing.DemoPlayerActivity
import io.newm.screens.Screen
import io.newm.screens.home.HomeScreen
import io.newm.screens.library.LibraryScreen
import io.newm.screens.library.NFTLibraryScreen
import io.newm.screens.profile.ProfileRoute
import io.newm.screens.profile.edit.ProfileRoute
import io.newm.screens.profile.view.ProfileViewScreen
import io.newm.shared.models.Song

@Composable
fun Navigation(
navController: NavHostController, isBottomBarVisible: MutableState<Boolean>
) {
val context = LocalContext.current
val onConnectWalletClick = { navController.navigate(Screen.BarcodeScanner.route) }
val onEditProfileClick = { navController.navigate(Screen.Profile.route) }
NavHost(
navController = navController, startDestination = Screen.NFTLibraryRoot.route
) {
addNFTLibraryTree(
onPlaySong = { song ->
context.startActivity(DemoPlayerActivity.createIntent(context, song.id))
onPlaySong = { songId ->
navController.navigate(Screen.MusicPlayer.routeOf(songId.id))
},
onConnectWalletClick = { navController.navigate(Screen.BarcodeScanner.route) }
onConnectWalletClick = onConnectWalletClick
)
addHomeTree(navController, isBottomBarVisible)
addProfileViewTree(onConnectWalletClick, onEditProfileClick)
addLibraryTree(navController)
addMusicPlayerTree()
addBarcodeScannerTree()
Expand All @@ -44,18 +45,17 @@ fun Navigation(
private fun NavGraphBuilder.addHomeTree(
navController: NavHostController, isBottomBarVisible: MutableState<Boolean>
) {
val nowPlaying = { navController.navigate(Screen.NowPlayingScreen.route) }
navigation(
route = Screen.HomeRoot.route, startDestination = Screen.HomeLanding.route
) {
composable(route = Screen.HomeLanding.route) {
HomeScreen(
onShowProfile = { navController.navigate(Screen.Profile.route) },
onThisWeekViewAll = { nowPlaying.invoke() }, //TODO: Implement View All screen
onRecentlyPlayedViewAll = { nowPlaying.invoke() }, //TODO: Implement View All screen
onArtistListViewMore = { nowPlaying.invoke() }, //TODO: Implement View More screen
onArtistViewDetails = { nowPlaying.invoke() }, //TODO: Implement Artist Details screen
onMusicViewDetails = { nowPlaying.invoke() }, //TODO: Implement Music Details screen
onThisWeekViewAll = { }, //TODO: Implement View All screen
onRecentlyPlayedViewAll = { }, //TODO: Implement View All screen
onArtistListViewMore = { }, //TODO: Implement View More screen
onArtistViewDetails = { }, //TODO: Implement Artist Details screen
onMusicViewDetails = { }, //TODO: Implement Music Details screen
)
}

Expand Down Expand Up @@ -87,6 +87,22 @@ private fun NavGraphBuilder.addLibraryTree(navController: NavHostController) {
}
}

private fun NavGraphBuilder.addProfileViewTree(
onConnectWalletClick: () -> Unit,
onEditProfileClick: () -> Unit
) {
navigation(
route = Screen.ProfileViewRoot.route, startDestination = Screen.ProfileViewLanding.route
) {
composable(Screen.ProfileViewLanding.route) {
ProfileViewScreen(
onConnectWalletClick = onConnectWalletClick,
onEditProfileClick = onEditProfileClick
)
}
}
}

private fun NavGraphBuilder.addNFTLibraryTree(
onPlaySong: (Song) -> Unit, onConnectWalletClick: () -> Unit
) {
Expand Down
6 changes: 5 additions & 1 deletion android/app-newm/src/main/java/io/newm/screens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ sealed class Screen(val route: String) {
object HomeRoot : Screen("home-root")
object HomeLanding : Screen("home-landing")

object ProfileViewRoot : Screen("profile-view-root")

object ProfileViewLanding : Screen("profile-view-landing")

object LibraryRoot : Screen("library-root")

object LibraryLanding : Screen("library-landing")
Expand All @@ -19,10 +23,10 @@ sealed class Screen(val route: String) {
//Single Screens
@Parcelize
object LoginLandingScreen : Screen("login-landing"), CircuitScreen

@Parcelize
object LoginScreen : Screen("login"), CircuitScreen
object Signup : Screen("signup")
object NowPlayingScreen : Screen("now-playing")
object Profile : Screen("profile")
object BarcodeScanner : Screen("barcode-scanner")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,18 @@ import org.koin.compose.koinInject

internal const val TAG_NFTLIBRARY_SCREEN = "TAG_LIBRARY_SCREEN"

val XPUB = "xpub1j6l5sgu597d72mu6tnzmrlt3mfv8d8qru2ys5gy4hf09g2v97ct8gslwcvkjyd8jkpefj226ccyw6al76af5hcf328myun6pwjl7wcgshjjxl"
@OptIn(ExperimentalTextApi::class)
@Composable
fun NFTLibraryScreen(
onPlaySong: (Song) -> Unit,
onConnectWalletClick: () -> Unit,
viewModel: NFTLibraryViewModel = koinInject(),
) {
val state by viewModel.state.collectAsState()
viewModel.setXPub(XPUB)
when (state) {
NFTLibraryState.Loading -> LoadingScreen()
is NFTLibraryState.Content -> {
SongList(songs = (state as NFTLibraryState.Content).songs, onPlaySong, onConnectWalletClick)
}
}

}

@OptIn(ExperimentalTextApi::class)
@Composable
fun SongList(songs: List<Song>, onPlaySong: (Song) -> Unit, onConnectWalletClick: () -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp)
.verticalScroll(state = rememberScrollState())
.testTag(TAG_NFTLIBRARY_SCREEN)
) {
Text(
Expand All @@ -75,29 +61,59 @@ fun SongList(songs: List<Song>, onPlaySong: (Song) -> Unit, onConnectWalletClick
brush = textGradient(SteelPink, CerisePink)
)
)
if (savedSongModels.isNotEmpty() ||
savedAlbumsModels.isNotEmpty() ||
libraryArtistListModels.isNotEmpty()
) {
SearchBar(
placeholderResId = R.string.library_search,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp),
)
when (state) {
NFTLibraryState.Loading -> LoadingScreen()
NFTLibraryState.NoWalletFound -> EmptyNFTListScreen(onConnectWalletClick)
is NFTLibraryState.Content -> {
SongList(
songs = (state as NFTLibraryState.Content).songs,
onPlaySong = onPlaySong
)
}

}
}

}

@Composable
fun EmptyNFTListScreen(onConnectWalletClick: () -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.testTag(TAG_NFTLIBRARY_SCREEN)
) {
Text(
text = stringResource(id = R.string.title_nft_library),
)

PrimaryButton(text = "Connect Wallet", onClick = {
Log.d("NFTLibraryScreen", "Login")
onConnectWalletClick.invoke()
})
}
}

@Composable
fun SongList(songs: List<Song>, onPlaySong: (Song) -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = rememberScrollState())
.testTag(TAG_NFTLIBRARY_SCREEN)
) {
// TODO: Implement Search
// SearchBar(
// placeholderResId = R.string.library_search,
// modifier = Modifier
// .fillMaxWidth()
// .padding(vertical = 16.dp),
// )
if (songs.isNotEmpty()) {
songs.forEach { song ->
RowSongItem(song = song, onClick = onPlaySong)
}
}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,32 @@ class NFTLibraryViewModel(
private val walletConnectManager: WalletConnectUseCase
) : ViewModel() {

private val xPub: MutableStateFlow<String?> = MutableStateFlow(null)

private var _state: StateFlow<NFTLibraryState> = xPub.filterNotNull().flatMapLatest { xPub ->
useCase.getAllWalletNFTSongs(xPub).mapLatest {
private var _state: StateFlow<NFTLibraryState> =
useCase.getAllWalletNFTSongs().mapLatest {
NFTLibraryState.Content(it)
}
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = NFTLibraryState.Loading
)

}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = NFTLibraryState.NoWalletFound
)

val state: StateFlow<NFTLibraryState>
get() = _state

fun setXPub(xPub: String) {
this.xPub.value = xPub
if(!walletConnectManager.isConnected()) {
walletConnectManager.connect(xPub)
}

viewModelScope.launch {
useCase.getWalletNFTs()
}
}
// init {
// viewModelScope.launch {
// useCase.getWalletNFTs()
// }
// }
}

sealed interface NFTLibraryState {
data object Loading : NFTLibraryState

data object NoWalletFound : NFTLibraryState

data class Content(val songs: List<Song>) : NFTLibraryState
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.newm.screens.profile
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -31,7 +32,7 @@ fun ProfileBanner(
model = avatarUrl,
modifier = Modifier
.size(128.dp)
.offset(x = 20.dp, y = 113.dp)
.align(Alignment.BottomCenter)
.clip(CircleShape),
contentScale = ContentScale.Crop,
contentDescription = null,
Expand Down
Loading

0 comments on commit 4bd758d

Please sign in to comment.