← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~mrqtros/ubuntu-rssreader-app/ubuntu-rssreader-app-ng-refactor into lp:ubuntu-rssreader-app

 

Roman Shchekin has proposed merging lp:~mrqtros/ubuntu-rssreader-app/ubuntu-rssreader-app-ng-refactor into lp:ubuntu-rssreader-app.

Commit message:
Non-Google engine refactor.

Requested reviews:
  Ubuntu Shorts Developers (ubuntu-shorts-dev)

For more details, see:
https://code.launchpad.net/~mrqtros/ubuntu-rssreader-app/ubuntu-rssreader-app-ng-refactor/+merge/281508

Non-Google engine refactor.

Please, check carefully its functionality.
-- 
Your team Ubuntu Shorts Developers is requested to review the proposed merge of lp:~mrqtros/ubuntu-rssreader-app/ubuntu-rssreader-app-ng-refactor into lp:ubuntu-rssreader-app.
=== modified file 'shorts/qml/components/NetworkManager.qml'
--- shorts/qml/components/NetworkManager.qml	2015-12-02 17:03:41 +0000
+++ shorts/qml/components/NetworkManager.qml	2016-01-04 11:48:53 +0000
@@ -19,14 +19,10 @@
     signal downloadStarted(int tagId)
 
     property string operationStatus: "success"
+    property bool __useGFA: optionsKeeper.useGoogleSearch
 
     function updateFeeds(feedsArray, topicId) {
-        if (optionsKeeper.useGoogleSearch()) {
-             d.updateFeeds(feedsArray, topicId)
-        }
-        else {
-            dNG.updateFeeds(feedsArray, topicId)
-        }
+        d.updateFeeds(feedsArray, topicId)
     }
 
     function cancelDownload() {
@@ -69,13 +65,17 @@
             }
 
             currentFeed = feedList.shift()
-            googleFeedApi.loadFeed(currentFeed.source)
+            if (__useGFA)
+                googleFeedApi.loadFeed(currentFeed.source)
+            else nonGoogleFeedApi.loadFeed(currentFeed.source)
         }
 
         function cancelDownload() {
             feedList = []
             operationStatus = "abort"
-            googleFeedApi.abort()
+            if (__useGFA)
+                googleFeedApi.abort()
+            nonGoogleFeedApi.abort()
         }
 
         function updateFeedInfo(feedId, feedLink, responseData) {
@@ -122,67 +122,7 @@
             console.timeEnd("addArticlesEx")
         }
 
