diff --git a/qml/lib/storage.js b/qml/lib/storage.js index 43dbad9..1f86a57 100644 --- a/qml/lib/storage.js +++ b/qml/lib/storage.js @@ -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(); diff --git a/qml/pages/MainView.qml b/qml/pages/MainView.qml index d6e1406..1bdbf75 100644 --- a/qml/pages/MainView.qml +++ b/qml/pages/MainView.qml @@ -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