Esempio n. 1
0
        private void SetupNotificationPlayOnce(NotificationItem item)
        {
            long     time = 0;
            TimeSpan span;
            DateTime today = DateTime.Today;

            switch (item.notificationTimeType)
            {
            case NotificationTimeType.DelayDate:
                //DateTime currentDate = DateTime.Today;
                //span = new TimeSpan(item.delayDate, item.exactHour, item.exactMinute, item.exactSecond);
                today = today.AddDays(item.delayDate).AddHours(almostHours).AddMinutes(item.exactMinute).AddSeconds(item.exactSecond);
                time  = (long)today.Subtract(DateTime.Now).TotalMilliseconds;
                Debug.Log(time);
                break;

            case NotificationTimeType.DelayTime:
                time = item.delayTime * 1000L;
                break;

            case NotificationTimeType.SpecificDate:
                DateTime targetDate = DateTime.ParseExact(item.exactDate, "dd/mm/yyyy", CultureInfo.CurrentCulture);
                span       = new TimeSpan(0, almostHours, item.exactMinute, item.exactSecond);
                targetDate = targetDate.Add(span);
                span       = targetDate.Subtract(DateTime.Now);
                time       = (long)span.TotalMilliseconds;
                break;

            case NotificationTimeType.DelayDateInWeek:
                DateTime currentDate = DateTime.Today;
                int      diff        = item.dateInWeek - currentDate.DayOfWeek;
                if (diff < 0)
                {
                    diff += 7;
                }
                today = today.AddDays(diff).AddHours(almostHours).AddMinutes(item.exactMinute).AddSeconds(item.exactSecond);
                span  = today.Subtract(DateTime.Now);
                time  = (long)span.TotalMilliseconds;
                break;
            }
#if UNITY_ANDROID
            //SendNotification(item.id, item.title, item.content[UnityEngine.Random.Range(0, item.content.Length)],
            //    item.small_icon, item.big_icon, time, item.hasSound);

            SendNotification(item.id, RemoteSettingsHandler.remoteSettingsHandler.notify_day_title_value,
                             RemoteSettingsHandler.remoteSettingsHandler.notify_day_content_value,
                             item.small_icon, item.big_icon, time, item.hasSound);
#endif

#if UNITY_IOS
            DateTime dateTime = DateTime.Now.AddMilliseconds(time); // new DateTime(time * 10L * 1000L);
            //Debug.Log("dateTime: " + dateTime.ToString());
            ScheduleNotificationIOS(item.title, item.content[UnityEngine.Random.Range(0, item.content.Length)],
                                    dateTime, (item.hasSound && item.hasVibrate));
#endif
        }
Esempio n. 2
0
        public void SetupNotify(NotificationItem item)
        {
            switch (item.notificationType)
            {
            case NotificationType.Once:
                SetupNotificationPlayOnce(item);
                break;

            case NotificationType.Repeat:
                SetupNotificationPlayMultipleTime(item);
                break;
            }
        }
Esempio n. 3
0
        private void SetupNotificationPlayMultipleTime(NotificationItem item)
        {
            long     time = 0;
            TimeSpan span;
            DateTime today = DateTime.Today;

            switch (item.notificationTimeType)
            {
            case NotificationTimeType.DelayDate:
                for (int i = 0; i < item.repeatTimes; i++)
                {
                    today = DateTime.Today;
                    today = today.AddDays(item.delayDate * (i + 1)).AddHours(almostHours).AddMinutes(item.exactMinute).AddSeconds(item.exactSecond);
                    time  = (long)today.Subtract(DateTime.Now).TotalMilliseconds;
#if UNITY_ANDROID
                    SendNotification(item.id + repeatitionID * i, RemoteSettingsHandler.remoteSettingsHandler.notify_day_title_value,
                                     RemoteSettingsHandler.remoteSettingsHandler.notify_day_content_value,
                                     item.small_icon, item.big_icon, time, item.hasSound, item.hasVibrate);
#endif

#if UNITY_IOS
                    DateTime dateTime = DateTime.Now.AddMilliseconds(time);     // new DateTime(time * 10L * 1000L);
                    //Debug.Log("dateTime: " + dateTime.ToString());
                    ScheduleNotificationIOS(item.title, item.content[UnityEngine.Random.Range(0, item.content.Length)],
                                            dateTime, (item.hasSound && item.hasVibrate));
#endif
                }
                break;

            case NotificationTimeType.DelayTime:
                for (int i = 0; i < item.repeatTimes; i++)
                {
                    time = item.delayTime * 1000L * (i + 1);

                    //Debug.Log("item.content[UnityEngine.Random.Range(0, item.content.Length)]: " + item.content[UnityEngine.Random.Range(0, item.content.Length)]);

#if UNITY_ANDROID
                    SendNotification(item.id + repeatitionID * i, RemoteSettingsHandler.remoteSettingsHandler.notify_day_title_value,
                                     RemoteSettingsHandler.remoteSettingsHandler.notify_day_content_value,
                                     item.small_icon, item.big_icon, time, item.hasSound, item.hasVibrate);
#endif

#if UNITY_IOS
                    DateTime dateTime = DateTime.Now.AddMilliseconds(time);     // new DateTime(time * 10L * 1000L);
                    //Debug.Log("dateTime: " + dateTime.ToString());
                    ScheduleNotificationIOS(item.title, item.content[UnityEngine.Random.Range(0, item.content.Length)],
                                            dateTime, (item.hasSound && item.hasVibrate));
#endif
                }
                break;

            case NotificationTimeType.DelayDateInWeek:
                DateTime currentDate = DateTime.Today;
                int      diff        = item.dateInWeek - currentDate.DayOfWeek;
                int      remain      = diff;
                if (diff < 0)
                {
                    // For next week
                    diff += 7;
                }
                for (int i = 0; i < item.repeatTimes; i++)
                {
                    // For next week
                    //if ((remain % 3) == 0)
                    //{
                    //    remain += 7;
                    //    continue;
                    //}

                    today = DateTime.Today;
                    today = today.AddDays(diff + i * 7).AddHours(almostHours).AddMinutes(item.exactMinute).AddSeconds(item.exactSecond);
                    span  = today.Subtract(DateTime.Now);
                    time  = (long)span.TotalMilliseconds;

#if UNITY_ANDROID
                    SendNotification(item.id + repeatitionID * i, RemoteSettingsHandler.remoteSettingsHandler.notify_week_title_value,
                                     RemoteSettingsHandler.remoteSettingsHandler.notify_week_content_value,
                                     item.small_icon, item.big_icon, time, item.hasSound, item.hasVibrate);
#endif

#if UNITY_IOS
                    DateTime dateTime = DateTime.Now.AddMilliseconds(time);     // new DateTime(time * 10L * 1000L);
                    //Debug.Log("dateTime: " + dateTime.ToString());
                    ScheduleNotificationIOS(item.title, item.content[UnityEngine.Random.Range(0, item.content.Length)],
                                            dateTime, (item.hasSound && item.hasVibrate));
#endif
                }
                break;
            }
        }