なろうブックマーク分析用ツールのPrism+WinUI3サンプル実装
修订版 | 87e58c084a85279aa2ad83d3cdb09dc632aca535 (tree) |
---|---|
时间 | 2022-08-25 03:24:46 |
作者 | yoshy <yoshy.org.bitbucket@gz.j...> |
Commiter | yoshy |
[MOD] 詳細リストの ViewComparer/ValueComparer をライブラリ側に移動
@@ -1,15 +1,12 @@ | ||
1 | 1 | using CleanAuLait.Core.Log; |
2 | 2 | using CleanAuLait.ObservableCollectionsMod; |
3 | 3 | using NLog; |
4 | -using ObservableCollections; | |
5 | 4 | using Prism.Navigation; |
6 | 5 | using Reactive.Bindings; |
7 | 6 | using Reactive.Bindings.Extensions; |
8 | -using System.Collections.ObjectModel; | |
9 | 7 | using System.ComponentModel; |
10 | 8 | using System.Diagnostics; |
11 | 9 | using System.Reactive.Disposables; |
12 | -using System.Windows.Input; | |
13 | 10 | using TestNarou3.Adaptor.Boundary.Controller; |
14 | 11 | using TestNarou3.Adaptor.Boundary.Gateway.ViewModel; |
15 | 12 | using TestNarou3.Adaptor.Boundary.Gateway.ViewModel.Child; |
@@ -30,8 +27,10 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
30 | 27 | |
31 | 28 | public ReactiveProperty<IBookmarkDetailListRowViewModel> SelectedItem { get; } |
32 | 29 | |
33 | - public INotifyCollectionChangedListSynchronizedSingleView<BookmarkDetailListRow, IBookmarkDetailListRowViewModel> Rows { get; private set; } = null; | |
34 | - private ISortableSynchronizedCoupleView<BookmarkDetailListRow, string, IBookmarkDetailListRowViewModel> SortableRows { get; set; } | |
30 | + public INotifyCollectionChangedListSynchronizedSingleView< | |
31 | + BookmarkDetailListRow, IBookmarkDetailListRowViewModel> Rows { get; private set; } = null; | |
32 | + private ISortableSynchronizedCoupleView< | |
33 | + BookmarkDetailListRow, string, IBookmarkDetailListRowViewModel> SortableRows { get; set; } | |
35 | 34 | |
36 | 35 | public ReactiveCommand CommandOpenBookmark { get; } |
37 | 36 |
@@ -90,7 +89,9 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
90 | 89 | if (this.Source == null) |
91 | 90 | { |
92 | 91 | this.SortableRows = source.Rows |
93 | - .ToSortableSynchronizedCoupleView(r => r.NCode, r => this.vmTranslator.Translate(r, this), new DetailListViewComparer<string>(r => r.Title.Value, true)); | |
92 | + .ToSortableSynchronizedCoupleView( | |
93 | + r => r.NCode, r => this.vmTranslator.Translate(r, this), | |
94 | + new DetailListViewComparer<string>(r => r.Title.Value)); | |
94 | 95 | |
95 | 96 | this.Rows = this.SortableRows |
96 | 97 | .ToSynchronizedSingleView() |
@@ -109,19 +110,23 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
109 | 110 | } |
110 | 111 | } |
111 | 112 | |
112 | - public void SortByViewColumn<TViewColumn>(string tag, Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending) | |
113 | + public void SortByViewColumn<TViewColumn>( | |
114 | + string tag, Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending) | |
113 | 115 | { |
114 | 116 | logger.Trace("Sort: {0}, ascending = {1}", tag, ascending); |
115 | - this.SortableRows.Sort(new DetailListViewComparer<TViewColumn>(selector, ascending)); | |
117 | + this.SortableRows.Sort(this.SortableRows.CreateViewComparer(selector, ascending)); | |
116 | 118 | } |
117 | 119 | |
118 | - public void SortByValueColumn<TValueColumn>(string tag, Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending) | |
120 | + public void SortByValueColumn<TValueColumn>( | |
121 | + string tag, Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending) | |
119 | 122 | { |
120 | 123 | logger.Trace("Sort: {0}, ascending = {1}", tag, ascending); |
121 | - this.SortableRows.Sort(new DetailListValueComparer<TValueColumn>(selector, ascending)); | |
124 | + this.SortableRows.Sort(this.SortableRows.CreateValueComparer(selector, ascending)); | |
122 | 125 | } |
123 | 126 | |
124 | - internal class DetailListViewComparer<TViewColumn> : ViewComparer<string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TViewColumn> | |
127 | + private class DetailListViewComparer<TViewColumn> | |
128 | + : SortableSynchronizedCoupleViewViewComparer< | |
129 | + string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TViewColumn> | |
125 | 130 | { |
126 | 131 | public DetailListViewComparer( |
127 | 132 | Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending = true |
@@ -130,31 +135,9 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
130 | 135 | } |
131 | 136 | } |
132 | 137 | |
133 | - internal class ViewComparer<TKey, T, TView, TViewColumn> : IComparer<(TKey, T, TView)> | |
134 | - { | |
135 | - readonly Func<TView, TViewColumn> selector; | |
136 | - readonly int f; | |
137 | - | |
138 | - public ViewComparer(Func<TView, TViewColumn> selector, bool ascending = true) | |
139 | - { | |
140 | - this.selector = selector; | |
141 | - this.f = ascending ? 1 : -1; | |
142 | - } | |
143 | - | |
144 | - public int Compare((TKey, T, TView) x, (TKey, T, TView) y) | |
145 | - { | |
146 | - int c = Comparer<TViewColumn>.Default.Compare(selector(x.Item3), selector(y.Item3)) * f; | |
147 | - | |
148 | - if (c == 0) | |
149 | - { | |
150 | - c = Comparer<TKey>.Default.Compare(x.Item1, y.Item1) * f; | |
151 | - } | |
152 | - | |
153 | - return c; | |
154 | - } | |
155 | - } | |
156 | - | |
157 | - internal class DetailListValueComparer<TValueColumn> : ValueComparer<string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TValueColumn> | |
138 | + private class DetailListValueComparer<TValueColumn> | |
139 | + : SortableSynchronizedCoupleViewValueComparer< | |
140 | + string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TValueColumn> | |
158 | 141 | { |
159 | 142 | public DetailListValueComparer( |
160 | 143 | Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending = true |
@@ -163,30 +146,6 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
163 | 146 | } |
164 | 147 | } |
165 | 148 | |
166 | - internal class ValueComparer<TKey, T, TView, TValueColumn> : IComparer<(TKey, T, TView)> | |
167 | - { | |
168 | - readonly Func<T, TValueColumn> selector; | |
169 | - readonly int f; | |
170 | - | |
171 | - public ValueComparer(Func<T, TValueColumn> selector, bool ascending = true) | |
172 | - { | |
173 | - this.selector = selector; | |
174 | - this.f = ascending ? 1 : -1; | |
175 | - } | |
176 | - | |
177 | - public int Compare((TKey, T, TView) x, (TKey, T, TView) y) | |
178 | - { | |
179 | - int c = Comparer<TValueColumn>.Default.Compare(selector(x.Item2), selector(y.Item2)) * f; | |
180 | - | |
181 | - if (c == 0) | |
182 | - { | |
183 | - c = Comparer<TKey>.Default.Compare(x.Item1, y.Item1) * f; | |
184 | - } | |
185 | - | |
186 | - return c; | |
187 | - } | |
188 | - } | |
189 | - | |
190 | 149 | #endregion |
191 | 150 | |
192 | 151 | #region IDestructible, IDisposable |
@@ -213,7 +172,6 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel | ||
213 | 172 | |
214 | 173 | public void Dispose() |
215 | 174 | { |
216 | - // このコードを変更しないでください。クリーンアップ コードを 'Dispose(bool disposing)' メソッドに記述します | |
217 | 175 | Dispose(disposing: true); |
218 | 176 | GC.SuppressFinalize(this); |
219 | 177 | } |