return groups
}
+ public fun swapFeedCollectionPos(feed1: FeedCollection, feed2: FeedCollection) {
+ val sql = """
+ update feedcollections set
+ pos = case
+ when feedcollection_id = ?1 then (SELECT pos from feedcollections where feedcollection_id = ?2)
+ when feedcollection_id = ?2 then (SELECT pos from feedcollections where feedcollection_id = ?1)
+ else pos
+ end
+ where feedcollection_id in (?1, ?2)
+ """.trimIndent()
+
+ dataSource.connection.use { conn ->
+ conn.prepareStatement(sql).use { stmt ->
+ stmt.setInt(1, feed1.id)
+ stmt.setInt(2, feed2.id)
+ stmt.execute()
+ }
+ }
+ }
+
public fun newFeedGroup(context: Context, name: String) : FeedGroup {
var groupId = 0
dataSource.connection.use { conn ->
groups.add(group)
}
+ fun swapFeedCollections(group: Int, feed1: Int, feed2: Int) {
+ if(group < 0 || group >= groups.size) {
+ return
+ }
+ val gr = groups[group]
+ if(feed1 < 0 || feed1 >= gr.feeds.size) {
+ return
+ }
+ if(feed2 < 0 || feed2 >= gr.feeds.size) {
+ return
+ }
+
+ // swap feeds in the lists and in the database
+ val f1 = gr.feeds[feed1]
+ val f2 = gr.feeds[feed2]
+ gr.feeds[feed1] = f2
+ gr.feeds[feed2] = f1
+ gr.feeds.update()
+
+ Database.swapFeedCollectionPos(f1, f2)
+ }
+
fun invalidateCache() {
groups.forEach {
it.feeds.forEach { feed ->
contextMenuReset()
}
separator()
- menuItem("Move Up") {
-
+ menuItem("Move Up") { event ->
+ val evt = event.subListEventData
+ sourceList.swapFeedCollections(evt.sublistIndex, evt.rowIndex, evt.rowIndex-1)
contextMenuReset()
}
- menuItem("Move Down") {
+ menuItem("Move Down") { event ->
+ val evt = event.subListEventData
+ sourceList.swapFeedCollections(evt.sublistIndex, evt.rowIndex, evt.rowIndex+1)
contextMenuReset()
}
menuItem("Delete") {
}
}
+ public SubList get(int index) {
+ return list.get(index);
+ }
+
public void update() {
ListFuncs ui = ListFuncs.getInstance();
try {