
var imgpath=APPLI_PATH+PRODUCT_ID+"/gadget/";
function showcase(){
var frame_size=[218,150];
this.visible_p=false;
this.components=[
this.episode_img=new gimage({width:frame_size[0],height:frame_size[1],limit_mode:LIMIT_NONE}),
this.frame=new gimage({src:imgpath+"frame.png",width:frame_size[0],height:frame_size[1]}),
this.label=new gtext({translate:[0,-frame_size[1]/2+20,0],
width:frame_size[0]-8*2,font_size:26,omitter:"...",redraw:false}),
this.logo=new gimage({limit_mode:LIMIT_NONE}),
];
this.episode_img.parent=this;
this.episode_img.onload=function (obj){
var asp=(this.src_height/this.src_width);
this.translate[1]=(150-2-(asp*(frame_size[0])))/2;
this.parent.visible_p=true;
force_redraw();}
this.episode_img.onerror=function (obj){
if(this.parent.onerror_func instanceof Function)this.parent.onerror_func(obj);}
this.logo.onload=function (obj){
this.translate[0]=-frame_size[0]/2 + this.src_width/2+4;
this.translate[1]=-frame_size[1]/2 + this.src_height/2+24;
force_redraw();}
}
showcase.prototype=new container({});
showcase.prototype.setErrorHook=function (error_func){
this.onerror_func=error_func;}
showcase.prototype.setSkin=function (episode_img_url,logo_url,t1){
this.episode_img.src=episode_img_url;
this.logo.src=logo_url;
setf_text(this.label,t1);}
var gadget=new Gadget();
gadget.init=function(){
this.list=[];
for(var i=0;i<2;i++){
this.list[(i+1).toString()]=new showcase();
this.list[(i+1).toString()].translate=[70+i*230,0,0];}
var widget_showcase ="widget_showcase_extended.png";
if(system.product.match("^GBL15")!=null){
widget_showcase ="widget_showcase_2015.png";}
this.components=[
this.bg=new gimage({src:imgpath+widget_showcase,width:this.$width,height:this.$height}),
];
this.components.push.apply(this.components,this.list);};
gadget._finished=false;
gadget.update=function (){
var str=read_file("file:///transient/freetime/freetimed/showcaseHomeHighlights.json");
if(!isString(str))
return this.updateLocalData();
var expiryDT=null;
var episodes=null;
try{
var data=JSON.parse(str);
episodes=data.showcase_home_highlights.items.item;
if(!(episodes instanceof Array))
return this.updateLocalData();
expiryDT=data.showcase_home_highlights.version["expiryDT"];
if(parseInt(expiryDT)<~~(new Date().getTime()/1000))
return this.updateLocalData();}catch(e){
return this.updateLocalData();};
return this.updateEpisodes(episodes);}
gadget.updateLocalData=function(){
var str=read_file("file:///transient/freetime/freetimed/localShowcaseHomeHighligts.json");
var episodes=null;
try{
var data=JSON.parse(str);
episodes=data.showcase_home_highlights.items.item;
if(!(episodes instanceof Array))
return this.updateLocalData();}catch(e){
console.log("[freetime_showcase] cannot parse freetime's local data.");
this._finished=true;
return;}
return this.updateEpisodes(episodes);};
gadget.updateEpisodes=function(episodes){
var me=this;
this._error_cnt=0;
var errorHook=function (){
me._error_cnt++;
if(me._error_cnt>1){
me.updateLocalData();}
}
for(var i=0;i<2;i++){
var id=episodes[i]["id"]||"0";
var episode_img=episodes[i].episode_img||"";
var logo=episodes[i].logo||"";
var t1=episodes[i].t1||"";
this.list[id].setErrorHook(errorHook);
this.list[id].setSkin(episode_img,logo,t1);}
this._finished=true;};
gadget.animation=function(count){

return false;}
gadget.freeResource=function(bool){
gimageResource(this.bg,bool);}
return gadget;