-        function clearFromBadTags(content) {
-            /* Remove non empty too. Useless anyway.
-             */
-            content = content.replace(/alt=".*?"/g, "")
-            content = content.replace(/title=".*?"/g, "")
-            return content
-        }
-
-        property var googleFeedApi: GoogleFeedApi {
-            onLoadResult: {
-                if (result.responseStatus !== 200) {
-                    console.log("XML NETWORK GFA:", JSON.stringify(result))
-                    if (operationStatus == "success")
-                        operationStatus = "withErrors"
-                } else d.updateFeedInfo(d.currentFeed.id, d.currentFeed.link, result.responseData)
-
-                d.updateNextFeed()
-            }
-        } // GFA
-    } // QtObject
-
-    //////////////////////////////////////////  add a new object to refresh non-google feeds
-    QtObject {
-        id: dNG
-
-        property var feedList: []                 // Feed list to update.
-        property var currentFeed                  // Current downloading feed.
-        property int tagId: 0                     // Tag to update.
-
-        /* Method updates feeds one by another.
-             * Input: array of objects, each should include
-             * source, link and id (of feed in DB) properties.
-             */
-        function updateFeeds(feedsArray, topicId) {
-            tagId = topicId || 0
-
-            downloadStarted(tagId)
-
-            feedList = feedsArray
-            operationStatus = "success"
-            updateNextFeed()
-        }
-
-        // For inner usage only.
-        function updateNextFeed() {
-            if (feedList.length == 0) {
-                downloadFinished(tagId)
-                return
-            }
-
-            currentFeed = feedList.shift()
-            nonGoogleFeedApi.loadFeed(currentFeed.source)
-        }
-
-        function cancelDownload() {
-            feedList = []
-            operationStatus = "abort"
-            nonGoogleFeedApi.abort()
-        }
-
-        function updateFeedInfo(feedId, feedLink, responseData) {
+        function updateFeedInfoNg(feedId, feedLink, responseData) {
             var entries = responseData.item
             var f = responseData
 
@@ -190,8 +130,8 @@
             var fti = f.title == undefined ? "" : f.title["#text"] == undefined ? f.title : f.title["#text"]
 
             DB.updateFeedByXml(feedId, feedLink, fde, fti)
-            console.log(" -------- UPDATE INFO -------- ")
-            //            console.log(f.title, f.link, f.feedUrl, f.description)
+            console.log(" -------- UPDATE INFO (NG) -------- ")
+            console.log(fti, feedLink, f.feedUrl, fde)
 
             console.time("addArticlesEx")
 
@@ -200,11 +140,6 @@
             for (var i = 0; i < maxLength; i++) {
                 var e = entries[i]
 
-                //                print("article detail: ", JSON.stringify(e))
-                // Grab image from for article.
-                //                var articleImage = ImageUtils.grabArticleImage(e)
-                //                e.content = clearFromBadTags(e.content)
-
                 var ti = e.title == undefined ? "" : e.title["#text"] == undefined ? e.title : e.title["#text"]
                 var li = e.link == undefined ? "" : e.link["#text"] == undefined ? e.link : e.link["#text"]
                 var au = e.author == undefined ? "" : e.author["#text"] == undefined ? e.author : e.author["#text"]
@@ -212,34 +147,25 @@
                 var de = e.description == undefined ? "" : e.description["#text"] == undefined ? e.description : e.description["#text"]
                 var pu = e.pubDate == undefined ? "" : e.pubDate["#text"] == undefined ? e.pubDate : e.pubDate["#text"]
                 var co = e.content == undefined ? "" : e.content["#text"] == undefined ? e.content : e.content["#text"]
+
                 var articleImage = utilities.htmlGetImg(de)
-                if (articleImage.length == 0) { articleImage = utilities.htmlGetImg(co) }
-                else {
-                    print("articleImage: ", articleImage[0])
-                }
-                //                print("date parse 0: ", pu, DateUtils.parseDate(pu))
-                //                print("date parse 1: ", DateUtils.formatRelativeTime(i18n, DateUtils.parseDate(pu)))
+                if (!articleImage.length)
+                    articleImage = utilities.htmlGetImg(co)
 
-                var temp =
-                        {
+                var temp = {
                     "title": ti,
-                    "content": co == "" ? de : co,
-                                          "link": li,
-                                          "author": creator == "" ? au : creator,
-                                                                    "description": de,
-                                                                    "pubDate": DateUtils.parseDate(pu),
-                                                                    "guid": Qt.md5(li + pu),
-                                                                    "image" : articleImage.length > 0 ? articleImage[0] : "",
-                                                                                                        "media_groups" : ""
+                    "content": co ? co : de,
+                    "link": li,
+                    "author": creator ? creator : au ,
+                    "description": de,
+                    "pubDate": DateUtils.parseDate(pu),
+                    "guid": Qt.md5(li + pu),
+                    "image" : articleImage.length ? articleImage[0] : "",
+                    "media_groups" : ""
                 }
 
                 newArticles.push(temp)
             }
-//            print("new article length: ", newArticles.length)
-
-            //            /* Add new articles to DB and restore 'read' status of some of them.
-            //             */
-            //            DB.addArticles(articleModel, feedId, articleProperties);
 
             /* Add new articles to DB and restore 'read' status of some of them. */
             try {
@@ -253,22 +179,34 @@
 
         function clearFromBadTags(content) {
             /* Remove non empty too. Useless anyway.
-                 */
+             */
             content = content.replace(/alt=".*?"/g, "")
             content = content.replace(/title=".*?"/g, "")
             return content
         }
 
+        property var googleFeedApi: GoogleFeedApi {
+            onLoadResult: {
+                if (result.responseStatus !== 200) {
+                    console.log("XML NETWORK GFA:", JSON.stringify(result))
+                    if (operationStatus == "success")
+                        operationStatus = "withErrors"
+                } else d.updateFeedInfo(d.currentFeed.id, d.currentFeed.link, result.responseData)
+
+                d.updateNextFeed()
+            }
+        } // GFA
+
         property var nonGoogleFeedApi: XmlNetwork {
             onLoadResult: {
-                if (result.rss == undefined || result.rss == "") {
-//                    console.log("XML NETWORK GFA:", JSON.stringify(result))
+                if (!result.rss) {
+                    console.log("XML NETWORK NGA:", JSON.stringify(result))
                     if (operationStatus == "success")
                         operationStatus = "withErrors"
-                } else dNG.updateFeedInfo(dNG.currentFeed.id, dNG.currentFeed.link, result.rss.channel)
+                } else d.updateFeedInfoNg(d.currentFeed.id, d.currentFeed.link, result.rss.channel)
 
-                dNG.updateNextFeed()
+                d.updateNextFeed()
             }
-        } // GFA
+        } // NGA
     } // QtObject
 }

=== modified file 'shorts/qml/components/OptionsKeeper.qml'
--- shorts/qml/components/OptionsKeeper.qml	2015-12-02 17:03:41 +0000
+++ shorts/qml/components/OptionsKeeper.qml	2016-01-04 11:48:53 +0000
@@ -9,21 +9,19 @@
     property int fontSize
     property bool useDarkTheme
     property bool useListMode
+    property bool useGoogleSearch
 
     Component.onCompleted: {
         fontSize = getFontSize()
         useDarkTheme = getUseDarkTheme()
         useListMode = getUseListMode()
-
-
-        if (useGoogleSearch() == undefined ) {
-            setUseGoogleSearch(true)
-        }
+        useGoogleSearch = getUseGoogleSearch()
     }
 
     onFontSizeChanged: setFontSize(fontSize)
     onUseDarkThemeChanged: setUseDarkTheme(useDarkTheme)
     onUseListModeChanged: setUseListMode(useListMode)
+    onUseGoogleSearchChanged: setUseGoogleSearch(useGoogleSearch)
 
     function getFontSize() {
         return settingsDocument.contents.fontSize
@@ -69,8 +67,7 @@
         return settingsDocument.contents.dbLastUpdate
     }
 
-    ///////////////////////////////////////////////////////    below two functions are get/set "useGoogleSearch" value
-    function useGoogleSearch() {
+    function getUseGoogleSearch() {
         return settingsDocument.contents.useGoogleSearch
     }
 

=== modified file 'shorts/qml/nongoogle/AppendNGFeedPage.qml'
--- shorts/qml/nongoogle/AppendNGFeedPage.qml	2015-12-15 15:58:12 +0000
+++ shorts/qml/nongoogle/AppendNGFeedPage.qml	2016-01-04 11:48:53 +0000
@@ -58,18 +58,15 @@
         id: xmlFeedApi
 
         onLoadResult: {
-            if (result.rss == undefined || result.rss == "") {
-                // TODO  alert that fail retriving feed data
+            if (!result.rss) {
                 print("onLoadResult failed")
             }
             else {
-//                d.updateFeedInfo(d.currentFeed.id, d.currentFeed.link, result.rss.channel)
                 var f = result.rss.channel
 
-                feedDesc = f.description == undefined ? "" : f.description["#text"] == undefined ? f.description : f.description["#text"]
-                feedTitle = f.title == undefined ? "" : f.title["#text"] == undefined ? f.title : f.title["#text"]
-//                feedUrl = l
-                feedLink = f.link == undefined ? "" : f.link["#text"] == undefined ? f.link : f.link["#text"]
+                feedDesc = f.description ? (f.description["#text"] ? f.description["#text"] : f.description ) : ""
+                feedTitle = f.title ? (f.title["#text"] ? f.title["#text"] : f.title ) : ""
+                feedLink = f.link ? (f.link["#text"] ? f.link["#text"] : f.link) : ""
                 feedObj = {
                     "url" : feedUrl,
                     "title" : feedTitle,
@@ -77,7 +74,6 @@
                     "link" : feedLink
                 }
             }
-
         }
     }
 
@@ -114,20 +110,18 @@
                     anchors.fill: parent
                     onClicked: {
                         if (Qt.inputMethod.visible)
-                            tfFeedUrl.accapt()
+                            tfFeedUrl.accept()
                     }
                 }
             }
 
-            onAccepted: {
-                accapt()
-            }
+            onAccepted: accept()
 
-            function accapt() {
+            function accept() {
                 Qt.inputMethod.hide()
                 var userInput = text
 
-                if (userInput == "")
+                if (!userInput)
                     return
 
                 // Very simple logic, URL if there are no spaces and contains dots.
@@ -240,11 +234,8 @@
                             return
 
                         var selectedFeeds = []
-
                         selectedFeeds.push(feedObj)
-
                         pageStack.push(chooseTopicPage, {"feedsToAdd" : selectedFeeds})
-//                        pageStack.push(Qt.resolvedUrl("../pages/ChooseTopicPage.qml"), {"feedsToAdd" : selectedFeeds})
                     }
                 }
             } // Button

