psa: improve nagivation using 2 flickables
authorYves Marcoz <yves@marcoz.org>
Tue, 24 Jan 2012 05:57:09 +0000 (21:57 -0800)
committerYves Marcoz <yves@marcoz.org>
Tue, 24 Jan 2012 05:57:09 +0000 (21:57 -0800)
psa_harmattan/feedingit/pysrc/feedingit.py
psa_harmattan/feedingit/qml/Articles.qml

index 9d70a3c..6866f9b 100644 (file)
@@ -31,6 +31,7 @@ from cgi import escape
 from re import sub
 
 class Controller(QtCore.QObject):
+    cachedList = None
     
     def __init__(self, listing):
         QtCore.QObject.__init__(self)
@@ -70,18 +71,30 @@ class Controller(QtCore.QObject):
     
     @QtCore.Slot(str,result=str)
     def getArticlesXml(self, key):
+        feed = listing.getFeed(key)
+        self.cachedList = feed.getIds(onlyUnread=True)
         #onlyUnread = arguments.get("onlyUnread","False")
         return self._handler.generateArticlesXml(key, config.getHideReadArticles())
     
-    @QtCore.Slot(str,str,result=str)
-    def getNextId(self, key, articleid):
-        feed = listing.getFeed(key)
-        return feed.getNextId(articleid)
+    @QtCore.Slot(str,str,bool,result=str)
+    def getNextId(self, key, articleid, onlyUnread):
+        if (onlyUnread):
+            print self.cachedList, articleid
+            index = self.cachedList.index(articleid)
+            return self.cachedList[(index + 1) % len(self.cachedList)]
+        else:
+            feed = listing.getFeed(key)
+            return feed.getNextId(articleid)
         
-    @QtCore.Slot(str,str,result=str)
-    def getPreviousId(self, key, articleid):
-        feed = listing.getFeed(key)
-        return feed.getPreviousId(articleid)
+    @QtCore.Slot(str,str,bool,result=str)
+    def getPreviousId(self, key, articleid, onlyUnread):
+        if (onlyUnread):
+            print self.cachedList, articleid
+            index = self.cachedList.index(articleid)
+            return self.cachedList[(index - 1) % len(self.cachedList)]
+        else:
+            feed = listing.getFeed(key)
+            return feed.getPreviousId(articleid)
     
     @QtCore.Slot(result=str)
     def getCategoryXml(self):
index 5019df4..25ec145 100644 (file)
@@ -27,6 +27,14 @@ Item {
         }
     }
 
+    function setNextId() {
+        articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId, settings.hideReadArticles)
+    }
+
+    function setPreviousId() {
+        articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId, settings.hideReadArticles)
+    }
+
     Component.onCompleted: {
         webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
     }
@@ -46,6 +54,7 @@ Item {
         //flickableDirection: Flickable.VerticalFlick
 
         property bool contentIsReady: false
+        property bool isSwitchable: false
         Rectangle {
             id: boundsRecFront
             color: "white"
@@ -68,11 +77,10 @@ Item {
                     controller.setEntryRead(articlePage.feedid, articlePage.mainArticleId)
                      //flickable.width/2
                     flickableFront.contentIsReady = true
+                    switchableTimer.start()
                 }
 
-
             }
-
         }
 
         state: "visible"
