Skip to content

Commit 8d1e34c

Browse files
committed
[기능추가] 사용자 상세화면에서 뷰페이저, 프래그먼트를 통해 Repository, Follower, Following 조회 되도록 추가
1 parent f9baa95 commit 8d1e34c

27 files changed

+789
-174
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ dependencies {
5050
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
5151

5252
// For ViewModel simple create
53-
implementation 'androidx.activity:activity-ktx:1.1.0'
54-
implementation 'androidx.fragment:fragment-ktx:1.2.5'
53+
implementation 'androidx.activity:activity-ktx:1.7.0'
54+
implementation 'androidx.fragment:fragment-ktx:1.5.6'
5555

5656
// Mockk
5757
testImplementation 'io.mockk:mockk:1.13.4'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.gun.githubapi.common
2+
3+
import androidx.fragment.app.Fragment
4+
5+
abstract class BaseFragment : Fragment()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.gun.githubapi.common
2+
3+
import android.view.View
4+
import androidx.viewpager2.widget.ViewPager2
5+
6+
private const val MIN_SCALE = 0.85f
7+
private const val MIN_ALPHA = 0.5f
8+
9+
class ZoomOutPageTransformer : ViewPager2.PageTransformer {
10+
11+
override fun transformPage(view: View, position: Float) {
12+
view.apply {
13+
val pageWidth = width
14+
val pageHeight = height
15+
when {
16+
position < -1 -> {
17+
alpha = 0f
18+
}
19+
position <= 1 -> {
20+
val scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position))
21+
val vertMargin = pageHeight * (1 - scaleFactor) / 2
22+
val horzMargin = pageWidth * (1 - scaleFactor) / 2
23+
translationX = if (position < 0) {
24+
horzMargin - vertMargin / 2
25+
} else {
26+
horzMargin + vertMargin / 2
27+
}
28+
29+
scaleX = scaleFactor
30+
scaleY = scaleFactor
31+
32+
alpha = (MIN_ALPHA +
33+
(((scaleFactor - MIN_SCALE) / (1 - MIN_SCALE)) * (1 - MIN_ALPHA)))
34+
}
35+
else -> {
36+
alpha = 0f
37+
}
38+
}
39+
}
40+
}
41+
}
42+

app/src/main/java/com/gun/githubapi/data/repository/UserRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ import com.gun.githubapi.data.dto.user.User
66
interface UserRepository {
77
suspend fun fetchUserList(): Pager<Int, User>
88
suspend fun fetchUser(userName: String): User
9+
suspend fun fetchFollowerList(userName: String): MutableList<User>
10+
suspend fun fetchFollowingList(userName: String): MutableList<User>
911
}

app/src/main/java/com/gun/githubapi/data/repository/UserRepositoryImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ class UserRepositoryImpl(
2323
override suspend fun fetchUser(userName: String): User {
2424
return userRemoteDataSource.fetchUser(userName)
2525
}
26+
27+
override suspend fun fetchFollowerList(userName: String): MutableList<User> {
28+
return userRemoteDataSource.fetchFollowerList(userName)
29+
}
30+
31+
override suspend fun fetchFollowingList(userName: String): MutableList<User> {
32+
return userRemoteDataSource.fetchFollowingList(userName)
33+
}
2634
}

app/src/main/java/com/gun/githubapi/data/service/UserService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ interface UserService {
1111

1212
@GET("users/{userName}")
1313
suspend fun fetchUser(@Path("userName") userName: String): User
14+
15+
@GET("users/{userName}/followers")
16+
suspend fun fetchFollowerList(@Path("userName") userName: String): MutableList<User>
17+
18+
@GET("users/{userName}/following")
19+
suspend fun fetchFollowing(@Path("userName") userName: String): MutableList<User>
1420
}

app/src/main/java/com/gun/githubapi/data/source/UserRemoteDataSource.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ import com.gun.githubapi.data.dto.user.User
44

55
interface UserRemoteDataSource {
66
suspend fun fetchUser(userName: String): User
7+
suspend fun fetchFollowerList(userName: String):MutableList<User>
8+
suspend fun fetchFollowingList(userName: String):MutableList<User>
79
}

app/src/main/java/com/gun/githubapi/data/source/UserRemoteDataSourceImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ class UserRemoteDataSourceImpl(private val userService: UserService) : UserRemot
77
override suspend fun fetchUser(userName: String): User {
88
return userService.fetchUser(userName)
99
}
10+
11+
override suspend fun fetchFollowerList(userName: String): MutableList<User> {
12+
return userService.fetchFollowerList(userName)
13+
}
14+
15+
override suspend fun fetchFollowingList(userName: String): MutableList<User> {
16+
return userService.fetchFollowing(userName)
17+
}
1018
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.gun.githubapi.ui.user.detail
2+
3+
import android.view.LayoutInflater
4+
import android.view.ViewGroup
5+
import com.gun.githubapi.common.recyclerview.BaseListAdapter
6+
import com.gun.githubapi.common.recyclerview.BaseViewHolder
7+
import com.gun.githubapi.common.recyclerview.ItemClickListener
8+
import com.gun.githubapi.data.dto.user.User
9+
import com.gun.githubapi.databinding.HolderUserInterestingBinding
10+
11+
class InterestingUserRecyclerAdapter(val listener: ItemClickListener<User>?) :
12+
BaseListAdapter<User, InterestingUserRecyclerAdapter.UserViewHolder>() {
13+
14+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
15+
val view =
16+
HolderUserInterestingBinding.inflate(LayoutInflater.from(parent.context), parent, false)
17+
return UserViewHolder(view)
18+
}
19+
20+
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
21+
getItem(holder.bindingAdapterPosition)?.let {
22+
holder.setData(it)
23+
}
24+
}
25+
26+
inner class UserViewHolder(private val binding: HolderUserInterestingBinding) :
27+
BaseViewHolder(binding.root) {
28+
fun setData(user: User) {
29+
binding.user = user
30+
31+
if (listener != null) {
32+
binding.listener = listener
33+
}
34+
}
35+
}
36+
}

app/src/main/java/com/gun/githubapi/ui/user/detail/RepositoryViewModel.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)