Ported to 1.3.1 - required changes to the patch
[webos-internals:modifications.git] / video-player / video-player-swipe-to-delete-videos.patch
1 Name: Swipe to Delete Videos
2 Version: 1.3.1-1
3 Author: Jason Robitaille
4 Modified: Rod Whitby
5 Description: Adds the ability to swipe to delete videos
6
7 --- .orig/usr/palm/applications/com.palm.app.videoplayer/app/controllers/browser-assistant.js
8 +++ /usr/palm/applications/com.palm.app.videoplayer/app/controllers/browser-assistant.js
9 @@ -15,6 +15,8 @@
10                         itemTemplate: 'browser/browser-entry',
11                         filterFunction: this.requestVideosList.bind(this),
12                         optimizedOptIn: true,
13 +                       swipeToDelete: true,
14 +                       autoconfirmDelete: true,
15                         formatters: {
16                                 videoPictureUrl: this.videoPictureUrlFormatter,
17                                 videoSize: this.videoSizeFormatter.bind(this),
18 @@ -42,6 +44,33 @@
19                 this.controller.document.addEventListener(Mojo.Event.activate, this.boundFocusHandle.bind(this));
20         },
21         
22 +       handleDelete: function(event){
23 +               event.stop(event);
24 +               this.deletePath = event.item.videoPath;
25 +               this.controller.showAlertDialog({
26 +                       onChoose: function(value) {
27 +                               if (value == 'Yes') {
28 +                                       this.controller.serviceRequest('palm://com.palm.mediadb/', {
29 +                                               method: 'deletefile',
30 +                                               parameters: {
31 +                                                       path: this.deletePath
32 +                                               },
33 +                                               onSuccess: function() {
34 +                                                       this.controller.showBanner("Video deleted!", "");
35 +                                               }.bind(this)
36 +                                       });
37 +                               }
38 +                       },
39 +                       title: $L("Delete?"),
40 +                       message: $L("Are you sure you want to delete \"" + event.item.videoNameFormatted + "\"?" + " This cannot be undone."),
41 +                       choices:[
42 +                               {label:$L('Yes'), value:"Yes", type:'affirmative'},  
43 +                               {label:$L('No'), value:"No", type:'negative'} 
44 +                       ]
45 +               });
46 +               
47 +       },
48 +       
49         cleanup: function(){
50                 this.controller.document.removeEventListener(Mojo.Event.deactivate, this.boundBlurHandle.bind(this));
51                 this.controller.document.removeEventListener(Mojo.Event.activate, this.boundFocusHandle.bind(this));
52 @@ -56,10 +85,13 @@
53         },
54         
55         activate: function(){
56 +               this.handleDelete = this.handleDelete.bindAsEventListener(this);
57 +               this.controller.listen('videoslist', Mojo.Event.listDelete, this.handleDelete);
58                 Util.markForeground(this.controller, true);
59         },
60         
61         deactivate: function(){
62 +               this.controller.stopListening('videoslist', Mojo.Event.listDelete, this.handleDelete);
63                 Util.markForeground(this.controller, false);
64         },
65         
66 --- .orig/usr/palm/applications/com.palm.app.videoplayer.launcher/app/controllers/browser-assistant.js
67 +++ /usr/palm/applications/com.palm.app.videoplayer.launcher/app/controllers/browser-assistant.js
68 @@ -15,6 +15,8 @@
69                         itemTemplate: 'browser/browser-entry',
70                         filterFunction: this.requestVideosList.bind(this),
71                         optimizedOptIn: true,
72 +                       swipeToDelete: true,
73 +                       autoconfirmDelete: true,
74                         formatters: {
75                                 videoPictureUrl: this.videoPictureUrlFormatter,
76                                 videoSize: this.videoSizeFormatter.bind(this),
77 @@ -42,6 +44,33 @@
78                 this.controller.document.addEventListener(Mojo.Event.activate, this.boundFocusHandle.bind(this));
79         },
80         
81 +       handleDelete: function(event){
82 +               event.stop(event);
83 +               this.deletePath = event.item.videoPath;
84 +               this.controller.showAlertDialog({
85 +                       onChoose: function(value) {
86 +                               if (value == 'Yes') {
87 +                                       this.controller.serviceRequest('palm://com.palm.mediadb/', {
88 +                                               method: 'deletefile',
89 +                                               parameters: {
90 +                                                       path: this.deletePath
91 +                                               },
92 +                                               onSuccess: function() {
93 +                                                       this.controller.showBanner("Video deleted!", "");
94 +                                               }.bind(this)
95 +                                       });
96 +                               }
97 +                       },
98 +                       title: $L("Delete?"),
99 +                       message: $L("Are you sure you want to delete \"" + event.item.videoNameFormatted + "\"?" + " This cannot be undone."),
100 +                       choices:[
101 +                               {label:$L('Yes'), value:"Yes", type:'affirmative'},  
102 +                               {label:$L('No'), value:"No", type:'negative'} 
103 +                       ]
104 +               });
105 +               
106 +       },
107 +       
108         cleanup: function(){
109                 this.controller.document.removeEventListener(Mojo.Event.deactivate, this.boundBlurHandle.bind(this));
110                 this.controller.document.removeEventListener(Mojo.Event.activate, this.boundFocusHandle.bind(this));
111 @@ -56,10 +85,13 @@
112         },
113         
114         activate: function(){
115 +               this.handleDelete = this.handleDelete.bindAsEventListener(this);
116 +               this.controller.listen('videoslist', Mojo.Event.listDelete, this.handleDelete);
117                 Util.markForeground(this.controller, true);
118         },
119         
120         deactivate: function(){
121 +               this.controller.stopListening('videoslist', Mojo.Event.listDelete, this.handleDelete);
122                 Util.markForeground(this.controller, false);
123         },
124