initToolbar()
}
+ fun syncAll() {
+ SyncJob({ Database.getAllFeeds()}).sync() {
+ window?.reload()
+ }
+ }
+
fun initToolbar() {
toolbarItem(name = "reload", icon = "view-refresh") { event ->
- val window = event.windowData as MainWindow
- SyncJob({ Database.getAllFeeds()}).sync() {
- window.sourceList.invalidateCache()
- window.sourceList.reloadStatus()
- window.feedList.reloadCurrentFeed()
- }
+ syncAll()
}
toolbarAppMenu {
menuItem(label = "Update All") {
-
+ syncAll()
+ }
+ separator()
+ menuItem(label = "Mark Current Feed as Read") {
+ if(window?.feedList?.currentFeed != null) {
+ window?.feedList?.currentFeed?.unreadItemsCount = 0
+ window?.feedList?.currentFeed?.items?.forEach { item ->
+ item.isRead = true
+ }
+ window?.feedList?.items?.update()
+ window?.updateCurrentFeedState()
+ GlobalScope.launch(Dispatchers.IO) {
+ Database.updateFeedReadState(window?.feedList?.currentFeed!!, true)
+ }
+ }
+ }
+ menuItem(label = "Mark All as Read") {
+ GlobalScope.launch(Dispatchers.IO) {
+ Database.updateAllItems(true)
+ GlobalScope.launch(ToolkitDispatcher) {
+ window?.reload()
+ }
+ }
}
separator()
menuItem(label = "Settings") {
}
}
+ public fun updateAllItems(read: Boolean) {
+ dataSource.connection.use { conn ->
+ conn.prepareStatement("""
+ update items set is_read = ?
+ """.trimIndent()).use { stmt ->
+ stmt.setBoolean(1, read)
+ stmt.execute()
+ }
+ }
+ }
+
public fun getUpdateWaitTime(defaultUpdateInterval: Int) : Int {
var seconds = 0
dataSource.connection.use { conn ->
val dateTodayFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormatToday).withZone(ZoneId.systemDefault())
var newFeedPrevGroup = 0
+ var currentSublistIndex = -1
+ var currentFeedIndex = -1
init {
window = sidebarWindow("RSS Reader") {
varname = "feeds",
onActivate = { event ->
val evt = event.subListEventData
+ currentSublistIndex = evt.sublistIndex
+ currentFeedIndex = evt.rowIndex
try {
val feed = sourceList.groups[evt.sublistIndex].feeds[evt.rowIndex]
feed?.let {
// mode 1: mark all items as read when opening the feed
// update the sourcelist to remove the unread counter badge from this feed
if(feed.itemStateMode == 1) {
- sourceList.groups[evt.sublistIndex].feeds.update(evt.rowIndex)
+ updateCurrentFeedState()
}
}
} catch (e: Exception) {
window.ui.attach(feedList)
}
+ fun reload() {
+ sourceList.invalidateCache()
+ sourceList.reloadStatus()
+ feedList.reloadCurrentFeed()
+ }
+
+ fun updateCurrentFeedState() {
+ if(currentFeedIndex >= 0 && currentSublistIndex >= 0) {
+ sourceList.groups[currentFeedIndex].feeds.update(currentSublistIndex)
+ }
+ }
+
private fun createFeedDialog() {
var groups: UiList<FeedGroup>? = null
var name: UiString? = null