Merge pull request #8 from Akasha-Chronicles/self-host-updates

fix/mobile-saves
This commit is contained in:
Tom Rogers 2024-12-14 17:41:28 +01:00 committed by GitHub
commit 735e39607c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 4 deletions

View file

@ -1,5 +1,12 @@
# Omnivore - Android
## Setup with gradle
In case you do not have Android Studio and you do not want to install it, you may want to use gradlew scripts to build the application.
`./gradlew assembleDebug` should create `./app/build/outputs/apk/debug/app-debug.apk`
## Setup
From the root directory run the following command:

View file

@ -10,6 +10,7 @@ import app.omnivore.omnivore.R
import app.omnivore.omnivore.core.data.DataService
import app.omnivore.omnivore.core.datastore.DatastoreRepository
import app.omnivore.omnivore.core.datastore.omnivoreAuthToken
import app.omnivore.omnivore.core.datastore.omnivoreSelfHostedApiServer
import app.omnivore.omnivore.graphql.generated.UpdatePageMutation
import app.omnivore.omnivore.graphql.generated.type.UpdatePageInput
import app.omnivore.omnivore.utils.Constants
@ -48,6 +49,12 @@ class EditInfoViewModel @Inject constructor(
datastoreRepo.getString(omnivoreAuthToken)
}
fun baseUrl() = runBlocking {
datastoreRepo.getString(omnivoreSelfHostedApiServer) ?: Constants.apiURL
}
private fun serverUrl() = "${baseUrl()}/api/graphql"
fun editInfo(itemId: String, title: String, author: String?, description: String?) {
viewModelScope.launch {
isLoading = true
@ -62,7 +69,7 @@ class EditInfoViewModel @Inject constructor(
}
val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.apiURL}/api/graphql")
.serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken)
.build()

View file

@ -176,6 +176,12 @@ class OnboardingViewModel @Inject constructor(
resetPendingEmailUserCreds()
}
fun baseUrl() = runBlocking {
datastoreRepository.getString(omnivoreSelfHostedApiServer) ?: Constants.apiURL
}
private fun serverUrl() = "${baseUrl()}/api/graphql"
fun validateUsername(potentialUsername: String) {
validateUsernameJob?.cancel()
@ -209,7 +215,7 @@ class OnboardingViewModel @Inject constructor(
}
val apolloClient =
ApolloClient.Builder().serverUrl("${Constants.apiURL}/api/graphql").build()
ApolloClient.Builder().serverUrl(serverUrl()).build()
try {
val response = apolloClient.query(

View file

@ -16,6 +16,7 @@ import androidx.work.WorkerParameters
import app.omnivore.omnivore.R
import app.omnivore.omnivore.core.datastore.DatastoreRepository
import app.omnivore.omnivore.core.datastore.omnivoreAuthToken
import app.omnivore.omnivore.core.datastore.omnivoreSelfHostedApiServer
import app.omnivore.omnivore.graphql.generated.SaveUrlMutation
import app.omnivore.omnivore.graphql.generated.type.SaveUrlInput
import app.omnivore.omnivore.utils.Constants
@ -59,11 +60,16 @@ class SaveURLWorker @AssistedInject constructor(
}
}
suspend fun baseUrl() =
datastoreRepository.getString(omnivoreSelfHostedApiServer) ?: Constants.apiURL
private suspend fun serverUrl() = "${baseUrl()}/api/graphql"
private suspend fun saveURL(url: String): Boolean {
val authToken = datastoreRepository.getString(omnivoreAuthToken) ?: return false
val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.apiURL}/api/graphql")
.serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken)
.build()

View file

@ -11,6 +11,7 @@ import androidx.lifecycle.viewModelScope
import app.omnivore.omnivore.R
import app.omnivore.omnivore.core.datastore.DatastoreRepository
import app.omnivore.omnivore.core.datastore.omnivoreAuthToken
import app.omnivore.omnivore.core.datastore.omnivoreSelfHostedApiServer
import app.omnivore.omnivore.graphql.generated.SaveUrlMutation
import app.omnivore.omnivore.graphql.generated.type.SaveUrlInput
import app.omnivore.omnivore.utils.Constants
@ -71,6 +72,12 @@ class SaveViewModel @Inject constructor(
return null
}
fun baseUrl() = runBlocking {
datastoreRepo.getString(omnivoreSelfHostedApiServer) ?: Constants.apiURL
}
private fun serverUrl() = "${baseUrl()}/api/graphql"
fun saveURL(url: String) {
viewModelScope.launch {
isLoading = true
@ -86,7 +93,7 @@ class SaveViewModel @Inject constructor(
}
val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.apiURL}/api/graphql")
.serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken)
.build()