Example #1
0
        public static void RegisterLiveTiles()
        {
            UnregisterAllScheduledLiveTiles();

            for (int i = 0; i < Data.data.vakatNames.Count; i++)
            {
                if (Data.VakatTime(DateTime.Now, i) > DateTime.Now)
                {
                    Vakat vakat = new Vakat {
                        time = Data.VakatTime(DateTime.Now, i), name = Data.data.vakatNames[i].Replace("Izlazak", "Izl."), rbr = i
                    };

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(XMLforLiveTile(vakat.time));
                    try
                    {
                        Windows.UI.Notifications.ScheduledTileNotification scheduledTile = new Windows.UI.Notifications.ScheduledTileNotification(doc, vakat.time);
                        Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTile);
                    }
                    catch
                    {
                        System.Diagnostics.Debug.WriteLine("Greška pri registraciji livetile za " + vakat.name + " (" + vakat.time.ToString() + ")");
                    }
                }
            }
        }
Example #2
0
        public static void Create_New_Alarm(Vakat vakat, bool firstDel = false)
        {
            if (vakat.time <= DateTime.Now.AddMinutes(Memory.predAlarm[vakat.rbr]))
            {
                return;
            }
            string key = Create_Key(vakat, "alarm");

            if (firstDel)
            {
                Delete(Create_Key(vakat, "alarm"));
            }
            else
            {
                if (If_Different_Delete(key, vakat, Memory.predAlarm[vakat.rbr]))
                {
                    return;
                }
            }

            try
            {
                string toastXmlString =
                    "<toast duration=\"long\">\n" +
                    "<visual>\n" +
                    "<binding template=\"ToastText02\">\n" +
                    "<text id=\"1\">" + vakat.name + " je za " + Memory.predAlarm[vakat.rbr] + " minuta" + "</text>\n" +
                    "<text id=\"2\">" + Fixed.App_Name + "</text>\n" +
                    "</binding>\n" +
                    "</visual>\n" +
                    "<commands scenario=\"alarm\">\n" +
                    "<command id=\"snooze\"/>\n" +
                    "<command id=\"dismiss\"/>\n" +
                    "</commands>\n" +
                    "<audio src=\"" + Memory.Alarm_Sound + "\" loop=\"true\" />\n" +
                    "</toast>\n";

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(toastXmlString);

                ScheduledToastNotification scheduledToast = new ScheduledToastNotification(doc, vakat.time.AddMinutes(-Memory.predAlarm[vakat.rbr]));
                scheduledToast.Id = key;
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
                System.Diagnostics.Debug.WriteLine("Alarm created at " + vakat.time + " (" + vakat.name + ")");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Greška pri registraciji alarma za " + vakat.name + " u vrijeme " + vakat.time + " (" + ex.Message + ")");
            }
        }
Example #3
0
        public static void Create_New_Toast(Vakat vakat, bool firstDel = false)
        {
            if (vakat.time <= DateTime.Now.AddMinutes(Memory.predToast[vakat.rbr]))
            {
                return;
            }
            string key = Create_Key(vakat, "toast");

            if (firstDel)
            {
                Delete(Create_Key(vakat, "toast"));
            }
            else
            {
                if (If_Different_Delete(key, vakat, Memory.predToast[vakat.rbr]))
                {
                    return;
                }
            }

            try
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
                XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                toastTextElements[0].AppendChild(toastXml.CreateTextNode(vakat.name + " je za " + Memory.predToast[vakat.rbr] + " minuta"));
                toastTextElements[1].AppendChild(toastXml.CreateTextNode("Utišajte zvukove uređaja!"));

                IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                ((XmlElement)toastNode).SetAttribute("launch", "MainPage.xaml");

                XmlElement audio = toastXml.CreateElement("audio");
                audio.SetAttribute("src", Memory.Toast_Sound);
                toastNode.AppendChild(audio);

                ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, vakat.time.AddMinutes(-Memory.predToast[vakat.rbr]));
                scheduledToast.Id = key;
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
                System.Diagnostics.Debug.WriteLine("Notification created at " + vakat.time + " (" + vakat.name + ")");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Greška pri registraciji notifikacije za " + vakat.name + " u vrijeme " + vakat.time + " (" + ex.Message + ")");
            }
        }
