Skip to content
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

로그아웃 및 탈퇴 로직 구현 #93

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
minSdk = 26
targetSdk = 33
versionCode = 1
versionName = "1.0.15"
versionName = "1.0.16"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ val viewModelModule =
viewModel { AddPostViewModel(get()) }
viewModel { SearchFriendViewModel(get(), get(), get()) }
viewModel { DialogViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { CommunityScreenViewModel(get(), get(), get()) }
viewModel { CommunityScreenViewModel(get(), get(), get(), get(), get()) }
viewModel { FollowingViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { SettingViewModel(get(), get()) }
viewModel { TotalBadgeViewModel(get(), get()) }
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/whyranoid/walkie/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.whyranoid.walkie

import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import com.whyranoid.presentation.screens.AppScreen
import com.whyranoid.presentation.screens.setting.SettingViewModel
import com.whyranoid.presentation.theme.WalkieTheme
import com.whyranoid.walkie.walkiedialog.AppManageDialog
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
Expand All @@ -23,5 +29,18 @@ class MainActivity : ComponentActivity() {
AppScreen { startWorker(this) }
}
}

observeRestart()
}

private fun observeRestart() {
lifecycleScope.launch {
SettingViewModel.appRestartEvent.collectLatest { isRestart ->
if (isRestart == true) {
startActivity(Intent(this@MainActivity, MainActivity::class.java))
finish()
}
}
}
}
}
2 changes: 2 additions & 0 deletions data/src/main/java/com/whyranoid/data/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ object API {

const val SIGN_UP = "api/walkies/signup"

const val LEAVE = "api/walkies/leave"

const val FOLLOW = "api/follow/follow"

const val WALKING_FOLLOWING = "api/follow/{uid}/walking-followings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ class AccountDataSourceImpl(private val accountService: AccountService) : Accoun
accountService.getMyInfo(walkieId).getResult { it.toUserInfo() }
}
}

