update timezone gadget
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Wed, 17 Jan 2024 13:33:43 +0000 (14:33 +0100)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Wed, 24 Jan 2024 07:15:28 +0000 (08:15 +0100)
SettingMainGadget/SettingMainGadget/DateTime/DateTimeSetTimezoneGadget.cs
SettingMainGadget/SettingMainGadget/res/allowed/SettingMainGadget/search.svg [new file with mode: 0644]

index e7a1da14a096709812c2404b22180dae139c62c2..89c7a9e20e51140c4ef5a2d4257392c646618cc9 100644 (file)
@@ -1,11 +1,13 @@
 using SettingMainGadget.TextResources;
-using SettingCore.Views;
-using SettingMainGadget.DateTime;
+using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
 using Tizen.NUI.Components;
 using Tizen.System;
+using static SettingMainGadget.DateTime.DateTimeTimezoneManager;
 
 namespace Setting.Menu.DateTime
 {
@@ -13,54 +15,196 @@ namespace Setting.Menu.DateTime
     {
         public override string ProvideTitle() => NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_TIME_ZONE));
 
-        private ScrollableBase content = null;
+        private View content = null;
+        private List<TimeZone> timeZones;
+        private Loading loadingIndicator;
+        private CollectionView collectionView;
 
         protected override View OnCreate()
         {
             base.OnCreate();
 
-            content = new ScrollableBase
+            content = new View
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.MatchParent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                },
+            };
+
+            CreateView();
+
+            return content;
+        }
+
+        private async void CreateView()
+        {
+            var installedAppsContent = new View()
             {
                 WidthSpecification = LayoutParamPolicies.MatchParent,
                 HeightSpecification = LayoutParamPolicies.MatchParent,
-                ScrollingDirection = ScrollableBase.Direction.Vertical,
-                HideScrollbar = false,
                 Layout = new LinearLayout()
                 {
                     LinearOrientation = LinearLayout.Orientation.Vertical,
                 },
             };
 
-            RadioButtonGroup radioButtonGroup = new RadioButtonGroup();
+            await LoadData();
 
-            var timeZones = DateTimeTimezoneManager.GetTimeZones();
-            timeZones = timeZones.OrderBy(a => a.City).ThenBy(x => x.Continent).ToList();
+            content.Add(SearchView());
 
-            foreach (var timeZone in timeZones)
+            collectionView = new CollectionView()
             {
-                RadioButtonListItem item = new RadioButtonListItem(timeZone.DisplayName);
-                item.RadioButton.IsSelected = SystemSettings.LocaleTimeZone == timeZone.Info.Id;
+                ItemsLayouter = new LinearLayouter(),
+                ItemTemplate = new DataTemplate(() =>
+                {
+                    DefaultLinearItem item = new DefaultLinearItem()
+                    {
+                        WidthSpecification = LayoutParamPolicies.MatchParent,
+                    };
+                    item.Label.SetBinding(TextLabel.TextProperty, "DisplayName");
+                    item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
 
-                radioButtonGroup.Add(item.RadioButton);
-                content.Add(item);
+                    return item;
+                }),
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.MatchParent,
+                ScrollingDirection = ScrollableBase.Direction.Vertical,
+                SelectionMode = ItemSelectionMode.SingleAlways,
+            };
+            collectionView.ItemsSource = timeZones;
+
+            var currentTimeZone = timeZones.Where(x => x.Info.Id == SystemSettings.LocaleTimeZone).FirstOrDefault();
+            if(currentTimeZone != null)
+            {
+                collectionView.SelectedItem = currentTimeZone;
             }
 
-            radioButtonGroup.SelectedChanged += (o, e) =>
+            collectionView.SelectionChanged += (s, e) =>
+            {
+                var timeZone = e.CurrentSelection.FirstOrDefault() as TimeZone;
+
+                if(timeZone != null)
+                {
+                    SetTimezone(timeZone.Info.Id);
+                    NavigateBack();
+                }
+            };
+
+            content.Add(collectionView);
+        }
+
+        private async Task LoadData()
+        {
+            loadingIndicator = new Loading();
+            loadingIndicator.Play();
+            content.Add(loadingIndicator);
+
+            await Task.Run(() =>
+            {
+                timeZones = GetTimeZones();
+                timeZones = timeZones.OrderBy(a => a.City).ThenBy(x => x.Continent).ToList();
+            });
+
+            loadingIndicator?.Stop();
+            loadingIndicator?.Unparent();
+            loadingIndicator?.Dispose();
+        }
+
+        private View SearchView()
+        {
+            View searchView = new View()
+            {
+                BackgroundColor = IsLightTheme ? new Color("#FAFAFA") : new Color("#1D1A21"),
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+                Margin = new Extents(16, 16, 0, 2).SpToPx(),
+                SizeHeight = 49.SpToPx(),
+            };
+
+            var textFieldView = new View()
             {
-                DateTimeTimezoneManager.SetTimezone(timeZones[radioButtonGroup.SelectedIndex].Info.Id);
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                Layout = new FlexLayout()
+                {
+                    Justification = FlexLayout.FlexJustification.SpaceBetween,
+                    Direction = FlexLayout.FlexDirection.Row,
+                    ItemsAlignment = FlexLayout.AlignmentType.Center
+                },
             };
 
-            content.Relayout += (s, e) =>
+            var iconVisual = new ImageVisual
             {
-                var timeZone = timeZones.Where(x => x.Info.Id == SystemSettings.LocaleTimeZone).FirstOrDefault();
+                MixColor = IsLightTheme ? new Color("#17234D") : new Color("#FF8A00"),
+                URL = GetResourcePath("search.svg"),
+                FittingMode = FittingModeType.ScaleToFill,
+            };
 
-                if (timeZone != null)
+            var icon = new ImageView
+            {
+                Image = iconVisual.OutputVisualMap,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.MatchParent,
+                Size = new Size(32, 32).SpToPx(),
+            };
+
+            var textField = new TextField
+            {
+                PlaceholderText = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_ST_BODY_SEARCH)),
+                BackgroundColor = IsLightTheme ? new Color("#FAFAFA") : new Color("#1D1A21"),
+                PlaceholderTextColor = IsLightTheme ? new Color("#CACACA") : new Color("#666666"),
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                VerticalAlignment = VerticalAlignment.Center,
+                Margin = new Extents(16, 0, 0, 0).SpToPx(),
+                SizeHeight = 48.SpToPx(),
+                PixelSize = 24.SpToPx(),
+                EnableCursorBlink = true,
+            };
+
+            var input = textField.GetInputMethodContext();
+            input.Activate();
+
+            textField.TouchEvent += (s, e) =>
+            {
+                var state = input.GetInputPanelState();
+
+                if (state == InputMethodContext.State.Hide)
                 {
-                    content.ScrollToIndex(timeZones.IndexOf(timeZone));
+                    input.Activate();
                 }
+
+                return false;
             };
 