Example #4
0
        public static void Obavijesti_Za_Dan(DateTime dt, Data.Obavijest obavijest)
        {
            for (int i = 0; i < Data.data.vakatNames.Count; i++)
            {
                Vakat vakat = new Vakat {
                    time = Data.VakatTime(dt, i), name = Data.data.vakatNames[i], rbr = i
                };

                if (obavijest == Data.Obavijest.All)
                {
                    Kreiraj_Novu_Obavijest(vakat, Data.Obavijest.Alarm);
                    Kreiraj_Novu_Obavijest(vakat, Data.Obavijest.Toast);
                }
                else
                {
                    Kreiraj_Novu_Obavijest(vakat, obavijest);
                }
            }
        }
Example #5
0
        public static bool Obavijest_Postavljena(Vakat vakat, Data.Obavijest obavijest)
        {
            var notifier  = ToastNotificationManager.CreateToastNotifier();
            var scheduled = notifier.GetScheduledToastNotifications();

            string key = vakat.NotificationKey(obavijest);

            if (vakat.isSkipped(obavijest))
            {
                Obrisi_Obavijest(vakat.NotificationKey(obavijest));
                return(true);
            }

            if (vakat.blockedNotifications(obavijest))
            {
                Obrisi_Obavijest(key);
                return(true);
            }

            int predNotif = vakat.notificationsOffset(obavijest);

            for (int i = 0; i < scheduled.Count; i++)
            {
                if (scheduled[i].Id == key)
                {
                    if (scheduled[i].DeliveryTime.DateTime == vakat.time.AddMinutes(-predNotif))
                    {
                        System.Diagnostics.Debug.WriteLine("Obavijest [key]: " + key + " - već postoji...");
                        return(true);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Obavijest [key]: " + key + " - na pogrešnom mjestu - BRIŠEM...");
                        ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(scheduled[i]);
                        return(false);
                    }
                }
            }
            return(false);
        }
Example #6
0
        public static bool If_Different_Delete(string key, Vakat vakat, int predNotif)
        {
            var notifier  = ToastNotificationManager.CreateToastNotifier();
            var scheduled = notifier.GetScheduledToastNotifications();

            for (int i = 0; i < scheduled.Count; i++)
            {
                if (scheduled[i].Id == key)
                {
                    if (scheduled[i].DeliveryTime.DateTime == vakat.time.AddMinutes(-predNotif))
                    {
                        return(true);
                    }
                    else
                    {
                        ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(scheduled[i]);
                        return(false);
                    }
                }
            }
            return(false);
        }
Example #7
0
        public static Vakat GetCurrentPrayer(DateTime date)
        {
            Vakat tmp = new Vakat {
                time = VakatTime(date, 0), name = data.vakatNames[0], rbr = 0
            };

            for (int i = 0; i < data.vakatNames.Count; i++)
            {
                if (VakatTime(date, i) > date)
                {
                    return(tmp);
                }
                else
                {
                    tmp = new Vakat {
                        time = VakatTime(date, i), name = data.vakatNames[i], rbr = i
                    }
                };
            }

            return(new Vakat {
                time = VakatTime(date, 0), name = data.vakatNames[0], rbr = 0
            });
        }
Example #8
0
 public static string Create_Key(Vakat vakat, string type)
 {
     return((vakat.time.Year + "|" + vakat.time.Month + "|" + vakat.time.Day + "|" + vakat.name.Substring(0, 2).ToLower() + "|" + type.Substring(0, 1)).ToLower());
 }
