parent.feeds.add(feedCol)
return feedCol
}
+
+ public fun getItems(feedCollection: FeedCollection, maxItems: Int) : MutableList<Item> {
+ val items = mutableListOf<Item>()
+
+ connection.prepareStatement("""
+ select I.*, F.URL from items I
+ inner join feeds F on I.feed_id = F.feed_id
+ where F.feedcollection_id = ? order by pub_date desc limit ?
+ """.trimIndent()).use { stmt ->
+ stmt.setInt(1, feedCollection.id)
+ stmt.setInt(2, maxItems)
+ stmt.executeQuery().use { rs ->
+ while(rs.next()) {
+ val item = Item(rs.getInt("item_id"))
+ item.feedId = rs.getInt("feed_id")
+ item.title = rs.getString("title")
+ item.link = rs.getString("link")
+ item.description = rs.getString("description")
+ item.author = rs.getString("author")
+ item.pubDate = rs.getString("pub_date")
+ item.guid = rs.getString("guid")
+ item.content = rs.getString("content")
+ item.feedName = feedCollection.name
+ item.feedUrl = rs.getString("URL")
+ items.add(item)
+ }
+ }
+ }
+ return items
+ }
}
class FeedCollection(id: Int, name: String) {
val id = id
val name = name
- val items = mutableListOf<Item>()
+ var items = mutableListOf<Item>()
var itemsLoaded = false
}
\ No newline at end of file
class FeedList : Document() {
val items = list<Item>("items")
+ val feedName = string("feedname")
+ val author = string("author")
+ val link = string("link")
+ val webview = webview("webview")
fun loadFeed(feed: FeedCollection) {
items.clear()
- if(feed.itemsLoaded) {
- feed.items.forEach { item ->
- items.add(item)
- }
- } else {
- // TODO: load items from DB
+ if(!feed.itemsLoaded) {
+ feed.items = Database.getItems(feed, 100)
+ feed.itemsLoaded = true
}
+ feed.items.forEach { item ->
+ items.add(item)
+ }
+ items.update()
+ }
+
+ fun selectItem(item: Item) {
+ feedName.setString(item.feedName)
+ author.setString(item.author)
+ link.setString(item.link)
+ webview.loadContent(null, item.content ?: "", "text/html", "utf-8")
}
}
\ No newline at end of file
package de.unixwork.rssreader
-class Item {
- val title: String? = null
- val link: String? = null
+class Item(id: Int) {
+ val id = id
+ var feedId = -1
+ var title: String? = null
+ var link: String? = null
+ var description: String? = null
+ var author: String? = null
+ var pubDate: String? = null
+ var guid: String? = null
+ var content: String? = null
+
+ var feedName: String? = null
+ var feedUrl: String? = null
}
\ No newline at end of file
hsplitpane(fill = true, initialPosition = 300) {
vbox(fill = true) {
- listview<Item>(varname = "items", fill = true) { elm, col ->
+ listview<Item>(
+ varname = "items",
+ fill = true,
+ onSelection = { event ->
+ feedList.items.selected?.let {
+ feedList.selectItem(it)
+ }
+ }
+ )
+ { elm, col ->
elm.title
}
}
- vbox(fill = true) {
- webview(varname = "webview", fill = true)
+ grid(fill = true, columnspacing = 8, rowspacing = 8, margin = 8) {
+ row {
+ rlabel("Feed:", hfill = true)
+ llabel(varname = "feedname", hexpand = true)
+ }
+ row {
+ rlabel("Author:", hfill = true)
+ llabel(varname = "author")
+ }
+ row {
+ rlabel("Link:", hfill = true)
+ llabel(varname = "link")
+ }
+
+ row {
+ webview(varname = "webview", hfill = true, vfill = true, hexpand = true, vexpand = true, colspan = 2)
+ }
}
}
return new UiInteger(this, name);
}
+ public WebView webview() {
+ return webview(null);
+ }
+
+ public WebView webview(String name) {
+ return new WebView(this, name);
+ }
+
public <T> UiList<T> list() {
UiList<T> ls = list(null);
return ls;
eventData = new SubListEventData(eventDataPtr);
break;
}
+ case LIST_SELECTION: {
+ break;
+ }
case EventDataType.FILE_LIST: {
int flistCount = (int)ui.filelist_count.invoke(eventDataPtr);
String[] files = new String[flistCount];
return this;
}
+ public ListViewBuilder<T> onSelection(EventHandler onSelection) {
+ this.onSelection = onSelection;
+ return this;
+ }
+
public ListViewBuilder<T> onDragStart(EventHandler onDragStart) {
this.onDragStart = onDragStart;
return this;
rowspan: Int = -1,
name: String? = null,
styleClass: String? = null,
+ onActivate: EventHandler? = null,
+ onSelection: EventHandler? = null,
getvalue: ListValueConverter<T>? = null
): UiWidget {
varname?.let {
styleClass?.let {
list.styleClass(it)
}
+ onActivate?.let {
+ list.onActivate(it)
+ }
+ onSelection?.let {
+ list.onSelection(it)
+ }
getvalue?.let {
list.getvalue(it)
}
rowspan: Int = -1,
name: String? = null,
styleClass: String? = null,
+ onActivate: EventHandler? = null,
+ onSelection: EventHandler? = null,
getvalue: ListValueConverter<T>? = null
): UiWidget {
val list = ListView.list<T>(ui)
rowspan = rowspan,
name = name,
styleClass = styleClass,
+ onActivate = onActivate,
+ onSelection = onSelection,
getvalue = getvalue
)
}
rowspan: Int = -1,
name: String? = null,
styleClass: String? = null,
+ onActivate: EventHandler? = null,
getvalue: ListValueConverter<T>? = null
): UiWidget {
val list = ListView.dropdown<T>(ui)
rowspan = rowspan,
name = name,
styleClass = styleClass,
+ onActivate = onActivate,
getvalue = getvalue
)
}