feat(chat-character): 캐릭터 탭 모든 액션
- 로그인과 본인인증이 되어 있어야 가능하도록 수정
This commit is contained in:
		@@ -26,6 +26,11 @@ import kr.co.vividnext.sodalive.common.SharedPreferenceManager
 | 
			
		||||
import kr.co.vividnext.sodalive.databinding.FragmentCharacterTabBinding
 | 
			
		||||
import kr.co.vividnext.sodalive.extensions.dpToPx
 | 
			
		||||
import kr.co.vividnext.sodalive.main.MainActivity
 | 
			
		||||
import kr.co.vividnext.sodalive.mypage.MyPageViewModel
 | 
			
		||||
import kr.co.vividnext.sodalive.mypage.auth.Auth
 | 
			
		||||
import kr.co.vividnext.sodalive.mypage.auth.AuthVerifyRequest
 | 
			
		||||
import kr.co.vividnext.sodalive.splash.SplashActivity
 | 
			
		||||
import com.google.gson.Gson
 | 
			
		||||
import org.koin.android.ext.android.inject
 | 
			
		||||
 | 
			
		||||
// 캐릭터 탭 프래그먼트
 | 
			
		||||
@@ -34,6 +39,7 @@ class CharacterTabFragment : BaseFragment<FragmentCharacterTabBinding>(
 | 
			
		||||
    FragmentCharacterTabBinding::inflate
 | 
			
		||||
) {
 | 
			
		||||
    private val viewModel: CharacterTabViewModel by inject()
 | 
			
		||||
    private val myPageViewModel: MyPageViewModel by inject()
 | 
			
		||||
 | 
			
		||||
    private lateinit var contentBannerAdapter: CharacterBannerAdapter
 | 
			
		||||
    private lateinit var recentCharacterAdapter: RecentCharacterAdapter
 | 
			
		||||
@@ -75,14 +81,12 @@ class CharacterTabFragment : BaseFragment<FragmentCharacterTabBinding>(
 | 
			
		||||
            pagerWidth,
 | 
			
		||||
            pagerHeight
 | 
			
		||||
        ) {
 | 
			
		||||
            if (SharedPreferenceManager.token.isNotBlank()) {
 | 
			
		||||
            ensureLoginAndAuth {
 | 
			
		||||
                startActivity(
 | 
			
		||||
                    Intent(requireContext(), CharacterDetailActivity::class.java).apply {
 | 
			
		||||
                        putExtra(EXTRA_CHARACTER_ID, it.characterId)
 | 
			
		||||
                    }
 | 
			
		||||
                )
 | 
			
		||||
            } else {
 | 
			
		||||
                (requireActivity() as MainActivity).showLoginActivity()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -353,6 +357,47 @@ class CharacterTabFragment : BaseFragment<FragmentCharacterTabBinding>(
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun ensureLoginAndAuth(onAuthed: () -> Unit) {
 | 
			
		||||
        if (SharedPreferenceManager.token.isBlank()) {
 | 
			
		||||
            (requireActivity() as MainActivity).showLoginActivity()
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!SharedPreferenceManager.isAuth) {
 | 
			
		||||
            Toast.makeText(requireContext(), "본인인증이 필요합니다.", Toast.LENGTH_LONG).show()
 | 
			
		||||
            startAuthFlow()
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        onAuthed()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun startAuthFlow() {
 | 
			
		||||
        Auth.auth(requireActivity(), requireContext()) { json ->
 | 
			
		||||
            val bootpayResponse = Gson().fromJson(
 | 
			
		||||
                json,
 | 
			
		||||
                kr.co.vividnext.sodalive.mypage.auth.BootpayResponse::class.java
 | 
			
		||||
            )
 | 
			
		||||
            val request = AuthVerifyRequest(receiptId = bootpayResponse.data.receiptId)
 | 
			
		||||
            requireActivity().runOnUiThread {
 | 
			
		||||
                myPageViewModel.authVerify(request) {
 | 
			
		||||
                    startActivity(
 | 
			
		||||
                        Intent(
 | 
			
		||||
                            requireContext(),
 | 
			
		||||
                            SplashActivity::class.java
 | 
			
		||||
                        ).apply {
 | 
			
		||||
                            addFlags(
 | 
			
		||||
                                Intent.FLAG_ACTIVITY_CLEAR_TASK or
 | 
			
		||||
                                    Intent.FLAG_ACTIVITY_NEW_TASK
 | 
			
		||||
                            )
 | 
			
		||||
                        }
 | 
			
		||||
                    )
 | 
			
		||||
                    requireActivity().finish()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun observeViewModel() {
 | 
			
		||||
        viewModel.isLoading.observe(viewLifecycleOwner) {
 | 
			
		||||
            if (it) {
 | 
			
		||||
@@ -372,14 +417,12 @@ class CharacterTabFragment : BaseFragment<FragmentCharacterTabBinding>(
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun onCharacterClick(characterId: Long) {
 | 
			
		||||
        if (SharedPreferenceManager.token.isNotBlank()) {
 | 
			
		||||
        ensureLoginAndAuth {
 | 
			
		||||
            startActivity(
 | 
			
		||||
                Intent(requireContext(), CharacterDetailActivity::class.java).apply {
 | 
			
		||||
                    putExtra(EXTRA_CHARACTER_ID, characterId)
 | 
			
		||||
                }
 | 
			
		||||
            )
 | 
			
		||||
        } else {
 | 
			
		||||
            (requireActivity() as MainActivity).showLoginActivity()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user