1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-05-16 23:50:54 +00:00

Changed MainView to support favourites

* Added switch to show status
* Save selected favourite to LocalStorage DB
This commit is contained in:
seiichiro 2014-01-09 22:12:55 +01:00
parent 11072b2f16
commit 40f53fc47a
2 changed files with 47 additions and 14 deletions

View file

@ -67,7 +67,7 @@ function getOTP() {
function(tx) {
var res = tx.executeSql("select * from OTPStorage;");
for (var i=0; i < res.rows.length; i++) {
mainPage.appendOTP(res.rows.item(i).title, res.rows.item(i).secret);
mainPage.appendOTP(res.rows.item(i).title, res.rows.item(i).secret, res.rows.item(i).type, res.rows.item(i).counter, res.rows.item(i).fav);
}
}
)
@ -95,6 +95,17 @@ function removeOTP(title, secret) {
)
}
function setFav(title, secret) {
var db = getDB();
db.transaction(
function(tx) {
tx.executeSql("UPDATE OTPStorage set fav = 0");
tx.executeSql("UPDATE OTPStorage set fav = 1 WHERE title=? and secret=?;", [title, secret]);
}
)
}
// Change an existing OTP
function changeOTP(title, secret, oldtitle, oldsecret) {
var db = getDB();

View file

@ -44,15 +44,17 @@ Page {
property double lastUpdated: null
// Add an entry to the list
function appendOTP(title, secret) {
otpListModel.append({"secret": secret, "title": title, "otp": ""});
function appendOTP(title, secret, type, counter, fav) {
otpListModel.append({"secret": secret, "title": title, "fav": fav, "otp": ""});
}
// Reload the List of OTPs from storage
function refreshOTPList() {
otpList.visible = false;
otpListModel.clear();
DB.getOTP();
refreshOTPValues();
otpList.visible = true;
}
// Calculate new OTPs for every entry
@ -67,7 +69,6 @@ Page {
if (otpListModel.get(i).otp == "" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) {
var curOTP = OTP.calcOTP(otpListModel.get(i).secret)
otpListModel.setProperty(i, "otp", curOTP);
console.log("Updating Value ", i);
}
}
@ -79,7 +80,8 @@ Page {
Timer {
interval: 1000
running: Qt.application.active // Timer only runs when App is active
// Timer only runs when app is acitive and we have entries
running: Qt.application.active && otpListModel.count
repeat: true
onTriggered: refreshOTPValues();
}
@ -104,6 +106,8 @@ Page {
maximumValue: 29
anchors.top: parent.top
anchors.topMargin: 48
// Only show when there are enries
visible: otpListModel.count
}
SilicaListView {
@ -121,37 +125,55 @@ Page {
hintText: "Pull down to add a OTP"
}
delegate: ListItem {
id: otpListItem
menu: otpContextMenu
width: otpList.width
contentHeight: Theme.itemSizeMedium
width: parent.width
function remove() {
function remove() {
// Show 5s countdown, then delete from DB and List
remorseAction("Deleting", function() { DB.removeOTP(title, secret); otpListModel.remove(index) })
}
ListView.onRemove: animateRemoval()
Rectangle {
id: listRow
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
Label {
Switch {
checked: model.fav
anchors.left: parent.left
onClicked: {
if (checked) DB.setFav(title, secret)
refreshOTPList();
/*model.fav = checked ? 1 : 0;
for (var i=0; i<otpListModel.count; i++) {
if (i != index) {
otpListModel.setProperty(i, "fav", 0);
}
}*/
}
}
Column {
anchors.horizontalCenter: parent.horizontalCenter
Label {
id: otpLabel
text: model.title
color: Theme.secondaryColor
anchors.horizontalCenter: parent.horizontalCenter
}
}
Label {
Label {
id: otpValue
anchors.top: otpLabel.bottom
text: model.otp
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeLarge
anchors.horizontalCenter: parent.horizontalCenter
}
}
}