override suspend fun leave(walkieId: Long): Result<Unit> {
return kotlin.runCatching {
accountService.leave(walkieId).getResult{ }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.whyranoid.data.datasource.account

import com.whyranoid.data.API
import com.whyranoid.data.model.account.ChangeMyInfoResponse
import com.whyranoid.data.model.account.LeaveResponse
import com.whyranoid.data.model.account.LoginDataResponse
import com.whyranoid.data.model.account.NickCheckResponse
import com.whyranoid.data.model.account.SignUpRequest
Expand All @@ -10,6 +11,7 @@ import com.whyranoid.data.model.account.UserInfoResponse
import okhttp3.MultipartBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Part
Expand Down Expand Up @@ -42,4 +44,9 @@ interface AccountService {
suspend fun getMyInfo(
@Query("walkieId") id: Long
): Response<UserInfoResponse>

@DELETE(API.LEAVE)
suspend fun leave(
@Query("walkieId") id: Long
): Response<LeaveResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.whyranoid.data.model.account

data class LeaveResponse(
val status: Int,
val message: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class AccountRepositoryImpl(
agreeSubscription: Boolean,
): Result<Long> {
return kotlin.runCatching {
accountDataSource.signUp(userName, nickName, profileUrl, authId, agreeGps, agreeSubscription)
accountDataSource.signUp(
userName,
nickName,
profileUrl,
authId,
agreeGps,
agreeSubscription
)
.onSuccess { uid ->
accountDataStore.updateUId(uid)
accountDataStore.updateAuthId(authId)
Expand Down Expand Up @@ -107,4 +114,10 @@ class AccountRepositoryImpl(
override suspend fun getUserInfo(walkieId: Long): Result<UserInfo> {
return accountDataSource.getUserInfo(walkieId)
}

override suspend fun leave(walkieId: Long): Result<Unit> {
return kotlin.runCatching {
accountDataSource.leave(walkieId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ interface AccountDataSource {
suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>

suspend fun leave(walkieId: Long): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ interface AccountRepository {
suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>

suspend fun leave(walkieId: Long): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class GetFollowingsPostsUseCase(
) {
suspend operator fun invoke(isEveryPost: Boolean): Result<List<Post>> {
val myUid = requireNotNull(accountRepository.walkieId.first())
return postRepository.getMyFollowingsPost(myUid)
return if (isEveryPost) postRepository.getEveryPost(myUid) else postRepository.getMyFollowingsPost(myUid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun RunningFollowerItem(
contentAlignment = Alignment.Center,
) {
AsyncImage(
model = "https://picsum.photos/250/250 ",
model = user.imageUrl,
contentDescription = "달리고 있는 친구의 프로필 이미지",
modifier = Modifier
.size(65.dp)
Expand All @@ -57,7 +57,7 @@ fun RunningFollowerItem(
if (isDisplayName) {
Spacer(modifier = Modifier.size(6.dp))

Text(text = "내 기록")
Text(text = "내 기록") // 내꺼면 내기록 아니면 사람 이름
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material3.Icon
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
Expand All @@ -34,6 +38,8 @@ fun RunningFollowerItemWithLikable(
isDisplayName: Boolean = false,
isLiked: Boolean = false,
) {
var isLikedStatus by remember { mutableStateOf(isLiked) }

Box(
modifier = Modifier.wrapContentSize(),
contentAlignment = Alignment.TopEnd,
Expand All @@ -50,6 +56,7 @@ fun RunningFollowerItemWithLikable(
.clip(CircleShape)
.clickable {
onClick.invoke(user.uid)
isLikedStatus = isLikedStatus.not()
}
.size(48.dp)
.padding(4.dp)
Expand All @@ -62,8 +69,10 @@ fun RunningFollowerItemWithLikable(
) {
Icon(
Icons.Default.Favorite,
tint = if (isLiked) WalkieColor.Primary else WalkieColor.GrayBorder,
modifier = Modifier.size(20.dp).align(Alignment.Center),
tint = if (isLikedStatus) WalkieColor.Primary else WalkieColor.GrayBorder,
modifier = Modifier
.size(20.dp)
.align(Alignment.Center),
contentDescription = "like image",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -47,6 +49,10 @@ fun CommunityScreen(navController: NavController) {
val viewModel = koinViewModel<CommunityScreenViewModel>()
val state by viewModel.collectAsState()

LaunchedEffect(LocalLifecycleOwner.current) {
viewModel.getRunningFollowingsState()
}

Scaffold(
topBar = {
WalkieTopBar(
Expand Down Expand Up @@ -113,8 +119,24 @@ fun CommunityScreen(navController: NavController) {
modifier = Modifier.padding(it)
) {
LazyRow {
repeat(10) {
item { RunningFollowerItemWithLikable(isDisplayName = true) }
state.runningFollowerState.getDataOrNull()?.let { (running, notRunning) ->
items(running.size) {
RunningFollowerItemWithLikable(
user = running[it].user,
onClickProfile = { user ->
navController.navigate("userPage/${user.uid}/${user.nickname}/${true}")
},
onClick = viewModel::sendLike,
circleBorderColor = WalkieColor.Primary,
isLiked = running[it].isLiked,
)
}
items(notRunning.size) {
RunningFollowerItemWithLikable(
user = notRunning[it],
circleBorderColor = WalkieColor.GrayBorder,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whyranoid.presentation.screens.setting

import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.annotation.StringRes
Expand Down Expand Up @@ -41,6 +42,7 @@ import coil.compose.AsyncImage
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import com.whyranoid.presentation.R
import com.whyranoid.presentation.reusable.MenuItem
import com.whyranoid.presentation.reusable.SingleToast
import com.whyranoid.presentation.screens.Screen
import com.whyranoid.presentation.screens.mypage.editprofile.UserInfoUiState
import com.whyranoid.presentation.theme.SystemColor
Expand All @@ -55,6 +57,7 @@ fun SettingsScreen(navHostController: NavHostController) {
val user = viewModel.userInfoUiState.collectAsState()

val scrollState = rememberScrollState()
val context = LocalContext.current

user.value?.let {
Column(
Expand All @@ -68,6 +71,16 @@ fun SettingsScreen(navHostController: NavHostController) {
SettingsList(
navigateToInAppBrowser = { url ->
navHostController.navigate(Screen.WebViewScreen.createRoute(url))
},
onClickSignOut = {
viewModel.signOutFromGoogle(context) {
SingleToast.show(context, "로그아웃 되었습니다.")
}
},
onClickLeave = {
viewModel.revokeGoogleAccess(context) {
SingleToast.show(context, "계정 탈퇴가 완료되었습니다.")
}
}
)
}
Expand Down Expand Up @@ -164,6 +177,8 @@ fun ProfileSection(
@Composable
fun SettingsList(
navigateToInAppBrowser: (url: String) -> Unit = {},
onClickSignOut: () -> Unit = {},
onClickLeave: () -> Unit = {},
) {
Spacer(
modifier = Modifier
Expand Down Expand Up @@ -234,7 +249,9 @@ fun SettingsList(
MenuItem(
text = R.string.logout,
icon = null
)
) {
onClickSignOut()
}

Spacer(
modifier = Modifier
Expand All @@ -246,7 +263,9 @@ fun SettingsList(
MenuItem(
text = R.string.delete_account,
icon = null
)
) {
onClickLeave()
}
}

@Composable
Expand Down
Loading
Loading