Example #9
0
        public static string XMLforLiveTile(DateTime date)
        {
            #region Lock screen details
            string rowOnLockScreen1 = Data.VakatTime(date, 0).ToString("HH:mm") + " " + Data.data.vakatNames[0];
            rowOnLockScreen1 += Environment.NewLine + Data.VakatTime(date, 1).ToString("HH:mm") + " " + Data.data.vakatNames[1].Replace("Izlazak", "Izl.");

            string rowOnLockScreen2 = Data.VakatTime(date, 2).ToString("HH:mm") + " " + Data.data.vakatNames[2];
            rowOnLockScreen2 += Environment.NewLine + Data.VakatTime(date, 3).ToString("HH:mm") + " " + Data.data.vakatNames[3];

            string rowOnLockScreen3 = Data.VakatTime(date, 4).ToString("HH:mm") + " " + Data.data.vakatNames[4];
            rowOnLockScreen3 += Environment.NewLine + Data.VakatTime(date, 5).ToString("HH:mm") + " " + Data.data.vakatNames[5];

            rowOnLockScreen3 += Environment.NewLine + "Vaktija za " + Data.data.locationsDative[Memory.location];
            #endregion

            Vakat nextPrayer = Data.GetNextPrayer(date);

            string xml = "";
            xml += "<tile>\n";
            xml += "    <visual version=\"2\">\n";
            xml += "        <binding template=\"TileSquare310x310BlockAndText01\">";
            xml += "            <text id=\"1\">Vaktija za " + Data.data.locationsDative[Memory.location] + "</text>";
            xml += "            <text id=\"2\">" + Data.VakatTime(date, 0).ToString("HH:mm") + " " + Data.data.vakatNames[0] + "</text>";
            xml += "            <text id=\"3\">" + Data.VakatTime(date, 1).ToString("HH:mm") + " " + Data.data.vakatNames[1].Replace("Izlazak", "Izl.") + "</text>";
            xml += "            <text id=\"4\">" + Data.VakatTime(date, 2).ToString("HH:mm") + " " + Data.data.vakatNames[2] + "</text>";
            xml += "            <text id=\"5\">" + Data.VakatTime(date, 3).ToString("HH:mm") + " " + Data.data.vakatNames[3] + "</text>";
            xml += "            <text id=\"6\">" + Data.VakatTime(date, 4).ToString("HH:mm") + " " + Data.data.vakatNames[4] + "</text>";
            xml += "            <text id=\"7\">" + Data.VakatTime(date, 5).ToString("HH:mm") + " " + Data.data.vakatNames[5] + "</text>";
            xml += "            <text hint-align=\"center\" id=\"8\">" + date.Day + "</text>";
            xml += "            <text hint-align=\"center\" id=\"9\">" + Data.data.monthnames[DateTime.Now.Month % 12] + "</text>";
            xml += "        </binding>";
            xml += "        <binding template=\"TileWide\" hint-lockDetailedStatus1=\"" + rowOnLockScreen1 + "\" hint-lockDetailedStatus2=\"" + rowOnLockScreen2 + "\" hint-lockDetailedStatus3=\"" + rowOnLockScreen3 + "\">";
            xml += "            <group>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[0] + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 0).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[1].Replace("Izlazak", "Izl.") + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 1).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[2] + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 2).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "            </group>";
            xml += "            <group>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[3] + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 3).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[4] + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 4).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "                <subgroup hint-weight=\"1\">";
            xml += "                    <text hint-align=\"center\">" + Data.data.vakatNames[5] + "</text>";
            xml += "                    <text hint-align=\"center\" hint-style=\"body\">" + Data.VakatTime(date, 5).ToString("HH:mm") + "</text>";
            xml += "                </subgroup>";
            xml += "            </group>";
            xml += "        </binding>";
            xml += "        <binding template=\"TileMedium\" hint-textStacking=\"center\">";
            xml += "            <text hint-style=\"body\" hint-align=\"center\">" + nextPrayer.name.Replace("Izlazak", "Izl.") + "</text>";
            xml += "            <text hint-style=\"subtitle\" hint-align=\"center\">" + nextPrayer.time.ToString("HH:mm") + "</text>";
            xml += "        </binding>";
            xml += "        <binding template=\"TileSmall\" hint-textStacking=\"center\">";
            xml += "            <text hint-align=\"center\">" + nextPrayer.name.Replace("Izlazak", "Izl.") + "</text>";
            xml += "            <text hint-style=\"body\" hint-align=\"center\">" + nextPrayer.time.ToString("HH:mm") + "</text>";
            xml += "        </binding>";
            xml += "    </visual>";
            xml += "</tile>";

            return(xml);
        }
