Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #77 from Burstaholic/burstaholic-easy-share
Browse files Browse the repository at this point in the history
Allow server switching during Easy Share action
  • Loading branch information
rodrigok committed Feb 19, 2016
2 parents 41260d2 + fde7641 commit 6065cf6
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 34 deletions.
9 changes: 5 additions & 4 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<splash width="1024" height="748" src="resources/splash/Resources/iphone/Default-Landscape.png" />
<splash width="2048" height="1496" src="resources/splash/Resources/iphone/Default-Landscape@2x.png" />
</platform>
<preference name="xwalkVersion" value="14+" />
<preference name="xwalkVersion" value="16+" />
<preference name="xwalkCommandLine" value="--disable-pull-to-refresh-effect" />
<preference name="xwalkMode" value="embedded" />
<preference name="webviewbounce" value="false" />
Expand All @@ -88,13 +88,13 @@
<preference name="StatusBarStyle" value="blackopaque" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<preference name="deployment-target" value="8.0" />
<preference name="AndroidLaunchMode" value="singleTask"/>
<preference name="AndroidLaunchMode" value="singleTask" />
<hook src="hooks/beforePrepare.js" type="before_prepare" />
<engine name="ios" spec="~3.9.2" />
<engine name="android" spec="~5.0.0" />
<plugin name="com.meteor.cordova-update" spec="https://github.com/RocketChat/com.meteor.cordova-update" />
<plugin name="cordova-plugin-sharingreceptor" spec="https://github.com/stample/cordova-sharingreceptor.git" />
<plugin name="cordova-plugin-crosswalk-webview" spec="~1.3.1" />
<plugin name="cordova-plugin-sharingreceptor" spec="https://github.com/burstaholic/cordova-sharingreceptor.git" />
<plugin name="cordova-plugin-crosswalk-webview" spec="~1.5.0" />
<plugin name="cordova-plugin-file" spec="~3.0.0" />
<plugin name="cordova-plugin-file-transfer" spec="~1.3.0" />
<plugin name="cordova-plugin-legacy-whitelist" spec="~1.1.0" />
Expand All @@ -112,4 +112,5 @@
<plugin name="cordova-plugin-inappbrowser" spec="~1.0.1" />
<plugin name="cordova-plugin-dialogs" spec="~1.2.0" />
<plugin name="cordova-plugin-appinfo" spec="~2.0.2" />
<preference name="xwalkMultipleApk" value="true" />
</widget>
8 changes: 8 additions & 0 deletions www/coffee/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ window.readFile = (directoryPath, fileName, cb) ->

window.resolveLocalFileSystemURL directoryPath, resolveSuccess, fail

window.removeFile = (directoryPath, fileName, cb) ->
resolveSuccess = (dirEntry) ->
getFileSuccess = (fileEntry) ->
fileEntry.remove cb

dirEntry.getFile fileName, {}, getFileSuccess

window.resolveLocalFileSystemURL directoryPath, resolveSuccess

window.writeDir = (directoryPath, dirName, cb) ->
fail = (err) ->
Expand Down
127 changes: 97 additions & 30 deletions www/shared/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,114 @@
Meteor.subscribe('subscription', {
onReady: function()
{
var roomPrefixes = {
d: '@',
p: '&',
c: '#'
};
readFile(cordova.file.cacheDirectory, 'pendingShare.json', function(err, shareInfo)
{
if(err)
{
return;
}

removeFile(cordova.file.cacheDirectory, 'pendingShare.json', function() { });
selectRoom(JSON.parse(shareInfo));
});

cordova.SharingReceptor.listen(function(data)
{
var rooms = _.sortBy(ChatSubscription.find({open: true}).fetch(), function(room)
var serverOptions = '';
if(Servers.getServers().length > 1)
{
return [room.t, room.name].join('-');
});
serverOptions = _.reduce(Servers.getServers(), function(accString, server)
{
return accString + '<option value="' + server.url + '">' + server.name + '</option>';
}, '');

var innerString = _.reduce(rooms, function(accString, room)
{
return accString + '<option value="' + room.name + '">' + roomPrefixes[room.t] + ' ' + room.name + '</option>';
}, '');

var tempString = '<select id="room-select" name="room-list">' + innerString + '</select>';

swal({
title: 'Select room to share',
text: tempString,
html: true,
animation: true,
showCancelButton: true
}, function()
{
var roomName = $('#room-select')[0].value;
var roomModel = ChatSubscription.findOne({name: roomName});
var serverString = '<select id="server-select" name="server-list">' + serverOptions + '</select>';

if(roomModel)
{
doShare(roomModel, data);
}
});
swal({
title: 'Select server',
text: serverString,
html: true,
animation: true,
showCancelButton: true
},
function()
{
var currentServerUrl = Servers.getActiveServer().url;
var serverUrl = $('#server-select')[0].value;

if(serverUrl != currentServerUrl)
{
writeFile(cordova.file.cacheDirectory, 'pendingShare.json', JSON.stringify(data), function(err, data)
{
if(err)
{
console.log('Error saving share file', err);
return;
}
localStorage.setItem('pendingShare', JSON.stringify(data));

$(document.body).addClass('loading');
$('.loading-text').text(cordovai18n("Loading_s", serverUrl));
setTimeout(function()
{
Servers.setActiveServer(serverUrl);
Servers.startServer(serverUrl, function() { });
}, 200);
});
}
else
{
selectRoom(data);
}
});
}
else
{
selectRoom(data);
}
});

}
});

function selectRoom(data)
{
var roomPrefixes = {
d: '@',
p: '&',
c: '#'
};

var rooms = _.sortBy(ChatSubscription.find({open: true}).fetch(), function(room)
{
return [room.t, room.name].join('-');
});

var innerString = _.reduce(rooms, function(accString, room)
{
return accString + '<option value="' + room.name + '">' + roomPrefixes[room.t] + ' ' + room.name + '</option>';
}, '');

var tempString = '<select id="room-select" name="room-list">' + innerString + '</select>';

swal({
title: 'Select room to share',
text: tempString,
html: true,
animation: true,
showCancelButton: true
}, function()
{
var roomName = $('#room-select')[0].value;
var roomModel = ChatSubscription.findOne({name: roomName});

if(roomModel)
{
doShare(roomModel, data);
}
});
}

function doShare(roomModel, data)
{
if(_.startsWith(data.intent.type, 'text'))
Expand Down

0 comments on commit 6065cf6

Please sign in to comment.