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

[QA] 홈 뷰 #90

Merged
merged 16 commits into from
Jan 19, 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package sopt.motivoo.data.repository

import android.graphics.Bitmap
import com.google.firebase.Firebase
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import com.google.firebase.database.database
import okhttp3.RequestBody.Companion.toRequestBody
import sopt.motivoo.data.datasource.remote.HomeDataSource
import sopt.motivoo.data.model.request.home.RequestHomeDto
Expand All @@ -26,37 +28,26 @@ class HomeRepositoryImpl @Inject constructor(
@Inject
lateinit var pref: MotivooStorage

override fun getMyStepCount(myUid: Long, myStepCount: (Long) -> Unit) {
firebaseRealtimeDB.reference.child(USERS)
override fun getOtherStepCount(otherUid: String, onStepCountAction: (Long) -> Unit) {
firebaseRealtimeDB.reference.child(USERS).child(otherUid)
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
snapshot.child(myUid.toString()).apply {
if (exists()) (value as Long).let { if (it == 0L) pref.myStepCount = 0 }
if (snapshot.value != null) {
onStepCountAction(snapshot.value as Long)
}
}

override fun onCancelled(error: DatabaseError) {}
})
}

override fun getEventOtherStepCount(otherUid: Long, otherStepCount: (Long) -> Unit) {
firebaseRealtimeDB.reference.child(USERS)
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
snapshot.child(otherUid.toString()).apply {
if (exists()) {
otherStepCount(value as Long)
pref.otherStepCount = (value as Long).toInt()
}
}
override fun setMyStepCount(uid: String) {
firebaseRealtimeDB.reference.child(USERS).child(uid).get()
.addOnSuccessListener {
if (it.value == null) {
Firebase.database.reference.child(USERS).child(uid).setValue(pref.myStepCount)
}

override fun onCancelled(error: DatabaseError) {}
})
}

override fun setMyStepCount(myUid: Long, stepCount: Int) {
firebaseRealtimeDB.reference.child(USERS).child(myUid.toString()).setValue(stepCount)
}
}

override suspend fun patchHome(myStepCount: Int, otherStepCount: Int): Result<HomeData> =
Expand All @@ -71,7 +62,9 @@ class HomeRepositoryImpl @Inject constructor(
runCatching { homeDataSource.postMissionToday(requestMissionTodayDto) }

override suspend fun patchMissionImage(requestMissionImageDto: RequestMissionImageDto): Result<MissionImageData> =
runCatching { homeDataSource.patchMissionImage(requestMissionImageDto).toMissionImageData() }
runCatching {
homeDataSource.patchMissionImage(requestMissionImageDto).toMissionImageData()
}

override suspend fun uploadPhoto(url: String, bitmap: Bitmap): Result<Unit> {
val outputStream = ByteArrayOutputStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import sopt.motivoo.domain.entity.home.MissionChoiceData
import sopt.motivoo.domain.entity.home.MissionImageData

interface HomeRepository {
fun getMyStepCount(myUid: Long, myStepCount: (Long) -> Unit)
fun getEventOtherStepCount(otherUid: Long, otherStepCount: (Long) -> Unit)
fun setMyStepCount(myUid: Long, stepCount: Int)
fun getOtherStepCount(otherUid: String, onStepCountAction: (Long) -> Unit)
fun setMyStepCount(uid: String)
suspend fun patchHome(myStepCount: Int, otherStepCount: Int): Result<HomeData>
suspend fun postMissionTodayChoice(): Result<MissionChoiceData>
suspend fun postMissionToday(requestMissionTodayDto: RequestMissionTodayDto): Result<Unit>
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/java/sopt/motivoo/presentation/MyLogoutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand All @@ -17,7 +16,6 @@ import sopt.motivoo.presentation.auth.AuthViewModel
import sopt.motivoo.util.UiState
import sopt.motivoo.util.binding.BindingDialogFragment
import sopt.motivoo.util.extension.setOnSingleClickListener
import sopt.motivoo.util.findStartDestination
import javax.inject.Inject

@AndroidEntryPoint
Expand Down Expand Up @@ -60,12 +58,6 @@ class MyLogoutFragment :
}

private fun navigateToLogin() {
val navController = findNavController()
val startDestinationId = navController.findStartDestination().id
val navOptions = NavOptions.Builder()
.setPopUpTo(startDestinationId, true)
.build()

navController.navigate(R.id.action_myLogout_to_loginFragment, null, navOptions)
findNavController().navigate(R.id.action_myLogout_to_loginFragment)
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/sopt/motivoo/presentation/auth/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.animation.AnimationUtils
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -40,6 +41,18 @@ class LoginFragment : BindingFragment<FragmentLoginBinding>(R.layout.fragment_lo
super.onViewCreated(view, savedInstanceState)
clickKakaoLoginButton()
collectData()
backPressed()
}

private fun backPressed() {
requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
requireActivity().finishAffinity()
}
}
)
}

private fun checkReLoginUser() {
Expand Down
Loading
Loading