Skip to content

Commit

Permalink
✨ 친구찾기 화면 틀 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach committed Oct 28, 2023
1 parent a963294 commit 226e397
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.whyranoid.data.API
import com.whyranoid.data.AccountDataStore
import com.whyranoid.data.AppDatabase
import com.whyranoid.data.datasource.ChallengeDataSourceImpl
import com.whyranoid.data.datasource.OtherUserPagingSource
import com.whyranoid.data.datasource.UserDataSourceImpl
import com.whyranoid.data.datasource.account.AccountDataSourceImpl
import com.whyranoid.data.datasource.account.AccountService
Expand All @@ -21,6 +22,7 @@ import com.whyranoid.data.repository.ChallengeRepositoryImpl
import com.whyranoid.data.repository.FollowRepositoryImpl
import com.whyranoid.data.repository.GpsRepositoryImpl
import com.whyranoid.data.repository.NetworkRepositoryImpl
import com.whyranoid.data.repository.OtherUserRepositoryImpl
import com.whyranoid.data.repository.PostRepositoryImpl
import com.whyranoid.data.repository.RunningHistoryRepositoryImpl
import com.whyranoid.data.repository.RunningRepositoryImpl
Expand All @@ -36,6 +38,7 @@ import com.whyranoid.domain.repository.ChallengeRepository
import com.whyranoid.domain.repository.FollowRepository
import com.whyranoid.domain.repository.GpsRepository
import com.whyranoid.domain.repository.NetworkRepository
import com.whyranoid.domain.repository.OtherUserRepository
import com.whyranoid.domain.repository.PostRepository
import com.whyranoid.domain.repository.RunningHistoryRepository
import com.whyranoid.domain.repository.RunningRepository
Expand All @@ -45,6 +48,7 @@ import com.whyranoid.domain.usecase.GetChallengePreviewsByTypeUseCase
import com.whyranoid.domain.usecase.GetChallengingPreviewsUseCase
import com.whyranoid.domain.usecase.GetNewChallengePreviewsUseCase
import com.whyranoid.domain.usecase.GetPostUseCase
import com.whyranoid.domain.usecase.GetSearchedUserUseCase
import com.whyranoid.domain.usecase.GetUserBadgesUseCase
import com.whyranoid.domain.usecase.GetUserDetailUseCase
import com.whyranoid.domain.usecase.GetUserPostPreviewsUseCase
Expand All @@ -58,6 +62,7 @@ import com.whyranoid.presentation.screens.mypage.editprofile.EditProfileViewMode
import com.whyranoid.presentation.viewmodel.AddPostViewModel
import com.whyranoid.presentation.viewmodel.RunningEditViewModel
import com.whyranoid.presentation.viewmodel.RunningViewModel
import com.whyranoid.presentation.viewmodel.SearchFriendViewModel
import com.whyranoid.presentation.viewmodel.SelectHistoryViewModel
import com.whyranoid.presentation.viewmodel.SignInViewModel
import com.whyranoid.presentation.viewmodel.SplashViewModel
Expand Down Expand Up @@ -87,6 +92,7 @@ val viewModelModule = module {
factory { SelectHistoryViewModel(get()) }
factory { EditProfileViewModel(get()) }
factory { AddPostViewModel(get()) }
factory { SearchFriendViewModel(get()) }
}

