-
Notifications
You must be signed in to change notification settings - Fork 29
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
Ajustando o conteúdo das Activitys e a navegação #89
Open
giseletoledo
wants to merge
11
commits into
devpass-tech:main
Choose a base branch
from
giseletoledo:main
base: main
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b73285c
Recriando a LaunchActivity linkando no manifest
giseletoledo 7d85d3b
Registrando a LaunchActivity no manifest
giseletoledo 19b86b6
Corrigindo links entre as Activities
giseletoledo 550008f
Corrigindo view more e adicionando voltar
giseletoledo 3fe93f9
mostrar uma parte do texto e view more
giseletoledo 157dfa2
Adicionando cardView
giseletoledo 38b2039
Texto fixo no strings.xml
giseletoledo 591343f
Codereview refatoração
giseletoledo abc2db7
Testando carregamento de rockets da API
giseletoledo ed57d01
Recriando RocketDetailsActivity
giseletoledo 98cd50e
Visualizando chamada no logcat RocketDetails
giseletoledo 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 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
3 changes: 1 addition & 2 deletions
3
...tions/devsprint-bruno-almeida-2/app/src/main/java/com/devpass/spaceapp/RetrofitService.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
11 changes: 11 additions & 0 deletions
11
...-bruno-almeida-2/app/src/main/java/com/devpass/spaceapp/data/api/RocketdetailAPIClient.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,11 @@ | ||
package com.devpass.spaceapp.data.api | ||
|
||
import com.devpass.spaceapp.data.model.RocketDetailResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface RocketdetailAPIClient { | ||
|
||
@GET("rockets") | ||
suspend fun getRocketDetails(@Query("id") id: String): List<RocketDetailResponse> | ||
} |
10 changes: 10 additions & 0 deletions
10
...meida-2/app/src/main/java/com/devpass/spaceapp/data/datasource/RocketDetailsDataSource.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,10 @@ | ||
package com.devpass.spaceapp.data.datasource | ||
|
||
import com.devpass.spaceapp.data.api.RocketdetailAPIClient | ||
import com.devpass.spaceapp.data.model.RocketDetailResponse | ||
|
||
class RocketDetailsDataSource(private val rocketdetailAPIClient: RocketdetailAPIClient) { | ||
suspend fun getRocketDetails(id: String) : RocketDetailResponse { | ||
return rocketdetailAPIClient.getRocketDetails(id)[0] | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...bruno-almeida-2/app/src/main/java/com/devpass/spaceapp/data/model/RocketDetailResponse.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,10 @@ | ||
package com.devpass.spaceapp.data.model | ||
|
||
import java.io.Serializable | ||
|
||
data class RocketDetailResponse( | ||
val id: String, | ||
val name: String, | ||
val flickr_images: List<String>, | ||
val description: String | ||
) : Serializable |
24 changes: 24 additions & 0 deletions
24
...meida-2/app/src/main/java/com/devpass/spaceapp/data/repository/RocketDetailsRepository.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,24 @@ | ||
package com.devpass.spaceapp.data.repository | ||
|
||
import com.devpass.spaceapp.data.datasource.RocketDetailsDataSource | ||
import com.devpass.spaceapp.data.model.RocketDetailResponse | ||
|
||
class RocketDetailsRepository(private val rocketDetailsDataSource: RocketDetailsDataSource) { | ||
|
||
suspend fun getRocketDetails(id: String): Result<RocketDetailResponse> { | ||
return handleResult(rocketDetailsDataSource.getRocketDetails(id)) | ||
} | ||
|
||
private fun handleResult(rocketDetails: RocketDetailResponse): Result<RocketDetailResponse> { | ||
return try { | ||
Result.success(rocketDetails) | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
81 changes: 80 additions & 1 deletion
81
...int-bruno-almeida-2/app/src/main/java/com/devpass/spaceapp/presentation/LaunchActivity.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 |
---|---|---|
@@ -1,4 +1,83 @@ | ||
package com.devpass.spaceapp.presentation | ||
|
||
class LaunchActivity { | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
|
||
import com.bumptech.glide.Glide | ||
import com.devpass.spaceapp.R | ||
import com.devpass.spaceapp.RetrofitService | ||
import com.devpass.spaceapp.data.api.RocketdetailAPIClient | ||
import com.devpass.spaceapp.data.datasource.RocketDetailsDataSource | ||
import com.devpass.spaceapp.data.model.NextLaunchesModel | ||
import com.devpass.spaceapp.data.repository.RocketDetailsRepository | ||
|
||
import com.devpass.spaceapp.databinding.ActivityLaunchBinding | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
|
||
class LaunchActivity : AppCompatActivity() { | ||
|
||
private val service = RetrofitService.retrofit.create(RocketdetailAPIClient::class.java) | ||
private val rocketDetailsDataSource = RocketDetailsDataSource(service) | ||
private val repository:RocketDetailsRepository = RocketDetailsRepository(rocketDetailsDataSource) | ||
private val rocketDetailsViewModel = RocketDetailsViewModel(repository) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val binding = ActivityLaunchBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
// Recuperar o objeto launch da intent | ||
val launch = intent.getSerializableExtra("nextLaunch") as NextLaunchesModel | ||
|
||
// Preencher os campos com as informações do objeto launch | ||
binding.apply { | ||
launchTitleTextView.text = launch.name | ||
launchDateTextView.text = launch.date_utc | ||
launchStatusTextView.text = launch.status.toString() | ||
} | ||
|
||
if(launch.links.image.small.isEmpty()) { | ||
// caso a URL da imagem seja nula ou vazia, carrega uma imagem padrão | ||
Glide.with(this) | ||
.load(R.drawable.space_logo) | ||
.circleCrop() | ||
.into(binding.launchImage) | ||
} else { | ||
// carrega a imagem usando Glide | ||
Glide.with(this) | ||
.load(launch.links.image.small) | ||
.circleCrop() | ||
.into(binding.launchImage) | ||
} | ||
|
||
rocketDetailsViewModel.rocketDetail.observe(this) { result -> | ||
result.onSuccess { rocketDetail -> | ||
Log.d("LaunchActivity", "Rocket Detail: $rocketDetail") | ||
// faça algo com os dados de RocketDetail | ||
}.onFailure { exception -> | ||
Log.e("LaunchActivity", "Failed to fetch rocket detail", exception) | ||
// trate o erro | ||
} | ||
} | ||
|
||
rocketDetailsViewModel.getRocketDetail(launch.id) | ||
|
||
// Cria uma instância do LaunchDetailsPagerAdapter com as informações do lançamento | ||
val launchDetailsPagerAdapter = LaunchDetailsPagerAdapter(this, launch) | ||
|
||
// Configura o ViewPager para usar o adapter | ||
binding.viewPager.adapter = launchDetailsPagerAdapter | ||
|
||
// Adiciona as abas ao TabLayout | ||
val titles = arrayOf(getString(R.string.tab_title_details), getString(R.string.tab_title_launchpad), getString(R.string.tab_title_rocket)) | ||
for (title in titles) { | ||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(title)) | ||
} | ||
|
||
// Conecta o TabLayout e ViewPager | ||
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position -> | ||
tab.text = titles[position] | ||
}.attach() | ||
} | ||
} |
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
19 changes: 17 additions & 2 deletions
19
...no-almeida-2/app/src/main/java/com/devpass/spaceapp/presentation/RocketDetailsActivity.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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
package com.devpass.spaceapp.presentation | ||
|
||
class RocketDetailsActivity { | ||
} | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
|
||
import com.devpass.spaceapp.databinding.ActivityRocketDetailsBinding | ||
|
||
class RocketDetailsActivity : AppCompatActivity() { | ||
private lateinit var binding: ActivityRocketDetailsBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityRocketDetailsBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
} | ||
} | ||
|
||
|
27 changes: 27 additions & 0 deletions
27
...o-almeida-2/app/src/main/java/com/devpass/spaceapp/presentation/RocketDetailsViewModel.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,27 @@ | ||
package com.devpass.spaceapp.presentation | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.devpass.spaceapp.data.model.RocketDetailResponse | ||
import com.devpass.spaceapp.data.repository.RocketDetailsRepository | ||
|
||
import androidx.lifecycle.LiveData | ||
|
||
import androidx.lifecycle.viewModelScope | ||
|
||
import kotlinx.coroutines.launch | ||
|
||
class RocketDetailsViewModel(private val repository: RocketDetailsRepository) : ViewModel() { | ||
|
||
private val _rocketDetail = MutableLiveData<Result<RocketDetailResponse>>() | ||
val rocketDetail: LiveData<Result<RocketDetailResponse>> | ||
get() = _rocketDetail | ||
|
||
fun getRocketDetail(id: String){ | ||
viewModelScope.launch { | ||
_rocketDetail.value = repository.getRocketDetails(id) | ||
} | ||
} | ||
} | ||
|
||
|
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.
Não está errado, mas nesse caso a gente pode colocar a função no Glide
.error("drawable desejado")
assim a gente evita de fazer um if sem "tanta necessidade"