diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt index 5039565..2b80fb6 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/MainActivity.kt @@ -1,7 +1,6 @@ package org.android.go.sopt.presentation.main import android.os.Bundle -import androidx.activity.viewModels import androidx.fragment.app.Fragment import androidx.fragment.app.commit import androidx.fragment.app.replace @@ -16,11 +15,8 @@ import org.android.go.sopt.util.binding.BindingActivity @AndroidEntryPoint class MainActivity : BindingActivity(R.layout.activity_main) { - private val viewModel by viewModels() - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding.vm = viewModel initNavigationBar() } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileFragment.kt index d863b64..cfd63d5 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileFragment.kt @@ -1,14 +1,37 @@ package org.android.go.sopt.presentation.main.profile +import android.content.Intent import android.os.Bundle import android.view.View +import androidx.fragment.app.viewModels +import dagger.hilt.android.AndroidEntryPoint import org.android.go.sopt.R import org.android.go.sopt.databinding.FragmentProfileBinding +import org.android.go.sopt.presentation.login.LoginActivity import org.android.go.sopt.util.binding.BindingFragment +import org.android.go.sopt.util.extension.setOnSingleClickListener +import org.android.go.sopt.util.extension.showToast +@AndroidEntryPoint class ProfileFragment : BindingFragment(R.layout.fragment_profile) { + private val viewModel by viewModels() + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.vm = viewModel + + initLogoutAndLeaveBtnClickListener() + } + + private fun initLogoutAndLeaveBtnClickListener() { + binding.btnProfileLogoutAndLeave.setOnSingleClickListener { + viewModel.clearLocalPref() + requireContext().showToast(getString(R.string.profile_logout_and_leave_msg)) + Intent(activity, LoginActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + startActivity(this) + } + } } companion object { diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt similarity index 61% rename from app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt rename to app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt index 4fbe58e..e72fb26 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/profile/ProfileViewModel.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.presentation.main +package org.android.go.sopt.presentation.main.profile import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -8,17 +8,18 @@ import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject @HiltViewModel -class MainViewModel @Inject constructor( +class ProfileViewModel @Inject constructor( private val authRepository: AuthRepository, ) : ViewModel() { - // TODO : 프로필 보여주는 Fragment ViewModel 으로 로직 옮기기 val signedUpUser = MutableLiveData() init { - signedUpUser.value = getSignedUpUser() + getSignedUpUser() } - private fun getSignedUpUser(): User = authRepository.getSignedUpUser() ?: User() + private fun getSignedUpUser() { + signedUpUser.value = authRepository.getSignedUpUser() ?: User() + } fun clearLocalPref() { authRepository.clearLocalPref() diff --git a/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt b/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt index aedeb6c..99653e6 100644 --- a/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt +++ b/app/src/main/java/org/android/go/sopt/util/binding/BindingAdapter.kt @@ -7,10 +7,10 @@ import coil.transform.RoundedCornersTransformation object BindingAdapter { @JvmStatic - @BindingAdapter("setCircleImage") - fun ImageView.setCircleImage(img: String?) { + @BindingAdapter("setRoundedCornersImage") + fun ImageView.setRoundedCornersImage(img: String?) { load(img) { - // TODO : placeholder & load error 이미지 추가 + // TODO: placeholder & load error 이미지 추가 transformations(RoundedCornersTransformation(50f)) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bb6d9b0..589df83 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,13 +6,10 @@ - diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 8fea224..a9165e1 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -1,19 +1,79 @@ - + - + - + + + + android:layout_height="match_parent"> + + - + android:id="@+id/tv_profile_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:text="@{@string/profile_name(vm.signedUpUser.name)}" + android:textColor="@color/black" + android:textSize="16sp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/iv_profile_profile" /> + + + + +