Skip to content

Commit

Permalink
Modified for central CustomConfigFileReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkotixwolf committed Oct 21, 2024
1 parent 03d81c4 commit 3a79070
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
17 changes: 17 additions & 0 deletions bVNC/src/main/java/com/iiordanov/bVNC/App.java
Original file line number Diff line number Diff line change
@@ -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> context;
private Database database;

public static CustomClientConfigFileReader configFileReader;

public static Context getContext() {
return context.get();
}
Expand All @@ -31,10 +38,20 @@ public void onCreate() {
Constants.DEFAULT_PROTOCOL_PORT = Utils.getDefaultPort(this);
database = new Database(this);
context = new WeakReference<Context>(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;}
}
2 changes: 1 addition & 1 deletion bVNC/src/main/java/com/iiordanov/bVNC/CustomVnc.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onCreate(Bundle icicle) {
Map<String, Map> configData = configFileReader.getConfigData();
Map<String, Integer> visibility = (Map<String, Integer>) 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();
Expand Down
14 changes: 4 additions & 10 deletions bVNC/src/main/java/com/iiordanov/bVNC/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map> configData, String configDataKey, String configDataKeyChild, String childAttribute) throws NullPointerException {
try {
CustomClientConfigFileReader configFileReader = new CustomClientConfigFileReader(
context.getAssets().open(Utils.pName(context) + ".yaml"));
Map<String, 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<String, Map> configData, String configDataKey, View view) throws NullPointerException {
try {
String packageName = Utils.pName(context);
CustomClientConfigFileReader configFileReader = new CustomClientConfigFileReader(
context.getAssets().open(packageName + ".yaml"));
Map<String, Map> configData = configFileReader.getConfigData();
Map<String, Integer> visibility = (Map<String, Integer>) configData.get(configDataKey).get("visibility");

for (String s : visibility.keySet()) {
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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.")
}
Expand Down

0 comments on commit 3a79070

Please sign in to comment.