In the previous article "Scopes keywords (keyword) and departments discussion (English video)", we have done some basic introduction to the keyword in scope. But we don't have a corresponding tutorial. In this article, we'll show you how to use keyword with Youku scope so that a scope can be rendered differently in different aggregation scopes.
If you are not familiar with how to develop scope, please refer to my tutorial, "Creating a dianping Scope (Qt JSON) on Ubuntu os." If you are familiar with creating a scope, believe that it will be one or two hours, you can create a and I am not much of a scope to.
Create a basic Youku video scope
As long as you follow the routines I have described above, we will quickly create a Youku video scope that is not as varied as the following:
The source code for the entire project is: Git clone https://gitcafe.com/ubuntu/youku.git
Simple, is a very simple Youku Scope.
In our code, we also modify the "youku.ini.in" file in the "Src/data" directory:
[Scopeconfig]_displayname=youku Scope_description=this is a Youku scopeart=screenshot.pngauthor=firstname Lastnameicon=icon.pngkeywords=video;videos[appearance]pageheader.logo=logo.png
It can be seen here that we used the keywords "
Videoand
Videos”。 Indicates that our scope can be aggregated by video scope and presented in the video aggregation scope. Of course, if our scope is also related to location, we can also join "nearby" in our scope. More keyword keywords can be found in the URL https://developer.ubuntu.com/en/scopes/tutorials/scope-keywords/. We open video aggregation scope in the phone and open its settings:
Remember in the "
Display results from Youku Scope"option on the hook. As we can see, in the video aggregation scope, we can look at the content of our Youku scope, although it is only part of it. If, we click on the "
Youku Scope Features"We can switch directly to our Youku scope:
Then if we return, we will go back to the previous picture.
Display a different UI for aggregation
The above design, we did not make any substantial changes to the code. We just added some of the keywords we need to the initialization file. So how do we show a different UI for aggregation? Also for some scopes, we may add more different kinds of keyword, so we may want to have different shows for different keyword, not all the same.
To achieve the purpose of the design, we have made the following modifications to our code:
Query.cpp
void Query::run (Sc::searchreplyproxy const& reply) { Auto Metadata_ = Search_metadata (); if (metadata_.is_aggregated ()) { Auto keywords = metadata_.aggregated_keywords (); if ((Keywords.find ("videos")! = Keywords.end ()) | | (Keywords.find ("video")! = Keywords.end ())) { qdebug () << "It is a video scope"; Do_videos_search (reply); } } else { qdebug () << "It is a normal video scope"; Do_normal_search (reply); }}
Here, we can make different presentations for our scope by analyzing keyword, and we can even use different APIs to get different data. To illustrate the convenience of the problem, we purposely used a different template to present the data in Youku scope when aggregating:
Const std::string videos_template = R "({ " schema-version ": 1, " TEMPLATE ": { " category-layout ":" Grid ", "card-size": "Large", "overlay": True }, "components": { "title": "title", "subtitle": " Subtitle ", " art ": { " field ":" Art ", " Aspect-ratio ": 2.0 }} )";
Here is a super-large grid template.
Re-run our scope, when there is no aggregation, the scope displays as follows:
When our scope is aggregated, the following is displayed:
Obviously, when aggregating, it shows a template that is not the same as normal. The display is a large picture. Of course click on "
Youku Scope Features", you will be entered into our normal scope interface.
The source code for the entire project is: Git clone https://gitcafe.com/ubuntu/youku_keywords.git
How to use keyword in scope to enable your scope to present itself in the aggregation scope