update gql schema

This commit is contained in:
Hongbo Wu
2023-07-13 18:49:28 +08:00
parent e46b3c0550
commit ebc8bca941
4 changed files with 19 additions and 12 deletions

View File

@ -1720,6 +1720,8 @@ input SaveUrlInput {
source: String!
state: ArticleSavingRequestStatus
url: String!
timezone: String
locale: String
}
type SearchError {

View File

@ -3,6 +3,7 @@ package app.omnivore.omnivore.networking
import android.content.ContentValues
import android.net.Uri
import android.util.Log
import androidx.compose.ui.text.intl.Locale
import androidx.lifecycle.viewModelScope
import app.omnivore.omnivore.Constants
import app.omnivore.omnivore.graphql.generated.SaveUrlMutation
@ -46,15 +47,18 @@ suspend fun Networker.updateArchiveStatusSavedItem(
}
}
suspend fun Networker.saveUrl(url: Uri, timeZone: String, locale: String): Boolean {
suspend fun Networker.saveUrl(url: Uri): Boolean {
return try {
val clientRequestId = UUID.randomUUID().toString()
// get locale and timezone from device
val timezone = TimeZone.getDefault().id
val locale = Locale.current.toLanguageTag()
val input = SaveUrlInput(
url = url.toString(),
clientRequestId = clientRequestId,
source = "android",
timezone = timeZone,
locale = locale
timezone = Optional.present(timezone),
locale = Optional.present(locale)
)
val result = authenticatedApolloClient().mutation(SaveUrlMutation(input)).execute()
result.data?.saveUrl?.onSaveSuccess?.url != null

View File

@ -36,7 +36,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.unit.dp
import app.omnivore.omnivore.R
import app.omnivore.omnivore.ui.library.SavedItemAction
@ -46,7 +45,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds
import java.util.TimeZone
// Not sure why we need this class, but directly opening SaveSheetActivity
// causes the app to crash.
@ -61,16 +59,12 @@ abstract class SaveSheetActivityBase : AppCompatActivity() {
val viewModel: SaveViewModel by viewModels()
var extractedText: String? = null
// get locale and timezone from device
val timezone = TimeZone.getDefault().id
val locale = Locale.current.toLanguageTag()
when (intent?.action) {
Intent.ACTION_SEND -> {
if (intent.type?.startsWith("text/plain") == true) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
extractedText = it
viewModel.saveURL(it, timezone, locale)
viewModel.saveURL(it)
Log.d(ContentValues.TAG, "Extracted text: $extractedText")
}
}

View File

@ -5,6 +5,7 @@ import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.intl.Locale
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@ -14,6 +15,7 @@ import app.omnivore.omnivore.DatastoreRepository
import app.omnivore.omnivore.graphql.generated.SaveUrlMutation
import app.omnivore.omnivore.graphql.generated.type.SaveUrlInput
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@ -31,7 +33,7 @@ enum class SaveState {
@HiltViewModel
class SaveViewModel @Inject constructor(
private val datastoreRepo: DatastoreRepository
): ViewModel() {
) : ViewModel() {
val saveState = MutableLiveData(SaveState.NONE)
var isLoading by mutableStateOf(false)
@ -81,13 +83,18 @@ class SaveViewModel @Inject constructor(
try {
clientRequestID = UUID.randomUUID().toString()
// get locale and timezone from device
val timezone = TimeZone.getDefault().id
val locale = Locale.current.toLanguageTag()
val response = apolloClient.mutation(
SaveUrlMutation(
SaveUrlInput(
clientRequestId = clientRequestID!!,
source = "android",
url = cleanedUrl
url = cleanedUrl,
timezone = Optional.present(timezone),
locale = Optional.present(locale)
)
)
).execute()