Merge the workflow of search feed
This commit is contained in:
		
							parent
							
								
									8cefff6a83
								
							
						
					
					
						commit
						794d898514
					
				@ -6,7 +6,6 @@ import android.app.NotificationManager
 | 
				
			|||||||
import android.app.PendingIntent
 | 
					import android.app.PendingIntent
 | 
				
			||||||
import android.content.Context
 | 
					import android.content.Context
 | 
				
			||||||
import android.content.Intent
 | 
					import android.content.Intent
 | 
				
			||||||
import android.os.Build
 | 
					 | 
				
			||||||
import android.util.Log
 | 
					import android.util.Log
 | 
				
			||||||
import androidx.core.app.NotificationCompat
 | 
					import androidx.core.app.NotificationCompat
 | 
				
			||||||
import androidx.core.content.ContextCompat.getSystemService
 | 
					import androidx.core.content.ContextCompat.getSystemService
 | 
				
			||||||
@ -52,15 +51,13 @@ class LocalRssRepository @Inject constructor(
 | 
				
			|||||||
            context,
 | 
					            context,
 | 
				
			||||||
            NotificationManager::class.java
 | 
					            NotificationManager::class.java
 | 
				
			||||||
        ) as NotificationManager).also {
 | 
					        ) as NotificationManager).also {
 | 
				
			||||||
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
 | 
					            it.createNotificationChannel(
 | 
				
			||||||
                it.createNotificationChannel(
 | 
					                NotificationChannel(
 | 
				
			||||||
                    NotificationChannel(
 | 
					                    NotificationGroupName.ARTICLE_UPDATE,
 | 
				
			||||||
                        NotificationGroupName.ARTICLE_UPDATE,
 | 
					                    NotificationGroupName.ARTICLE_UPDATE,
 | 
				
			||||||
                        NotificationGroupName.ARTICLE_UPDATE,
 | 
					                    NotificationManager.IMPORTANCE_DEFAULT
 | 
				
			||||||
                        NotificationManager.IMPORTANCE_DEFAULT
 | 
					 | 
				
			||||||
                    )
 | 
					 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            }
 | 
					            )
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override suspend fun updateArticleInfo(article: Article) {
 | 
					    override suspend fun updateArticleInfo(article: Article) {
 | 
				
			||||||
@ -92,28 +89,19 @@ class LocalRssRepository @Inject constructor(
 | 
				
			|||||||
                val preTime = System.currentTimeMillis()
 | 
					                val preTime = System.currentTimeMillis()
 | 
				
			||||||
                val accountId = context.currentAccountId
 | 
					                val accountId = context.currentAccountId
 | 
				
			||||||
                val articles = mutableListOf<Article>()
 | 
					                val articles = mutableListOf<Article>()
 | 
				
			||||||
                feedDao.queryAll(accountId).also { feed ->
 | 
					                feedDao.queryAll(accountId)
 | 
				
			||||||
                    updateSyncState {
 | 
					                    .also { feed -> updateSyncState { it.copy(feedCount = feed.size) } }
 | 
				
			||||||
                        it.copy(
 | 
					                    .map { feed -> async { syncFeed(feed) } }
 | 
				
			||||||
                            feedCount = feed.size,
 | 
					                    .awaitAll()
 | 
				
			||||||
                        )
 | 
					                    .forEach {
 | 
				
			||||||
 | 
					                        if (it.isNotify) {
 | 
				
			||||||
 | 
					                            notify(it.articles)
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        articles.addAll(it.articles)
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }.map { feed ->
 | 
					 | 
				
			||||||
                    async {
 | 
					 | 
				
			||||||
                        syncFeed(accountId, feed)
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }.awaitAll().forEach {
 | 
					 | 
				
			||||||
                    if (it.isNotify) {
 | 
					 | 
				
			||||||
                        notify(it.articles)
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    articles.addAll(it.articles)
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                articleDao.insertList(articles)
 | 
					                articleDao.insertList(articles)
 | 
				
			||||||
                Log.i(
 | 
					                Log.i("RlOG", "onCompletion: ${System.currentTimeMillis() - preTime}")
 | 
				
			||||||
                    "RlOG",
 | 
					 | 
				
			||||||
                    "onCompletion: ${System.currentTimeMillis() - preTime}"
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
                accountDao.queryById(accountId)?.let { account ->
 | 
					                accountDao.queryById(accountId)?.let { account ->
 | 
				
			||||||
                    accountDao.update(
 | 
					                    accountDao.update(
 | 
				
			||||||
                        account.apply {
 | 
					                        account.apply {
 | 
				
			||||||
@ -137,17 +125,9 @@ class LocalRssRepository @Inject constructor(
 | 
				
			|||||||
        val isNotify: Boolean,
 | 
					        val isNotify: Boolean,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private suspend fun syncFeed(
 | 
					    private suspend fun syncFeed(feed: Feed): ArticleNotify {
 | 
				
			||||||
        accountId: Int,
 | 
					        val latest = articleDao.queryLatestByFeedId(context.currentAccountId, feed.id)
 | 
				
			||||||
        feed: Feed
 | 
					        val articles = rssHelper.queryRssXml(feed, latest?.link).also {
 | 
				
			||||||
    ): ArticleNotify {
 | 
					 | 
				
			||||||
        val latest = articleDao.queryLatestByFeedId(accountId, feed.id)
 | 
					 | 
				
			||||||
        val articles = rssHelper.queryRssXml(
 | 
					 | 
				
			||||||
            rssNetworkDataSource,
 | 
					 | 
				
			||||||
            accountId,
 | 
					 | 
				
			||||||
            feed,
 | 
					 | 
				
			||||||
            latest?.link,
 | 
					 | 
				
			||||||
        ).also {
 | 
					 | 
				
			||||||
            if (feed.icon == null && it.isNotEmpty()) {
 | 
					            if (feed.icon == null && it.isNotEmpty()) {
 | 
				
			||||||
                rssHelper.queryRssIcon(feedDao, feed, it.first().link)
 | 
					                rssHelper.queryRssIcon(feedDao, feed, it.first().link)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
package me.ash.reader.data.repository
 | 
					package me.ash.reader.data.repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.content.Context
 | 
					import android.content.Context
 | 
				
			||||||
 | 
					import android.text.Html
 | 
				
			||||||
import android.util.Log
 | 
					import android.util.Log
 | 
				
			||||||
import dagger.hilt.android.qualifiers.ApplicationContext
 | 
					import dagger.hilt.android.qualifiers.ApplicationContext
 | 
				
			||||||
import me.ash.reader.currentAccountId
 | 
					import me.ash.reader.currentAccountId
 | 
				
			||||||
@ -35,30 +36,7 @@ class RssHelper @Inject constructor(
 | 
				
			|||||||
            groupId = "",
 | 
					            groupId = "",
 | 
				
			||||||
            accountId = accountId,
 | 
					            accountId = accountId,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        val articles = mutableListOf<Article>()
 | 
					        return FeedWithArticle(feed, queryRssXml(feed))
 | 
				
			||||||
        parseRss.items.forEach {
 | 
					 | 
				
			||||||
            articles.add(
 | 
					 | 
				
			||||||
                Article(
 | 
					 | 
				
			||||||
                    id = accountId.spacerDollar(UUID.randomUUID().toString()),
 | 
					 | 
				
			||||||
                    accountId = accountId,
 | 
					 | 
				
			||||||
                    feedId = feed.id,
 | 
					 | 
				
			||||||
                    date = it.publishDate.toString().let {
 | 
					 | 
				
			||||||
                        try {
 | 
					 | 
				
			||||||
                            Date(it)
 | 
					 | 
				
			||||||
                        } catch (e: IllegalArgumentException) {
 | 
					 | 
				
			||||||
                            parseDate(it) ?: Date()
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                    title = it.title.toString(),
 | 
					 | 
				
			||||||
                    author = it.author,
 | 
					 | 
				
			||||||
                    rawDescription = it.description.toString(),
 | 
					 | 
				
			||||||
                    shortDescription = (Readability4JExtended("", it.description.toString())
 | 
					 | 
				
			||||||
                        .parse().textContent ?: "").take(100).trim(),
 | 
					 | 
				
			||||||
                    link = it.link ?: "",
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return FeedWithArticle(feed, articles)
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun parseDescriptionContent(link: String, content: String): String {
 | 
					    fun parseDescriptionContent(link: String, content: String): String {
 | 
				
			||||||
@ -95,13 +73,12 @@ class RssHelper @Inject constructor(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    suspend fun queryRssXml(
 | 
					    suspend fun queryRssXml(
 | 
				
			||||||
        rssNetworkDataSource: RssNetworkDataSource,
 | 
					 | 
				
			||||||
        accountId: Int,
 | 
					 | 
				
			||||||
        feed: Feed,
 | 
					        feed: Feed,
 | 
				
			||||||
        latestLink: String? = null,
 | 
					        latestLink: String? = null,
 | 
				
			||||||
    ): List<Article> {
 | 
					    ): List<Article> {
 | 
				
			||||||
        val a = mutableListOf<Article>()
 | 
					        val a = mutableListOf<Article>()
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            val accountId = context.currentAccountId
 | 
				
			||||||
            val parseRss = rssNetworkDataSource.parseRss(feed.url)
 | 
					            val parseRss = rssNetworkDataSource.parseRss(feed.url)
 | 
				
			||||||
            parseRss.items.forEach {
 | 
					            parseRss.items.forEach {
 | 
				
			||||||
                if (latestLink != null && latestLink == it.link) return a
 | 
					                if (latestLink != null && latestLink == it.link) return a
 | 
				
			||||||
@ -111,8 +88,14 @@ class RssHelper @Inject constructor(
 | 
				
			|||||||
                        id = accountId.spacerDollar(UUID.randomUUID().toString()),
 | 
					                        id = accountId.spacerDollar(UUID.randomUUID().toString()),
 | 
				
			||||||
                        accountId = accountId,
 | 
					                        accountId = accountId,
 | 
				
			||||||
                        feedId = feed.id,
 | 
					                        feedId = feed.id,
 | 
				
			||||||
                        date = Date(it.publishDate.toString()),
 | 
					                        date = it.publishDate.toString().let {
 | 
				
			||||||
                        title = it.title.toString(),
 | 
					                            try {
 | 
				
			||||||
 | 
					                                Date(it)
 | 
				
			||||||
 | 
					                            } catch (e: IllegalArgumentException) {
 | 
				
			||||||
 | 
					                                parseDate(it) ?: Date()
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        },
 | 
				
			||||||
 | 
					                        title = Html.fromHtml(it.title.toString()).toString(),
 | 
				
			||||||
                        author = it.author,
 | 
					                        author = it.author,
 | 
				
			||||||
                        rawDescription = it.description.toString(),
 | 
					                        rawDescription = it.description.toString(),
 | 
				
			||||||
                        shortDescription = (Readability4JExtended("", it.description.toString())
 | 
					                        shortDescription = (Readability4JExtended("", it.description.toString())
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@ import androidx.compose.material.icons.rounded.Search
 | 
				
			|||||||
import androidx.compose.material3.*
 | 
					import androidx.compose.material3.*
 | 
				
			||||||
import androidx.compose.runtime.*
 | 
					import androidx.compose.runtime.*
 | 
				
			||||||
import androidx.compose.ui.Modifier
 | 
					import androidx.compose.ui.Modifier
 | 
				
			||||||
 | 
					import androidx.compose.ui.draw.alpha
 | 
				
			||||||
import androidx.compose.ui.input.pointer.pointerInput
 | 
					import androidx.compose.ui.input.pointer.pointerInput
 | 
				
			||||||
import androidx.compose.ui.platform.LocalContext
 | 
					import androidx.compose.ui.platform.LocalContext
 | 
				
			||||||
import androidx.compose.ui.res.stringResource
 | 
					import androidx.compose.ui.res.stringResource
 | 
				
			||||||
@ -132,7 +133,7 @@ fun FlowPage(
 | 
				
			|||||||
            Crossfade(targetState = pagingItems) { pagingItems ->
 | 
					            Crossfade(targetState = pagingItems) { pagingItems ->
 | 
				
			||||||
                if (pagingItems.loadState.source.refresh is LoadState.NotLoading && pagingItems.itemCount == 0) {
 | 
					                if (pagingItems.loadState.source.refresh is LoadState.NotLoading && pagingItems.itemCount == 0) {
 | 
				
			||||||
                    LottieAnimation(
 | 
					                    LottieAnimation(
 | 
				
			||||||
                        modifier = Modifier.padding(80.dp),
 | 
					                        modifier = Modifier.alpha(0.7f).padding(80.dp),
 | 
				
			||||||
                        url = "https://assets7.lottiefiles.com/packages/lf20_l4ny0jjm.json",
 | 
					                        url = "https://assets7.lottiefiles.com/packages/lf20_l4ny0jjm.json",
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@ import androidx.compose.material3.*
 | 
				
			|||||||
import androidx.compose.runtime.*
 | 
					import androidx.compose.runtime.*
 | 
				
			||||||
import androidx.compose.ui.Alignment
 | 
					import androidx.compose.ui.Alignment
 | 
				
			||||||
import androidx.compose.ui.Modifier
 | 
					import androidx.compose.ui.Modifier
 | 
				
			||||||
 | 
					import androidx.compose.ui.draw.alpha
 | 
				
			||||||
import androidx.compose.ui.platform.LocalContext
 | 
					import androidx.compose.ui.platform.LocalContext
 | 
				
			||||||
import androidx.compose.ui.res.stringResource
 | 
					import androidx.compose.ui.res.stringResource
 | 
				
			||||||
import androidx.compose.ui.unit.dp
 | 
					import androidx.compose.ui.unit.dp
 | 
				
			||||||
@ -208,7 +209,7 @@ private fun Content(
 | 
				
			|||||||
        if (articleWithFeed == null) {
 | 
					        if (articleWithFeed == null) {
 | 
				
			||||||
            Spacer(modifier = Modifier.height(64.dp))
 | 
					            Spacer(modifier = Modifier.height(64.dp))
 | 
				
			||||||
            LottieAnimation(
 | 
					            LottieAnimation(
 | 
				
			||||||
                modifier = Modifier.padding(80.dp),
 | 
					                modifier = Modifier.alpha(0.7f).padding(80.dp),
 | 
				
			||||||
                url = "https://assets8.lottiefiles.com/packages/lf20_jm7mv1ib.json",
 | 
					                url = "https://assets8.lottiefiles.com/packages/lf20_jm7mv1ib.json",
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user