diff --git a/.idea/misc.xml b/.idea/misc.xml index f0177a5..ccaf527 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -9,11 +9,15 @@ + + + + - + diff --git a/app/build.gradle b/app/build.gradle index 426ee8e..63417d2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,9 +59,10 @@ dependencies { implementation("io.coil-kt:coil-compose:1.3.2") implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' implementation 'androidx.activity:activity-compose:1.3.1' - implementation "androidx.navigation:navigation-compose:2.4.0-alpha09" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' + implementation "androidx.navigation:navigation-compose:2.4.0-alpha10" + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' implementation "com.google.accompanist:accompanist-swiperefresh:0.19.0" + implementation "org.jsoup:jsoup:1.13.1" testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/MainActivity.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/MainActivity.kt index 1667afa..459074d 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/MainActivity.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/MainActivity.kt @@ -15,7 +15,10 @@ import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Settings import androidx.compose.runtime.* +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview @@ -26,6 +29,7 @@ import com.google.accompanist.swiperefresh.SwipeRefresh import com.google.accompanist.swiperefresh.rememberSwipeRefreshState import eu.toldi.balazs.anotherfeedreader.entities.Article import eu.toldi.balazs.anotherfeedreader.entities.Feed +import eu.toldi.balazs.anotherfeedreader.entities.FeedData import eu.toldi.balazs.anotherfeedreader.entities.FeedGroup import eu.toldi.balazs.anotherfeedreader.ui.theme.AnotherFeedReaderTheme import kotlinx.coroutines.launch @@ -33,11 +37,6 @@ import java.net.URL import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.time.format.FormatStyle -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.ui.Alignment -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.res.stringResource -import eu.toldi.balazs.anotherfeedreader.entities.FeedData class MainActivity : ComponentActivity() { @@ -81,7 +80,9 @@ class MainActivity : ComponentActivity() { }, ) { LazyColumn( - modifier = Modifier.fillMaxHeight() + modifier = Modifier + .fillMaxHeight() + .fillMaxWidth() ) { items(articleList.value.size) { index -> @@ -161,7 +162,7 @@ class MainActivity : ComponentActivity() { contentScale = ContentScale.Crop, alignment = Alignment.Center, modifier = Modifier - .height(150.dp) + .height(200.dp) .fillMaxWidth() .fillMaxHeight() ) @@ -169,13 +170,21 @@ class MainActivity : ComponentActivity() { Row { if (article.author != null) { Text( - article.author, + text = (fun(): String { + if (article.author.length > 25) + return article.author.dropLast(article.author.length - 25) + else return article.author + }).invoke(), fontSize = 11.sp ) } else Text("") article.feedName?.let { Text( - it, + text = (fun(): String { + return if (it.length > 25) + return it.dropLast(it.length - 25) + else return it + }).invoke(), fontSize = 11.sp, textAlign = TextAlign.Center, modifier = Modifier.padding(horizontal = 10.dp), @@ -241,7 +250,7 @@ class MainActivity : ComponentActivity() { ModalDrawer(drawerState = drawerState, drawerContent = { LazyColumn { item { - Text(text=stringResource(id = R.string.all_feeds), + Text(text = stringResource(id = R.string.all_feeds), fontSize = 26.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Article.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Article.kt index 2a48387..fdfe8da 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Article.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Article.kt @@ -1,23 +1,12 @@ package eu.toldi.balazs.anotherfeedreader.entities -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.w3c.dom.Document +import kotlinx.coroutines.runBlocking +import org.jsoup.Jsoup import org.w3c.dom.Element import org.w3c.dom.Node import org.w3c.dom.NodeList import java.time.LocalDateTime import java.time.format.DateTimeFormatter -import javax.xml.parsers.DocumentBuilder -import javax.xml.parsers.DocumentBuilderFactory -import android.R.xml - -import java.io.StringReader - -import org.xml.sax.InputSource -import java.net.URL class Article( @@ -67,7 +56,7 @@ class Article( * Cikk beolvasása egy megadott Node objektumból. Egy hírcsatorna beolvasásakor könnyedén alkalmazható egy "item" Node-ra * @param article Egy "item" Node egy RSS hírcsatornáról */ - fun createFromNode(article: Node,feedName: String?) : Article{ + fun createFromNode(article: Node, feedName: String?): Article { val properties: NodeList = article.getChildNodes() var title: String? = null var url: String? = null @@ -100,40 +89,24 @@ class Article( } } } - if(imageURL == null && url != null) { -/* GlobalScope.launch { + if (imageURL == null && url != null) { + runBlocking { + val con = Jsoup.connect(url) + val doc = con.userAgent("Mozilla").get() - val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance() - val builder: DocumentBuilder = factory.newDocumentBuilder() - var doc: Document - withContext(Dispatchers.IO) { - val ips = InputSource() - ips.characterStream = StringReader(URL(url).readText().replace("","")) - doc = builder.parse(ips) - } + val ogTags = doc.select("meta[property^=og:]") - val metas: NodeList = doc.getElementsByTagName("meta") - - for (i in 0 until metas.length) { - val meta: Node = metas.item(i) - val property = meta.attributes.getNamedItem("property") - if (property != null && property.textContent == "og:image"){ - val imageProperty = meta.attributes.getNamedItem("content") - if(imageProperty != null) - imageURL = imageProperty.textContent + if (ogTags.size > 0) { + ogTags.forEachIndexed { index, element -> + val tag = ogTags[index] + if (tag.attr("property") == "og:image") + imageURL = tag.attr("content") } } - }*/ + } } - return Article(title, url, description, imageURL, author, pubDate,feedName) + return Article(title, url, description, imageURL, author, pubDate, feedName) } } - /** - * A cikk megnyitása böngészőben (ha ez lehetséges) - */ - fun open() { - if (url == null) return - //TODO: open link in webview - } } \ No newline at end of file diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Feed.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Feed.kt index b5e058e..c03c0d3 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Feed.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/Feed.kt @@ -1,6 +1,5 @@ package eu.toldi.balazs.anotherfeedreader.entities -import android.util.Log import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.MutableStateFlow @@ -35,7 +34,7 @@ open class Feed /** * A hírcsatornához tartozó cikkek listája */ - open var articleList: List
= ArrayList() + open var articleList: List
= emptyList() private val _isRefreshing = MutableStateFlow(false) val isRefreshing: StateFlow @@ -82,7 +81,7 @@ open class Feed val a = Article.createFromNode(article,name) addArticle(a) } - Log.e(null, articleCount.toString()) + articleList.sortedByDescending { it.pubDate } _isRefreshing.emit(false) } } diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedData.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedData.kt index 54f0d8a..9cb6ddf 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedData.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedData.kt @@ -7,8 +7,10 @@ class FeedData : FeedGroup("MainFrame") { private var _articleList = emptyList
() override var articleList: List
- get() =limit?.articleList ?: _articleList - set(value) {_articleList = value.sortedByDescending { it.pubDate }} + get() = limit?.articleList?.sortedByDescending { it.pubDate } ?: _articleList + set(value) { + _articleList = value.sortedByDescending { it.pubDate } + } } \ No newline at end of file diff --git a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedGroup.kt b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedGroup.kt index 7aef1bf..92f67eb 100644 --- a/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedGroup.kt +++ b/app/src/main/java/eu/toldi/balazs/anotherfeedreader/entities/FeedGroup.kt @@ -1,9 +1,7 @@ package eu.toldi.balazs.anotherfeedreader.entities -import android.util.Log -import java.util.ArrayList - import java.io.IOException +import java.util.* open class FeedGroup(name: String) : Feed(name) { @@ -56,9 +54,9 @@ open class FeedGroup(name: String) : Feed(name) { if (articleList == null) articleList = ArrayList() for (f in feedList) { f.updateFeed() - for (i in 0 until f.articleCount) { - if (!hasAricle(f[i])) - articleList += f[i] + f.articleList.forEach { + if (!hasAricle(it)) + articleList += it } } articleList = articleList.sortedByDescending { it.pubDate }