-
Notifications
You must be signed in to change notification settings - Fork 29
Ajustando o conteúdo das Activitys e a navegação #89
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
b73285c
7d85d3b
19b86b6
550008f
3fe93f9
157dfa2
38b2039
591343f
abc2db7
ed57d01
98cd50e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,55 @@ | ||
package com.devpass.spaceapp.presentation | ||
|
||
class LaunchActivity { | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import com.bumptech.glide.Glide | ||
import com.devpass.spaceapp.R | ||
import com.devpass.spaceapp.data.model.NextLaunchesModel | ||
import com.devpass.spaceapp.databinding.ActivityLaunchBinding | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
|
||
class LaunchActivity : AppCompatActivity() { | ||
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.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. Choose a reason for hiding this commentThe 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 |
||
// 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) | ||
} | ||
|
||
// 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("Overview", "Mission", "Rocket") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Os títulos são "Details", "Rocket", "Launchpad", e poderiamos deixar esses textos no |
||
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() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.devpass.spaceapp.presentation | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
|
@@ -31,8 +32,24 @@ class LaunchDetailsFragment : Fragment() { | |
// Recupera o objeto NextLaunchesModel dos argumentos | ||
val launch = arguments?.getSerializable(ARG_LAUNCH) as NextLaunchesModel? | ||
|
||
// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Podemos colocar o texto no |
||
|
||
// Exibe as 3 primeiras linhas de details em um TextView | ||
val shortDescription = fullDescription.lineSequence().take(1).joinToString("\n") | ||
binding.launchDescriptionFragment.text = shortDescription | ||
|
||
val viewMore:String = "View more..." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. podemos colocar o ´string.xml´ |
||
|
||
val viewMoreLink = binding.launchViewMore | ||
|
||
viewMoreLink.text = viewMore | ||
|
||
viewMoreLink.setOnClickListener { | ||
val intent = Intent(context, LaunchDetailsActivity::class.java) | ||
intent.putExtra("fullLaunchDescription", fullDescription) | ||
startActivity(intent) | ||
} | ||
|
||
} | ||
|
||
companion object { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presentation.LaunchActivity"> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="16dp"> | ||
|
||
<ImageView | ||
android:id="@+id/launchImage" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
android:scaleType="centerCrop" | ||
android:layout_gravity="center" | ||
android:src="@drawable/ic_launcher_background" | ||
android:contentDescription="@string/imagem_nextlaunch" /> | ||
|
||
<TextView | ||
android:id="@+id/launch_number" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:layout_gravity="center" | ||
android:textColor="@color/black" | ||
android:textSize="18sp" | ||
android:textStyle="bold" | ||
android:text="@string/launch_number_text" /> | ||
|
||
<TextView | ||
android:id="@+id/launchTitleTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
|
||
android:textAllCaps="true" | ||
android:layout_marginBottom="8dp" | ||
android:layout_gravity="center" | ||
android:fontFamily="@font/roboto" | ||
android:textStyle="normal" | ||
android:text="@string/titulo_launch" | ||
|
||
android:textColor="@color/black" | ||
android:textSize="24sp" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/launchDateTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:textStyle="normal" | ||
android:fontFamily="@font/roboto" | ||
android:textColor="@color/black" | ||
android:textSize="14sp" | ||
android:text="@string/data_launch" /> | ||
|
||
<TextView | ||
android:id="@+id/launchStatusTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="@font/roboto" | ||
android:layout_gravity="center" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:textStyle="normal" | ||
android:textColor="@color/black" | ||
android:textSize="14sp" | ||
android:text="@string/status_launch" /> | ||
|
||
<com.google.android.material.tabs.TabLayout | ||
android:id="@+id/tab_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/white" | ||
android:fontFamily="@font/roboto" | ||
android:layout_marginTop="8dp" | ||
android:elevation="8dp" | ||
android:textAllCaps="true" | ||
android:minHeight="?attr/actionBarSize" | ||
app:tabGravity="fill" | ||
app:tabIndicatorColor="@color/tabSelectedText" | ||
app:tabMode="fixed" | ||
app:tabSelectedTextColor="@color/tabSelectedIndicator" | ||
app:tabTextColor="@color/tabUnselectedText" | ||
/> | ||
|
||
<androidx.viewpager2.widget.ViewPager2 | ||
android:id="@+id/view_pager" | ||
android:backgroundTint="@color/primaryColor" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginTop="14dp" | ||
/> | ||
</LinearLayout> | ||
</ScrollView> | ||
|
||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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 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 }