diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountFactory.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountFactory.kt index 8f97d01..daa38ac 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountFactory.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountFactory.kt @@ -6,8 +6,8 @@ import android.content.Intent interface AccountFactory { val apiFactory: Class<*> - val name: String - val url: String + val name: String? + val url: String? fun initAccount(context: Context) fun isConnected(context: Context): Boolean fun connect(activity: Activity) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/account/SSOAccountFactory.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/SSOAccountFactory.kt index eca24a9..de2d149 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/account/SSOAccountFactory.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/SSOAccountFactory.kt @@ -22,10 +22,10 @@ import org.unifiedpush.distributor.nextpush.utils.TAG class SSOAccountFactory : AccountFactory { override val apiFactory: Class<*> = ApiSSOFactory::class.java - override val name: String - get() = ssoAccount!!.name - override val url: String - get() = ssoAccount!!.url + override val name: String? + get() = ssoAccount?.name + override val url: String? + get() = ssoAccount?.url private var ssoAccount: SingleSignOnAccount? = null diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt index ea57275..6b6323b 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt @@ -29,6 +29,9 @@ object Api { private var provider: ApiProviderFactory? = null private var source: EventSource? = null + private val Context.baseUrl: String + get() = getAccount(this)?.url ?: "http://0.0.0.0/" + private fun Context.withApiProvider(block: (ApiProvider) -> Unit) { ( provider ?: run { @@ -79,7 +82,7 @@ object Api { } override fun onComplete() { - saveUrl(this@apiSync, "${getAccount(this@apiSync)?.url}$mApiEndpoint") + saveUrl(this@apiSync, "$baseUrl$mApiEndpoint") // Sync once it is registered deviceId?.let { @@ -97,7 +100,7 @@ object Api { .readTimeout(0, TimeUnit.SECONDS) .retryOnConnectionFailure(false) .build() - val url = "${getAccount(this)?.url}$mApiEndpoint/device/$deviceId" + val url = "$baseUrl$mApiEndpoint/device/$deviceId" val request = Request.Builder().url(url) .get()