Skip to content

Commit

Permalink
Merge pull request #3 from getyourguide/addingCompose
Browse files Browse the repository at this point in the history
Adding Compose to the Code and removing XML
  • Loading branch information
savvisingh authored Oct 18, 2024
2 parents 0a2906e + 5f872ef commit cf6a278
Show file tree
Hide file tree
Showing 18 changed files with 448 additions and 293 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ As a potential traveler, I want to be able to fetch reviews for one of our most
We’ll evaluate platform, architecture, testing, and problem solving-knowledge.

What you’ll need:
- Java 17 and Android Studio configured
- Java 21 and Android Studio configured
73 changes: 0 additions & 73 deletions app/build.gradle

This file was deleted.

88 changes: 88 additions & 0 deletions app/build.gradle.kts
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")
}
4 changes: 2 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand All @@ -18,4 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
25 changes: 25 additions & 0 deletions app/src/main/java/com/getyourguide/interview/Colors.kt
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 app/src/main/java/com/getyourguide/interview/RatingBar.kt
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 app/src/main/java/com/getyourguide/interview/ReviewsAdapter.kt

This file was deleted.

Loading

0 comments on commit cf6a278

Please sign in to comment.