Ajustando o conteúdo das Activitys e a navegação#89
Ajustando o conteúdo das Activitys e a navegação#89giseletoledo wants to merge 11 commits intodevpass-tech:mainfrom
Conversation
There was a problem hiding this comment.
Gi, baixei o código e quando clico no ver mais o aplicativo está crashando com o erro abaixo
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.devpass.spaceapp/com.devpass.spaceapp.presentation.LaunchDetailsActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to com.devpass.spaceapp.data.model.NextLaunchesModel
| binding.viewPager.adapter = launchDetailsPagerAdapter | ||
|
|
||
| // Adiciona as abas ao TabLayout | ||
| val titles = arrayOf("Overview", "Mission", "Rocket") |
There was a problem hiding this comment.
Os títulos são "Details", "Rocket", "Launchpad", e poderiamos deixar esses textos no string.xml
| val launch = intent.getSerializableExtra("nextLaunch") as NextLaunchesModel | ||
|
|
||
| // Preencher os campos com as informações do objeto launch | ||
| binding.launchTitleTextView.text = launch.name |
There was a problem hiding this comment.
Não está errado, mas a gente tratar as variáveis com a extension do kotlin .apply.
Ficaria mais ou menos assim
binding.apply { lunchTitleTextView.text = launch.name launchStatusTextView.text = launch.date_utc //outros elementos da view }
| binding.launchTitleTextView.text = launch.name | ||
| binding.launchDateTextView.text = launch.date_utc | ||
| binding.launchStatusTextView.text = launch.status.toString() | ||
| if(launch.links.image.small.isEmpty()) { |
There was a problem hiding this comment.
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"
|
|
||
| // Exibe o nome da missão em um TextView | ||
| binding.launchDescription.text = launch?.name ?: "Nome da missão desconhecido" | ||
| val fullDescription = launch?.details ?: "Erro ao carregar detalhes" |
There was a problem hiding this comment.
Podemos colocar o texto no string.xml
| val shortDescription = fullDescription.lineSequence().take(1).joinToString("\n") | ||
| binding.launchDescriptionFragment.text = shortDescription | ||
|
|
||
| val viewMore:String = "View more..." |
There was a problem hiding this comment.
podemos colocar o ´string.xml´
Descrição e Solução
Checklist:
Evidências:
| print | print |