Skip to content

Commit

Permalink
fixed clone, rename, delete project actions
Browse files Browse the repository at this point in the history
  • Loading branch information
victordiaz committed Oct 10, 2022
1 parent c8a9d09 commit 6afdc85
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 337 deletions.
2 changes: 0 additions & 2 deletions PHONK-android/phonk_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
// flavorDimensions "normal", "extended"
// flavorDimensions "default"
flavorDimensions "version"

compileSdkVersion project.compileSdkVersion
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import io.phonk.gui.info.UpdateActivity;
import io.phonk.gui.welcome.WelcomeActivity;
import io.phonk.runner.base.utils.MLog;

public class LauncherActivity extends Activity {

Expand Down Expand Up @@ -62,6 +63,7 @@ public void onCreate(Bundle savedInstanceState) {
* or Launch the MainApp
*/

MLog.d(TAG, firstLaunch + "qq");
if (firstLaunch) {
intent = new Intent(this, WelcomeActivity.class);
} else if (BuildConfig.VERSION_CODE > userDetails.getInt("last_version_reinstalled", 125)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public static ArrayList<ProtoFile> listFilesInProjectFolder(Project p, String fo

// remove the project folder
for (ProtoFile file : files) {
String[] splittedPath = file.path.split(p.getSandboxPath());
file.path = file.path.replace(p.getSandboxPath(), "");
}

Expand Down Expand Up @@ -248,6 +247,8 @@ private static void fileWalker(ArrayList<ProtoFile> tree, File dir, int levels,
return pathname.getName().endsWith(extensionFilter);
});

if (all_projects == null) return;

for (File f : all_projects) {

ProtoFile protoFile = new ProtoFile();
Expand Down Expand Up @@ -357,16 +358,13 @@ public static ArrayList<ProtoFile> listFilesInProject(Project p) {
}

public static boolean renameProject(Project p, String newName) {
MLog.d(TAG, "renameProject 1 -->" + p.getFullPath());
MLog.d(TAG, "renameProject 2 -->" + p.getParentPath());
// if new path doesn't exist then => rename
File fd = new File(p.getParentPath() + File.separator + newName + File.separator);

// if new path doent exist then => rename
File fd = new File(p.getParentPath() + "/" + newName);
if (!fd.exists()) {
if (!fd.exists())
return new File(p.getFullPath()).renameTo(fd);
} else {
return false;
}

return false;
}

public static boolean cloneProject(Project p, String newName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void installExamples(final Context c, final InstallListener l) {

File demosFolder = new File(PhonkSettings.getBaseDir() + PhonkSettings.DEMOS_FOLDER);
FileIO.deleteDir(demosFolder);
FileIO.copyAssetFolder(c.getAssets(), "contributed_projects", demosFolder.getAbsolutePath());
// FileIO.copyAssetFolder(c.getAssets(), "contributed_projects", demosFolder.getAbsolutePath());

l.onReady();
}).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ else if (uri.startsWith("/playground") || uri.startsWith("/examples"))
res = serveFileFromStorage(session);
else res = serveWebIDE(session);

//adding CORS mode for WebIDE debugging from the computer
// adding CORS mode for WebIDE debugging from the computer
if (PhonkSettings.DEBUG) {
res.addHeader("Access-Control-Allow-Methods", "DELETE, GET, POST, PUT");
res.addHeader("Access-Control-Allow-Origin", "*");
Expand Down Expand Up @@ -142,24 +142,30 @@ else if (uri.startsWith("/playground") || uri.startsWith("/examples"))
*/
private Response serveAPI(IHTTPSession session) {
Response res = null;
MLog.d(TAG, "--> ");

String uri = session.getUri();
String[] uriSplitted = uri.split("/");
MLog.d(TAG, session.getUri().toString() + "--> qq 1");

HashMap<String, String> cmd;

// debug the params


/**
* Project global actions
*
* /api/project/command
*/

// General
if (uriSplitted.length >= 4 && uriSplitted.length <= 5) {
switch (uriSplitted[COMMAND]) {
case "list":
case "list": {
MLog.d(TAG, "--> qq 2");
String json;
final HashMap<String, String> map = new HashMap<>();
try {
session.parseBody(map);
} catch (IOException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
} catch (ResponseException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
}

MLog.d(TAG, "listing projects");
HashMap<String, ArrayList> files = new HashMap<>();

ArrayList<ProtoFile> userFolder = PhonkScriptHelper.listProjectsInFolder(PhonkSettings.USER_PROJECTS_FOLDER, 1);
Expand All @@ -170,11 +176,12 @@ private Response serveAPI(IHTTPSession session) {

String jsonFiles = gson.toJson(files);

// MLog.d("list", jsonFiles);
EventBus.getDefault().post(new Events.HTTPServerEvent("project_list_all"));

res = NanoHTTPD.newFixedLengthResponse(Response.Status.OK, MIME_TYPES.get("json"), jsonFiles);
MLog.d(TAG, "listing projects 2");
break;
}
case "execute_code": {
// MLog.d(TAG, "run code");

Expand All @@ -199,7 +206,7 @@ private Response serveAPI(IHTTPSession session) {
}
break;
}
case "stop_all":
case "stop_all": {
// MLog.d(TAG, "stop all");
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_STOP_ALL, null));
res = newFixedLengthResponse("OK");
Expand All @@ -208,6 +215,7 @@ private Response serveAPI(IHTTPSession session) {
* This is for the UI editor
*/
break;
}
case "views_list_types": {
ArrayList<String> arrayList = new ArrayList();
arrayList.add("button");
Expand All @@ -217,30 +225,26 @@ private Response serveAPI(IHTTPSession session) {
res = NanoHTTPD.newFixedLengthResponse(Response.Status.OK, MIME_TYPES.get("json"), json);
break;
}
case "views_get_all":
case "views_get_all": {
if (views == null) {
res = newFixedLengthResponse("NOP");
} else {
res = NanoHTTPD.newFixedLengthResponse(Response.Status.OK, MIME_TYPES.get("json"), views);
}
break;
case "views_set_all":
}
case "views_set_all": {

break;
}
}


/**
* Project dependent actions
*
* /api/project/[ff]/[sf]/[p]/action
*/

// Project
} else if (uriSplitted.length == 7) {
Project p = new Project(uriSplitted[TYPE] + "/" + uriSplitted[FOLDER], uriSplitted[PROJECT_NAME]);

switch (uriSplitted[PROJECT_ACTION]) {
case "create":
case "create": {
// MLog.d(TAG, "create project " + p.getFullPath() + " " + p.exists());

if (!p.exists()) {
Expand All @@ -251,12 +255,12 @@ private Response serveAPI(IHTTPSession session) {
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_NEW, p));
}
break;
}
case "save": {
// MLog.d(TAG, "project save");
String json;
final HashMap<String, String> map = new HashMap<>(); // POST DATA


try {
session.parseBody(map);
if (map.isEmpty()) return newFixedLengthResponse("BUG");
Expand Down Expand Up @@ -303,17 +307,28 @@ private Response serveAPI(IHTTPSession session) {

break;
}
case "delete":
case "delete": {
MLog.d(TAG, "delete");
PhonkScriptHelper.deleteFileOrFolder(p.getFullPath());
res = newFixedLengthResponse("OK");

final HashMap<String, String> map = new HashMap<>();
try {
session.parseBody(map);
PhonkScriptHelper.deleteFileOrFolder(p.getFullPath());
res = newFixedLengthResponse("OK");
} catch (IOException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
} catch (ResponseException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
}

break;
}
case "rename": {
MLog.d(TAG, "rename");

String json;
final HashMap<String, String> map = new HashMap<>(); // POST DATA

MLog.d(TAG, "qq 22 rename " + session.getHeaders().toString());

try {
session.parseBody(map);
Expand All @@ -330,6 +345,7 @@ private Response serveAPI(IHTTPSession session) {
}

NEOProject neo = gson.fromJson(json, NEOProject.class);

if (PhonkScriptHelper.renameProject(p, neo.newName)) {
res = newFixedLengthResponse("OK");
} else {
Expand All @@ -343,7 +359,6 @@ private Response serveAPI(IHTTPSession session) {
String json;
final HashMap<String, String> map = new HashMap<>(); // POST DATA


try {
session.parseBody(map);
if (map.isEmpty()) {
Expand All @@ -366,22 +381,57 @@ private Response serveAPI(IHTTPSession session) {
}
break;
}
case "run":
MLog.d(TAG, "run --> " + p.getFolder());
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_RUN, p));
res = newFixedLengthResponse("OK");
case "run": {
final HashMap<String, String> map = new HashMap<>();
try {
session.parseBody(map);
MLog.d(TAG, "run --> " + p.getFolder());
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_RUN, p));
res = newFixedLengthResponse("OK");
} catch (IOException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
} catch (ResponseException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
}
break;
case "stop_all_and_run":
MLog.d(TAG, "stop_all_and_run --> ");
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_STOP_ALL_AND_RUN, p));
res = newFixedLengthResponse("STOP_AND_RUN");
}
case "stop_all_and_run": {
final HashMap<String, String> map = new HashMap<>();
try {
session.parseBody(map);
MLog.d(TAG, "stop_all_and_run --> ");
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_STOP_ALL_AND_RUN, p));
res = newFixedLengthResponse("STOP_AND_RUN");
} catch (IOException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
} catch (ResponseException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
}
break;
case "stop":
MLog.d(TAG, "stop --> ");
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_STOP_ALL, null));
res = newFixedLengthResponse("OK");
}
case "stop": {
final HashMap<String, String> map = new HashMap<>();
try {
session.parseBody(map);
MLog.d(TAG, "stop --> ");
EventBus.getDefault().post(new Events.ProjectEvent(Events.PROJECT_STOP_ALL, null));
res = newFixedLengthResponse("OK");
} catch (IOException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
} catch (ResponseException e) {
e.printStackTrace();
return newFixedLengthResponse("NOP");
}
break;
}
}

// Project data
} else if (uriSplitted.length >= 8 && uriSplitted[FILE_DELIMITER].equals("files")) {
// MLog.d(TAG, "-> files ");
Project p = new Project(uriSplitted[TYPE] + "/" + uriSplitted[FOLDER], uriSplitted[PROJECT_NAME]);
Expand Down Expand Up @@ -546,7 +596,6 @@ private Response serveAPI(IHTTPSession session) {
case "move": {
final HashMap<String, String> map = new HashMap<>(); // POST DATA


String json = null;
try {
session.parseBody(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public class NEOProject {
public Project project;
public String current_folder;
public ArrayList<ProtoFile> files = new ArrayList<>();
public final String code = "";
public final String newName = "";
public String code = "";
public String newName = "";
}
Loading

0 comments on commit 6afdc85

Please sign in to comment.