コード例 #1
0
        private void InsertOrMoveCountdown(CountdownViewModel viewModel)
        {
            var index = 0;

            var otherCountdowns = items.Where(x => x.CountdownId != viewModel.CountdownId).ToList();

            if (otherCountdowns.Count > 0)
            {
                index = otherCountdowns.FindIndex(x => CompareCountdowns(viewModel, x) < 0);
                if (index < 0)
                {
                    index = otherCountdowns.Count;
                }
            }

            var added = !items.Contains(viewModel);

            if (added)
            {
                items.Insert(index, viewModel);
            }
            else
            {
                var currentIndex = items.IndexOf(viewModel);
                if (currentIndex != index)
                {
                    items.Move(currentIndex, index);
                }
            }
        }
コード例 #2
0
        public static CountdownViewModel Create(Countdown countdown)
        {
            var viewModel = new CountdownViewModel();

            viewModel.Refresh(countdown);

            return(viewModel);
        }
コード例 #3
0
        public CountdownViewModel PreviousCountdown(CountdownViewModel countdown)
        {
            var index = items.IndexOf(countdown) - 1;

            if (index >= 0)
            {
                return(items[index]);
            }

            return(null);
        }
コード例 #4
0
        public CountdownViewModel NextCountdown(CountdownViewModel countdown)
        {
            var index = items.IndexOf(countdown) + 1;

            if (index < items.Count)
            {
                return(items[index]);
            }

            return(null);
        }
コード例 #5
0
        private static int CompareCountdowns(CountdownViewModel x, CountdownViewModel y)
        {
            var days1 = x.DaysRemaining;
            var days2 = y.DaysRemaining;

            if (days1 >= 0 && days2 >= 0)
            {
                var result = days1.CompareTo(days2);
                if (result != 0)
                {
                    return(result);
                }
            }
            else if (days1 >= 0)
            {
                return(-1);
            }
            else if (days2 >= 0)
            {
                return(1);
            }
            else
            {
                var result = days2.CompareTo(days1);
                if (result != 0)
                {
                    return(result);
                }
            }

            var result2 = x.ExpirationDate.CompareTo(y.ExpirationDate);

            if (result2 != 0)
            {
                return(result2);
            }

            result2 = string.Compare(x.Name, y.Name, StringComparison.CurrentCulture);
            if (result2 != 0)
            {
                return(result2);
            }

            return(x.CountdownId.CompareTo(y.CountdownId));
        }
コード例 #6
0
        public void RemoveCountdown(CountdownViewModel countdown, out CountdownViewModel nextCountdown)
        {
            var index = items.IndexOf(countdown);

            items.RemoveAt(index);

            if (items.Count > 0)
            {
                if (index >= items.Count)
                {
                    index = items.Count - 1;
                }

                nextCountdown = items[index];
            }
            else
            {
                nextCountdown = null;
            }
        }
コード例 #7
0
 private void SelectCountdown(CountdownViewModel countdown)
 {
     MasterListView.SelectedItem = countdown;
 }