-            return content;
+            textField.TextChanged += (s, e) =>
+            {
+                var filtered = timeZones.Where(a => a.DisplayName.Contains(textField.Text)).ToList();
+                collectionView.ItemsSource = filtered;
+            };
+
+            View separator = new View
+            {
+                BackgroundColor = IsLightTheme ? new Color("#FF6200") : new Color("#FF8A00"),
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                SizeHeight = 1.SpToPx(),
+            };
+
+            textFieldView.Add(textField);
+            textFieldView.Add(icon);
+
+            searchView.Add(textFieldView);
+            searchView.Add(separator);
+
+            return searchView;
         }
     }
 }
diff --git a/SettingMainGadget/SettingMainGadget/res/allowed/SettingMainGadget/search.svg b/SettingMainGadget/SettingMainGadget/res/allowed/SettingMainGadget/search.svg
new file mode 100644 (file)
index 0000000..7b51d9e
--- /dev/null
@@ -0,0 +1,4 @@
+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M17 19.3164L18.505 17.9992L24.0311 24.3129C24.3948 24.7284 24.3528 25.3602 23.9372 25.724C23.5216 26.0877 22.8898 26.0457 22.5261 25.6301L17 19.3164Z" fill="white"/>
+<circle cx="14" cy="14" r="6" stroke="white" stroke-width="2"/>
+</svg>