Simplify AppConfigManager

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-15 13:46:26 +02:00 committed by Alper Öztürk
parent 22e9a40fd4
commit ac1c41b6df
5 changed files with 19 additions and 20 deletions

View file

@ -326,7 +326,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
appConfigManager.readProxyConfig();
appConfigManager.setProxyConfig();
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
@ -373,7 +373,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
passCodeManager.setCanAskPin(true);
Log_OC.d(TAG, "APP IN BACKGROUND");
} else if (event == Lifecycle.Event.ON_RESUME) {
appConfigManager.readProxyConfig();
appConfigManager.setProxyConfig();
Log_OC.d(TAG, "APP ON RESUME");
}
});
@ -382,7 +382,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
private final BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
appConfigManager.readProxyConfig();
appConfigManager.setProxyConfig();
}
};

View file

@ -22,13 +22,13 @@ class AppConfigManager(private val context: Context) {
private val tag = "AppConfigManager"
fun readProxyConfig() {
fun setProxyConfig() {
val appRestrictions = restrictionsManager.applicationRestrictions
val host = if (appRestrictions.containsKey(AppConfigKeys.ProxyHost.key)) {
appRestrictions.getString(AppConfigKeys.ProxyHost.key)
} else {
context.resources.getString(R.string.proxy_host)
context.getString(R.string.proxy_host)
}
val port = if (appRestrictions.containsKey(AppConfigKeys.ProxyPort.key)) {
@ -48,10 +48,14 @@ class AppConfigManager(private val context: Context) {
try {
OwnCloudClientManagerFactory.setProxyHost(host)
OwnCloudClientManagerFactory.setProxyPort(port)
Log_OC.d(tag, "Proxy configuration successfully set")
} catch (e: Resources.NotFoundException) {
context.enterpriseFeedback(AppConfigKeys.ProxyHost, R.string.app_config_proxy_config_cannot_be_set_message)
context.enterpriseFeedback(AppConfigKeys.ProxyPort, R.string.app_config_proxy_config_cannot_be_set_message)
Log_OC.d(tag, "Proxy config cannot able to set due to: $e")
context.run {
enterpriseFeedback(AppConfigKeys.ProxyHost, R.string.app_config_proxy_config_cannot_be_set_message)
enterpriseFeedback(AppConfigKeys.ProxyPort, R.string.app_config_proxy_config_cannot_be_set_message)
}
Log_OC.e(tag, "Proxy config cannot able to set due to: $e")
}
}
}

View file

@ -26,11 +26,8 @@
<string name="ecosystem_apps_display_assistant">Assistant</string>
<string name="app_config_proxy_host_title">Host</string>
<string name="app_config_proxy_host_description">Select a proxy host configuration</string>
<string name="app_config_proxy_port_title">Port</string>
<string name="app_config_proxy_port_description">Select a proxy port configuration</string>
<string name="app_config_proxy_host_title">Proxy Host Name</string>
<string name="app_config_proxy_port_title">Proxy Port</string>
<string name="app_config_proxy_config_cannot_be_found_message">Proxy configuration cannot be found</string>
<string name="app_config_proxy_config_cannot_be_set_message">Proxy configuration cannot be set</string>

View file

@ -9,16 +9,14 @@
<restriction
android:key="proxy_host"
android:restrictionType="string"
android:defaultValue=""
android:title="@string/app_config_proxy_host_title"
android:description="@string/app_config_proxy_host_description" />
android:restrictionType="string"
android:title="@string/app_config_proxy_host_title" />
<restriction
android:key="proxy_port"
android:restrictionType="integer"
android:defaultValue="0"
android:title="@string/app_config_proxy_port_title"
android:description="@string/app_config_proxy_port_description" />
android:restrictionType="integer"
android:title="@string/app_config_proxy_port_title" />
</restrictions>

View file

@ -21,4 +21,4 @@ org.gradle.parallel=true
org.gradle.configureondemand=true
# Needed for local libs
# org.gradle.dependency.verification=lenient
org.gradle.dependency.verification=lenient