Skip to content

Commit

Permalink
[feature/fix-build-issues] 코드 일부 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
l2hyunwoo committed Sep 19, 2024
1 parent 8c1e261 commit ea7f327
Showing 1 changed file with 79 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.sopt.official.common.navigator.DeepLinkType
import org.sopt.official.common.util.extractQueryParameter
import org.sopt.official.common.util.isExpiredDate
import org.sopt.official.common.util.serializableExtra
import org.sopt.official.feature.home.HomeActivity
import org.sopt.official.feature.notification.detail.NotificationDetailActivity
import org.sopt.official.network.persistence.SoptDataStore
import timber.log.Timber
Expand All @@ -45,70 +44,96 @@ import javax.inject.Inject

@AndroidEntryPoint
class SchemeActivity : AppCompatActivity() {
@Inject
lateinit var dataStore: SoptDataStore
private val args by serializableExtra(Argument("", ""))

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleDeepLink()
}
@Inject
lateinit var dataStore: SoptDataStore
private val args by serializableExtra(
Argument(
"",
""
)
)

private fun handleDeepLink() {
val link = args?.link
val linkIntent = when (link.isNullOrBlank()) {
true -> NotificationDetailActivity.getIntent(this, args?.notificationId.orEmpty())
false -> checkLinkExpiration(link)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleDeepLink()
}

when (!isTaskRoot) {
true -> startActivity(linkIntent)
false -> TaskStackBuilder.create(this).apply {
if (!isIntentToHome(linkIntent)) {
addNextIntentWithParentStack(
DeepLinkType.getHomeIntent(UserStatus.of(dataStore.userStatus))
)
private fun handleDeepLink() {
val link = args?.link
val linkIntent = if (link.isNullOrBlank()) {
NotificationDetailActivity.getIntent(
this,
args?.notificationId.orEmpty()
)
} else {
checkLinkExpiration(link)
}

when (!isTaskRoot) {
true -> startActivity(linkIntent)
false -> TaskStackBuilder.create(this).apply {
if (!isIntentToHome()) {
addNextIntentWithParentStack(
DeepLinkType.getHomeIntent(UserStatus.of(dataStore.userStatus))
)
}
addNextIntent(linkIntent)
}.startActivities()
}
addNextIntent(linkIntent)
}.startActivities()
finish()
}
finish()
}

private fun checkLinkExpiration(link: String): Intent {
return try {
val expiredAt = link.extractQueryParameter("expiredAt")
when (expiredAt.isExpiredDate()) {
true -> DeepLinkType.getHomeIntent(
UserStatus.of(dataStore.userStatus), DeepLinkType.EXPIRED
)
private fun checkLinkExpiration(link: String): Intent {
return try {
val expiredAt = link.extractQueryParameter("expiredAt")
when (expiredAt.isExpiredDate()) {
true -> DeepLinkType.getHomeIntent(
UserStatus.of(dataStore.userStatus),
DeepLinkType.EXPIRED
)

else -> when (link.contains("http://") || link.contains("https://")) {
true -> Intent(
Intent.ACTION_VIEW,
Uri.parse(link)
)

else -> when (link.contains("http://") || link.contains("https://")) {
true -> Intent(Intent.ACTION_VIEW, Uri.parse(link))
false -> DeepLinkType.of(link).getIntent(
this, UserStatus.of(dataStore.userStatus), link
)
false -> DeepLinkType.of(link).getIntent(
this,
UserStatus.of(dataStore.userStatus),
link
)
}
}
} catch (exception: Exception) {
Timber.e(exception)
DeepLinkType.getHomeIntent(
UserStatus.of(dataStore.userStatus),
DeepLinkType.UNKNOWN
)
}
}
} catch (exception: Exception) {
Timber.e(exception)
DeepLinkType.getHomeIntent(
UserStatus.of(dataStore.userStatus), DeepLinkType.UNKNOWN
)
}
}

private fun Intent.isIntentToHome(): Boolean =
intent.component?.className == HomeActivity::class.java.name
private fun isIntentToHome(): Boolean {
return intent.action == Intent.ACTION_MAIN && intent.categories?.contains(Intent.CATEGORY_LAUNCHER) == true
}
}

data class Argument(
val notificationId: String, val link: String
) : Serializable
data class Argument(
val notificationId: String,
val link: String
) : Serializable

companion object {
@JvmStatic
fun getIntent(context: Context, args: Argument) = Intent(context, SchemeActivity::class.java).putExtra("args", args)
}
companion object {
@JvmStatic
fun getIntent(
context: Context,
args: Argument
) = Intent(
context,
SchemeActivity::class.java
).putExtra(
"args",
args
)
}
}

0 comments on commit ea7f327

Please sign in to comment.