Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions solutions/devsprint-gustavo-santorio-2/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

implementation "com.squareup.retrofit2:retrofit:+"
implementation 'com.squareup.retrofit2:converter-gson:+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</activity>

<activity
android:name=".presentation.LaunchpadDetailsActivity"
android:name=".launchpad.presentation.LaunchpadDetailsActivity"
android:exported="true"/>

<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.devpass.spaceapp.data.api

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object NetworkModule {
val retrofitInstance by lazy {
Retrofit.Builder()
.baseUrl("https://api.spacexdata.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.devpass.spaceapp.data.api

import com.devpass.spaceapp.launchpad.domain.dto.LaunchpadDTO
import retrofit2.http.GET
import retrofit2.http.Query

interface SpaceXAPIService {

@GET("/v4/launchpads/{id}")
suspend fun fetchLaunchpadDetails(@Query("id") id: String): LaunchpadDTO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.devpass.spaceapp.launchpad.data

import com.devpass.spaceapp.data.api.NetworkModule
import com.devpass.spaceapp.data.api.SpaceXAPIService
import com.devpass.spaceapp.launchpad.domain.repository.FetchLaunchesRepository
import com.devpass.spaceapp.launchpad.domain.model.LaunchpadVO

class FetchLaunchesRepositoryImpl(
private val service: SpaceXAPIService = NetworkModule.retrofitInstance.create(SpaceXAPIService::class.java)
) : FetchLaunchesRepository {
override suspend fun fetchLaunchpadDetails(id: String): Result<LaunchpadVO> {
return runCatching {
val response = service.fetchLaunchpadDetails(id = id)
with(response) {
LaunchpadVO(
name = name,
fullName = full_name,
region = region,
launchAttempts = launch_attempts.toString(),
launchSuccesses = launch_successes.toString()
)
}
}
}
return runCatching {
val response = service.fetchLaunchpadDetails(id = id)
with(response) {
LaunchpadVO(
name = name,
fullName = full_name,
region = region,
launchAttempts = launch_attempts.toString(),
launchSuccesses = launch_successes.toString()
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.devpass.spaceapp.launchpad.domain.dto

data class LaunchpadDTO(
val full_name: String,
val id: String,
val latitude: Double,
val launch_attempts: Int,
val launch_successes: Int,
val launches: List<String>,
val locality: String,
val longitude: Double,
val name: String,
val region: String,
val rockets: List<String>,
val status: String,
val timezone: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.devpass.spaceapp.launchpad.domain.model

data class LaunchpadVO(
val name: String,
val fullName: String,
val region: String,
val launchAttempts: String,
val launchSuccesses: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.devpass.spaceapp.launchpad.domain.repository

import com.devpass.spaceapp.launchpad.domain.model.LaunchpadVO

interface FetchLaunchesRepository {
suspend fun fetchLaunchpadDetails(id: String): Result<LaunchpadVO>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devpass.spaceapp.presentation
package com.devpass.spaceapp.launchpad.presentation

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toBottomOf="@id/include_toolbar"
tools:context=".presentation.LaunchpadDetailsActivity" />
tools:context=".launchpad.presentation.LaunchpadDetailsActivity" />

<TextView
android:id="@+id/tv_launchpad"
Expand Down