From b3fa8086e0afca8545aa941a3ec175a0e1cb02ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 15 Apr 2022 11:32:20 +0200 Subject: Sort by episode number if rating is equal. --- c/defs.h | 10 ++++++++++ c/episodelistview.c | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'c') diff --git a/c/defs.h b/c/defs.h index 5dfed69..c5e80c2 100644 --- a/c/defs.h +++ b/c/defs.h @@ -27,6 +27,16 @@ void ElvUpdateItem(LPLVITEM); HWND DlvCreate(); void DlvShowEpisode(int); +inline int +Cmp(int a, int b) +{ + if (a == b) + return 0; + if (a > b) + return 1; + return -1; +} + inline int Dpi(int i) { diff --git a/c/episodelistview.c b/c/episodelistview.c index bd5a28c..21a8e3d 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -193,9 +193,10 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort) lvi1.iItem = iItem1; lvi2.iItem = iItem2; if (!ListView_GetItem(HElv, &lvi1)) return 0; if (!ListView_GetItem(HElv, &lvi2)) return 0; + iOrder = Cmp(iSort, 0); switch (abs(iSort)) { case 1: /* Sort by episode number. */ - iOrder = lvi1.lParam > lvi2.lParam? 1: -1; + return iOrder*Cmp(lvi1.lParam, lvi2.lParam); break; case 2: /* Sort by rating. */ { @@ -211,7 +212,9 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort) PI(t2,lvi2.lParam) goto f; P("episode_data","episode_rating",2,t2) goto f; GI(t2+1,&iRating2); - f: iOrder = iRating1 > iRating2? 1: -1; + f: if (iRating1 == iRating2) + return Cmp(lvi1.lParam, lvi2.lParam); + return iOrder*Cmp(iRating1, iRating2); break; } case 3: /* Sort by title. */ @@ -230,13 +233,12 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort) cch1 = strlen(sz1); cch2 = strlen(sz2); cch = cch1 > cch2? cch2: cch1; - iOrder = _strnicmp(sz1, sz2, cch); + return iOrder*_strnicmp(sz1, sz2, cch); break; } default: return 0; } - return iSort > 0? iOrder: iOrder*-1; } /* Update episode list. */ -- cgit v1.2.3