Updated on 2026-08-14
This commit is contained in:
parent
92034d6106
commit
625cf611f2
9 changed files with 151 additions and 7 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package com.tangem.features.feed.deeplink
|
||||
|
||||
import android.net.Uri
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.features.feed.entry.deeplink.NewsDetailsDeepLinkHandler
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultNewsDetailsDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted private val scope: CoroutineScope,
|
||||
@Assisted private val deeplinkUri: Uri,
|
||||
private val appRouter: AppRouter,
|
||||
) : NewsDetailsDeepLinkHandler {
|
||||
|
||||
init {
|
||||
handleDeepLink()
|
||||
}
|
||||
|
||||
private fun handleDeepLink() {
|
||||
scope.launch {
|
||||
val articleId = extractArticleIdFromUri(deeplinkUri)
|
||||
if (articleId == null) {
|
||||
Timber.e(
|
||||
"""
|
||||
Failed to extract article ID from deep link
|
||||
|- Received URI: $deeplinkUri
|
||||
""".trimIndent(),
|
||||
)
|
||||
return@launch
|
||||
}
|
||||
|
||||
appRouter.push(
|
||||
AppRoute.NewsDetails(newsId = articleId),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing URI with format https://tangem.com/news/{category}/{id}-{slug} to get id
|
||||
*/
|
||||
private fun extractArticleIdFromUri(uri: Uri): Int? {
|
||||
val path = uri.path ?: return null
|
||||
val pathSegments = path.split("/").filter { it.isNotBlank() }
|
||||
if (pathSegments.isEmpty() || pathSegments[0] != "news" || pathSegments.size < 2) {
|
||||
return null
|
||||
}
|
||||
val lastSegment = pathSegments.last()
|
||||
val idPart = lastSegment.substringBefore("-")
|
||||
return idPart.toIntOrNull()
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : NewsDetailsDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope, deeplinkUri: Uri): DefaultNewsDetailsDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.features.feed.deeplink.di
|
||||
|
||||
import com.tangem.features.feed.deeplink.DefaultNewsDetailsDeepLinkHandler
|
||||
import com.tangem.features.feed.entry.deeplink.NewsDetailsDeepLinkHandler
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal interface FeedDeepLinkModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindNewsDetailsDeepLinkHandlerFactory(
|
||||
impl: DefaultNewsDetailsDeepLinkHandler.Factory,
|
||||
): NewsDetailsDeepLinkHandler.Factory
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ import com.tangem.common.ui.news.ArticleHeader
|
|||
import com.tangem.core.ui.R
|
||||
import com.tangem.core.ui.components.SecondaryButtonIconStart
|
||||
import com.tangem.core.ui.components.SpacerH
|
||||
import com.tangem.core.ui.components.SpacerHMax
|
||||
import com.tangem.core.ui.components.SpacerW
|
||||
import com.tangem.core.ui.components.buttons.common.TangemButtonSize
|
||||
import com.tangem.core.ui.components.pager.PagerIndicator
|
||||
|
|
@ -171,7 +172,10 @@ private fun ArticleDetail(article: ArticleUM, modifier: Modifier = Modifier, onL
|
|||
items = article.sources,
|
||||
key = SourceUM::id,
|
||||
) { source ->
|
||||
SourceItem(source = source)
|
||||
SourceItem(
|
||||
source = source,
|
||||
modifier = Modifier.fillParentMaxHeight(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -259,9 +263,11 @@ private fun SourceItem(source: SourceUM, modifier: Modifier = Modifier) {
|
|||
color = TangemTheme.colors.text.primary1,
|
||||
maxLines = 3,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(bottom = 12.dp),
|
||||
)
|
||||
}
|
||||
|
||||
SpacerHMax()
|
||||
|
||||
Text(
|
||||
text = source.publishedAt.resolveReference(),
|
||||
style = TangemTheme.typography.caption2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue