Skip to content

Commit a3bfcb1

Browse files
Implement navigation from RepositoryListActivity to RepositoryDetailsActivity (#19)
1 parent d3671f8 commit a3bfcb1

File tree

7 files changed

+87
-11
lines changed

7 files changed

+87
-11
lines changed

solutions/devsprint-denis-vieira-1/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
android:roundIcon="@mipmap/ic_launcher_round"
1212
android:supportsRtl="true"
1313
android:theme="@style/Theme.GitHubApp">
14-
<activity
15-
android:name=".presentation.RepositoryDetails"
16-
android:exported="false"
17-
android:label="@string/title_activity_repository_details"
18-
android:theme="@style/Theme.GitHubApp.NoActionBar" />
14+
1915
<activity
2016
android:name=".presentation.RepositoryListActivity"
2117
android:exported="true"
22-
android:label="@string/app_name"
18+
android:label="@string/title_activity_repository_list"
2319
android:theme="@style/Theme.GitHubApp.NoActionBar">
2420
<intent-filter>
2521
<action android:name="android.intent.action.MAIN" />
2622

2723
<category android:name="android.intent.category.LAUNCHER" />
2824
</intent-filter>
2925
</activity>
26+
27+
<activity
28+
android:name=".presentation.RepositoryDetailsActivity"
29+
android:exported="true"
30+
android:label="@string/title_activity_repository_details"
31+
android:theme="@style/Theme.GitHubApp.NoActionBar">
32+
</activity>
33+
3034
</application>
3135

3236
</manifest>

solutions/devsprint-denis-vieira-1/app/src/main/java/com/devpass/githubapp/presentation/RepositoryCellItem.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class RepositoryCellItem(
1010
private val binding: ItemCellRepositoryBinding
1111
) : RecyclerView.ViewHolder(binding.root) {
1212

13-
fun bind(item: Repository) {
14-
with(binding){
13+
fun bind(item: Repository, itemListener: RepositoryListAdapter.RepositoryItemListener?) {
14+
with(binding) {
1515
textviewRepositoryName.text = item.name
1616
textviewOwnerName.text = item.owner.login
1717

@@ -21,6 +21,10 @@ class RepositoryCellItem(
2121
.centerCrop()
2222
.placeholder(R.drawable.ic_placeholder)
2323
.into(imageviewAvatar)
24+
25+
root.setOnClickListener {
26+
itemListener?.onItemClick()
27+
}
2428
}
2529
}
2630
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.devpass.githubapp.presentation
2+
3+
import android.os.Bundle
4+
import android.view.MenuItem
5+
import androidx.appcompat.app.AppCompatActivity
6+
import com.devpass.githubapp.databinding.ActivityDetailsRepositoryBinding
7+
8+
class RepositoryDetailsActivity : AppCompatActivity() {
9+
10+
private lateinit var binding: ActivityDetailsRepositoryBinding
11+
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
binding = ActivityDetailsRepositoryBinding.inflate(layoutInflater)
15+
setContentView(binding.root)
16+
setSupportActionBar(binding.repositoryToolbar)
17+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
18+
supportActionBar?.setDisplayShowHomeEnabled(true)
19+
}
20+
21+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
22+
return when (item.itemId) {
23+
android.R.id.home -> {
24+
finish()
25+
true
26+
}
27+
else -> super.onOptionsItemSelected(item)
28+
}
29+
}
30+
}

solutions/devsprint-denis-vieira-1/app/src/main/java/com/devpass/githubapp/presentation/RepositoryListActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.devpass.githubapp.presentation
22

3+
import android.content.Intent
34
import android.os.Bundle
45
import android.view.Menu
56
import android.view.MenuInflater
@@ -16,7 +17,7 @@ import retrofit2.Call
1617
import retrofit2.Callback
1718
import retrofit2.Response
1819

19-
class RepositoryListActivity : AppCompatActivity() {
20+
class RepositoryListActivity : AppCompatActivity(), RepositoryListAdapter.RepositoryItemListener {
2021

2122
private lateinit var binding: ActivityMainBinding
2223
private val cellItemAdapter = RepositoryListAdapter()
@@ -64,6 +65,8 @@ class RepositoryListActivity : AppCompatActivity() {
6465
}
6566

6667
private fun setupLayout() {
68+
cellItemAdapter.repositoryItemListener = this
69+
6770
binding.contentList.repositoriesRecyclerview.layoutManager =
6871
LinearLayoutManager(baseContext, LinearLayoutManager.VERTICAL, false)
6972
binding.contentList.repositoriesRecyclerview.adapter = cellItemAdapter
@@ -88,4 +91,9 @@ class RepositoryListActivity : AppCompatActivity() {
8891
private fun goToSettings() {
8992

9093
}
94+
95+
override fun onItemClick() {
96+
val intent = Intent(this, RepositoryDetailsActivity::class.java)
97+
startActivity(intent)
98+
}
9199
}

solutions/devsprint-denis-vieira-1/app/src/main/java/com/devpass/githubapp/presentation/RepositoryListAdapter.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.devpass.githubapp.databinding.ItemCellRepositoryBinding
99
class RepositoryListAdapter : RecyclerView.Adapter<RepositoryCellItem>() {
1010

1111
var repositories: List<Repository> = listOf()
12+
var repositoryItemListener: RepositoryItemListener? = null
1213

1314
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepositoryCellItem {
1415
val inflater = LayoutInflater.from(parent.context)
@@ -18,9 +19,12 @@ class RepositoryListAdapter : RecyclerView.Adapter<RepositoryCellItem>() {
1819

1920
override fun onBindViewHolder(holder: RepositoryCellItem, position: Int) {
2021
val item = repositories[position]
21-
holder.bind(item)
22+
holder.bind(item, repositoryItemListener)
2223
}
2324

2425
override fun getItemCount(): Int = repositories.size
2526

27+
interface RepositoryItemListener {
28+
fun onItemClick()
29+
}
2630
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto">
6+
7+
<com.google.android.material.appbar.AppBarLayout
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:theme="@style/Theme.GitHubApp.AppBarOverlay"
11+
app:layout_constraintTop_toTopOf="parent"
12+
app:layout_constraintStart_toStartOf="parent"
13+
app:layout_constraintEnd_toEndOf="parent">
14+
15+
<androidx.appcompat.widget.Toolbar
16+
android:id="@+id/repository_toolbar"
17+
android:layout_width="match_parent"
18+
android:layout_height="?attr/actionBarSize"
19+
android:background="?attr/colorPrimary"
20+
app:popupTheme="@style/Theme.GitHubApp.PopupOverlay"
21+
app:layout_constraintTop_toTopOf="parent"/>
22+
23+
</com.google.android.material.appbar.AppBarLayout>
24+
25+
</androidx.constraintlayout.widget.ConstraintLayout>

solutions/devsprint-denis-vieira-1/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<string name="action_settings">Settings</string>
44
<string name="first_fragment_label">GitHubApp</string>
55
<string name="hello_first_fragment">Hello, Devpass!</string>
6-
<string name="title_activity_repository_details">RepositoryDetails</string>
76
<string name="second_fragment_label">Second Fragment</string>
87
<string name="next">Next</string>
98
<string name="previous">Previous</string>
@@ -12,4 +11,6 @@
1211
<string name="search_button_content_description">Search button</string>
1312
<string name="snackbar_error">An error occurred while trying to get the list</string>
1413
<string name="retry">Retry</string>
14+
<string name="title_activity_repository_list">Repositories</string>
15+
<string name="title_activity_repository_details">Repository</string>
1516
</resources>

0 commit comments

Comments
 (0)