Skip to content

Commit

Permalink
Added Playlist Detail Shared Module, added API integration
Browse files Browse the repository at this point in the history
  • Loading branch information
AshuTyagi16 committed Jan 9, 2024
1 parent c7a65ee commit e3e6ba6
Show file tree
Hide file tree
Showing 67 changed files with 814 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ shared/core-base/build
shared/core-logger/build
shared/core-network/build
shared/core-preferences/build
shared/feature-homepage/build
shared/feature-homepage/build
shared/feature-playlist-detail/build
4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dependencies {
// Feature HomePage Module
implementation(project(":feature-homepage"))

// Feature Playlist Detail Module
implementation(project(":feature-playlist-detail"))

// Shared Module
implementation(project(":shared"))

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/spotify/app/kmp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.spotify.app.kmp.ui.SpotifyRootView
import com.spotify.app.kmp.ui.theme.SpotifyKMPTheme

class MainActivity : ComponentActivity() {
Expand Down
54 changes: 0 additions & 54 deletions app/src/main/java/com/spotify/app/kmp/SpotifyRootView.kt

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/com/spotify/app/kmp/navigation/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sealed class Screen(val route: String) {

data object HomePage : Screen("home_page")

data object PlaylistTracks : Screen("playlist_tracks")
data object PlaylistDetail : Screen("playlist_detail")

data object AlbumTracks : Screen("album_tracks")

Expand Down
107 changes: 107 additions & 0 deletions app/src/main/java/com/spotify/app/kmp/ui/SpotifyRootView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.spotify.app.kmp.ui

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.spotify.app.feature_homepage.shared.ui.HomePageViewModel
import com.spotify.app.feature_homepage.ui.HomePageComposable
import com.spotify.app.feature_playlist_detail.shared.ui.PlaylistDetailViewModel
import com.spotify.app.feature_playlist_detail.ui.PlaylistDetailComposable
import com.spotify.app.kmp.navigation.Screen
import org.koin.androidx.compose.koinViewModel

private const val ANIMATION_DURATION = 500
private const val PLAYLIST_ID = "PLAYLIST_ID"

@Composable
fun SpotifyRootView() {

val navController = rememberNavController()

NavHost(navController = navController, startDestination = Screen.HomePage.route) {

composable(
route = Screen.HomePage.route,
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(ANIMATION_DURATION)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(ANIMATION_DURATION)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(ANIMATION_DURATION)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(ANIMATION_DURATION)
)
}
) {
val viewModel = koinViewModel<HomePageViewModel>()
HomePageComposable(
viewModel = viewModel,
onPlaylistClick = { playlistId ->
navController.navigate(
Screen.PlaylistDetail.withArgs(playlistId)
)
}
)
}

composable(
route = Screen.PlaylistDetail.route + "/{$PLAYLIST_ID}",
arguments = listOf(
navArgument(PLAYLIST_ID) {
type = NavType.StringType
nullable = false
},
),
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(ANIMATION_DURATION)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
animationSpec = tween(ANIMATION_DURATION)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(ANIMATION_DURATION)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
animationSpec = tween(ANIMATION_DURATION)
)
}
) { entry ->
val playlistId = entry.arguments?.getString(PLAYLIST_ID)!!
val viewModel = koinViewModel<PlaylistDetailViewModel>()
PlaylistDetailComposable(
playlistId = playlistId,
viewModel = viewModel
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.spotify.app.feature_homepage.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -28,13 +29,14 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.spotify.app.feature_homepage.shared.domain.model.album.AlbumItem
import com.spotify.app.feature_homepage.shared.domain.model.playlist.PlaylistItem
import com.spotify.app.feature_homepage.shared.ui.HomePageViewModel
import kotlinx.coroutines.launch

@Composable
fun HomePageComposable(viewModel: HomePageViewModel) {
fun HomePageComposable(
viewModel: HomePageViewModel,
onPlaylistClick: (playlistId: String) -> Unit
) {
LaunchedEffect(viewModel) {
launch {
viewModel.fetchFeaturedPlaylists()
Expand Down Expand Up @@ -95,6 +97,9 @@ fun HomePageComposable(viewModel: HomePageViewModel) {
.clip(RoundedCornerShape(8.dp))
.width(200.dp)
.height(200.dp)
.clickable {
onPlaylistClick.invoke(it.id)
}
)

Text(
Expand Down
1 change: 1 addition & 0 deletions feature-playlist-detail/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
76 changes: 76 additions & 0 deletions feature-playlist-detail/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
}

android {
namespace = "com.spotify.app.feature_playlist_detail"
compileSdk = libs.versions.compileSdkVersion.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdkVersion.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = libs.versions.jvmTargetVersion.get()
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
)
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.kotlinCompilerExtensionVersion.get()
}
}

dependencies {

// Shared Feature Playlist Detail Module
implementation(project(":shared:feature-playlist-detail"))

// Coil (Image Loading)
implementation(libs.coil)

// Core Ktx
implementation(libs.core.ktx)

// Lifecycle Ktx
implementation(libs.lifecycle.runtime.ktx)

// Koin
implementation(libs.koin)
implementation(libs.koin.android)

//Compose
implementation(libs.activity.compose)
implementation(platform(libs.compose.bom))
implementation(libs.ui)
implementation(libs.ui.graphics)
implementation(libs.ui.tooling.preview)
implementation(libs.material3)

// Testing
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
Empty file.
21 changes: 21 additions & 0 deletions feature-playlist-detail/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http:https://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.spotify.app.feature_playlist_detail

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http:https://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.spotify.app.feature_playlist_detail.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature-playlist-detail/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit e3e6ba6

Please sign in to comment.