-
-
Notifications
You must be signed in to change notification settings - Fork 46
Store #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
almuheetushihab
wants to merge
7
commits into
dev
Choose a base branch
from
store
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Store #71
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75431fc
feat: initial structure
almuheetu c78481a
fix: text style change
almuheetushihab 6ac36b2
feat: checkout screen
almuheetushihab 757df1d
fix:categories screen design
almuheetushihab 6fc980e
feature: product list api integration
almuheetushihab 135c9f8
feature: category api integration
almuheetushihab 4f12e3a
feature: product details api integration
almuheetushihab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,3 +56,4 @@ include(":exoplayer") | |
| include(":cms") | ||
| include(":popbackstack") | ||
| include(":benchmarks") | ||
| include(":store") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| plugins { | ||
| alias(libs.plugins.android.library) | ||
| alias(libs.plugins.kotlin.android) | ||
| alias(libs.plugins.kotlin.serialization) | ||
| alias(libs.plugins.compose) | ||
| alias(libs.plugins.ksp) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "org.imaginativeworld.whynotcompose.store" | ||
| compileSdk = BuildConfigConst.compileSdk | ||
|
|
||
| defaultConfig { | ||
| minSdk = BuildConfigConst.minSdk | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = "17" | ||
|
|
||
| freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn" | ||
|
|
||
| // Enable experimental compose APIs | ||
| freeCompilerArgs = | ||
| freeCompilerArgs + "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api" | ||
| freeCompilerArgs = | ||
| freeCompilerArgs + "-opt-in=androidx.compose.animation.ExperimentalAnimationApi" | ||
| freeCompilerArgs = | ||
| freeCompilerArgs + "-opt-in=androidx.compose.ui.ExperimentalComposeUiApi" | ||
| freeCompilerArgs = | ||
| freeCompilerArgs + "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi" | ||
| } | ||
|
|
||
| ksp { | ||
| arg("room.schemaLocation", "$projectDir/schemas") | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig = true | ||
| compose = true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":base")) | ||
| implementation(project(":common-ui-compose")) | ||
|
|
||
| implementation(libs.kotlin.stdlib) | ||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.appcompat) | ||
| implementation(libs.androidx.swiperefreshlayout) | ||
|
|
||
| // ---------------------------------------------------------------- | ||
| // Compose | ||
| // ---------------------------------------------------------------- | ||
| implementation(platform(libs.androidx.compose.bom)) | ||
|
|
||
| implementation(libs.androidx.compose.ui) | ||
| implementation(libs.androidx.compose.ui.util) | ||
| // Tooling support (Previews, etc.) | ||
| debugImplementation(libs.androidx.compose.ui.tooling) | ||
| implementation(libs.androidx.compose.ui.tooling.preview) | ||
| // Animation | ||
| implementation(libs.androidx.compose.animation) | ||
| // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.) | ||
| implementation(libs.androidx.compose.foundation) | ||
| implementation(libs.androidx.compose.foundation.layout) | ||
| // Material Design | ||
| implementation(libs.androidx.compose.material3) | ||
| implementation(libs.androidx.compose.material3.windowSizeClass) | ||
| // Material design icons | ||
| implementation(libs.androidx.compose.material.iconsCore) | ||
| implementation(libs.androidx.compose.material.iconsExtended) | ||
| // Integration with observables | ||
| implementation(libs.androidx.compose.runtime) | ||
| implementation(libs.androidx.compose.runtime.livedata) | ||
| implementation(libs.androidx.compose.runtime.tracing) | ||
| // compose Navigation Component | ||
| implementation(libs.androidx.navigation.compose) | ||
| // Constraint Layout | ||
| implementation(libs.androidx.constraintlayout.compose) | ||
| // Integration with activities | ||
| implementation(libs.androidx.activity.compose) | ||
|
|
||
| // Jetpack compose Integration for ViewModel | ||
| implementation(libs.androidx.lifecycle.viewmodel.compose) | ||
|
|
||
| // Paging | ||
| implementation(libs.androidx.paging.compose) | ||
|
|
||
| // ---------------------------------------------------------------- | ||
|
|
||
| // Timber | ||
| implementation(libs.timber) | ||
|
|
||
| // Hilt | ||
| implementation(libs.hilt.android) | ||
| ksp(libs.hilt.compiler) | ||
| implementation(libs.androidx.hilt.navigation.compose) | ||
|
|
||
| // Retrofit | ||
| implementation(libs.retrofit.core) | ||
| implementation(libs.okhttp.logging) | ||
| implementation("com.squareup.retrofit2:retrofit:2.9.0") | ||
| implementation("com.squareup.retrofit2:converter-gson:2.9.0") | ||
|
|
||
| // Moshi | ||
| implementation(libs.retrofit.moshi) | ||
| implementation(libs.moshi.kotlin) | ||
| ksp(libs.moshi.kotlin.codegen) | ||
|
|
||
| // Room Persistence Library | ||
| implementation(libs.room.runtime) | ||
| ksp(libs.room.compiler) | ||
|
|
||
| // Room: Kotlin Extensions and Coroutines support for Room | ||
| implementation(libs.room.ktx) | ||
|
|
||
| // Coil | ||
| implementation(libs.coil.compose) | ||
| implementation(libs.coil.svg) | ||
| implementation(libs.coil.network) | ||
|
|
||
| // Serialization | ||
| implementation(libs.kotlinx.serialization.json) | ||
|
|
||
| // Haze | ||
| implementation(libs.haze) | ||
| implementation(libs.haze.materials) | ||
|
|
||
| implementation(libs.androidx.material3) | ||
| implementation(libs.material) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest> | ||
|
|
||
| </manifest> |
62 changes: 62 additions & 0 deletions
62
store/src/main/kotlin/com/example/store/datasource/ProductPagingSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.example.store.datasource | ||
|
|
||
| import androidx.paging.PagingSource | ||
| import androidx.paging.PagingState | ||
| import com.example.store.models.product.Product | ||
| import com.example.store.repositories.ProductRepository | ||
| import okio.IOException | ||
| import org.imaginativeworld.whynotcompose.base.network.ApiException | ||
| import retrofit2.HttpException | ||
|
|
||
| class ProductPagingSource( | ||
| private val repository: ProductRepository | ||
| ) : PagingSource<Long, Product>() { | ||
|
|
||
| override suspend fun load(params: LoadParams<Long>): LoadResult<Long, Product> { | ||
| val pagePosition = params.key ?: 1 | ||
|
|
||
| return try { | ||
| val products = repository.getProducts( | ||
| pagePosition | ||
| ) | ||
|
|
||
| if (products == null) { | ||
| LoadResult.Error(ApiException("No data returned!")) | ||
| } else { | ||
| val nextKey = if (products.isEmpty()) { | ||
| null | ||
| } else { | ||
| pagePosition + 1 | ||
| } | ||
|
|
||
| LoadResult.Page( | ||
| data = products, | ||
| prevKey = if (pagePosition == 1L) null else pagePosition - 1, | ||
| nextKey = nextKey | ||
| ) | ||
| } | ||
| } catch (exception: IOException) { | ||
| return LoadResult.Error(exception) | ||
| } catch (exception: HttpException) { | ||
| return LoadResult.Error(exception) | ||
| } catch (exception: ApiException) { | ||
| return LoadResult.Error(exception) | ||
| } | ||
| } | ||
|
|
||
| // The refresh key is used for subsequent refresh calls to PagingSource.load after the initial load | ||
| override fun getRefreshKey(state: PagingState<Long, Product>): Long? { | ||
| // We need to get the previous key (or next key if previous is null) of the page | ||
| // that was closest to the most recently accessed index. | ||
| // Anchor position is the most recently accessed index | ||
| return state.anchorPosition?.let { anchorPosition -> | ||
| state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) | ||
| ?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) | ||
|
|
||
| // For cursor paging use this: | ||
| // https://stackoverflow.com/questions/67691903/how-to-implement-pagingsource-getrefreshkey-for-cursor-based-pagination-androi | ||
| // val anchorPageIndex = state.pages.indexOf(state.closestPageToPosition(anchorPosition)) | ||
| // state.pages.getOrNull(anchorPageIndex + 1)?.prevKey ?: state.pages.getOrNull(anchorPageIndex - 1)?.nextKey | ||
| } | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
store/src/main/kotlin/com/example/store/di/StoreAppModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.example.store.di | ||
|
|
||
| import com.example.store.network.api.CategoriesApiInterface | ||
| import com.example.store.network.api.ProductDetailsApiInterface | ||
| import com.example.store.network.api.ProductsApiInterface | ||
| import com.squareup.moshi.Moshi | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import javax.inject.Named | ||
| import javax.inject.Singleton | ||
| import org.imaginativeworld.whynotcompose.base.network.ApiClient | ||
| import org.imaginativeworld.whynotcompose.base.utils.Constants | ||
| import retrofit2.Retrofit | ||
|
|
||
| @InstallIn(SingletonComponent::class) | ||
| @Module | ||
| class StoreAppModule { | ||
| @Singleton | ||
| @Provides | ||
| @Named("STORE") | ||
| fun provideRetrofit(moshi: Moshi): Retrofit = ApiClient.getRetrofit( | ||
| moshi, | ||
| Constants.STORE_SERVER_ENDPOINT + "/", | ||
| mapOf() | ||
| ) | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideProductApiInterface(@Named("STORE") retrofit: Retrofit): ProductsApiInterface = retrofit.create(ProductsApiInterface::class.java) | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideProductDetailsApiInterface(@Named("STORE") retrofit: Retrofit): ProductDetailsApiInterface = retrofit.create(ProductDetailsApiInterface::class.java) | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideCategoriesApiInterface(@Named("STORE") retrofit: Retrofit): CategoriesApiInterface = retrofit.create(CategoriesApiInterface::class.java) | ||
| } |
3 changes: 3 additions & 0 deletions
3
store/src/main/kotlin/com/example/store/models/categorie/Categories.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||
| package com.example.store.models.categorie | ||||||
|
|
||||||
| class Categories : ArrayList<String>() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extending
Suggested change
|
||||||
14 changes: 14 additions & 0 deletions
14
store/src/main/kotlin/com/example/store/models/categorie/Category.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.store.models.categorie | ||
|
|
||
| data class Category( | ||
| val id: Int, | ||
| val name: String, | ||
| val imageUrl: String | ||
| ) | ||
|
|
||
| val categories = listOf( | ||
| Category(id = 1, name = "Electron-ics", imageUrl = "https://fakestoreapi.com/img/61IBBVJvSDL._AC_SY879_.jpg"), | ||
| Category(id = 2, name = "Jewelery", imageUrl = "https://fakestoreapi.com/img/71pWzhdJNwL._AC_UL640_QL65_ML3_.jpg"), | ||
| Category(id = 3, name = "Men's Clothing", imageUrl = "https://fakestoreapi.com/img/71pWzhdJNwL._AC_UL640_QL65_ML3_.jpg"), | ||
| Category(id = 4, name = "Women's Clothing", imageUrl = "https://fakestoreapi.com/img/61IBBVJvSDL._AC_SY879_.jpg") | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
fakestoreapi.comdocumentation indicates that the/productsendpoint supportslimitandsortquery parameters, but notpage. UsingpagePositionhere will likely not result in correct pagination from the API. You might need to adjust the API call to uselimitand handle pagination manually based on the number of items fetched, or find an alternative API that supports page-based pagination.