1 /* Copyright (c) 2021 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using System.Collections;
18 using System.Collections.Generic;
19 using System.Collections.Specialized;
20 //using AndroidX.RecyclerView.Widget; ??? need to find whot it needs? adapter?
22 namespace Tizen.NUI.Components
24 internal static class ItemsSourceFactory
26 public static IItemSource Create(IEnumerable itemsSource, ICollectionChangedNotifier notifier)
28 if (itemsSource == null)
30 return new EmptySource();
35 case IList list when itemsSource is INotifyCollectionChanged:
36 return new ObservableItemSource(new MarshalingObservableCollection(list), notifier);
37 case IEnumerable _ when itemsSource is INotifyCollectionChanged:
38 return new ObservableItemSource(itemsSource, notifier);
39 case IEnumerable<object> generic:
40 return new ListSource(generic);
43 return new ListSource(itemsSource);
46 public static IItemSource Create(RecyclerView recyclerView)
48 return Create(recyclerView.ItemsSource, recyclerView);
51 public static IGroupableItemSource Create(CollectionView colView)
53 var source = colView.ItemsSource;
55 if (colView.IsGrouped && source != null)
56 return new ObservableGroupedSource(colView, colView);
59 return new UngroupedItemSource(Create(colView.ItemsSource, colView));