refactor(main): 메인 접근 가드를 공통화한다
This commit is contained in:
@@ -50,7 +50,9 @@ import kr.co.vividnext.sodalive.message.MessageActivity
|
|||||||
import kr.co.vividnext.sodalive.mypage.MyPageFragment
|
import kr.co.vividnext.sodalive.mypage.MyPageFragment
|
||||||
import kr.co.vividnext.sodalive.settings.event.EventDetailActivity
|
import kr.co.vividnext.sodalive.settings.event.EventDetailActivity
|
||||||
import kr.co.vividnext.sodalive.settings.notification.NotificationSettingsDialog
|
import kr.co.vividnext.sodalive.settings.notification.NotificationSettingsDialog
|
||||||
import kr.co.vividnext.sodalive.user.login.LoginActivity
|
import kr.co.vividnext.sodalive.v2.access.AccessRequirement
|
||||||
|
import kr.co.vividnext.sodalive.v2.access.ensureV2Access
|
||||||
|
import kr.co.vividnext.sodalive.v2.access.isV2AccessAllowed
|
||||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||||
import kr.co.vividnext.sodalive.v2.creator.channel.CreatorChannelActivity
|
import kr.co.vividnext.sodalive.v2.creator.channel.CreatorChannelActivity
|
||||||
import kr.co.vividnext.sodalive.v2.main.chat.ChatMainFragment
|
import kr.co.vividnext.sodalive.v2.main.chat.ChatMainFragment
|
||||||
@@ -88,12 +90,12 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
pushTokenUpdate()
|
pushTokenUpdate()
|
||||||
|
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
if (!handleAudioNotificationRoute(intent) && isLoggedIn()) {
|
if (!handleAudioNotificationRoute(intent) && isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
executeDeeplink(intent)
|
executeDeeplink(intent)
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
if (isLoggedIn()) {
|
if (isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
updatePidAndGaid()
|
updatePidAndGaid()
|
||||||
getEventPopup()
|
getEventPopup()
|
||||||
observePlayerState()
|
observePlayerState()
|
||||||
@@ -124,7 +126,7 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handleAudioNotificationRoute(intent) && isLoggedIn()) {
|
if (!handleAudioNotificationRoute(intent) && isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
executeDeeplink(intent)
|
executeDeeplink(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,23 +178,14 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showLoginActivity() {
|
|
||||||
if (!isLoggedIn()) {
|
|
||||||
val extras = intent.extras
|
|
||||||
startActivity(
|
|
||||||
Intent(applicationContext, LoginActivity::class.java).apply {
|
|
||||||
putExtra(Constants.EXTRA_DATA, extras)
|
|
||||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
||||||
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun openChatTab() {
|
fun openChatTab() {
|
||||||
selectChatTabWithLoginGuard()
|
selectChatTabWithLoginGuard()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showLoginActivity() {
|
||||||
|
ensureV2Access(AccessRequirement.Login)
|
||||||
|
}
|
||||||
|
|
||||||
fun openContentAllTab(type: MainContentAllType, sort: ContentSort = ContentSort.LATEST) {
|
fun openContentAllTab(type: MainContentAllType, sort: ContentSort = ContentSort.LATEST) {
|
||||||
if (viewModel.currentTab.value != MainV2Tab.CONTENT) {
|
if (viewModel.currentTab.value != MainV2Tab.CONTENT) {
|
||||||
viewModel.clickTab(MainV2Tab.CONTENT)
|
viewModel.clickTab(MainV2Tab.CONTENT)
|
||||||
@@ -292,13 +285,9 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun selectChatTabWithLoginGuard(): Boolean {
|
private fun selectChatTabWithLoginGuard(): Boolean {
|
||||||
if (!isLoggedIn()) {
|
return ensureV2Access(AccessRequirement.Login) {
|
||||||
showLoginActivity()
|
viewModel.clickTab(MainV2Tab.CHAT)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.clickTab(MainV2Tab.CHAT)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observePlayerState() {
|
private fun observePlayerState() {
|
||||||
@@ -434,10 +423,8 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
|
|
||||||
return when (route) {
|
return when (route) {
|
||||||
ROUTE_AUDIO_PLAYER -> {
|
ROUTE_AUDIO_PLAYER -> {
|
||||||
if (isLoggedIn()) {
|
ensureV2Access(AccessRequirement.Login) {
|
||||||
showPlayerFragment()
|
showPlayerFragment()
|
||||||
} else {
|
|
||||||
showLoginActivity()
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -445,14 +432,16 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
ROUTE_AUDIO_DETAIL -> {
|
ROUTE_AUDIO_DETAIL -> {
|
||||||
val contentId = intent.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
val contentId = intent.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
||||||
intent.removeExtra(Constants.EXTRA_AUDIO_CONTENT_ID)
|
intent.removeExtra(Constants.EXTRA_AUDIO_CONTENT_ID)
|
||||||
if (contentId > 0 && isLoggedIn()) {
|
if (contentId > 0) {
|
||||||
startActivity(
|
ensureV2Access(AccessRequirement.Login) {
|
||||||
Intent(applicationContext, AudioContentDetailActivity::class.java).apply {
|
startActivity(
|
||||||
putExtra(Constants.EXTRA_AUDIO_CONTENT_ID, contentId)
|
Intent(applicationContext, AudioContentDetailActivity::class.java).apply {
|
||||||
}
|
putExtra(Constants.EXTRA_AUDIO_CONTENT_ID, contentId)
|
||||||
)
|
}
|
||||||
} else if (!isLoggedIn()) {
|
)
|
||||||
showLoginActivity()
|
}
|
||||||
|
} else if (!isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
|
ensureV2Access(AccessRequirement.Login)
|
||||||
}
|
}
|
||||||
contentId > 0
|
contentId > 0
|
||||||
}
|
}
|
||||||
@@ -503,7 +492,7 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
val pushToken = it.result
|
val pushToken = it.result
|
||||||
if (pushToken != null) {
|
if (pushToken != null) {
|
||||||
SharedPreferenceManager.pushToken = pushToken
|
SharedPreferenceManager.pushToken = pushToken
|
||||||
if (isLoggedIn()) {
|
if (isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
viewModel.pushTokenUpdate(pushToken)
|
viewModel.pushTokenUpdate(pushToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -517,7 +506,7 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getMemberInfo() {
|
private fun getMemberInfo() {
|
||||||
if (isLoggedIn()) {
|
if (isV2AccessAllowed(AccessRequirement.Login)) {
|
||||||
viewModel.getMemberInfo(context = applicationContext) {
|
viewModel.getMemberInfo(context = applicationContext) {
|
||||||
notificationSettingsDialog.show(screenWidth)
|
notificationSettingsDialog.show(screenWidth)
|
||||||
}
|
}
|
||||||
@@ -786,10 +775,6 @@ class MainV2Activity : BaseActivity<ActivityMainV2Binding>(ActivityMainV2Binding
|
|||||||
SharedPreferenceManager.marketingLinkValueId = 0
|
SharedPreferenceManager.marketingLinkValueId = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isLoggedIn(): Boolean {
|
|
||||||
return SharedPreferenceManager.token.isNotBlank() && SharedPreferenceManager.token.length > 10
|
|
||||||
}
|
|
||||||
|
|
||||||
inner class AudioContentReceiver : BroadcastReceiver() {
|
inner class AudioContentReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
val contentId = intent?.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
val contentId = intent?.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ class MainV2ActivitySourceTest {
|
|||||||
assertTrue(source.contains("val roomId = bundle.getString(\"room_id\")?.toLongOrNull()"))
|
assertTrue(source.contains("val roomId = bundle.getString(\"room_id\")?.toLongOrNull()"))
|
||||||
assertTrue(source.contains("DmChatRoomActivity.newIntentByRoomId(applicationContext, roomId)"))
|
assertTrue(source.contains("DmChatRoomActivity.newIntentByRoomId(applicationContext, roomId)"))
|
||||||
assertTrue(source.contains("if (isDmChatDeepLink(bundle) && roomId != null && roomId > 0)"))
|
assertTrue(source.contains("if (isDmChatDeepLink(bundle) && roomId != null && roomId > 0)"))
|
||||||
|
assertFalse(source.contains("private fun isLoggedIn()"))
|
||||||
|
assertTrue(source.contains("fun showLoginActivity()"))
|
||||||
|
assertBefore(
|
||||||
|
source.substringFrom("fun showLoginActivity()"),
|
||||||
|
"ensureV2Access(AccessRequirement.Login)",
|
||||||
|
"fun openContentAllTab"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -53,9 +60,10 @@ class MainV2ActivitySourceTest {
|
|||||||
assertTrue(source.contains("private fun selectChatTabWithLoginGuard(): Boolean"))
|
assertTrue(source.contains("private fun selectChatTabWithLoginGuard(): Boolean"))
|
||||||
|
|
||||||
val guardSource = source.substringFrom("private fun selectChatTabWithLoginGuard(): Boolean")
|
val guardSource = source.substringFrom("private fun selectChatTabWithLoginGuard(): Boolean")
|
||||||
assertBefore(guardSource, "if (!isLoggedIn())", "viewModel.clickTab(MainV2Tab.CHAT)")
|
assertTrue(guardSource.contains("return ensureV2Access(AccessRequirement.Login)"))
|
||||||
assertBefore(guardSource, "showLoginActivity()", "return false")
|
assertBefore(guardSource, "ensureV2Access(AccessRequirement.Login)", "viewModel.clickTab(MainV2Tab.CHAT)")
|
||||||
assertTrue(guardSource.contains("return true"))
|
assertFalse(guardSource.contains("isLoggedIn()"))
|
||||||
|
assertFalse(guardSource.contains("showLoginActivity()"))
|
||||||
|
|
||||||
val setupViewSource = source.substringFrom("override fun setupView()")
|
val setupViewSource = source.substringFrom("override fun setupView()")
|
||||||
assertTrue(setupViewSource.contains("selectChatTabWithLoginGuard()"))
|
assertTrue(setupViewSource.contains("selectChatTabWithLoginGuard()"))
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ class MainV2AudioNotificationRouteSourceTest {
|
|||||||
fun `오디오 알림 route는 채팅 필터 이후 딥링크 이전에 처리된다`() {
|
fun `오디오 알림 route는 채팅 필터 이후 딥링크 이전에 처리된다`() {
|
||||||
val onNewIntentSource = source.substringFrom("override fun onNewIntent(intent: Intent)")
|
val onNewIntentSource = source.substringFrom("override fun onNewIntent(intent: Intent)")
|
||||||
assertBefore(onNewIntentSource, "if (intent.hasExtra(EXTRA_CHAT_FILTER))", "handleAudioNotificationRoute(intent)")
|
assertBefore(onNewIntentSource, "if (intent.hasExtra(EXTRA_CHAT_FILTER))", "handleAudioNotificationRoute(intent)")
|
||||||
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "isLoggedIn()")
|
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "isV2AccessAllowed(AccessRequirement.Login)")
|
||||||
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
||||||
|
|
||||||
val onCreateSource = source.substringFrom("override fun onCreate(savedInstanceState: Bundle?)")
|
val onCreateSource = source.substringFrom("override fun onCreate(savedInstanceState: Bundle?)")
|
||||||
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "isLoggedIn()")
|
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "isV2AccessAllowed(AccessRequirement.Login)")
|
||||||
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
assertBefore(onCreateSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user