diff --git a/bVNC/src/main/java/com/iiordanov/bVNC/App.java b/bVNC/src/main/java/com/iiordanov/bVNC/App.java index 7a7270d59..48d694a48 100644 --- a/bVNC/src/main/java/com/iiordanov/bVNC/App.java +++ b/bVNC/src/main/java/com/iiordanov/bVNC/App.java @@ -1,19 +1,26 @@ package com.iiordanov.bVNC; import android.content.Context; +import android.util.Log; import androidx.appcompat.app.AppCompatDelegate; import androidx.multidex.MultiDex; import androidx.multidex.MultiDexApplication; +import java.io.IOException; import java.lang.ref.WeakReference; +import com.iiordanov.util.CustomClientConfigFileReader; + public class App extends MultiDexApplication { + private final static String TAG = "App"; public static boolean debugLog = false; private static WeakReference context; private Database database; + public static CustomClientConfigFileReader configFileReader; + public static Context getContext() { return context.get(); } @@ -31,10 +38,20 @@ public void onCreate() { Constants.DEFAULT_PROTOCOL_PORT = Utils.getDefaultPort(this); database = new Database(this); context = new WeakReference(this); + if(Utils.isCustom(getApplicationContext())){ + try { + configFileReader = new CustomClientConfigFileReader( + getApplicationContext().getAssets().open(Utils.pName(getApplicationContext()) + ".yaml")); + } catch (IOException e) { + Log.e(TAG, "Error opening config file from assets."); + } + } debugLog = Utils.querySharedPreferenceBoolean(getApplicationContext(), "moreDebugLoggingTag"); } public Database getDatabase() { return database; } + + public static CustomClientConfigFileReader getConfigFileReader(){ return configFileReader;} } diff --git a/bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java b/bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java index ed5f6175c..e27153d9b 100644 --- a/bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java +++ b/bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java @@ -25,7 +25,7 @@ public void onCreate(Bundle icicle) { Map configData = configFileReader.getConfigData(); Map visibility = (Map) configData.get("mainConfiguration").get("visibility"); - Utils.setVisibilityForViewElementsViaConfig(this, "mainConfiguration", findViewById(android.R.id.content).getRootView()); + Utils.setVisibilityForViewElementsViaConfig(this, App.getConfigFileReader().getConfigData(),"mainConfiguration", findViewById(android.R.id.content).getRootView()); Locale current = getResources().getConfiguration().locale; String currentLanguage = current.getLanguage(); diff --git a/bVNC/src/main/java/com/iiordanov/bVNC/Utils.java b/bVNC/src/main/java/com/iiordanov/bVNC/Utils.java index 72abb4068..bf306cf76 100644 --- a/bVNC/src/main/java/com/iiordanov/bVNC/Utils.java +++ b/bVNC/src/main/java/com/iiordanov/bVNC/Utils.java @@ -277,25 +277,19 @@ public static boolean isOpaque(Context context) { return packageName.toLowerCase().contains("opaque"); } - public static String getStringConfigAttribute(Context context, String configDataKey, String configDataKeyChild, String childAttribute) throws IOException, NullPointerException { + public static String getStringConfigAttribute(Map configData, String configDataKey, String configDataKeyChild, String childAttribute) throws NullPointerException { try { - CustomClientConfigFileReader configFileReader = new CustomClientConfigFileReader( - context.getAssets().open(Utils.pName(context) + ".yaml")); - Map configData = configFileReader.getConfigData(); String attr = (String) ((Map) configData.get(configDataKey).get(configDataKeyChild)).get(childAttribute); return attr; } - catch (IOException | NullPointerException e) { + catch (NullPointerException e) { throw e; } } - public static void setVisibilityForViewElementsViaConfig(Context context, String configDataKey, View view) throws IOException, NullPointerException { + public static void setVisibilityForViewElementsViaConfig(Context context, Map configData, String configDataKey, View view) throws NullPointerException { try { String packageName = Utils.pName(context); - CustomClientConfigFileReader configFileReader = new CustomClientConfigFileReader( - context.getAssets().open(packageName + ".yaml")); - Map configData = configFileReader.getConfigData(); Map visibility = (Map) configData.get(configDataKey).get("visibility"); for (String s : visibility.keySet()) { @@ -304,7 +298,7 @@ public static void setVisibilityForViewElementsViaConfig(Context context, String viewElement.setVisibility(visibility.get(s)); } } - catch (IOException | NullPointerException e) { + catch (NullPointerException e) { throw e; } } diff --git a/bVNC/src/main/java/com/iiordanov/bVNC/dialogs/RateOrShareFragment.kt b/bVNC/src/main/java/com/iiordanov/bVNC/dialogs/RateOrShareFragment.kt index 2f7734f14..d064a20d7 100644 --- a/bVNC/src/main/java/com/iiordanov/bVNC/dialogs/RateOrShareFragment.kt +++ b/bVNC/src/main/java/com/iiordanov/bVNC/dialogs/RateOrShareFragment.kt @@ -27,11 +27,10 @@ import android.widget.Button import android.widget.TableLayout import android.widget.TextView import androidx.fragment.app.DialogFragment +import com.iiordanov.bVNC.App import com.iiordanov.bVNC.Utils import com.undatech.remoteClientUi.R import java.io.IOException -import java.lang.Exception -import java.lang.NullPointerException class RateOrShareFragment : DialogFragment() { private var layout: TableLayout? = null @@ -70,7 +69,15 @@ class RateOrShareFragment : DialogFragment() { fun setTitle() { if (Utils.isCustom(context)){ try { - dialog?.setTitle(getString(requireContext().resources.getIdentifier(Utils.getStringConfigAttribute(context, TAG.replaceFirstChar { it.lowercase() }, "title", "key"), "string", Utils.pName(context)))) + dialog?.setTitle( + getString( + requireContext().resources.getIdentifier( + Utils.getStringConfigAttribute(App.configFileReader.configData, TAG.replaceFirstChar { it.lowercase() }, "title", "key"), + "string", + Utils.pName(context) + ) + ) + ) return } catch (e: Exception) { @@ -83,7 +90,7 @@ class RateOrShareFragment : DialogFragment() { fun setVisibilityOfElements(v: View) { if (Utils.isCustom(context)){ try { - Utils.setVisibilityForViewElementsViaConfig(context, TAG.replaceFirstChar { it.lowercase() }, v) + Utils.setVisibilityForViewElementsViaConfig(context, App.configFileReader.configData, TAG.replaceFirstChar { it.lowercase() }, v) } catch (e: Exception) { isCustomException(e) @@ -93,9 +100,6 @@ class RateOrShareFragment : DialogFragment() { fun isCustomException(e: Exception) { when (e) { - is IOException -> { - Log.e(TAG, "Error opening config file from assets.") - } is NullPointerException -> { Log.e(TAG, "Error referencing attribute in config file.") }