Example #10
0
        public static void RegisterLiveTiles()
        {
            UnregisterAllScheduledLiveTiles();

            Day juce  = Year.year.months[DateTime.Now.AddDays(-1).Month - 1].days[DateTime.Now.AddDays(-1).Day - 1];
            Day danas = Year.year.months[DateTime.Now.Month - 1].days[DateTime.Now.Day - 1];
            Day sutra = Year.year.months[DateTime.Now.AddDays(1).Month - 1].days[DateTime.Now.AddDays(1).Day - 1];

            List <Day> jds = new List <Day> {
                juce, danas, sutra
            };

            string tempStr = "";

            foreach (var it in danas.vakti)
            {
                if (it.time.DayOfWeek == DayOfWeek.Friday && it.rbr == 2)
                {
                    it.name = "Podne (Džuma)".ToLower();                                                       //Ako je petak i vakat podna, postavit dzumu
                }
                tempStr += "<text id=\"" + (it.rbr + 2).ToString() + "\">" + it.time.ToString("HH:mm") + " " + it.name.ToLower() + "</text>\n";
            }

            #region Lock screen details
            string row1 = "";
            string row2 = "";
            string row3 = "";
            row1 = danas.vakti[0].time.ToString("HH:mm") + " zora       " + " izl sunca " + danas.vakti[1].time.ToString("HH:mm");
            row2 = danas.vakti[2].time.ToString("HH:mm") + " podne   " + "    ikindija " + danas.vakti[3].time.ToString("HH:mm");
            row3 = danas.vakti[4].time.ToString("HH:mm") + " akšam   " + "        jacija " + danas.vakti[5].time.ToString("HH:mm") + "\n" + Memory.location.ime.ToLower();
            #endregion

            var nextPrayer = Get.Next_Prayer_Time();
            System.Diagnostics.Debug.WriteLine("Next prayer: " + nextPrayer.name);

            string xml = "<tile>\n";
            xml += "<visual version=\"2\">\n";
            xml += "  <binding template=\"TileWide310x150Text02\" fallback=\"TileWideText02\" hint-lockDetailedStatus1=\"" + row1.ToLower() + "\" hint-lockDetailedStatus2=\"" + row2.ToLower() + "\" hint-lockDetailedStatus3=\"" + row3.ToLower() + "\">\n";
            xml += "  <image id=\"1\" src=\"Assets/Wide310x150Logo.png\" alt=\"alt text\"/>";
            xml += tempStr;
            xml += "  <text id=\"1\">" + Memory.location.ime.ToLower() + "</text>\n";
            xml += "  </binding>\n";
            xml += "  <binding template=\"TileSquare150x150Text01\" fallback=\"TileSquareText01\">\n";
            xml += "  <text id=\"1\">[text1]</text>";
            xml += "  <text id=\"2\">[text2]</text>";
            xml += "  </binding>\n";
            xml += "</visual>\n";
            xml += "</tile>";
            xml  = xml.Replace("izlazak sunca", "izl sunca");

            Vakat trenV         = Get.Current_Prayer_Time();
            var   currentPrayer = Get.Current_Prayer_Time();

            int j = 0;

            bool el = false;

            foreach (var day in jds)
            {
                foreach (var it in day.vakti)
                {
                    if (el)
                    {
                        j++;
                        if (j > 6)
                        {
                            var notifier  = Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication();
                            var scheduled = notifier.GetScheduledTileNotifications();
                            for (int i = 0; i < scheduled.Count; i++)
                            {
                                System.Diagnostics.Debug.WriteLine("Livetile at: " + scheduled[i].DeliveryTime);
                            }
                            return;
                        }
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(xml.Replace("[text1]", it.time.ToString("H:mm")).Replace("[text2]", it.name.ToLower()));
                        try
                        {
                            Windows.UI.Notifications.ScheduledTileNotification scheduledTile = new Windows.UI.Notifications.ScheduledTileNotification(doc, trenV.time);
                            Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTile);
                        }
                        catch
                        {
                            System.Diagnostics.Debug.WriteLine("Greška pri registraciji livetile za " + it.name + " (" + it.time.ToString() + ")");
                        }
                    }

                    trenV = it;

                    if (it.time == nextPrayer.time)
                    {
                        el = true;
                    }
                }
            }
        }
