Skip to content

Commit

Permalink
some polishing for the Android application + switched to vertical lay…
Browse files Browse the repository at this point in the history
…out in history details view
  • Loading branch information
xavierlacot committed Mar 16, 2011
1 parent 2a2c81b commit 7363bad
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 200 deletions.
8 changes: 8 additions & 0 deletions Resources/app.js
Expand Up @@ -12,6 +12,14 @@ if (Titanium.Platform.name != 'android') {
// create tab group
var tabGroup = Titanium.UI.createTabGroup({barColor: '#273f95'});

if (Titanium.Platform.name == 'android') {
tabGroup.softKeyboardOnFocus = Titanium.UI.Android.SOFT_KEYBOARD_HIDE_ON_FOCUS;

tabGroup.addEventListener('focus', function(e) {
Ti.UI.Android.hideSoftKeyboard();
});
}

// add windows and tabs
var win1 = Titanium.UI.createWindow({
url:'js/views/encode.js',
Expand Down
71 changes: 60 additions & 11 deletions Resources/js/lib/xavcc.js
Expand Up @@ -9,6 +9,20 @@ var xavcc = (function() {
};

api.decode = function(alias) {
// first, search in the local history if enabled
var result = new joli.query()
.select()
.from('shorturl')
.where('shorturl LIKE ?', '%/' + alias)
.limit(1)
.execute();

if (result.length != 0) {
log('found in history');
Ti.App.fireEvent('xavcc.decode.result', { result: result[0].longurl });
return;
}

var escapedUrl = api.encodeUrl(alias);
var url = Titanium.App.Properties.getString('api_url', 'http://api.xav.cc/');
url = url + 'simple/decode?alias=' + escapedUrl;
Expand All @@ -34,9 +48,26 @@ var xavcc = (function() {
client.send(null);
};


api.encode = function(longurl, alias) {
// first, search in the local history if enabled
var query = new joli.query()
.select()
.from('shorturl')
.where('longurl = ?', longurl)
.limit(1);

if ('' != alias)
{
query.where('shorturl LIKE ?', '%/' + alias);
}

var result = query.execute();

if (result.length != 0) {
log('found in history');
Ti.App.fireEvent('xavcc.encode.result', { result: result[0].shorturl });
return;
}

// else shorten the value
var escapedUrl = api.encodeUrl(longurl);
Expand Down Expand Up @@ -133,20 +164,39 @@ var xavcc = (function() {
};


api.showResponse = function(label, shorturl) {
var length = Math.max(8, Math.min(30, shorturl.length));
var size = Math.ceil(12 + (30 - length) * (15 / 10));
api.showResponse = function(label, response) {
var length = Math.max(8, Math.min(30, response.length));
log('length: ' + length);
var size = Math.ceil(15 + (30 - length) * (13 / 10));
log('size: ' + size);
label.font = {'fontSize':size};
label.text = shorturl;
label.text = response;
};


api.strpos = function (haystack, needle) {
api.strpos = function(haystack, needle) {
var i = (haystack + '').indexOf(needle, 0);
return i === -1 ? false : i;
};


api.strrpos = function(haystack, needle, offset) {
var i = -1;

if (offset) {
i = (haystack + '').slice(offset).lastIndexOf(needle);

if (i !== -1) {
i += offset;
}
} else {
i = (haystack + '').lastIndexOf(needle);
}

return i >= 0 ? i : false;
};


api.trim = function(str) {
if (!str) {
return str;
Expand Down Expand Up @@ -255,11 +305,10 @@ var xavcc = (function() {

api.url.has = function(shorturl) {
var result = new joli.query()
.count()
.from('shorturl')
.where('shorturl.shorturl = ?', shorturl)
.execute();
Titanium.API.log('info', 'count returns : ' + result);
.count()
.from('shorturl')
.where('shorturl.shorturl LIKE ?', '%/' + shorturl)
.execute();
return (result > 0);
};

Expand Down
19 changes: 11 additions & 8 deletions Resources/js/views/decode.js
@@ -1,5 +1,6 @@
Ti.include('../../redux.js');
var win = Titanium.UI.currentWindow;
win.backgroundImage = '../../images/background.png';

// label and first field
var l1a = Titanium.UI.createLabel({
Expand All @@ -13,6 +14,7 @@ var l1a = Titanium.UI.createLabel({
});
var l1b = Titanium.UI.createLabel({
text:Titanium.App.Properties.getString('site_url', 'http://xav.cc/'),
font: {fontSize:15},
width:100,
height:35,
top:120,
Expand All @@ -22,7 +24,7 @@ var l1b = Titanium.UI.createLabel({
});
var tf1 = Titanium.UI.createTextField({
color:'#192578',
height:35,
height:40,
top:120,
left:130,
width:160,
Expand All @@ -36,9 +38,9 @@ var tf1 = Titanium.UI.createTextField({
var l2 = Titanium.UI.createLabel({
text:'',
width:260,
height:90,
height:'auto',
left:30,
top:300,
top:280,
color:'#fff',
textAlign:'left',
font:{'fontSize':17}
Expand All @@ -47,7 +49,7 @@ var l2 = Titanium.UI.createLabel({
// submit button
var b1 = Titanium.UI.createButton({
title:'Decode this short url',
height:30,
height:40,
width:260,
left:30,
top:200
Expand All @@ -58,8 +60,7 @@ var doDecode = function() {
var alias = xavcc.trim(tf1.value);

if (!alias) {
alert('Please write an alias!');
tf1.focus();
tf1.blur();
return;
}

Expand Down Expand Up @@ -88,10 +89,12 @@ Ti.App.addEventListener('xavcc.decode.result', function(event) {
Titanium.UI.Clipboard.setText(url);
}

var shorturl = Titanium.App.Properties.getString('site_url', 'http://xav.cc/') + xavcc.trim(tf1.value);
var alias = xavcc.trim(tf1.value);
var shorturl = Titanium.App.Properties.getString('site_url', 'http://xav.cc/') + alias;

if (Titanium.App.Properties.getBool('use_history', true) && !xavcc.url.has(shorturl)) {
if (Titanium.App.Properties.getBool('use_history', true) && !xavcc.url.has(alias)) {
// save in the local database
Titanium.API.log('info', 'saving url ' + url);
xavcc.url.save(url, shorturl);
}
} else if (url.length > 0) {
Expand Down
27 changes: 10 additions & 17 deletions Resources/js/views/encode.js
@@ -1,5 +1,6 @@
Ti.include('../../redux.js');
var win = Titanium.UI.currentWindow;
win.backgroundImage = '../../images/background.png';

// label and first field
var l1 = Titanium.UI.createLabel({
Expand All @@ -14,7 +15,7 @@ var l1 = Titanium.UI.createLabel({
var tf1 = Titanium.UI.createTextField({
hintText:'type or paste here a valid url',
color:'#192578',
height:35,
height:40,
top:70,
left:30,
width:260,
Expand All @@ -26,7 +27,7 @@ var tf1 = Titanium.UI.createTextField({
});
if (Titanium.UI.Clipboard.hasText() && Titanium.App.Properties.getBool('auto_paste', false)) {
var text = Titanium.UI.Clipboard.getText();
if (text.indexOf('http') == 0) {
if ((text.indexOf('http') == 0) && (text.indexOf('http://xav.cc/') != 0) && (text.indexOf('http://xa.vc/') != 0)) {
tf1.value = text;
}
}
Expand All @@ -45,7 +46,7 @@ var l2b = Titanium.UI.createLabel({
text:Titanium.App.Properties.getString('site_url', 'http://xav.cc/'),
font: {fontSize:15},
width:120,
height:35,
height:40,
top:150,
left:30,
color:'#fff',
Expand All @@ -54,7 +55,7 @@ var l2b = Titanium.UI.createLabel({
var tf2 = Titanium.UI.createTextField({
hintText:'(optional)',
color:'#192578',
height:35,
height:40,
top:150,
left:130,
width:160,
Expand All @@ -77,7 +78,7 @@ var l3 = Titanium.UI.createLabel({
// submit button
var b1 = Titanium.UI.createButton({
title:'Shorten this url',
height:30,
height:40,
width:260,
left:30,
top:220
Expand All @@ -89,8 +90,7 @@ var doShorten = function() {
var alias = xavcc.trim(tf2.value);

if (!longurl) {
alert('Please type in a url');
tf1.focus();
tf1.blur();
return;
}

Expand All @@ -112,23 +112,16 @@ Ti.App.addEventListener('xavcc.encode.result', function(event) {
xavcc.hideIndicator();

if (event.result && event.result.indexOf('http://') == 0) {
var url = Titanium.App.Properties.getString('site_url', 'http://xav.cc/') + event.result.slice(14);
var alias = event.result.slice(xavcc.strrpos(event.result, '/', 7) + 1);
var url = Titanium.App.Properties.getString('site_url', 'http://xav.cc/') + alias;
xavcc.showResponse(l3, url);

if (Titanium.App.Properties.getBool('auto_copy', true)) {
// put the shortened url in the clipboard
Titanium.UI.Clipboard.setText(url);
}

if (Titanium.App.Properties.getBool('use_history', true)) {
info('using history');
}

if (!xavcc.url.has(url)) {
Titanium.API.log('info', 'do not have the url in memory');
}

if (Titanium.App.Properties.getBool('use_history', true) && !xavcc.url.has(url)) {
if (Titanium.App.Properties.getBool('use_history', true) && !xavcc.url.has(alias)) {
// save in the local database
Titanium.API.log('info', 'saving url ' + url);
var longurl = xavcc.trim(tf1.value);
Expand Down

0 comments on commit 7363bad

Please sign in to comment.