Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

69
LINES

< > BotCompany Repo | #1004132 // Phone File Browser (On PC!)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3874K of libraries. Click here for Pure Java version (8888L/64K/229K).

!752

static L<Map> origData, data;
static S dir = "/";
static JTable table;

p-substance {
  load("dir");
  browse(dir);
}

svoid browse(S path) {
  dir = path;
  save("dir");
  S s = sendToPhoneBot("Awareness", "list directory *", dir);
  origData = (L) safeUnstructure(s);
  data = sortedByField("Name", map(func(Map map) {
    putKeysFirst(renameKeys(map,
      "dir", "Directory?", "m", "Last modified",
      "n", "Name", "l", "File Size (Bytes)"),
      "Name", "Directory?")
  }, origData));
  
  S title = dir + " [Phone Browser]";
  bool firstTime = table == null;
  table = showTableWithSearcher(table, data, title);

  if (firstTime) {
    onDoubleClickOrEnter(table, voidfunc(int row) {
      Map map = getTableLineAsMap(table, row);
      if (map == null) ret;
      Map map2 = findByField(origData, "n", map.get("Name"));
      print("map2=" + struct(map2));
      S name = getString(map, "Name");
      if (isTrue(_get(map2, "dir")))
        browse(addSlash(dir) + name);
      else
        swingOpenPhoneFile(addSlash(dir) + name);
    });
    registerKey(getFrame(table), KeyEvent.VK_BACK_SPACE, "Back", r {
      browse(or2(substring(dir, 0, dir.lastIndexOf('/')), "/"));
    });
    
    tablePopupMenu(table, voidfunc(JPopupMenu menu, int row) {
      Map map = getTableLineAsMap(table, row);
      if (map == null) ret;
      Map map2 = findByField(origData, "n", map.get("Name"));
      print("map2=" + struct(map2));
      final S name = getString(map, "Name");
      final S path = addSlash(dir) + name;
      
      if (!isTrue(_get(map2, "dir")))
        addMenuItem(menu, "Download File", r {
          thread "Downloading" {
            print("Downloading from phone...");
            byte[] data = readFileFromPhone(path);
            File f = userHome("Downloads/" + name);
            saveBinaryFile(f, data);
            print("Saved: " + f.getAbsolutePath());
          }
        });
        
      addMenuItem(menu, "Delete", r {
        if (confirmYesNo("Delete " + path + "?"))
          sendToPhoneBot("Awareness", "delete file *", path);
      });
    });
  }
}

Author comment

Began life as a copy of #1004129

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): ajlfxifxfcul, aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, cysqohhbtkwd, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004132
Snippet name: Phone File Browser (On PC!)
Eternal ID of this version: #1004132/2
Text MD5: e5e96c0f0b7b142134a08814ce2cd2fd
Transpilation MD5: e63bd0d33e48cccc89262d4752bd9f83
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-21 00:42:48
Source code size: 2170 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 1156 / 1322
Version history: 1 change(s)
Referenced in: [show references]