val repositoryModule = module {
Expand All @@ -99,6 +105,7 @@ val repositoryModule = module {
single<FollowRepository> { FollowRepositoryImpl(get()) }
single<NetworkRepository> { NetworkRepositoryImpl(get()) }
single<GpsRepository> { GpsRepositoryImpl(get()) }
single<OtherUserRepository> { OtherUserRepositoryImpl(OtherUserPagingSource()) }
}

val dataSourceModule = module {
Expand All @@ -125,6 +132,7 @@ val useCaseModule = module {
single { SignOutUseCase(get()) }
single { UploadPostUseCase(get(), get()) }
single { SendLikeUseCase(get(), get()) }
single { GetSearchedUserUseCase(get()) }
}

val databaseModule = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.whyranoid.presentation.screens.challenge.ChallengeCompleteScreen
import com.whyranoid.presentation.screens.challenge.ChallengeDetailScreen
import com.whyranoid.presentation.screens.challenge.ChallengeExitScreen
import com.whyranoid.presentation.screens.challenge.ChallengeMainScreen
import com.whyranoid.presentation.screens.community.SearchFriendScreen
import com.whyranoid.presentation.screens.mypage.MyPageScreen
import com.whyranoid.presentation.screens.mypage.addpost.AddPostScreen
import com.whyranoid.presentation.screens.mypage.editprofile.EditProfileScreen
Expand Down Expand Up @@ -158,6 +159,9 @@ fun AppScreenContent(startWorker: () -> Unit, navController: NavHostController)
composable(Screen.Community.route) {
CommunityScreen(navController)
}
composable(Screen.SearchFriendScreen.route) {
SearchFriendScreen(navController)
}
composable(Screen.ChallengeMainScreen.route) {
ChallengeMainScreen(navController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun CommunityScreen(
Icon(
modifier = Modifier
.clickable {
navController.navigate(Screen.SearchFriendScreen.route)
},
imageVector = Icons.Filled.Search,
contentDescription = "검색 버튼",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ sealed class Screen(
R.drawable.ic_community_screen_selected,
)

object SearchFriendScreen : Screen(
"searchFriendScreen",
)

object ChallengeMainScreen :
Screen(
"challengeMain",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package com.whyranoid.presentation.screens.community

import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.paging.LoadState
import androidx.paging.compose.collectAsLazyPagingItems
import com.whyranoid.domain.util.EMPTY
import com.whyranoid.presentation.component.bar.WalkieTopBar
import com.whyranoid.presentation.theme.WalkieColor
import com.whyranoid.presentation.theme.WalkieTypography
import com.whyranoid.presentation.viewmodel.SearchFriendViewModel
import org.koin.androidx.compose.koinViewModel

@Composable
fun SearchFriendScreen(
navController: NavController
) {

val viewModel = koinViewModel<SearchFriendViewModel>()

Scaffold(
topBar = {
WalkieTopBar(
leftContent = {
Icon(
modifier = Modifier
.clickable {
navController.popBackStack()
},
imageVector = Icons.Filled.Close,
contentDescription = "Cancel"
)
},
middleContent = {
Text(
text = "친구찾기",
style = WalkieTypography.Title.copy(
fontSize = 15.sp,
fontWeight = FontWeight(600)
),
)
},
rightContent = {
Spacer(modifier = Modifier.width(Icons.Filled.Close.defaultWidth))
},
)
},
) {

var query by remember { mutableStateOf("") }

Column(
modifier = Modifier
.padding(it)
.fillMaxWidth()
) {
Box(
modifier =
Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth()
.height(34.dp)
.border(
width = 1.dp,
color = Color(0xFFE4E4E4),
shape = RoundedCornerShape(10.dp)
)
.clip(shape = RoundedCornerShape(10.dp))
) {
Row(
modifier = Modifier
.padding(horizontal = 11.dp, vertical = 8.dp)
.fillMaxWidth()
.fillMaxHeight(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Filled.Search, contentDescription = "Search Icon",
tint = Color(0x80000000)
)

Spacer(modifier = Modifier.width(8.dp))

BasicTextField(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(),
value = query,
onValueChange = { changedText ->
query = changedText
},
cursorBrush = SolidColor(WalkieColor.Primary),
singleLine = true,
) {
if (query.isEmpty()) {
Text(
text = "워키 아이디로 친구찾기",
style = WalkieTypography.Body1_Normal.copy(
color = Color(0x80000000)
),
)
} else {
Text(
text = query,
style = WalkieTypography.Body1_Normal
)
}

}
}


}

Spacer(modifier = Modifier.height(20.dp))

val pager = remember {
viewModel.searchUsers(String.EMPTY)
}

val lazyPagingItems = pager.collectAsLazyPagingItems()

LazyColumn {
if (lazyPagingItems.loadState.refresh == LoadState.Loading) {
item {
Text(
text = "Waiting for items to load from the backend",
modifier = Modifier
.fillMaxWidth()
.wrapContentWidth(Alignment.CenterHorizontally)
)
}
}

items(count = lazyPagingItems.itemCount) { index ->

val item = lazyPagingItems[index]
SearchedFriendItem(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp),
nickname = item?.nickname ?: ""
)
Spacer(modifier = Modifier.height(5.dp))
}

if (lazyPagingItems.loadState.append == LoadState.Loading) {
item {
CircularProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.wrapContentWidth(Alignment.CenterHorizontally)
)
}
}

}

}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.whyranoid.presentation.screens.community

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.whyranoid.presentation.theme.WalkieColor
import com.whyranoid.presentation.theme.WalkieTypography

@Composable
fun SearchedFriendItem(
modifier: Modifier = Modifier,
nickname: String
) {

Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {

AsyncImage(
model = "https://picsum.photos/250/250 ", contentDescription = "",
modifier = Modifier
.size(56.dp)
.clip(RoundedCornerShape(50.dp)),
contentScale = ContentScale.Crop
)

Text(
modifier = Modifier.padding(15.dp),
text = nickname,
style = WalkieTypography.Body2
)

Text(
text = "·",
style = WalkieTypography.Body2
)

Spacer(modifier = Modifier.width(5.dp))

Text(
modifier = Modifier.clickable {

},
text = "팔로우",
style = WalkieTypography.Body2.copy(
color = WalkieColor.Primary
)
)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.whyranoid.presentation.viewmodel

import androidx.lifecycle.ViewModel
import com.whyranoid.domain.usecase.GetSearchedUserUseCase

class SearchFriendViewModel(
private val getSearchedUserUseCase: GetSearchedUserUseCase
): ViewModel() {

fun searchUsers(query: String) = getSearchedUserUseCase(query)
}

0 comments on commit 226e397

Please sign in to comment.