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).

1  
!752
2  
3  
static L<Map> origData, data;
4  
static S dir = "/";
5  
static JTable table;
6  
7  
p-substance {
8  
  load("dir");
9  
  browse(dir);
10  
}
11  
12  
svoid browse(S path) {
13  
  dir = path;
14  
  save("dir");
15  
  S s = sendToPhoneBot("Awareness", "list directory *", dir);
16  
  origData = (L) safeUnstructure(s);
17  
  data = sortedByField("Name", map(func(Map map) {
18  
    putKeysFirst(renameKeys(map,
19  
      "dir", "Directory?", "m", "Last modified",
20  
      "n", "Name", "l", "File Size (Bytes)"),
21  
      "Name", "Directory?")
22  
  }, origData));
23  
  
24  
  S title = dir + " [Phone Browser]";
25  
  bool firstTime = table == null;
26  
  table = showTableWithSearcher(table, data, title);
27  
28  
  if (firstTime) {
29  
    onDoubleClickOrEnter(table, voidfunc(int row) {
30  
      Map map = getTableLineAsMap(table, row);
31  
      if (map == null) ret;
32  
      Map map2 = findByField(origData, "n", map.get("Name"));
33  
      print("map2=" + struct(map2));
34  
      S name = getString(map, "Name");
35  
      if (isTrue(_get(map2, "dir")))
36  
        browse(addSlash(dir) + name);
37  
      else
38  
        swingOpenPhoneFile(addSlash(dir) + name);
39  
    });
40  
    registerKey(getFrame(table), KeyEvent.VK_BACK_SPACE, "Back", r {
41  
      browse(or2(substring(dir, 0, dir.lastIndexOf('/')), "/"));
42  
    });
43  
    
44  
    tablePopupMenu(table, voidfunc(JPopupMenu menu, int row) {
45  
      Map map = getTableLineAsMap(table, row);
46  
      if (map == null) ret;
47  
      Map map2 = findByField(origData, "n", map.get("Name"));
48  
      print("map2=" + struct(map2));
49  
      final S name = getString(map, "Name");
50  
      final S path = addSlash(dir) + name;
51  
      
52  
      if (!isTrue(_get(map2, "dir")))
53  
        addMenuItem(menu, "Download File", r {
54  
          thread "Downloading" {
55  
            print("Downloading from phone...");
56  
            byte[] data = readFileFromPhone(path);
57  
            File f = userHome("Downloads/" + name);
58  
            saveBinaryFile(f, data);
59  
            print("Saved: " + f.getAbsolutePath());
60  
          }
61  
        });
62  
        
63  
      addMenuItem(menu, "Delete", r {
64  
        if (confirmYesNo("Delete " + path + "?"))
65  
          sendToPhoneBot("Awareness", "delete file *", path);
66  
      });
67  
    });
68  
  }
69  
}

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: 1272 / 1445
Version history: 1 change(s)
Referenced in: [show references]