Skip to content

Commit

Permalink
Display coupons with images
Browse files Browse the repository at this point in the history
  • Loading branch information
Maruchin1 committed Apr 11, 2023
1 parent a618373 commit e984dea
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 325 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

1 change: 0 additions & 1 deletion .idea/misc.xml

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

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation(libs.navigation.compose)
implementation(libs.hilt.android)
implementation(libs.hilt.navigation.compose)
implementation(libs.coil)
kapt(libs.hilt.android.compiler)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".MyApplication"
android:allowBackup="true"
Expand All @@ -16,7 +19,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.DomainDrivenAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package com.maruchin.domaindrivenandroid.data.coupon

import java.net.URL
import java.util.Currency

data class Coupon(
val id: String,
val title: String,
val subtitle: String,
val value: Money,
val name: String,
val price: Money,
val image: URL,
)

val sampleForHomeCoupons = listOf(
val sampleCoupons = listOf(
Coupon(
id = "1",
title = "Coupon for Allegro",
subtitle = "Free delivery with Allegro Smart",
value = Money(value = 50.0, currency = Currency.getInstance("PLN"))
name = "Cheesburger with fries",
price = Money(value = 17.99, currency = Currency.getInstance("USD")),
image = URL("https://raw.githubusercontent.com/Maruchin1/domain-driven-android/master/images/cheesburger_with_fries_coupon.jpeg"),
),
Coupon(
id = "2",
title = "Coupon for H&M",
subtitle = "Fashion and quality clothes at a good price",
value = Money(value = 100.0, currency = Currency.getInstance("PLN"))
name = "Chicekburger with fries",
price = Money(value = 15.99, currency = Currency.getInstance("USD")),
image = URL("https://raw.githubusercontent.com/Maruchin1/domain-driven-android/master/images/chickenburger_with_fries_coupon.jpeg"),
),
Coupon(
id = "3",
title = "Coupon for Ikea",
subtitle = "Furniture and interior design for your home",
value = Money(value = 100.0, currency = Currency.getInstance("PLN"))
name = "Chicken nuggets with fries",
price = Money(value = 20.99, currency = Currency.getInstance("USD")),
image = URL("https://raw.githubusercontent.com/Maruchin1/domain-driven-android/master/images/chicken_nuggets_with_fries_coupon.jpeg"),
),
Coupon(
id = "4",
title = "Designer brands at TK Maxx",
subtitle = "Hunt for stylish pearls and unique products",
value = Money(value = 100.0, currency = Currency.getInstance("PLN"))
name = "2 x Milkshake",
price = Money(value = 8.99, currency = Currency.getInstance("USD")),
image = URL("https://raw.githubusercontent.com/Maruchin1/domain-driven-android/master/images/two_milkshakes_coupon.jpeg"),
),
Coupon(
id = "5",
title = "Coupon for Amazon.pl",
subtitle = "Thousands of products in one place",
value = Money(value = 94.0, currency = Currency.getInstance("PLN"))
)
name = "2 x Soda drink",
price = Money(value = 6.99, currency = Currency.getInstance("USD")),
image = URL("https://raw.githubusercontent.com/Maruchin1/domain-driven-android/master/images/two_soda_drinks_coupon.jpeg"),
),
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.maruchin.domaindrivenandroid.data.coupon

import com.maruchin.domaindrivenandroid.data.category.Category
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class CouponsRepository @Inject constructor() {

suspend fun getCouponsFromCategory(category: Category): List<Coupon> {
return when (category.id) {
"for_home" -> sampleForHomeCoupons
else -> emptyList()
}
suspend fun getAllCoupons(): List<Coupon> {
return sampleCoupons
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.maruchin.domaindrivenandroid.data.coupon

import java.text.DecimalFormat
import java.util.Currency

data class Money(val value: Double, val currency: Currency)
data class Money(val value: Double, val currency: Currency) {

override fun toString(): String {
val formatter = DecimalFormat.getCurrencyInstance()
formatter.currency = currency
return formatter.format(value)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fun NavGraphBuilder.homeScreen() {
composable(HOME_ROUTE) {
val viewModel = hiltViewModel<HomeViewModel>()
val state by viewModel.uiState.collectAsState()
HomeScreen(state = state, onSelectCategory = viewModel::selectCategory)
HomeScreen(state = state)
}
}
Loading

0 comments on commit e984dea

Please sign in to comment.