}
public fun addItems(items: Collection<Item>) {
- GlobalScope.launch(Dispatchers.IO) {
- dataSource.connection.use { conn ->
- conn.prepareStatement("""
+ dataSource.connection.use { conn ->
+ conn.prepareStatement("""
insert into items (feed_id, title, link, description, author, pub_date, guid, contentText, contentHTML)
select ?, ?, ?, ?, ?, ?, ?, ?, ?
where ? not in (select guid from items)
""".trimIndent()).use { stmt ->
- items.forEach { item ->
- stmt.setInt(1, item.feedId)
- stmt.setString(2, item.title)
- stmt.setString(3, item.link)
- stmt.setString(4, item.description)
- stmt.setString(5, item.author)
- stmt.setTimestamp(6, item.pubDate?.let { java.sql.Timestamp.from(it.toInstant()) })
- stmt.setString(7, item.guid)
- stmt.setString(8, item.contentText)
- stmt.setString(9, item.contentHtml)
- stmt.setString(10, item.guid)
- stmt.addBatch()
- }
- stmt.executeBatch()
+ items.forEach { item ->
+ stmt.setInt(1, item.feedId)
+ stmt.setString(2, item.title)
+ stmt.setString(3, item.link)
+ stmt.setString(4, item.description)
+ stmt.setString(5, item.author)
+ stmt.setTimestamp(6, item.pubDate?.let { java.sql.Timestamp.from(it.toInstant()) })
+ stmt.setString(7, item.guid)
+ stmt.setString(8, item.contentText)
+ stmt.setString(9, item.contentHtml)
+ stmt.setString(10, item.guid)
+ stmt.addBatch()
}
+ stmt.executeBatch()
}
}
}
val link = UiLinkData(linkstr)
val webview = webview("webview")
+ var currentFeed: FeedCollection? = null
+
fun loadFeed(feed: FeedCollection) {
items.clear()
if(!feed.itemsLoaded) {
- feed.items = Database.getItems(feed, 100)
+ feed.items = Database.getItems(feed, 10000)
feed.itemsLoaded = true
}
feed.items.forEach { item ->
items.add(item)
}
items.update()
+ currentFeed = feed
+ }
+
+ fun reloadCurrentFeed() {
+ currentFeed?.let { loadFeed(it) }
}
fun selectItem(item: Item) {
import com.rometools.rome.io.SyndFeedInput
import com.rometools.rome.io.XmlReader
+import de.unixwork.ui.kotlin.ToolkitDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.IO
class SyncJob {
val feeds: List<Feed>
+ var completionContext = ToolkitDispatcher
init {
feeds = Database.getAllFeeds()
}
- fun sync() {
+ fun sync(completion: () -> Unit = {}) {
GlobalScope.launch(Dispatchers.IO) {
val client = HttpClient.newBuilder().build()
val jobs = feeds.map { feed ->
}
}
jobs.awaitAll()
+
+ GlobalScope.launch(completionContext) {
+ completion()
+ }
}
}
}
\ No newline at end of file