From 469370a1e1b20316d1ca68b7f80599378c480382 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:59:07 -0400 Subject: [PATCH 01/15] Allow files in the data folder to be edited --- .../com/calsignlabs/apde/EditorActivity.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java index 3757c17..5b58bdb 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java @@ -2184,6 +2184,7 @@ public boolean loadSketch(String sketchPath, APDE.SketchLocation sketchLocation) // Get all the files in the directory DocumentFile[] files = sketchLoc.resolve().listFiles(); + MaybeDocumentFile datadir = sketchLoc.resolve().directory("data"); // Why do we need this...? for (SketchFile meta : tabs) { @@ -2218,6 +2219,34 @@ public boolean loadSketch(String sketchPath, APDE.SketchLocation sketchLocation) meta.getFragment().setSketchFile(meta); } } + + if(datadir.exists()){ + DocumentFile[] datafiles = datadir.resolve().listFiles(); + for (DocumentFile file : datafiles) { + String name = file.getName(); + if (name == null) { + continue; + } + + String[] parts = name.split("\\."); + if (parts.length != 2) { + continue; + } + String title = parts[0]; + String ext = parts[1]; + + if (ext.equals("glsl") || ext.equals("frag") || ext.equals("vert") || ext.equals("txt") || ext.equals("json")) { + // Build a SketchFile object + SketchFile meta = new SketchFile("data/"+title); + meta.readData(file, getContentResolver()); + meta.setExample(getGlobalState().isExample()); + meta.setSuffix("." + ext); + + addTabWithoutPagerUpdate(meta); + meta.getFragment().setSketchFile(meta); + } + } + } codePagerAdapter.notifyDataSetChanged(); From 8feab4523c0b5e6e7a81861cfc8f46ee6b0fe252 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:13:11 -0400 Subject: [PATCH 02/15] Add 'Add new file' option --- .../main/res/values/strings_activity_sketch_properties.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/APDE/src/main/res/values/strings_activity_sketch_properties.xml b/APDE/src/main/res/values/strings_activity_sketch_properties.xml index 99305f9..d5611eb 100644 --- a/APDE/src/main/res/values/strings_activity_sketch_properties.xml +++ b/APDE/src/main/res/values/strings_activity_sketch_properties.xml @@ -39,6 +39,8 @@ Sketch Folder Add File Add a file to the sketch\'s data folder + Add New File + Add a blank file to the sketch\'s data folder Show Sketch Folder @@ -54,4 +56,4 @@ Center Resize No Icon File Selected - \ No newline at end of file + From 646437fd38d6c0fb149726f3773d7975cb8ef6d8 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:09:48 -0400 Subject: [PATCH 03/15] Add 'addNewFile' --- .../apde/SketchPropertiesActivity.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java index 9d3e4c4..e0930c1 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java @@ -154,4 +154,21 @@ public void addFile(Uri source) { e.printStackTrace(); } } -} \ No newline at end of file + + public void addNewFile() { + try { + // Get the location of this sketch's data folder + MaybeDocumentFile dataFolder = getGlobalState().getSketchLocation().childDirectory("data"); + + name = DEFAULT_ADDED_FILENAME; + + mimeType = "application/octet-stream"; + + MaybeDocumentFile dest = dataFolder.child(name, mimeType); + dataFolder.resolve(); + dest.resolve(); + } catch (MaybeDocumentFile.MaybeDocumentFileException | IOException e) { + e.printStackTrace(); + } + } +} From b54270d24af1f9b8ad0862fa0eac9487e188e68f Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:10:11 -0400 Subject: [PATCH 04/15] Add 'addNewFile' --- .../com/calsignlabs/apde/SketchPropertiesFragment.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesFragment.java b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesFragment.java index bbed77c..a74c702 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesFragment.java +++ b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesFragment.java @@ -135,6 +135,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { return true; }); + Preference launchAddNewFile = findPreference("prop_add_new_file"); + launchAddNewFile.setOnPreferenceClickListener(preference -> { + launchAddNewFile(); + return true; + }); + Preference launchAddFile = findPreference("prop_add_file"); launchAddFile.setOnPreferenceClickListener(preference -> { launchAddFile(); @@ -276,6 +282,10 @@ public void launchAddFile() { getSketchPropertiesActivity().startActivityForResult(intent, SketchPropertiesActivity.REQUEST_CHOOSER); } + public void launchAddNewFile() { + getSketchPropertiesActivity().addNewFile(); + } + @SuppressLint({ "InlinedApi", "NewApi" }) public void launchChangeIcon() { AlertDialog.Builder builder = new AlertDialog.Builder(getSketchPropertiesActivity()); From cd0d1e96f55b6c436150c552605c1da934aec286 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:59:43 -0400 Subject: [PATCH 05/15] Fix minor error --- APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java index 5b58bdb..da3a394 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java @@ -2184,7 +2184,7 @@ public boolean loadSketch(String sketchPath, APDE.SketchLocation sketchLocation) // Get all the files in the directory DocumentFile[] files = sketchLoc.resolve().listFiles(); - MaybeDocumentFile datadir = sketchLoc.resolve().directory("data"); + MaybeDocumentFile datadir = sketchLoc.directory("data"); // Why do we need this...? for (SketchFile meta : tabs) { From 780ac189803205c1ceb8b23d467d022188c76e50 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:01:14 -0400 Subject: [PATCH 06/15] Fix minor error --- .../java/com/calsignlabs/apde/SketchPropertiesActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java index e0930c1..5e89169 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java @@ -160,9 +160,9 @@ public void addNewFile() { // Get the location of this sketch's data folder MaybeDocumentFile dataFolder = getGlobalState().getSketchLocation().childDirectory("data"); - name = DEFAULT_ADDED_FILENAME; + String name = DEFAULT_ADDED_FILENAME; - mimeType = "application/octet-stream"; + String mimeType = "application/octet-stream"; MaybeDocumentFile dest = dataFolder.child(name, mimeType); dataFolder.resolve(); From a3c113a7151c9350b1133589a85a09e14bbff0c9 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:10:28 -0400 Subject: [PATCH 07/15] Fix minor error --- APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java index da3a394..d49f697 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java @@ -2184,7 +2184,7 @@ public boolean loadSketch(String sketchPath, APDE.SketchLocation sketchLocation) // Get all the files in the directory DocumentFile[] files = sketchLoc.resolve().listFiles(); - MaybeDocumentFile datadir = sketchLoc.directory("data"); + MaybeDocumentFile datadir = sketchLoc.childDirectory("data"); // Why do we need this...? for (SketchFile meta : tabs) { From 9fe5a8cc4f892ecd7f896888a4c8879853ebd3c9 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:15:12 -0400 Subject: [PATCH 08/15] Remove unused IOException catch --- .../java/com/calsignlabs/apde/SketchPropertiesActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java index 5e89169..aaf4d02 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java +++ b/APDE/src/main/java/com/calsignlabs/apde/SketchPropertiesActivity.java @@ -167,7 +167,7 @@ public void addNewFile() { MaybeDocumentFile dest = dataFolder.child(name, mimeType); dataFolder.resolve(); dest.resolve(); - } catch (MaybeDocumentFile.MaybeDocumentFileException | IOException e) { + } catch (MaybeDocumentFile.MaybeDocumentFileException e) { e.printStackTrace(); } } From 55c90331544cdd01d5ea73e1178d30305767b0fa Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:58:12 -0400 Subject: [PATCH 09/15] Update android.yml --- .github/workflows/android.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 0741c09..9a7acc6 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,3 +13,5 @@ jobs: java-version: 11 - name: Build with Gradle run: ./gradlew :APDE:build + - name: List files + run: find|grep apk From ff9db3644d136dd783ae4eed998f7734bd58df9e Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Tue, 14 Mar 2023 22:11:31 -0400 Subject: [PATCH 10/15] Update android.yml --- .github/workflows/android.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 9a7acc6..9ece954 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,5 +13,13 @@ jobs: java-version: 11 - name: Build with Gradle run: ./gradlew :APDE:build - - name: List files - run: find|grep apk + - name: upload release + uses: actions/upload-artifact@v3 + with: + name: APDE.apk + path: APDE/build/outputs/apk/release/APDE-release-unsigned.apk + - name: upload debug + uses: actions/upload-artifact@v3 + with: + name: APDE-debug.apk + path: APDE/build/outputs/apk/debug/APDE-debug.apk From 69363d2ee996bd1e136c5401ffda302bd9c7f77f Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Wed, 15 Mar 2023 09:34:50 -0400 Subject: [PATCH 11/15] Revert to original android.yml --- .github/workflows/android.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 9ece954..0741c09 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,13 +13,3 @@ jobs: java-version: 11 - name: Build with Gradle run: ./gradlew :APDE:build - - name: upload release - uses: actions/upload-artifact@v3 - with: - name: APDE.apk - path: APDE/build/outputs/apk/release/APDE-release-unsigned.apk - - name: upload debug - uses: actions/upload-artifact@v3 - with: - name: APDE-debug.apk - path: APDE/build/outputs/apk/debug/APDE-debug.apk From 73f30a9617d23e6759d8ee52e4b3ff637846bae0 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Wed, 15 Mar 2023 09:41:13 -0400 Subject: [PATCH 12/15] Rename add new file to add empty file --- .../main/res/values/strings_activity_sketch_properties.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/APDE/src/main/res/values/strings_activity_sketch_properties.xml b/APDE/src/main/res/values/strings_activity_sketch_properties.xml index d5611eb..fe53dd7 100644 --- a/APDE/src/main/res/values/strings_activity_sketch_properties.xml +++ b/APDE/src/main/res/values/strings_activity_sketch_properties.xml @@ -39,8 +39,8 @@ Sketch Folder Add File Add a file to the sketch\'s data folder - Add New File - Add a blank file to the sketch\'s data folder + Add Empty File + Add an empty file to the sketch\'s data folder Show Sketch Folder From bdd36837f98f482947cbf42bad2bfdb9bd11a09c Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:32:04 -0400 Subject: [PATCH 13/15] Add a function to replace exit() --- .../java/com/calsignlabs/apde/build/Preprocessor.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java b/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java index 73caea0..a2e063a 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java +++ b/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java @@ -149,6 +149,7 @@ public CharSequence getText(int section) { // preserve the text, they rewrite it. This is OK, though, because there shouldn't be // any problems with them that doesn't get picked up by the preprocessor. List settingsStatements = extractSettings(scrubbed); + replaceExit(scrubbed); replaceTypeConstructors(scrubbed); replaceHexLiterals(scrubbed); @@ -572,6 +573,16 @@ private void extractImports(CharSequence scrubbed, List imp } } + private static final Pattern EXIT_REGEX = Pattern.compile("(?<=^|\\W)(exit)(?=\\s*\\()", Pattern.MULTILINE); + + private void replaceExit(CharSequence scrubbed) { + Matcher matcher = EXIT_REGEX.matcher(scrubbed); + while (matcher.find()) { + // Converts int() to PApplet.parseInt() + transform.replace(matcher.start(1), matcher.group(1).length(), "getActivity().finish"); + } + } + private static final Pattern TYPE_CONSTRUCTOR_REGEX = Pattern.compile("(?<=^|\\W)(int|char|float|boolean|byte)(?=\\s*\\()", Pattern.MULTILINE); private void replaceTypeConstructors(CharSequence scrubbed) { From 0164690838c1cb56213850d7cf80ea235eb4e64f Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:14:52 -0400 Subject: [PATCH 14/15] Revert the preprocessor --- .../java/com/calsignlabs/apde/build/Preprocessor.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java b/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java index a2e063a..73caea0 100644 --- a/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java +++ b/APDE/src/main/java/com/calsignlabs/apde/build/Preprocessor.java @@ -149,7 +149,6 @@ public CharSequence getText(int section) { // preserve the text, they rewrite it. This is OK, though, because there shouldn't be // any problems with them that doesn't get picked up by the preprocessor. List settingsStatements = extractSettings(scrubbed); - replaceExit(scrubbed); replaceTypeConstructors(scrubbed); replaceHexLiterals(scrubbed); @@ -573,16 +572,6 @@ private void extractImports(CharSequence scrubbed, List imp } } - private static final Pattern EXIT_REGEX = Pattern.compile("(?<=^|\\W)(exit)(?=\\s*\\()", Pattern.MULTILINE); - - private void replaceExit(CharSequence scrubbed) { - Matcher matcher = EXIT_REGEX.matcher(scrubbed); - while (matcher.find()) { - // Converts int() to PApplet.parseInt() - transform.replace(matcher.start(1), matcher.group(1).length(), "getActivity().finish"); - } - } - private static final Pattern TYPE_CONSTRUCTOR_REGEX = Pattern.compile("(?<=^|\\W)(int|char|float|boolean|byte)(?=\\s*\\()", Pattern.MULTILINE); private void replaceTypeConstructors(CharSequence scrubbed) { From 4a21f94528c3668897cacb18ffe10eecff45f1d7 Mon Sep 17 00:00:00 2001 From: RbCaVi <92527341+RbCaVi@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:18:23 +0700 Subject: [PATCH 15/15] Unrevert Android.yml --- .github/workflows/android.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 0741c09..9ece954 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,3 +13,13 @@ jobs: java-version: 11 - name: Build with Gradle run: ./gradlew :APDE:build + - name: upload release + uses: actions/upload-artifact@v3 + with: + name: APDE.apk + path: APDE/build/outputs/apk/release/APDE-release-unsigned.apk + - name: upload debug + uses: actions/upload-artifact@v3 + with: + name: APDE-debug.apk + path: APDE/build/outputs/apk/debug/APDE-debug.apk