Skip to content

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.devpass.spaceapp">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -11,7 +11,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SpaceApp">

<activity
android:name=".presentation.LaunchActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".presentation.nextlaunches.NextLaunchesActivity"
android:exported="true">
Expand All @@ -21,10 +27,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

<meta-data
android:name="preloaded_fonts"
Expand Down
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
Copy link
Contributor

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 }

binding.launchDateTextView.text = launch.date_utc
binding.launchStatusTextView.text = launch.status.toString()
if(launch.links.image.small.isEmpty()) {
Copy link
Contributor

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"

// 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")
Copy link
Contributor

Choose a reason for hiding this comment

The 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 string.xml

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
Expand Up @@ -2,55 +2,23 @@ package com.devpass.spaceapp.presentation

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.devpass.spaceapp.R
import com.devpass.spaceapp.data.model.NextLaunchesModel
import com.devpass.spaceapp.databinding.ActivityLaunchDetailsBinding
import com.google.android.material.tabs.TabLayoutMediator

private const val ARG_LAUNCH = "fullLaunchDescription"

class LaunchDetailsActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = ActivityLaunchDetailsBinding.inflate(layoutInflater)
setContentView(binding.root)

// Recuperar o objeto launch da intent
val launch = intent.getSerializableExtra("nextLaunch") as NextLaunchesModel
val launch = intent.getSerializableExtra(ARG_LAUNCH) as NextLaunchesModel

// Preencher os campos com as informações do objeto launch
binding.launchTitleTextView.text = launch.name
binding.launchDateTextView.text = launch.date_utc.toString()
binding.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)
}

// 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")
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()
binding.launchDescriptionTextView.text = launch.details
}
}
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
Expand Down Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podemos colocar o texto no string.xml


// 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..."
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager

import androidx.recyclerview.widget.RecyclerView
import com.devpass.spaceapp.R
import com.devpass.spaceapp.RetrofitService
import com.devpass.spaceapp.data.api.SpaceXAPIClient
import com.devpass.spaceapp.data.datasource.LaunchesListDataSourceImpl
import com.devpass.spaceapp.data.model.NextLaunchesModel
import com.devpass.spaceapp.data.repository.LaunchesListRepositoryImpl
import com.devpass.spaceapp.databinding.ActivityMainBinding
import com.devpass.spaceapp.presentation.LaunchDetailsActivity
import com.devpass.spaceapp.presentation.LaunchActivity
import com.devpass.spaceapp.presentation.NextLaunchesAdapter

class NextLaunchesActivity : AppCompatActivity() {
Expand Down Expand Up @@ -53,7 +51,7 @@ class NextLaunchesActivity : AppCompatActivity() {
}

private fun onLaunchClick(launch: NextLaunchesModel) {
val intent = Intent(this, LaunchDetailsActivity::class.java)
val intent = Intent(this, LaunchActivity::class.java)
intent.putExtra("nextLaunch", launch) // <- corrigido para "nextLaunch"
startActivity(intent)
}
Expand Down
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>
Loading