Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow files in data to be edited #128

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.childDirectory("data");

// Why do we need this...?
for (SketchFile meta : tabs) {
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,21 @@ public void addFile(Uri source) {
e.printStackTrace();
}
}
}

public void addNewFile() {
try {
// Get the location of this sketch's data folder
MaybeDocumentFile dataFolder = getGlobalState().getSketchLocation().childDirectory("data");

String name = DEFAULT_ADDED_FILENAME;

String mimeType = "application/octet-stream";

MaybeDocumentFile dest = dataFolder.child(name, mimeType);
dataFolder.resolve();
dest.resolve();
} catch (MaybeDocumentFile.MaybeDocumentFileException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<string name="prop_sketch_folder">Sketch Folder</string>
<string name="prop_add_file">Add File</string>
<string name="prop_add_file_desc">Add a file to the sketch\'s data folder</string>
<string name="prop_add_new_file">Add Empty File</string>
<string name="prop_add_new_file_desc">Add an empty file to the sketch\'s data folder</string>
<!-- The button shown in settings: -->
<string name="prop_show_sketch_folder">Show Sketch Folder</string>
<!-- The title of the activity that is started after pressing the button in settings: -->
Expand All @@ -54,4 +56,4 @@
<string name="change_icon_dialog_format_scale_center">Center</string>
<string name="change_icon_dialog_format_scale_resize">Resize</string>
<string name="change_icon_dialog_icon_file_not_selected">No Icon File Selected</string>
</resources>
</resources>