-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
224 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
basil/src/main/java/com/jocmp/basil/accounts/AccountDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.jocmp.basil.accounts | ||
|
||
import java.net.URL | ||
|
||
interface AccountDelegate { | ||
fun createFeed(feedURL: URL): ExternalFeed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.jocmp.basil.accounts | ||
|
||
data class ExternalFeed(val externalID: String) |
23 changes: 23 additions & 0 deletions
23
basil/src/main/java/com/jocmp/basil/accounts/LocalAccountDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.jocmp.basil.accounts | ||
|
||
import com.jocmp.basil.Account | ||
import com.jocmp.basil.Feed | ||
import java.net.URL | ||
import java.util.UUID | ||
|
||
internal class LocalAccountDelegate(private val account: Account): AccountDelegate { | ||
override fun createFeed(feedURL: URL): ExternalFeed { | ||
val allFeeds = mutableSetOf<Feed>().apply { | ||
addAll(account.feeds) | ||
addAll(account.folders.flatMap { it.feeds }) | ||
} | ||
|
||
val existingFeed = allFeeds.find { it.feedURL == feedURL.toString() } | ||
|
||
if (existingFeed != null) { | ||
return ExternalFeed(externalID = existingFeed.id) | ||
} | ||
|
||
return ExternalFeed(externalID = UUID.randomUUID().toString()) | ||
} | ||
} |
25 changes: 15 additions & 10 deletions
25
basil/src/main/java/com/jocmp/basil/extensions/FeedOutlineExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package com.jocmp.basil.extensions | ||
|
||
import com.jocmp.basil.Feed | ||
import com.jocmp.basil.opml.Outline | ||
|
||
internal val Outline.FeedOutline.asFeed: Feed | ||
get() { | ||
return Feed( | ||
id = feed.title.toString(), | ||
name = feed.title ?: "", | ||
feedURL = feed.xmlUrl ?: "" | ||
) | ||
} | ||
import com.jocmp.basil.db.Feeds as DBFeed | ||
import com.jocmp.basil.opml.Feed as OPMLFeed | ||
|
||
internal fun OPMLFeed.asFeed(feeds: Map<String, DBFeed>): Feed? { | ||
externalID ?: return null | ||
val feed = feeds[externalID] | ||
|
||
feed ?: return null | ||
|
||
return Feed( | ||
id = feed.external_id, | ||
name = title ?: "", | ||
feedURL = xmlUrl ?: "" | ||
) | ||
} |
23 changes: 9 additions & 14 deletions
23
basil/src/main/java/com/jocmp/basil/extensions/FolderOutlineExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package com.jocmp.basil.extensions | ||
|
||
import com.jocmp.basil.Feed | ||
import com.jocmp.basil.Folder | ||
import com.jocmp.basil.opml.Outline | ||
import com.jocmp.basil.db.Feeds as DBFeed | ||
|
||
internal val Outline.FolderOutline.asFolder: Folder | ||
get() { | ||
return Folder( | ||
title = folder.title ?: "", | ||
feeds = folder.feeds.map { feed -> | ||
Feed( | ||
id = "", | ||
name = feed.title ?: "", | ||
feedURL = feed.xmlUrl ?: "" | ||
) | ||
}.toMutableList() | ||
) | ||
} | ||
internal fun Outline.FolderOutline.asFolder(feeds: Map<String, DBFeed>): Folder { | ||
return Folder( | ||
title = folder.title ?: "", | ||
feeds = folder.feeds.mapNotNull { | ||
it.asFeed(feeds = feeds) | ||
}.toMutableList() | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE TABLE feeds ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
external_id TEXT NOT NULL, | ||
feed_url TEXT NOT NULL UNIQUE | ||
); | ||
|
||
allByExternalID: | ||
SELECT * | ||
FROM feeds | ||
WHERE external_id IN ?; | ||
|
||
create { | ||
REPLACE INTO feeds(external_id, feed_url) | ||
VALUES (?, ?); | ||
|
||
SELECT * | ||
FROM feeds | ||
WHERE id = last_insert_rowid(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.