generated from getyourguide/ios-challenge-refactor
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from getyourguide/addingCompose
Adding Compose to the Code and removing XML
- Loading branch information
Showing
18 changed files
with
448 additions
and
293 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,88 @@ | ||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.kotlin.compose) | ||
alias(libs.plugins.ksp) | ||
} | ||
|
||
android { | ||
namespace = "com.getyourguide.interview" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "com.getyourguide.interview" | ||
minSdk = 26 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildFeatures { | ||
viewBinding = true | ||
compose = true | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_21 | ||
targetCompatibility = JavaVersion.VERSION_21 | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(21) | ||
} | ||
|
||
packagingOptions { | ||
exclude("META-INF/*.kotlin_module") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.core.ktx) | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.11.0") | ||
implementation("androidx.fragment:fragment-ktx:1.6.2") | ||
|
||
// UI | ||
implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||
|
||
//Retrofit | ||
implementation("com.squareup.retrofit2:retrofit:2.9.0") | ||
implementation("com.squareup.retrofit2:converter-moshi:2.9.0") | ||
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") | ||
|
||
//Moshi | ||
implementation(libs.moshi) | ||
ksp(libs.moshi.codegen) | ||
|
||
//Image loader | ||
implementation(libs.coil) | ||
implementation(libs.coil.compose) | ||
|
||
implementation(platform(libs.androidx.compose.bom)) | ||
implementation(libs.androidx.ui) | ||
implementation(libs.androidx.ui.graphics) | ||
implementation(libs.androidx.ui.tooling.preview) | ||
implementation(libs.androidx.material3) | ||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
debugImplementation(libs.androidx.ui.tooling) | ||
debugImplementation(libs.androidx.ui.test.manifest) | ||
|
||
// Tests | ||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") | ||
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0") | ||
testImplementation("org.mockito:mockito-inline:5.2.0") | ||
testImplementation("com.google.truth:truth:1.2.0") | ||
testImplementation("app.cash.turbine:turbine:0.13.0") | ||
} |
This file contains 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 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,25 @@ | ||
package com.getyourguide.interview | ||
|
||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.ColorScheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
|
||
internal object Colors { | ||
internal val GREY_100 = Color(0xFFEBEEF1) | ||
internal val BASKING_YELLOW = Color(0xFFFFD938) | ||
internal val BLUE_900 = Color(0xFF1A2B49) | ||
internal val WHITE = Color(0xFFFFFFFF) | ||
internal val GREY_800 = Color(0xFF31343D) | ||
internal val GUIDING_RED = Color(0xFFFE5533) | ||
|
||
} | ||
|
||
|
||
val ColorScheme.labelPrimary: Color | ||
@Composable | ||
get() = if (!isSystemInDarkTheme()) Colors.BLUE_900 else Colors.WHITE | ||
|
||
val ColorScheme.surfaceSecondary: Color | ||
@Composable | ||
get() = if (!isSystemInDarkTheme()) Colors.GREY_100 else Colors.GREY_800 |
109 changes: 109 additions & 0 deletions
109
app/src/main/java/com/getyourguide/interview/RatingBar.kt
This file contains 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,109 @@ | ||
package com.getyourguide.interview | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.IntrinsicSize | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableFloatStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.drawWithContent | ||
import androidx.compose.ui.graphics.drawscope.clipRect | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.semantics.testTag | ||
import androidx.compose.ui.unit.dp | ||
import kotlin.math.roundToInt | ||
|
||
@Composable | ||
fun RatingBar( | ||
modifier: Modifier = Modifier, | ||
rating: Float, | ||
rounding: Boolean = true, | ||
) { | ||
var currentRating by remember(rating) { mutableFloatStateOf(rating) } | ||
val roundedRating = buildRoundedRating(currentRating, rounding) | ||
Row( | ||
modifier = modifier | ||
.height(16.dp) | ||
.width(IntrinsicSize.Min) | ||
.wrapContentWidth(), | ||
horizontalArrangement = Arrangement.spacedBy(1.dp), | ||
) { | ||
for (step in 1..5) { | ||
val stepRating = when { | ||
roundedRating > step -> 1f | ||
step.rem(roundedRating) < 1 -> roundedRating - (step - 1f) | ||
else -> 0f | ||
} | ||
RatingStar( | ||
modifier = Modifier | ||
.semantics { | ||
testTag = "RatingStar:$step" | ||
}, | ||
rating = stepRating, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun RatingStar( | ||
modifier: Modifier = Modifier, | ||
rating: Float, | ||
) { | ||
val starDrawable = R.drawable.ic_star_fill | ||
Box( | ||
modifier = modifier | ||
.fillMaxHeight() | ||
.aspectRatio(1f), | ||
) { | ||
Icon( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.drawWithContent { | ||
clipRect(left = size.width * rating) { | ||
this@drawWithContent.drawContent() | ||
} | ||
}, | ||
painter = painterResource(id = starDrawable), | ||
tint = MaterialTheme.colorScheme.surfaceSecondary, | ||
contentDescription = null, | ||
) | ||
Icon( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.starClip(rating), | ||
painter = painterResource(id = starDrawable), | ||
tint = Colors.BASKING_YELLOW, | ||
contentDescription = null, | ||
) | ||
} | ||
} | ||
|
||
private fun Modifier.starClip(rating: Float): Modifier { | ||
return this.drawWithContent { | ||
clipRect(right = size.width * rating) { | ||
this@drawWithContent.drawContent() | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun buildRoundedRating(rating: Float, rounding: Boolean) = | ||
if (rounding) { | ||
(rating * 2).roundToInt() / 2f | ||
} else { | ||
rating | ||
} |
27 changes: 0 additions & 27 deletions
27
app/src/main/java/com/getyourguide/interview/ReviewsAdapter.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.