@@ -92,21 +100,40 @@ Item {
         transitions: [
             Transition {
                 from: "visible";
-                PropertyAnimation { target: flickableFront
-                  easing.type: Easing.InOutSine
-                  properties: "x"; duration: 1000 }
+                SequentialAnimation {
+                    ScriptAction { script: flickableFront.isSwitchable=false; }
+                    PropertyAnimation { target: flickableFront
+                      easing.type: Easing.InOutSine
+                      properties: "x"; duration: 1000 }
+                    ScriptAction { script: flickableFront.isSwitchable=true; }
+                }
             },
             Transition {
                 to: "visible";
-                PropertyAnimation { target: flickableFront
-                easing.type: Easing.InOutSine
-                properties: "x"; duration: 1000 }
+                SequentialAnimation {
+                    ScriptAction { script: flickableFront.isSwitchable=false; }
+                    PropertyAnimation { target: flickableFront
+                    easing.type: Easing.InOutSine
+                    properties: "x"; duration: 1000 }
+                    ScriptAction { script: flickableFront.isSwitchable=true; }
+                }
             }
+
         ]
 
+        Timer {
+            // Disable animations/page shifting for 400ms, to give time to the page to setup properly
+            id: switchableTimer
+            interval: 400
+            running: false
+            repeat: false
+            onTriggered: flickableFront.isSwitchable=true;
+        }
+
         function moveFromLeft() {
             flickableFront.contentIsReady = false
-            articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
+            setPreviousId()
+            //articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
             state = "toLeft"
             state = "visible"
@@ -115,7 +142,8 @@ Item {
 
         function moveFromRight() {
             flickableFront.contentIsReady = false
-            articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
+            setNextId()
+            //articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
             state = "toRight"
             state = "visible"
@@ -128,21 +156,26 @@ Item {
             NumberAnimation { duration: 200 }
         }
         onMovingHorizontallyChanged: {
-            if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
-                flickableFront.contentX = buffer //flickable.width/2
+            if (flickableFront.isSwitchable) {
+                if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
+                    flickableFront.contentX = buffer //flickable.width/2
+                }
             }
         }
 
         onAtXBeginningChanged: {
-            if (atXBeginning && contentIsReady) {
-                flickableBack.moveFromLeft()
+            if (flickableFront.isSwitchable) {
+                if (atXBeginning && contentIsReady) {
+                    flickableBack.moveFromLeft()
+                }
             }
         }
 
         onAtXEndChanged: {
-            if (atXEnd && contentIsReady) {
-                //console.log("next")
-                flickableBack.moveFromRight()
+            if (flickableFront.isSwitchable) {
+                if (atXEnd && contentIsReady) {
+                    flickableBack.moveFromRight()
+                }
             }
         }
 
@@ -165,6 +198,7 @@ Item {
         //flickableDirection: Flickable.VerticalFlick
 
         property bool contentIsReady: false
+        property bool isSwitchable: false
         Rectangle {
             id: boundsRecBack
             color: "white"
@@ -208,21 +242,30 @@ Item {
         transitions: [
             Transition {
                 from: "visible";
-                PropertyAnimation { target: flickableBack
-                  easing.type: Easing.InOutSine
-                  properties: "x"; duration: 1000 }
+                SequentialAnimation {
+                    ScriptAction { script: flickableBack.isSwitchable=false; }
+                    PropertyAnimation { target: flickableBack
+                      easing.type: Easing.InOutSine
+                      properties: "x"; duration: 1000 }
+                    ScriptAction { script: flickableBack.isSwitchable=true; }
+                }
             },
             Transition {
                 to: "visible";
-                PropertyAnimation { target: flickableBack
-                easing.type: Easing.InOutSine
-                properties: "x"; duration: 1000 }
+                SequentialAnimation {
+                    ScriptAction { script: flickableBack.isSwitchable=false; }
+                    PropertyAnimation { target: flickableBack
+                    easing.type: Easing.InOutSine
+                    properties: "x"; duration: 1000 }
+                    ScriptAction { script: flickableBack.isSwitchable=true; }
+                }
             }
         ]
 
         function moveFromLeft() {
             flickableBack.contentIsReady = false
-            articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
+            setPreviousId()
+            //articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
             state = "toLeft"
             state = "visible"
@@ -231,7 +274,8 @@ Item {
 
         function moveFromRight() {
             flickableBack.contentIsReady = false
-            articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
+            setNextId()
+            //articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
             state = "toRight"
             state = "visible"
@@ -245,20 +289,26 @@ Item {
         }
 
         onMovingHorizontallyChanged: {
-            if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
-                flickableBack.contentX = buffer //flickable.width/2
+            if (flickableBack.isSwitchable) {
+                if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
+                    flickableBack.contentX = buffer //flickable.width/2
+                }
             }
         }
 
         onAtXBeginningChanged: {
-            if (atXBeginning && contentIsReady) {
-                flickableFront.moveFromLeft()
+            if (flickableBack.isSwitchable) {
+                if (atXBeginning && contentIsReady) {
+                    flickableFront.moveFromLeft()
+                }
             }
         }
 
         onAtXEndChanged: {
-            if (atXEnd && contentIsReady) {
-                flickableFront.moveFromRight()
+            if (flickableBack.isSwitchable) {
+                if (atXEnd && contentIsReady) {
+                    flickableFront.moveFromRight()
+                }
             }
         }
     }