refactor(main): 기존 로그인 가드를 제거한다
This commit is contained in:
@@ -1,76 +0,0 @@
|
|||||||
package kr.co.vividnext.sodalive.v2.main
|
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import kr.co.vividnext.sodalive.R
|
|
||||||
import kr.co.vividnext.sodalive.common.Constants
|
|
||||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
|
||||||
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.mypage.auth.BootpayResponse
|
|
||||||
import kr.co.vividnext.sodalive.settings.ContentSettingsActivity
|
|
||||||
import kr.co.vividnext.sodalive.splash.SplashActivity
|
|
||||||
import kr.co.vividnext.sodalive.v2.components.modal.V2ModalDialog
|
|
||||||
import org.koin.android.ext.android.get
|
|
||||||
|
|
||||||
fun Fragment.ensureMainV2NavigationAllowed(
|
|
||||||
requiresAdultContentAccess: Boolean = false,
|
|
||||||
onAllowed: () -> Unit
|
|
||||||
) {
|
|
||||||
if (SharedPreferenceManager.token.isBlank()) {
|
|
||||||
(activity as? MainV2Activity)?.showLoginActivity()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiresAdultContentAccess) {
|
|
||||||
val isKoreanCountry = SharedPreferenceManager.countryCode.ifBlank { "KR" } == "KR"
|
|
||||||
if (isKoreanCountry && !SharedPreferenceManager.isAuth) {
|
|
||||||
showMainV2AuthDialog()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SharedPreferenceManager.isAdultContentVisible) {
|
|
||||||
startActivity(
|
|
||||||
Intent(requireContext(), ContentSettingsActivity::class.java).apply {
|
|
||||||
putExtra(Constants.EXTRA_SHOW_SENSITIVE_CONTENT_GUIDE, true)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onAllowed()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Fragment.showMainV2AuthDialog() {
|
|
||||||
V2ModalDialog(
|
|
||||||
activity = requireActivity(),
|
|
||||||
layoutInflater = layoutInflater,
|
|
||||||
title = getString(R.string.auth_title),
|
|
||||||
desc = getString(R.string.auth_desc_live),
|
|
||||||
confirmButtonTitle = getString(R.string.auth_go),
|
|
||||||
confirmButtonClick = { startMainV2AuthFlow() },
|
|
||||||
cancelButtonTitle = getString(R.string.cancel),
|
|
||||||
cancelButtonClick = {}
|
|
||||||
).show(resources.displayMetrics.widthPixels)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Fragment.startMainV2AuthFlow() {
|
|
||||||
val myPageViewModel: MyPageViewModel = get()
|
|
||||||
Auth.auth(requireActivity(), requireContext()) { json ->
|
|
||||||
val bootpayResponse = Gson().fromJson(json, 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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user