마이페이지 메인 - UI, Api 적용
This commit is contained in:
@@ -10,6 +10,7 @@ import kr.co.vividnext.sodalive.live.LiveViewModel
|
||||
import kr.co.vividnext.sodalive.live.recommend.LiveRecommendApi
|
||||
import kr.co.vividnext.sodalive.live.recommend.LiveRecommendRepository
|
||||
import kr.co.vividnext.sodalive.main.MainViewModel
|
||||
import kr.co.vividnext.sodalive.mypage.MyPageViewModel
|
||||
import kr.co.vividnext.sodalive.network.TokenAuthenticator
|
||||
import kr.co.vividnext.sodalive.settings.event.EventApi
|
||||
import kr.co.vividnext.sodalive.settings.event.EventRepository
|
||||
@@ -77,6 +78,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
viewModel { FindPasswordViewModel(get()) }
|
||||
viewModel { MainViewModel(get()) }
|
||||
viewModel { LiveViewModel(get(), get(), get()) }
|
||||
viewModel { MyPageViewModel(get()) }
|
||||
}
|
||||
|
||||
private val repositoryModule = module {
|
||||
|
@@ -1,7 +1,131 @@
|
||||
package kr.co.vividnext.sodalive.mypage
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.URLUtil
|
||||
import android.widget.Toast
|
||||
import coil.load
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseFragment
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.databinding.FragmentMyBinding
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
import kr.co.vividnext.sodalive.settings.notification.MemberRole
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class MyPageFragment : BaseFragment<FragmentMyBinding>(FragmentMyBinding::inflate) {
|
||||
|
||||
private val viewModel: MyPageViewModel by inject()
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
loadingDialog = LoadingDialog(requireActivity(), layoutInflater)
|
||||
|
||||
setupView()
|
||||
bindData()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
viewModel.getUserInfo()
|
||||
}
|
||||
|
||||
private fun setupView() {
|
||||
binding.ivSettings.setOnClickListener {}
|
||||
|
||||
binding.ivEdit.setOnClickListener {}
|
||||
|
||||
binding.tvTotalCoin.setOnClickListener {}
|
||||
|
||||
binding.tvChargeCoin.setOnClickListener {}
|
||||
|
||||
binding.llReservationSuda.setOnClickListener {}
|
||||
|
||||
binding.rlServiceCenter.setOnClickListener {}
|
||||
|
||||
binding.tvAuth.setOnClickListener {}
|
||||
|
||||
if (SharedPreferenceManager.role == MemberRole.CREATOR.name) {
|
||||
binding.tvMyChannel.visibility = View.VISIBLE
|
||||
binding.tvMyChannel.setOnClickListener {}
|
||||
} else {
|
||||
binding.tvMyChannel.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun bindData() {
|
||||
viewModel.toastLiveData.observe(viewLifecycleOwner) {
|
||||
it?.let { Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
||||
viewModel.isLoading.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
loadingDialog.show(screenWidth)
|
||||
} else {
|
||||
loadingDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.myPageLiveData.observe(viewLifecycleOwner) {
|
||||
if (it.isAuth) {
|
||||
binding.tvAuth.visibility = View.GONE
|
||||
} else {
|
||||
binding.tvAuth.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
binding.ivProfile.load(it.profileUrl) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.bg_placeholder)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
binding.tvNickname.text = it.nickname
|
||||
|
||||
if (it.websiteUrl.isNullOrBlank() || !URLUtil.isValidUrl(it.websiteUrl)) {
|
||||
binding.ivWebsite.visibility = View.GONE
|
||||
} else {
|
||||
binding.ivWebsite.visibility = View.VISIBLE
|
||||
binding.ivWebsite.setOnClickListener { _ ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.websiteUrl)))
|
||||
}
|
||||
}
|
||||
|
||||
if (it.blogUrl.isNullOrBlank() || !URLUtil.isValidUrl(it.blogUrl)) {
|
||||
binding.ivBlog.visibility = View.GONE
|
||||
} else {
|
||||
binding.ivBlog.visibility = View.VISIBLE
|
||||
binding.ivBlog.setOnClickListener { _ ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.blogUrl)))
|
||||
}
|
||||
}
|
||||
|
||||
if (it.instagramUrl.isNullOrBlank() || !URLUtil.isValidUrl(it.instagramUrl)) {
|
||||
binding.ivInstagram.visibility = View.GONE
|
||||
} else {
|
||||
binding.ivInstagram.visibility = View.VISIBLE
|
||||
binding.ivInstagram.setOnClickListener { _ ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.instagramUrl)))
|
||||
}
|
||||
}
|
||||
|
||||
if (it.youtubeUrl.isNullOrBlank() || !URLUtil.isValidUrl(it.youtubeUrl)) {
|
||||
binding.ivYoutube.visibility = View.GONE
|
||||
} else {
|
||||
binding.ivYoutube.visibility = View.VISIBLE
|
||||
binding.ivYoutube.setOnClickListener { _ ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.youtubeUrl)))
|
||||
}
|
||||
}
|
||||
|
||||
binding.tvTotalCoin.text = "${(it.chargeCoin + it.rewardCoin).moneyFormat()} 캔"
|
||||
binding.tvReservationSuda.text = "${it.sudaReservationCount}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,19 @@
|
||||
package kr.co.vividnext.sodalive.mypage
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class MyPageResponse(
|
||||
@SerializedName("nickname") val nickname: String,
|
||||
@SerializedName("profileUrl") val profileUrl: String,
|
||||
@SerializedName("chargeCoin") val chargeCoin: Int,
|
||||
@SerializedName("rewardCoin") val rewardCoin: Int,
|
||||
@SerializedName("youtubeUrl") val youtubeUrl: String?,
|
||||
@SerializedName("instagramUrl") val instagramUrl: String?,
|
||||
@SerializedName("websiteUrl") val websiteUrl: String?,
|
||||
@SerializedName("blogUrl") val blogUrl: String?,
|
||||
@SerializedName("sudaReservationCount") val sudaReservationCount: Int,
|
||||
@SerializedName("counselingReservationCount") val counselingReservationCount: Int,
|
||||
@SerializedName("likeCount") val likeCount: Int,
|
||||
@SerializedName("reviewCount") val reviewCount: Int,
|
||||
@SerializedName("isAuth") val isAuth: Boolean,
|
||||
)
|
@@ -0,0 +1,59 @@
|
||||
package kr.co.vividnext.sodalive.mypage
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.orhanobut.logger.Logger
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.base.BaseViewModel
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.user.UserRepository
|
||||
|
||||
class MyPageViewModel(
|
||||
private val userRepository: UserRepository
|
||||
): BaseViewModel() {
|
||||
private val _toastLiveData = MutableLiveData<String?>()
|
||||
val toastLiveData: LiveData<String?>
|
||||
get() = _toastLiveData
|
||||
|
||||
private var _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
get() = _isLoading
|
||||
|
||||
private val _myPageLiveData = MutableLiveData<MyPageResponse>()
|
||||
val myPageLiveData: LiveData<MyPageResponse>
|
||||
get() = _myPageLiveData
|
||||
|
||||
fun getUserInfo() {
|
||||
if (!_isLoading.value!!) {
|
||||
_isLoading.value = true
|
||||
}
|
||||
|
||||
compositeDisposable.add(
|
||||
userRepository.getMyPage("Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
if (it.success && it.data != null) {
|
||||
_myPageLiveData.postValue(it.data!!)
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
}
|
||||
_isLoading.value = false
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.user
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.main.PushTokenUpdateRequest
|
||||
import kr.co.vividnext.sodalive.mypage.MyPageResponse
|
||||
import kr.co.vividnext.sodalive.settings.notification.GetMemberInfoResponse
|
||||
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
|
||||
import kr.co.vividnext.sodalive.user.find_password.ForgotPasswordRequest
|
||||
@@ -17,6 +18,7 @@ import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface UserApi {
|
||||
@POST("/member/login")
|
||||
@@ -48,4 +50,10 @@ interface UserApi {
|
||||
@Body request: PushTokenUpdateRequest,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<Any>>
|
||||
|
||||
@GET("/member/mypage")
|
||||
fun getMyPage(
|
||||
@Query("container") container: String = "aos",
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<MyPageResponse>>
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.user
|
||||
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.main.PushTokenUpdateRequest
|
||||
import kr.co.vividnext.sodalive.mypage.MyPageResponse
|
||||
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
|
||||
import kr.co.vividnext.sodalive.user.find_password.ForgotPasswordRequest
|
||||
import kr.co.vividnext.sodalive.user.login.LoginRequest
|
||||
@@ -28,4 +31,8 @@ class UserRepository(private val userApi: UserApi) {
|
||||
) = userApi.updatePushToken(request, authHeader = token)
|
||||
|
||||
fun getMemberInfo(token: String) = userApi.getMemberInfo(authHeader = token)
|
||||
|
||||
fun getMyPage(token: String): Single<ApiResponse<MyPageResponse>> {
|
||||
return userApi.getMyPage(authHeader = token)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user