마이페이지 메인 - UI, Api 적용

This commit is contained in:
2023-07-28 15:01:48 +09:00
parent bad5e6612a
commit 8e0a5ccc91
20 changed files with 572 additions and 6 deletions

View File

@@ -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}"
}
}
}

View File

@@ -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,
)

View File

@@ -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("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
}
)
)
}
}