diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/NewsDetailsModel.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/NewsDetailsModel.kt index 7d8791f935..b749723815 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/NewsDetailsModel.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/NewsDetailsModel.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Stable import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer +import com.tangem.core.navigation.share.ShareManager import com.tangem.core.navigation.url.UrlOpener import com.tangem.domain.news.usecase.ObserveNewsDetailsUseCase import com.tangem.features.feed.components.news.details.DefaultNewsDetailsComponent @@ -25,6 +26,7 @@ internal class NewsDetailsModel @Inject constructor( override val dispatchers: CoroutineDispatcherProvider, private val observeNewsDetailsUseCase: ObserveNewsDetailsUseCase, private val urlOpener: UrlOpener, + private val shareManager: ShareManager, paramsContainer: ParamsContainer, ) : Model() { @@ -42,10 +44,10 @@ internal class NewsDetailsModel @Inject constructor( NewsDetailsUM( articles = persistentListOf(), selectedArticleIndex = 0, - onShareClick = { /* [REDACTED_TODO_COMMENT] */ }, + onShareClick = {}, onLikeClick = { /* [REDACTED_TODO_COMMENT] */ }, onBackClick = params.onBackClicked, - onArticleIndexChanged = { /* [REDACTED_TODO_COMMENT] */ }, + onArticleIndexChanged = ::onArticleIndexChanged, ), ) @@ -59,6 +61,20 @@ internal class NewsDetailsModel @Inject constructor( } } + private fun onArticleIndexChanged(newIndex: Int) { + val currentArticle = state.value.articles.getOrNull(newIndex) + _state.update { currentState -> + currentState.copy( + selectedArticleIndex = newIndex, + onShareClick = { + currentArticle?.let { + shareManager.shareText(it.newsUrl) + } + }, + ) + } + } + private fun handlePreselectedArticles() { modelScope.launch { observeNewsDetailsUseCase.prefetch( @@ -80,10 +96,16 @@ internal class NewsDetailsModel @Inject constructor( } .onEach { articles -> val selectedIndex = articles.indexOfFirstOrNull { it.id == params.articleId } ?: 0 + val currentArticle = articles.getOrNull(selectedIndex) _state.update { newsDetailsUM -> newsDetailsUM.copy( articles = articles, selectedArticleIndex = selectedIndex, + onShareClick = { + currentArticle?.let { + shareManager.shareText(it.newsUrl) + } + }, ) } } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/converter/NewsDetailsConverter.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/converter/NewsDetailsConverter.kt index 6a0fa54bae..939c67a294 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/converter/NewsDetailsConverter.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/news/details/converter/NewsDetailsConverter.kt @@ -36,6 +36,7 @@ internal class NewsDetailsConverter( shortContent = value.shortContent, content = value.content, sources = buildSources(value), + newsUrl = value.newsUrl, ) } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/MockArticlesFactory.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/MockArticlesFactory.kt index 03b4990886..97aec724e5 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/MockArticlesFactory.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/MockArticlesFactory.kt @@ -44,6 +44,7 @@ internal object MockArticlesFactory { onClick = {}, ), ).toPersistentList(), + newsUrl = "", ), ArticleUM( id = 2, @@ -69,6 +70,7 @@ internal object MockArticlesFactory { onClick = {}, ), ).toPersistentList(), + newsUrl = "", ), ArticleUM( id = 3, @@ -94,6 +96,7 @@ internal object MockArticlesFactory { onClick = {}, ), ).toPersistentList(), + newsUrl = "", ), ArticleUM( id = 4, @@ -119,6 +122,7 @@ internal object MockArticlesFactory { onClick = {}, ), ).toPersistentList(), + newsUrl = "", ), ArticleUM( id = 5, @@ -131,6 +135,7 @@ internal object MockArticlesFactory { shortContent = "New DeFi protocol introduced innovative yield farming approach.", content = "A newly launched protocol unveiled innovative yield farming mechanism.\n\nAPY rates range from 15% to 30%.", sources = persistentListOf(), + newsUrl = "", ), ArticleUM( id = 6, @@ -144,6 +149,7 @@ internal object MockArticlesFactory { shortContent = "Comprehensive cryptocurrency regulation bill passed Senate Banking Committee.", content = "The US Senate Banking Committee advanced landmark crypto regulation bill.\n\nKey provisions include asset definitions.", sources = persistentListOf(), + newsUrl = "", ), ArticleUM( id = 7, @@ -156,6 +162,7 @@ internal object MockArticlesFactory { shortContent = "World's largest bank announced cryptocurrency custody services.", content = "Major financial institution announced comprehensive crypto custody services.\n\nSupporting Bitcoin and Ethereum initially.", sources = persistentListOf(), + newsUrl = "", ), ArticleUM( id = 8, @@ -168,6 +175,7 @@ internal object MockArticlesFactory { shortContent = "Leading NFT marketplace experienced dramatic surge in trading activity.", content = "Prominent NFT marketplace reported 300% increase in trading volume.\n\nNew features include lower fees.", sources = persistentListOf(), + newsUrl = "", ), ArticleUM( id = 9, @@ -181,6 +189,7 @@ internal object MockArticlesFactory { shortContent = "New Layer 2 scaling solution achieved 100,000 TPS in testing.", content = "Layer 2 solution processed 100,000 transactions per second.\n\nUsing zero-knowledge proof technology.", sources = persistentListOf(), + newsUrl = "", ), ArticleUM( id = 10, @@ -194,6 +203,7 @@ internal object MockArticlesFactory { shortContent = "Total stablecoin market capitalization surpassed \$180 billion.", content = "Stablecoin market cap reached \$180 billion all-time high.\n\nDriven by DeFi activity and institutional adoption.", sources = persistentListOf(), + newsUrl = "", ), ).toPersistentList() } \ No newline at end of file diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/NewsDetailsUM.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/NewsDetailsUM.kt index a7524862e0..d0049ca02b 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/NewsDetailsUM.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/news/details/state/NewsDetailsUM.kt @@ -22,6 +22,7 @@ internal data class ArticleUM( val shortContent: String, val content: String, val sources: ImmutableList, + val newsUrl: String, ) internal data class SourceUM(