Example #11
0
        public static void Kreiraj_Novu_Obavijest(Vakat vakat, Data.Obavijest obavijest)
        {
            if (vakat.time.AddMinutes(-vakat.notificationsOffset(obavijest)) <= DateTime.Now)
            {
                return;                                                                               // Ako je prošlo vrijeme za obavijest - prekid
            }
            if (Obavijest_Postavljena(vakat, obavijest))
            {
                return;                                          // Ako je obavijest već postavljena - prekid // Ako je isključena - obrisati - prekid
            }
            string key = vakat.NotificationKey(obavijest);

            if (obavijest == Data.Obavijest.Alarm)
            {
                if (vakat.time <= DateTime.Now.AddMinutes(vakat.predAlarm))
                {
                    return;                                                         // Ako je prošlo vrijeme za alarm - prekid
                }
                try
                {
                    string toastXmlString = "";
                    if (Fixed.IsPhone)
                    {
                        toastXmlString = "<toast duration=\"long\">\n" +
                                         "<visual>\n" +
                                         "<binding template=\"ToastText02\">\n" +
                                         "<text id=\"1\">" + vakat.name + " je za " + vakat.predAlarm + " minuta" + "</text>\n" +
                                         "<text id=\"2\">" + Fixed.App_Name + "</text>\n" +
                                         "</binding>\n" +
                                         "</visual>\n" +
                                         "<commands scenario=\"alarm\">\n" +
                                         "<command id=\"snooze\"/>\n" +
                                         "<command id=\"dismiss\"/>\n" +
                                         "</commands>\n" +
                                         "<audio src=\"" + Memory.Alarm_Sound + "\" loop=\"true\" />\n" +
                                         "</toast>\n";
                    }
                    else
                    {
                        toastXmlString =
                            "<toast duration=\"long\">\n" +
                            "<visual>\n" +
                            "<binding template=\"ToastText02\">\n" +
                            "<text id=\"1\">" + vakat.name + " je za " + vakat.predAlarm + " minuta" + "</text>\n" +
                            "<text id=\"2\">" + Fixed.App_Name + "</text>\n" +
                            "</binding>\n" +
                            "</visual>\n" +
                            "<commands scenario=\"alarm\">\n" +
                            "<command id=\"snooze\"/>\n" +
                            "<command id=\"dismiss\"/>\n" +
                            "</commands>\n" +
                            "<audio src=\"ms-winsoundevent:Notification.Looping.Alarm2\" loop=\"true\" />\n" +
                            "</toast>\n";
                    }

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(toastXmlString);

                    ScheduledToastNotification scheduledToast = new ScheduledToastNotification(doc, vakat.time.AddMinutes(-vakat.predAlarm));
                    scheduledToast.Id = key;
                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
                    System.Diagnostics.Debug.WriteLine("Alarm created at " + vakat.time.AddMinutes(-vakat.predToast) + " (" + vakat.name + ")");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Greška pri registraciji alarma za " + vakat.name + " u vrijeme " + vakat.time.AddMinutes(-vakat.predToast) + " (" + ex.Message + ")");
                }
            }
            else if (obavijest == Data.Obavijest.Toast)
            {
                if (vakat.time <= DateTime.Now.AddMinutes(vakat.predToast))
                {
                    return;                                                         // Ako je prošlo vrijeme za alarm - prekid
                }
                try
                {
                    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
                    XmlDocument       toastXml      = ToastNotificationManager.GetTemplateContent(toastTemplate);

                    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(vakat.name + " je za " + vakat.predToast + " minuta"));
                    toastTextElements[1].AppendChild(toastXml.CreateTextNode("Utišajte zvukove uređaja!"));

                    IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                    ((XmlElement)toastNode).SetAttribute("launch", "MainPage.xaml");

                    XmlElement audio = toastXml.CreateElement("audio");
                    if (Fixed.IsPhone)
                    {
                        audio.SetAttribute("src", Memory.Toast_Sound);
                    }
                    toastNode.AppendChild(audio);

                    ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, vakat.time.AddMinutes(-vakat.predToast));
                    scheduledToast.Id = key;
                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
                    System.Diagnostics.Debug.WriteLine("Notification created at " + vakat.time.AddMinutes(-vakat.predToast) + " (" + vakat.name + ")");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Greška pri registraciji notifikacije za " + vakat.name + " u vrijeme " + vakat.time.AddMinutes(-vakat.predToast) + " (" + ex.Message + ")");
                }
            }
        }