Skip to content

Commit

Permalink
Merge pull request #8 from Akasha-Chronicles/self-host-updates
Browse files Browse the repository at this point in the history
fix/mobile-saves
  • Loading branch information
Podginator authored Dec 14, 2024
2 parents 3215435 + 8a2906c commit 735e396
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions android/Omnivore/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -62,7 +69,7 @@ class EditInfoViewModel @Inject constructor(
}

val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.apiURL}/api/graphql")
.serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -86,7 +93,7 @@ class SaveViewModel @Inject constructor(
}

val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.apiURL}/api/graphql")
.serverUrl(serverUrl())
.addHttpHeader("Authorization", value = authToken)
.build()

Expand Down

0 comments on commit 735e396

Please sign in to comment.