diff --git a/developer/src/kmc/test/test-getLastGitCommitDate.ts b/developer/src/kmc/test/test-getLastGitCommitDate.ts index 90de59f6897..917cfdc7ad0 100644 --- a/developer/src/kmc/test/test-getLastGitCommitDate.ts +++ b/developer/src/kmc/test/test-getLastGitCommitDate.ts @@ -21,6 +21,6 @@ describe('getLastGitCommitDate', function () { // The expected date was manually extracted using the following command, with msec appended: // TZ=UTC git log --date=iso-strict-local -- fixtures/get-last-git-commit-date/README.md // If the fixture modified, then this will also need to be updated. - assert.equal(date, '2024-08-01T00:07:07.000Z'); + assert.equal(date, '2024-06-17T20:43:48.000Z'); }); }); diff --git a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVShared.java b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVShared.java index 95158826ba5..9b75b3eea95 100644 --- a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVShared.java +++ b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/FVShared.java @@ -7,22 +7,25 @@ import android.net.Uri; import android.util.Log; import android.widget.Toast; +import com.keyman.engine.JSONParser; import com.keyman.engine.KMManager; import com.keyman.engine.data.Keyboard; import com.keyman.engine.packages.PackageProcessor; import com.keyman.engine.util.KMLog; -import java.io.BufferedReader; +import org.json.JSONArray; +import org.json.JSONObject; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -30,6 +33,8 @@ final class FVShared { private static FVShared instance = null; private boolean isInitialized = false; + // File containing keyboard+region info for each keyboard + private static final String FVKeyboards_JSON = "keyboards.json"; private static final String FVLoadedKeyboardList = "loaded_keyboards.dat"; // Keys from earlier versions of app, used only in the upgrade process @@ -107,7 +112,8 @@ public synchronized void initialize(Context context) { } this.context = context.getApplicationContext(); - this.regionList = loadRegionList(); + String keyboardsJSONPath = getPackagesDir() + FVDefault_PackageID + File.separator + FVKeyboards_JSON; + this.regionList = loadRegionList(keyboardsJSONPath); this.loadedKeyboards = loadLoadedKeyboardList(); isInitialized = true; @@ -123,54 +129,86 @@ public static FVShared getInstance() { return instance; } - private FVRegionList loadRegionList() { - FVRegionList list = new FVRegionList(); - try { - // At this point in initialization, fv_all.kmp hasn't been extracted, so - // we get all the keyboard info from keyboards.csv - InputStream inputStream = context.getAssets().open("keyboards.csv"); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - - reader.readLine(); // skip header row - String line = reader.readLine(); - - while (line != null) { - while (line.contains(",,")) - line = line.replace(",,", ", ,"); - - String[] values = line.split(","); - if (values != null && values.length > 0) { - // Read in column info - String kbId = values[1]; - String kbName = values[2]; - String regionName = values[3]; - String legacyId = values[4]; - String version = values[5]; - String lgId = values[6].toLowerCase(); // Normalize language ID - String lgName = values[7]; - - FVRegion region = list.findRegion(regionName); - if(region == null) { - region = new FVRegion(regionName); - list.add(region); - } - - FVKeyboard keyboard = new FVKeyboard(kbId, kbName, legacyId, version, lgId, lgName); - - region.keyboards.add(keyboard); - } + /** + * Parse keyboards.json file to associate region info for each keyboard + * @param keyboardsJSONPath - path to the keyboards.json file containing region info for each keyboard + * @return FVRegionList + */ + private FVRegionList loadRegionList(String keyboardsJSONPath) { + FVRegionList list = new FVRegionList(); + JSONParser parser = new JSONParser(); + File jsonFile = new File(keyboardsJSONPath); + if (!jsonFile.exists()) { + // Fatal error + throw new Error("keyboards.json file doesn't exist"); + } + try { + // At this point in initialization, fv_all.kmp is now extracted, so + // populate keyboard info from keyboards.json + JSONArray keyboardsArray = parser.getJSONObjectFromFile(jsonFile, JSONArray.class); + + if (keyboardsArray == null) { + KMLog.LogError(TAG, "Unable to parse keyboards.json"); + return list; + } - line = reader.readLine(); - } + for (int i=0; i r1.name.compareTo(r2.name)); - return list; - } + for (int i=0; i k1.name.compareTo(k2.name)); + } + return list; + } private FVLoadedKeyboardList loadLoadedKeyboardList() { FVLoadedKeyboardList data = new FVLoadedKeyboardList(); diff --git a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java index f91657203bc..d38d5b9bc07 100644 --- a/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java +++ b/oem/firstvoices/android/app/src/main/java/com/firstvoices/keyboards/MainActivity.java @@ -49,17 +49,17 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); + if (BuildConfig.DEBUG) { + KMManager.setDebugMode(true); + } + KMManager.initialize(getApplicationContext(), KMManager.KeyboardType.KEYBOARD_TYPE_INAPP); + FVShared.getInstance().initialize(this); FVShared.getInstance().upgradeTo12(); FVShared.getInstance().upgradeTo14(); FVShared.getInstance().preloadPackages(); - if (BuildConfig.DEBUG) { - KMManager.setDebugMode(true); - } - KMManager.initialize(getApplicationContext(), KMManager.KeyboardType.KEYBOARD_TYPE_INAPP); - /** * We need to set the default (fallback) keyboard to sil_euro_latin inside the fv_all package * rather than the normal default of sil_euro_latin inside the sil_euro_latin package. diff --git a/oem/firstvoices/android/build.sh b/oem/firstvoices/android/build.sh index 3e10a79ae66..e27be069747 100755 --- a/oem/firstvoices/android/build.sh +++ b/oem/firstvoices/android/build.sh @@ -61,13 +61,9 @@ if builder_start_action clean; then fi if builder_start_action configure; then - KEYBOARDS_CSV="$KEYMAN_ROOT/oem/firstvoices/keyboards.csv" - KEYBOARDS_CSV_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/keyboards.csv" - KEYBOARD_PACKAGE_ID="fv_all" KEYBOARDS_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/${KEYBOARD_PACKAGE_ID}.kmp" - cp "$KEYBOARDS_CSV" "$KEYBOARDS_CSV_TARGET" downloadKeyboardPackage "$KEYBOARD_PACKAGE_ID" "$KEYBOARDS_TARGET" builder_finish_action success configure