File tree Expand file tree Collapse file tree 7 files changed +87
-11
lines changed
solutions/devsprint-denis-vieira-1/app/src/main
java/com/devpass/githubapp/presentation Expand file tree Collapse file tree 7 files changed +87
-11
lines changed Original file line number Diff line number Diff line change 11
11
android : roundIcon =" @mipmap/ic_launcher_round"
12
12
android : supportsRtl =" true"
13
13
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
+
19
15
<activity
20
16
android : name =" .presentation.RepositoryListActivity"
21
17
android : exported =" true"
22
- android : label =" @string/app_name "
18
+ android : label =" @string/title_activity_repository_list "
23
19
android : theme =" @style/Theme.GitHubApp.NoActionBar" >
24
20
<intent-filter >
25
21
<action android : name =" android.intent.action.MAIN" />
26
22
27
23
<category android : name =" android.intent.category.LAUNCHER" />
28
24
</intent-filter >
29
25
</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
+
30
34
</application >
31
35
32
36
</manifest >
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ class RepositoryCellItem(
10
10
private val binding : ItemCellRepositoryBinding
11
11
) : RecyclerView.ViewHolder(binding.root) {
12
12
13
- fun bind (item : Repository ) {
14
- with (binding){
13
+ fun bind (item : Repository , itemListener : RepositoryListAdapter . RepositoryItemListener ? ) {
14
+ with (binding) {
15
15
textviewRepositoryName.text = item.name
16
16
textviewOwnerName.text = item.owner.login
17
17
@@ -21,6 +21,10 @@ class RepositoryCellItem(
21
21
.centerCrop()
22
22
.placeholder(R .drawable.ic_placeholder)
23
23
.into(imageviewAvatar)
24
+
25
+ root.setOnClickListener {
26
+ itemListener?.onItemClick()
27
+ }
24
28
}
25
29
}
26
30
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
package com.devpass.githubapp.presentation
2
2
3
+ import android.content.Intent
3
4
import android.os.Bundle
4
5
import android.view.Menu
5
6
import android.view.MenuInflater
@@ -16,7 +17,7 @@ import retrofit2.Call
16
17
import retrofit2.Callback
17
18
import retrofit2.Response
18
19
19
- class RepositoryListActivity : AppCompatActivity () {
20
+ class RepositoryListActivity : AppCompatActivity (), RepositoryListAdapter.RepositoryItemListener {
20
21
21
22
private lateinit var binding: ActivityMainBinding
22
23
private val cellItemAdapter = RepositoryListAdapter ()
@@ -64,6 +65,8 @@ class RepositoryListActivity : AppCompatActivity() {
64
65
}
65
66
66
67
private fun setupLayout () {
68
+ cellItemAdapter.repositoryItemListener = this
69
+
67
70
binding.contentList.repositoriesRecyclerview.layoutManager =
68
71
LinearLayoutManager (baseContext, LinearLayoutManager .VERTICAL , false )
69
72
binding.contentList.repositoriesRecyclerview.adapter = cellItemAdapter
@@ -88,4 +91,9 @@ class RepositoryListActivity : AppCompatActivity() {
88
91
private fun goToSettings () {
89
92
90
93
}
94
+
95
+ override fun onItemClick () {
96
+ val intent = Intent (this , RepositoryDetailsActivity ::class .java)
97
+ startActivity(intent)
98
+ }
91
99
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import com.devpass.githubapp.databinding.ItemCellRepositoryBinding
9
9
class RepositoryListAdapter : RecyclerView .Adapter <RepositoryCellItem >() {
10
10
11
11
var repositories: List <Repository > = listOf ()
12
+ var repositoryItemListener: RepositoryItemListener ? = null
12
13
13
14
override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): RepositoryCellItem {
14
15
val inflater = LayoutInflater .from(parent.context)
@@ -18,9 +19,12 @@ class RepositoryListAdapter : RecyclerView.Adapter<RepositoryCellItem>() {
18
19
19
20
override fun onBindViewHolder (holder : RepositoryCellItem , position : Int ) {
20
21
val item = repositories[position]
21
- holder.bind(item)
22
+ holder.bind(item, repositoryItemListener )
22
23
}
23
24
24
25
override fun getItemCount (): Int = repositories.size
25
26
27
+ interface RepositoryItemListener {
28
+ fun onItemClick ()
29
+ }
26
30
}
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change 3
3
<string name =" action_settings" >Settings</string >
4
4
<string name =" first_fragment_label" >GitHubApp</string >
5
5
<string name =" hello_first_fragment" >Hello, Devpass!</string >
6
- <string name =" title_activity_repository_details" >RepositoryDetails</string >
7
6
<string name =" second_fragment_label" >Second Fragment</string >
8
7
<string name =" next" >Next</string >
9
8
<string name =" previous" >Previous</string >
12
11
<string name =" search_button_content_description" >Search button</string >
13
12
<string name =" snackbar_error" >An error occurred while trying to get the list</string >
14
13
<string name =" retry" >Retry</string >
14
+ <string name =" title_activity_repository_list" >Repositories</string >
15
+ <string name =" title_activity_repository_details" >Repository</string >
15
16
</resources >
You can’t perform that action at this time.
0 commit comments