@@ -21,15 +21,17 @@ void SubscribeItem::onTriggered(){
2121    std::ostringstream oss;
2222    std::time_t  tmTime = std::chrono::system_clock::to_time_t (time);
2323    oss<<eventid<<" :"  <<name<<std::put_time (std::localtime (&tmTime), " %F %T"  );
24-     // Toast::makeText(oss.str())->show();
2524    Dialog dialog;
26-     std::shared_ptr<Test>pp=std::make_shared<Test>();
27-     dialog.setTitle (" Prompt"  )
28-          .setMessage (oss.str ())
29-          .setPositiveButton (" Yes"  ,[pp](View&){NGLOG_DEBUG (" Pressed YES"  );})
30-          .setNegativeButton (" No"  ,[](View&){App::getInstance ().exit (1 );})
31-          .show ();
32-     Subscriber::getInstance ()->remove (time);
25+     struct  tm *t=std::localtime (&tmTime);
26+     if ( (weekday==0 ) || (weekday&(1 <<t->tm_wday )) ){
27+         std::shared_ptr<Test>pp=std::make_shared<Test>();
28+         dialog.setTitle (" Prompt"  )
29+           .setMessage (oss.str ())
30+           .setPositiveButton (" Yes"  ,[pp](View&){NGLOG_DEBUG (" Pressed YES"  );})
31+           .setNegativeButton (" No"  ,[](View&){App::getInstance ().exit (1 );})
32+           .show ();
33+         if (type==0 )Subscriber::getInstance ()->remove (time);
34+     }
3335}
3436
3537Subscriber*Subscriber::mInst =nullptr ;
@@ -65,21 +67,31 @@ int Subscriber::add(SubscribeItem&itm){
6567int  Subscriber::addOnce (SubscribeItem&itm){
6668    auto  p=items.insert (std::make_pair (itm.time ,itm));
6769    p.first ->second .type =0 ;
70+     p.first ->second .weekday =0 ;
6871    schedule (std::bind (&SubscribeItem::onTriggered,&p.first ->second ),itm.time );
6972}
7073
7174int  Subscriber::addDaily (SubscribeItem&itm){
7275    auto  p=items.insert (std::make_pair (itm.time ,itm));
73-      p.first ->second .type =1 ;
76+     p.first ->second .type =1 ;
77+     p.first ->second .weekday =0 ;
7478    scheduleDaily (std::bind (&SubscribeItem::onTriggered,&p.first ->second ),itm.time );
7579}
7680
7781int  Subscriber::addWeekly (SubscribeItem&itm){
7882    auto  p=items.insert (std::make_pair (itm.time ,itm));
79-      p.first ->second .type =2 ;
83+     p.first ->second .type =2 ;
84+     p.first ->second .weekday =0 ;
8085    scheduleWeekly (std::bind (&SubscribeItem::onTriggered,&p.first ->second ),itm.time );
8186}
8287
88+ int  Subscriber::addWeekly (SubscribeItem&itm,int  weekday){
89+     auto  p=items.insert (std::make_pair (itm.time ,itm));
90+     p.first ->second .type =1 ;
91+     p.first ->second .weekday =weekday;
92+     scheduleDaily (std::bind (&SubscribeItem::onTriggered,&p.first ->second ),itm.time );
93+ }
94+ 
8395int  Subscriber::getItems (std::vector<SubscribeItem>&itms){
8496    for (auto  i:items)
8597       itms.push_back (i.second );
@@ -119,6 +131,7 @@ int Subscriber::load(const std::string&filename){
119131           auto  t64=std::chrono::seconds (e[" time"  ].asInt64 ());
120132           itm.eventid =e[" eventid"  ].asInt ();
121133           itm.type =e[" type"  ].asInt ();
134+            itm.weekday =e[" weekday"  ].asInt ();
122135           itm.time =time_point<system_clock,seconds>(t64); 
123136           itm.name =e[" name"  ].asString ();
124137           add (itm);
@@ -147,6 +160,7 @@ int Subscriber::save(const std::string&filename){
147160       Json::Value evt;
148161       evt[" eventid"  ]=it->second .eventid ;
149162       evt[" type"  ]=it->second .type ;
163+        evt[" weekday"  ]=it->second ->weekday ;
150164       evt[" time"  ]=duration_cast<seconds>(it->second .time .time_since_epoch ()).count ();
151165       evt[" name"  ]=it->second .name ;
152166       if (0 ==comment)
0 commit comments