=== modified file 'shorts/qml/nongoogle/Positioner.qml'
--- shorts/qml/nongoogle/Positioner.qml	2015-12-15 15:58:12 +0000
+++ shorts/qml/nongoogle/Positioner.qml	2016-01-04 11:48:53 +0000
@@ -82,8 +82,6 @@
             var doc = new XMLHttpRequest()
 
             doc.onreadystatechange = function() {
-
-    //            print("positioner onreadystatechange: ", doc.readyState, doc.status, feedUrl)
                 if (doc.readyState === XMLHttpRequest.DONE) {
 
                     var resObj
@@ -92,14 +90,13 @@
                     } else { // Error
                         resObj = {"responseDetails" : doc.statusText,
                             "responseStatus" : doc.status}
-//                        resObj = ""
                     }
 
                     countryCode = resObj.countryName
                     print("countryCode", resObj)
 
                     if (countryCode == "China") {
-                        if (optionsKeeper.useGoogleSearch()) {
+                        if (optionsKeeper.useGoogleSearch) {
                             PopupUtils.open(componentDialogNG, tabstabs)
                         }
                     }

=== modified file 'shorts/qml/nongoogle/XmlNetwork.qml'
--- shorts/qml/nongoogle/XmlNetwork.qml	2015-12-15 15:58:12 +0000
+++ shorts/qml/nongoogle/XmlNetwork.qml	2016-01-04 11:48:53 +0000
@@ -29,7 +29,6 @@
 
                 var resObj
                 if (doc.status == 200) {
-//                    resObj = JSON.parse(doc.responseText)
                     resObj = utilities.xmlToJson(doc.responseText)
                 } else { // Error
                     resObj = {"responseDetails" : doc.statusText,
@@ -41,18 +40,6 @@
             }
         }
 
-
-        /* Number of articles to download.
-         */
-//        finalRequest += "&num=" + num
-
-        /* Add some optional params.
-         * May be usable:
-         * hl       - host language, for example "hl=ru", default en.
-         * num      - number of entries, for example "num=50", default 4, maximum 100.
-         * output   - format of output, for example "output=json", may be xml, json_xml, json.
-         */
-//        doc.open("GET", finalRequest, true);
         doc.open("GET", feedUrl, true);
         doc.send();
     }

=== modified file 'shorts/qml/pages/EditFeedPage.qml'
--- shorts/qml/pages/EditFeedPage.qml	2015-10-24 07:06:24 +0000
+++ shorts/qml/pages/EditFeedPage.qml	2016-01-04 11:48:53 +0000
@@ -11,7 +11,6 @@
     objectName: "editfeedpage"
     title: i18n.tr("Edit Feed")
     flickable: null/*content*/
-//    tools: null
 
     head.actions: [
                 Action {
@@ -20,7 +19,6 @@
                     text: i18n.tr("Done")
                     onTriggered: {
                         if (previousTopicId != newTopicId) {
-                            //                DB.updateFeedByUser(feedId, feedTitle, feedURL)
                             DB.deleteFeedTag(feedId, previousTopicId)
                             DB.addFeedTag(feedId, newTopicId)
                             apply(feedId, newTopicId, previousTopicId)
@@ -41,8 +39,7 @@
     property var dbTags
     property var topicArray
 
-    function setValues(feedid, title, url, pTopicId)
-    {
+    function setValues(feedid, title, url, pTopicId) {
         feedId = feedid ;
         feedTitle = title ;
         feedURL = url ;
@@ -53,12 +50,9 @@
         var tArray = [] ;
         var tagsArray = [] ;
         var index
-        for (var i=0; i<tags.rows.length; i++)
-        {
+        for (var i=0; i<tags.rows.length; i++) {
             if(tags.rows[i].id == previousTopicId)
-            {
-                index = i ;
-            }
+                index = i
             tArray.push(tags.rows[i].name) ;
             tagsArray.push(tags.rows[i]) ;
         }
@@ -67,28 +61,23 @@
         seletorTopic.selectedIndex = index ;
     }
 
-    function reloadPageContent() {
-//        editPage.tools = toolbar
-    }
+    function reloadPageContent() { }
 
     Flickable {
         id: content
-        anchors { fill: parent; topMargin: units.gu(2)/*margins: units.gu(2)*/ }
+        anchors { fill: parent; topMargin: units.gu(2) }
         contentHeight: contentItem.childrenRect.height
         boundsBehavior: (contentHeight > editPage.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
-        Column
-        {
+        Column {
             anchors{ left: parent.left; right: parent.right }
             spacing: units.gu(2)
 
-            Row
-            {
+            Row {
                 anchors{ left: parent.left; right: parent.right; leftMargin: units.gu(2); rightMargin: units.gu(2) }
                 spacing: units.gu(1)
 
-                Label
-                {
+                Label {
                     id: labelTitle
                     text: i18n.tr("Title: ")
                     width: units.gu(6)
@@ -105,21 +94,18 @@
                 }
             }
 
-            Row
-            {
+            Row {
                 anchors{ left: parent.left; right: parent.right; leftMargin: units.gu(2); rightMargin: units.gu(2) }
                 spacing: units.gu(1)
 
-                Label
-                {
+                Label {
                     id: labelURL
                     text: i18n.tr("URL: ")
                     width: labelTitle.width
                     anchors.verticalCenter: parent.verticalCenter
                 }
 
-                TextField
-                {
+                TextField {
                     text: feedURL
                     width: parent.width - labelURL.width - parent.spacing
                     anchors.verticalCenter: parent.verticalCenter
@@ -132,24 +118,20 @@
                 objectName: "valueselector"
                 id: seletorTopic
                 text: i18n.tr("Topic: ")
-                values: (topicArray == undefined || topicArray.length == 0) ? [""] : topicArray
-//                selectedIndex: 0
+                values: (topicArray && topicArray.length) ? topicArray : [""]
 
-                onSelectedIndexChanged:
-                {
-                    var tArray = topicArray ;
-                    var topicname = tArray[seletorTopic.selectedIndex] ;
-                    var tags = dbTags ;
-                    console.log("detail: ", JSON.stringify(tags)) ;
-                    for (var i=0; i<tags.length; i++)
-                    {
-                        if(tags[i].name == topicname)
-                        {
-                            newTopicId = tags[i].id ;
-                            break ;
+                onSelectedIndexChanged: {
+                    var tArray = topicArray
+                    var topicname = tArray[seletorTopic.selectedIndex]
+                    var tags = dbTags
+                    console.log("detail: ", JSON.stringify(tags))
+                    for (var i=0; i<tags.length; i++) {
+                        if(tags[i].name == topicname) {
+                            newTopicId = tags[i].id
+                            break
                         }
                     }
-                    console.log("new topic id: ", newTopicId) ;
+                    console.log("new topic id: ", newTopicId)
                 }
             }
         }

=== modified file 'shorts/qml/pages/PageSettings.qml'
--- shorts/qml/pages/PageSettings.qml	2015-12-03 16:01:09 +0000
+++ shorts/qml/pages/PageSettings.qml	2016-01-04 11:48:53 +0000
@@ -9,6 +9,18 @@
     title: i18n.tr("Settings")
     flickable: null
 
+    property bool preventSave: false
+
+    Component.onCompleted: updateInfoFromOptions()
+
+    function updateInfoFromOptions() {
+        preventSave = true
+
+        swUseGfa.checked = optionsKeeper.useGoogleSearch
+
+        preventSave = false
+    }
+
     Column {
         anchors {
             top: parent.top; topMargin: units.gu(1)
@@ -37,26 +49,19 @@
             }
 
             Switch {
+                id: swUseGfa
                 anchors.right: parent.right
-                checked: optionsKeeper.useGoogleSearch()
-
-                Component.onCompleted: {
-                    if (optionsKeeper.useGoogleSearch() == undefined ) {
-                        optionsKeeper.setUseGoogleSearch(true)
-                        checked = true
-                    }
-                }
 
                 onCheckedChanged: {
-                    optionsKeeper.setUseGoogleSearch(checked)
+                    if (preventSave)
+                        return
+                    optionsKeeper.useGoogleSearch = checked
                 }
             }
         }
 
-        ListItem.ThinDivider{}
+        ListItem.ThinDivider{ }
         /////////////////////////////////////////////////////////////////////   Google RSS engine switch    end here
-
-
     }// Column
 
 }

=== modified file 'shorts/qml/shorts-app.qml'
--- shorts/qml/shorts-app.qml	2015-12-02 17:03:41 +0000
+++ shorts/qml/shorts-app.qml	2016-01-04 11:48:53 +0000
@@ -251,7 +251,7 @@
             objectName: "tabstabs"
             visible: false
 
-            bottomEdgePage: optionsKeeper.useGoogleSearch() ? appendFeedPage : appendNGFeedPage
+            bottomEdgePage: optionsKeeper.useGoogleSearch ? appendFeedPage : appendNGFeedPage
             bottomEdgeTitle: i18n.tr("Add feeds")
             bottomEdgeBackgroundColor: "#F5F5F5" // "#875864"
             bottomEdgeTipColor: "#5533b5e5"// "#E0E0E0" //"#9b616c"


Follow ups