use bundle extensions

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-04 15:08:24 +01:00 committed by Alper Öztürk
parent c3c7606edc
commit 33d20128cc
2 changed files with 20 additions and 17 deletions

View file

@ -56,3 +56,19 @@ fun <T : Parcelable?> Bundle?.getParcelableArgument(key: String, type: Class<T>)
null
}
}
fun Bundle.getRestriction(key: String, defaultValue: String?): String? {
return if (containsKey(key)) {
getString(key)
} else {
defaultValue
}
}
fun Bundle.getRestriction(key: String, defaultValue: Int): Int {
return if (containsKey(key)) {
getInt(key)
} else {
defaultValue
}
}

View file

@ -11,6 +11,7 @@ import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import android.text.TextUtils
import com.nextcloud.utils.extensions.getRestriction
import com.owncloud.android.R
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.utils.Log_OC
@ -25,17 +26,8 @@ class AppConfigManager(private val context: Context, private val appRestrictions
return
}
val host = if (appRestrictions.containsKey(AppConfigKeys.ProxyHost.key)) {
appRestrictions.getString(AppConfigKeys.ProxyHost.key)
} else {
context.getString(R.string.proxy_host)
}
val port = if (appRestrictions.containsKey(AppConfigKeys.ProxyPort.key)) {
appRestrictions.getInt(AppConfigKeys.ProxyPort.key)
} else {
context.resources.getInteger(R.integer.proxy_port)
}
val host = appRestrictions.getRestriction(AppConfigKeys.ProxyHost.key, context.getString(R.string.proxy_host))
val port = appRestrictions.getRestriction(AppConfigKeys.ProxyPort.key, context.resources.getInteger(R.integer.proxy_port))
if (TextUtils.isEmpty(host) || port == -1) {
Log_OC.d(tag, "Proxy configuration cannot be found")
@ -58,11 +50,6 @@ class AppConfigManager(private val context: Context, private val appRestrictions
return null
}
return if (appRestrictions.containsKey(AppConfigKeys.BaseUrl.key)) {
appRestrictions.getString(AppConfigKeys.BaseUrl.key)
} else {
Log_OC.d(tag, "BaseUrl configuration cannot be found, default url applied")
null
}
return appRestrictions.getRestriction(AppConfigKeys.BaseUrl.key, null)
}
}