示例#1
0
        /// <summary>
        /// Compare two sub-items.
        /// </summary>
        /// <param name="subItemA">First sub-item to compare.</param><param name="subItemB">Second sub-item to compare.</param><param name="sortMethod">Item comparison method.</param><param name="order">Sort order.</param>
        /// <returns>
        /// Comparison result.
        /// </returns>
        protected override int CompareSubItems(BetterListViewSubItem subItemA, BetterListViewSubItem subItemB, BetterListViewSortMethod sortMethod, int order)
        {
            var itema = subItemA.Item as QueryResultListViewItem;
            var itemb = subItemB.Item as QueryResultListViewItem;

            if (QueryParam != null)
            {
                if (QueryParam.EnableAutoPreSubmit && QueryParam.AutoPreSubmitConfig != null)
                {
                    if (QueryParam.AutoPreSubmitConfig.SeatFirst)
                    {
                        var a = Compare(itema, itemb, s => s.ResultItem.Selected);
                        if (a != 0)
                        {
                            return(a);
                        }
                        a = Compare(itema, itemb, s => s.ResultItem.SeatSelected);
                        if (a != 0)
                        {
                            return(a);
                        }
                    }
                    else
                    {
                        var a = Compare(itema, itemb, s => s.ResultItem.SeatSelected);
                        if (a != 0)
                        {
                            return(a);
                        }
                        a = Compare(itema, itemb, s => s.ResultItem.Selected);
                        if (a != 0)
                        {
                            return(a);
                        }
                    }
                }
            }

            var value = (subItemA as ResultSubItems.SubItemBase).CompareTo((subItemB as ResultSubItems.SubItemBase)) * order;

            return(value);
        }
示例#2
0
        /// <summary>
        /// Compare two sub-items.
        /// </summary>
        /// <param name="subItemA">First sub-item to compare.</param><param name="subItemB">Second sub-item to compare.</param><param name="sortMethod">Item comparison method.</param><param name="order">Sort order.</param>
        /// <returns>
        /// Comparison result.
        /// </returns>
        protected override int CompareSubItems(BetterListViewSubItem subItemA, BetterListViewSubItem subItemB, BetterListViewSortMethod sortMethod, int order)
        {
            if (SuspendSort)
            {
                return(0);
            }

            var lx = subItemA.Item as ResourceListViewItem;
            var ly = subItemB.Item as ResourceListViewItem;

            if (lx.ParentItem != null && ly.ParentItem != null)
            {
                return(lx.Resource.CompareTo(ly.Resource));
            }

            //do not compare subitems

            if (lx.ParentItem != null || ly.ParentItem != null)
            {
                return(0);
            }

            var sx = lx.Resource;
            var sy = ly.Resource;


            if (sx.MatchWeight != sy.MatchWeight)
            {
                return(sy.MatchWeight - sx.MatchWeight);
            }


            var opt    = AppContext.Instance.Options;
            var weight = order;

            switch (opt.SortType)
            {
            case SortType.Default:
                return(0);                              //默认就是按照网站显示的顺序,不排序

            case SortType.Title:
                return(string.Compare(sx.Title, sy.Title, StringComparison.OrdinalIgnoreCase) * weight);

            case SortType.PubDate:
                if (sx.UpdateTime == null && sy.UpdateTime == null)
                {
                    return(0);
                }
                if (sx.UpdateTime == null ^ sy.UpdateTime == null)
                {
                    return((sx.UpdateTime == null ? -1 : 1) * weight);
                }
                return((int)((sx.UpdateTime.Value - sy.UpdateTime.Value).TotalMinutes) * -1);

            //case BtResourceGrabber.Entities.SortType.TorrentSize:
            //	break;
            case SortType.FileSize:
                var s1 = sx.DownloadSizeValue ?? EngineUtility.ToSize(sx.DownloadSize);
                var s2 = sy.DownloadSizeValue ?? EngineUtility.ToSize(sy.DownloadSize);

                return((s1 == s2 ? 0 : s1 < s2 ? -1 : 1) * weight);

            //case BtResourceGrabber.Entities.SortType.LeechCount:
            //	break;
            //case BtResourceGrabber.Entities.SortType.SeederCount:
            //	break;
            default:
                break;
            }

            return(0);
        }