diff --git a/android/Omnivore/app/src/main/graphql/ArticleContent.graphql b/android/Omnivore/app/src/main/graphql/ArticleContent.graphql new file mode 100644 index 000000000..350999bf7 --- /dev/null +++ b/android/Omnivore/app/src/main/graphql/ArticleContent.graphql @@ -0,0 +1,64 @@ +query GetArticle($slug: String!) { + article(username: "me", slug: $slug) { + ... on ArticleSuccess { + article { + ...ArticleFields + content + highlights(input: { includeFriends: false }) { + ...HighlightFields + } + labels { + ...LabelFields + } + } + } + ... on ArticleError { + errorCodes + } + } +} + +fragment ArticleFields on Article { + id + title + url + author + image + savedAt + createdAt + publishedAt + contentReader + originalArticleUrl + readingProgressPercent + readingProgressAnchorIndex + slug + isArchived + description + linkId + siteName + state + readAt + updatedAt + content +} + +fragment HighlightFields on Highlight { + id + shortId + quote + prefix + suffix + patch + annotation + createdByMe + updatedAt + sharedAt +} + +fragment LabelFields on Label { + id + name + color + description + createdAt +} diff --git a/android/Omnivore/app/src/main/graphql/Search.graphql b/android/Omnivore/app/src/main/graphql/Search.graphql index 2532cfc1e..7b231bafb 100644 --- a/android/Omnivore/app/src/main/graphql/Search.graphql +++ b/android/Omnivore/app/src/main/graphql/Search.graphql @@ -34,6 +34,8 @@ query Search($after: String, $first: Int, $query: String) { siteName subscription readAt + savedAt + updatedAt } } pageInfo { diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/models/LinkedItem.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/models/LinkedItem.kt index 16276ee23..bd1e0057f 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/models/LinkedItem.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/models/LinkedItem.kt @@ -2,28 +2,26 @@ package app.omnivore.omnivore.models import androidx.core.net.toUri -public data class LinkedItem( - public val id: String, - public val title: String, - public val createdAt: Any, -// public val savedAt: Any, - public val readAt: Any?, -// public val updatedAt: Any, - public val readingProgress: Double, - public val readingProgressAnchor: Int, - public val imageURLString: String?, -// public val onDeviceImageURLString: String?, -// public val documentDirectoryPath: String?, - public val pageURLString: String, - public val descriptionText: String?, - public val publisherURLString: String?, -// public val siteName: String?, - public val author: String?, - public val publishDate: Any?, - public val slug: String, -// public val isArchived: Boolean, -// public val contentReader: String?, -// public val originalHtml: String?, +data class LinkedItem( + val id: String, + val title: String, + val createdAt: Any, + val savedAt: Any, + val readAt: Any?, + val updatedAt: Any?, + val readingProgress: Double, + val readingProgressAnchor: Int, + val imageURLString: String?, + val pageURLString: String, + val descriptionText: String?, + val publisherURLString: String?, + val siteName: String?, + val author: String?, + val publishDate: Any?, + val slug: String, + val isArchived: Boolean, + val contentReader: String?, + val content: String? ) { fun publisherDisplayName(): String? { return publisherURLString?.toUri()?.host diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeViewModel.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeViewModel.kt index 2213b30d1..97f1ff200 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeViewModel.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/home/HomeViewModel.kt @@ -1,6 +1,5 @@ package app.omnivore.omnivore.ui.home -import androidx.core.net.toUri import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -89,16 +88,22 @@ class HomeViewModel @Inject constructor( id = it.node.id, title = it.node.title, createdAt = it.node.createdAt, + savedAt = it.node.savedAt, readAt = it.node.readAt, + updatedAt = it.node.updatedAt, readingProgress = it.node.readingProgressPercent, readingProgressAnchor = it.node.readingProgressAnchorIndex, imageURLString = it.node.image, pageURLString = it.node.url, descriptionText = it.node.description, publisherURLString = it.node.originalArticleUrl, + siteName = it.node.siteName, author = it.node.author, + publishDate = it.node.publishedAt, slug = it.node.slug, - publishDate = it.node.publishedAt + isArchived = it.node.isArchived, + contentReader = it.node.contentReader.rawValue, + content = null ) } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReader.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReader.kt index 4a0bea118..b0a33f757 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReader.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReader.kt @@ -15,7 +15,7 @@ fun WebReaderLoadingContainer(slug: String, webReaderViewModel: WebReaderViewMod val webReaderParams: WebReaderParams? by webReaderViewModel.webReaderParamsLiveData.observeAsState(null) if (webReaderParams == null) { - webReaderViewModel.loadItem() + webReaderViewModel.loadItem(slug = slug) } if (webReaderParams != null) { diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReaderViewModel.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReaderViewModel.kt index c31e68c8c..d858f05aa 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReaderViewModel.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/WebReaderViewModel.kt @@ -2,9 +2,16 @@ package app.omnivore.omnivore.ui.reader import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import app.omnivore.omnivore.Constants +import app.omnivore.omnivore.DatastoreKeys import app.omnivore.omnivore.DatastoreRepository +import app.omnivore.omnivore.graphql.generated.GetArticleQuery import app.omnivore.omnivore.models.LinkedItem +import com.apollographql.apollo3.ApolloClient import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import javax.inject.Inject data class WebReaderParams( @@ -18,44 +25,64 @@ class WebReaderViewModel @Inject constructor( ): ViewModel() { val webReaderParamsLiveData = MutableLiveData(null) - fun loadItem() { - // TODO: make network calls - webReaderParamsLiveData.value = mockParams() + private fun getAuthToken(): String? = runBlocking { + datastoreRepo.getString(DatastoreKeys.omnivoreAuthToken) + } + + fun loadItem(slug: String) { + viewModelScope.launch { + val authToken = getAuthToken() + + val apolloClient = ApolloClient.Builder() + .serverUrl("${Constants.apiURL}/api/graphql") + .addHttpHeader("Authorization", value = authToken ?: "") + .build() + + val response = apolloClient.query( + GetArticleQuery(slug = slug) + ).execute() + + val article = response.data?.article?.onArticleSuccess?.article ?: return@launch + + // TODO: handle errors + + val linkedItem = LinkedItem( + id = article.articleFields.id, + title = article.articleFields.title, + createdAt = article.articleFields.createdAt, + savedAt = article.articleFields.savedAt, + readAt = article.articleFields.readAt, + updatedAt = article.articleFields.updatedAt, + readingProgress = article.articleFields.readingProgressPercent, + readingProgressAnchor = article.articleFields.readingProgressAnchorIndex, + imageURLString = article.articleFields.image, + pageURLString = article.articleFields.url, + descriptionText = article.articleFields.description, + publisherURLString = article.articleFields.originalArticleUrl, + siteName = article.articleFields.siteName, + author = article.articleFields.author, + publishDate = article.articleFields.publishedAt, + slug = article.articleFields.slug, + isArchived = article.articleFields.isArchived, + contentReader = article.articleFields.contentReader.rawValue, + content = article.articleFields.content + ) + + val articleContent = ArticleContent( + title = article.articleFields.title, + htmlContent = article.articleFields.content ?: "", + highlightsJSONString = "[]", + contentStatus = "SUCCEEDED", + objectID = "" + ) + + webReaderParamsLiveData.value = WebReaderParams(linkedItem, articleContent) + } } fun reset() { webReaderParamsLiveData.value = null } - - private fun mockParams(): WebReaderParams { - val item = LinkedItem( - id = "1", - title = "test title", - createdAt = "", - readAt = "", - readingProgress = 0.0, - readingProgressAnchor = 0, - imageURLString = "", - pageURLString = "https://omnivore.app", - descriptionText = "mock item", - publisherURLString = "", - author = "someone", - slug = "sluggo", - publishDate = "" - ) - - val content = """ -
Cowboys quarterback Dak Prescott

ARLINGTON, TEXAS - JANUARY 02: Dak Prescott #4 of the Dallas Cowboys reacts after completing a pass against the Arizona Cardinals in the fourth quarter at AT&T Stadium on January 02, 2022 in Arlington, Texas. (Photo by Tom Pennington/Getty Images)

Dak Prescott will not take the field for the Cowboys' preseason finale against the Seahawks on Friday, per Dallas beat writer Clarence Hill Jr.

The Cowboys' starting quarterback has not notched any in-game action this preseason despite being fully healthy.

Prescott didn't play in the preseason last year as he continued to recover from a devastating leg injury he suffered during the 2020 season. This year, his absence from preseason action likely stems from his veteran status and a desire to keep him healthy ahead of the 2022 campaign.

While Prescott hasn't notched any in-game action this preseason, he has impressed during training camp practices. Cowboys vice president Stephen Jones says this year is the "best camp" he's ever seen out of the former fourth-round draft pick.

After not suiting up for any preseason action in 2021, Prescott took the field and delivered a 403-yard, three-touchdown performance against the Tampa Bay Buccaneers in Week 1. 

This year, Dak and the Cowboys will open up their 2022 season with another Week 1 matchup against the Bucs.

Backups Cooper Rush and Ben DiNucci have taken the majority of in-game preseason snaps this year. Injured backup Will Grier returned to practice in a limited capacity this evening.

- """ - - val articleContent = ArticleContent( - title = "test title", - htmlContent = content, - highlightsJSONString = "[]", - contentStatus = "SUCCEEDED", - objectID = "" - ) - - return WebReaderParams(item, articleContent) - } } + +// TODO: add labels and highlights values