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 c298c4b66..4a0bea118 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 @@ -4,57 +4,41 @@ import android.annotation.SuppressLint import android.view.ViewGroup import android.webkit.WebView import android.webkit.WebViewClient +import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.viewinterop.AndroidView -import app.omnivore.omnivore.models.LinkedItem @Composable fun WebReaderLoadingContainer(slug: String, webReaderViewModel: WebReaderViewModel) { - // TODO: create a viewmodel where we can fetch item and articleContent - 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 webReaderParams: WebReaderParams? by webReaderViewModel.webReaderParamsLiveData.observeAsState(null) - 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.

- """ + if (webReaderParams == null) { + webReaderViewModel.loadItem() + } - val articleContent = ArticleContent( - title = "test title", - htmlContent = content, - highlightsJSONString = "[]", - contentStatus = "SUCCEEDED", - objectID = "" - ) - - WebReader(item = item, articleContent = articleContent) + if (webReaderParams != null) { + WebReader(webReaderParams!!) + } else { + // TODO: add a proper loading view + Text("Loading...") + } } @SuppressLint("SetJavaScriptEnabled") @Composable -fun WebReader(item: LinkedItem, articleContent: ArticleContent) { +fun WebReader(params: WebReaderParams) { WebView.setWebContentsDebuggingEnabled(true) val webReaderContent = WebReaderContent( textFontSize = 12, lineHeight = 150, maxWidthPercentage = 100, - item = item, + item = params.item, themeKey = "LightGray", fontFamily = WebFont.SYSTEM , - articleContent = articleContent, + articleContent = params.articleContent, prefersHighContrastText = false, ) 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 17cc970f9..c31e68c8c 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 @@ -1,13 +1,61 @@ package app.omnivore.omnivore.ui.reader +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import app.omnivore.omnivore.DatastoreRepository +import app.omnivore.omnivore.models.LinkedItem import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +data class WebReaderParams( + val item: LinkedItem, + val articleContent: ArticleContent +) + @HiltViewModel class WebReaderViewModel @Inject constructor( private val datastoreRepo: DatastoreRepository ): ViewModel() { - val testVar = "" + val webReaderParamsLiveData = MutableLiveData(null) + + fun loadItem() { + // TODO: make network calls + webReaderParamsLiveData.value = mockParams() + } + + 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) + } } diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/root/RootView.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/root/RootView.kt index 5cc7585aa..60619015c 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/root/RootView.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/root/RootView.kt @@ -84,6 +84,8 @@ fun PrimaryNavigator( } composable("WebReader/{slug}") { + webReaderViewModel.reset() // clear previously loaded item + WebReaderLoadingContainer( it.arguments?.getString("slug") ?: "", webReaderViewModel = webReaderViewModel