Locations Page implementation 53/173753/4
authorPaweł Kupiecki <p.kupiecki@partner.samsung.com>
Fri, 23 Mar 2018 14:33:33 +0000 (15:33 +0100)
committerPaweł Kupiecki <p.kupiecki@partner.samsung.com>
Wed, 28 Mar 2018 10:28:11 +0000 (12:28 +0200)
OAPSAN-503
Design & Implement LocationsPage
Extended navigations NavigateBack methods to initialize last page.

Change-Id: I89cbe481271ac60295519c72c14ef99e5301d487

18 files changed:
Clock/Clock.Tizen.Mobile/Clock.Tizen.Mobile.csproj
Clock/Clock.Tizen.Mobile/Clock.xaml
Clock/Clock.Tizen.Mobile/Clock.xaml.cs
Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml [new file with mode: 0644]
Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml.cs [new file with mode: 0644]
Clock/Clock.Tizen.Mobile/Controls/TimeLabel.cs
Clock/Clock.Tizen.Mobile/Factory/ViewModelFactory.cs
Clock/Clock.Tizen.Mobile/Services/ViewModelLocator.cs
Clock/Clock.Tizen.Mobile/Views/MainView.xaml
Clock/Clock.Tizen.Mobile/Views/WorldClockPage.xaml [moved from Clock/Clock.Tizen.Mobile/Views/WorldClockView.xaml with 62% similarity]
Clock/Clock.Tizen.Mobile/Views/WorldClockPage.xaml.cs [new file with mode: 0644]
Clock/Clock.Tizen.Mobile/Views/WorldClockView.xaml.cs [deleted file]
Clock/Clock/ViewModels/LocationViewModel.cs [new file with mode: 0644]
Clock/Clock/ViewModels/WorldClockViewModel.cs
Navigation.Tools/Navigation/Interfaces/INavigationService.cs
Navigation.Tools/Navigation/NavigationService.cs
clock/Clock/Tools/Converters/ClockLocationToDayMonthConverter.cs
clock/Clock/Tools/Converters/ClockLocationToOffsetConverter.cs

index acb13f3..51a6817 100644 (file)
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Compile Update="Controls\GmtTimeLabel.xaml.cs">
+      <DependentUpon>GmtTimeLabel.xaml</DependentUpon>
+    </Compile>
+    <Compile Update="Views\WorldClockPage.xaml.cs">
+      <DependentUpon>WorldClockPage.xaml</DependentUpon>
+    </Compile>
     <Compile Update="Controls\AmPmChooser.xaml.cs">
       <DependentUpon>AmPmChooser.xaml</DependentUpon>
     </Compile>
     <EmbeddedResource Update="Controls\Lists\MultiSelectList.xaml">
       <Generator>MSBuild:Compile</Generator>
     </EmbeddedResource>
+    <EmbeddedResource Update="Controls\GmtTimeLabel.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Update="Views\AddAlarmPage.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
     <EmbeddedResource Update="Controls\TimeSelector.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
     <EmbeddedResource Update="Views\TimerView.xaml">
       <Generator>MSBuild:Compile</Generator>
     </EmbeddedResource>
-    <EmbeddedResource Update="Views\WorldClockView.xaml">
+    <EmbeddedResource Update="Views\WorldClockPage.xaml">
       <Generator>MSBuild:Compile</Generator>
     </EmbeddedResource>
   </ItemGroup>
index 8aa9b1a..71b8d32 100644 (file)
@@ -2,12 +2,37 @@
 <Application x:Class="Clock.App"
              xmlns="http://xamarin.com/schemas/2014/forms" 
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
-             xmlns:services="clr-namespace:Clock.Tizen.Mobile.Services;assembly=Clock.Tizen.Mobile">
+             xmlns:services="clr-namespace:Clock.Tizen.Mobile.Services;assembly=Clock.Tizen.Mobile"
+             xmlns:controls="clr-namespace:Clock.Tizen.Mobile.Controls;assembly=Clock.Tizen.Mobile"
+             xmlns:converters="clr-namespace:Clock.Tools.Converters;assembly=Clock">
     <Application.Resources>
         <ResourceDictionary>
             <x:Boolean x:Key="FalseValue">False</x:Boolean>
             <x:Boolean x:Key="TrueValue">True</x:Boolean>
+            <converters:ClockLocationToDayMonthConverter x:Key="ClockLocationToDayMonthConverter"/>
+            <converters:ClockLocationToOffsetConverter x:Key="ClockLocationToOffsetConverter"/>
             <services:ViewModelLocator x:Key="ViewModelLocator"/>
+            <DataTemplate x:Key="LocationViewCellTemplate" x:Name="LocationViewCellTemplate">
+                <ViewCell>
+                    <AbsoluteLayout HeightRequest="144">
+                        <controls:GmtTimeLabel AbsoluteLayout.LayoutBounds="0.06, 0.2, 0.24, 0.45"
+                                                AbsoluteLayout.LayoutFlags="All"
+                                                GmtMinutesOffset="{Binding GmtMinutesOffset}"/>
+                        <Label AbsoluteLayout.LayoutBounds="0.06, 0.76, 0.24, 0.27"
+                                   AbsoluteLayout.LayoutFlags="All"
+                                   Text="{Binding GmtMinutesOffset, Converter={StaticResource ClockLocationToDayMonthConverter}}"
+                                   FontSize="16" TextColor="Gray" />
+                        <Label AbsoluteLayout.LayoutBounds="0.91, 0.23, 0.56, 0.35"
+                                   AbsoluteLayout.LayoutFlags="All"
+                                   Text="{Binding Name}"
+                                   FontSize="24" TextColor="Black" />
+                        <Label AbsoluteLayout.LayoutBounds="0.91, 0.70, 0.56, 0.29"
+                                   AbsoluteLayout.LayoutFlags="All"
+                                   Text="{Binding GmtMinutesOffset, Converter={StaticResource ClockLocationToOffsetConverter}}"
+                                   FontSize="18" TextColor="Gray" />
+                    </AbsoluteLayout>
+                </ViewCell>
+            </DataTemplate>
         </ResourceDictionary>
     </Application.Resources>
 </Application>
\ No newline at end of file
index ed4a8d3..b8181de 100644 (file)
@@ -4,6 +4,7 @@ using System.IO;
 using Clock.Abstractions;
 using Clock.Abstractions.Repositories;
 using Clock.Data;
+using Clock.Services;
 using Clock.Tizen.Mobile.Factory;
 using Clock.Tizen.Mobile.Navigation;
 using Clock.Tizen.Mobile.Repositories;
@@ -25,7 +26,7 @@ namespace Clock
     {
         private UnityContainer _ioCContainer;
 
-        public const string Tag = "d";
+        public const string Tag = "clock";
 
         public string ApplicationId { get; set; }
 
@@ -59,8 +60,7 @@ namespace Clock
         private void ConfigureIoCContainer()
         {
             _ioCContainer.RegisterType<IAlarmRepository, AlarmsRepository>(
-                new InjectionConstructor(
-                    Path.Combine(TizenApp.Current.DirectoryInfo.Data, ClockSettings.CLOCK_DATABASE_FILENAME),
+                new InjectionConstructor(Path.Combine(TizenApp.Current.DirectoryInfo.Data, ClockSettings.CLOCK_DATABASE_FILENAME),
                     typeof(ILogger)));
             _ioCContainer.RegisterType<ILocationsRepository, LocationsRepository>(
                 new InjectionConstructor(Path.Combine(TizenApp.Current.DirectoryInfo.Data, ClockSettings.CLOCK_DATABASE_FILENAME),
@@ -70,11 +70,11 @@ namespace Clock
             _ioCContainer.RegisterType<ILogger, TizenLogger>(new InjectionConstructor(Tag));
             _ioCContainer.RegisterType<IPageFactory, PageFactory>(new SingletonLifetimeManager());
             _ioCContainer.RegisterType<ISystemSettings, SystemSettings>();
-
+            _ioCContainer.RegisterType<ILocationsManager, LocationsManager>(new SingletonLifetimeManager());
+            _ioCContainer.RegisterType<ITimeZonePickerService, TizenTimeZonePickerService>();
             _ioCContainer.RegisterType<INavigationService, ClockNavigationService>(
                 new SingletonLifetimeManager(),
                 new InjectionConstructor(MainPage.Navigation, typeof(IPageFactory)));
-
             _ioCContainer.RegisterType<AlarmManager>(new InjectionConstructor(
                 typeof(IPlatformAlarmsService),
                 typeof(IAlarmRepository),
diff --git a/Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml b/Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml
new file mode 100644 (file)
index 0000000..d472a40
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="Clock.Tizen.Mobile.Controls.GmtTimeLabel"
+             xmlns:controls="clr-namespace:Clock.Tizen.Mobile.Controls;assembly=Clock.Tizen.Mobile">
+    <ContentView.Content>
+        <AbsoluteLayout>
+            <controls:CustomStyleLabel x:Name="Time"
+                                       AbsoluteLayout.LayoutBounds="0,0,0.65,1"
+                                       AbsoluteLayout.LayoutFlags="All"
+                                       CustomStyle="Light"
+                                       HorizontalTextAlignment="End" 
+                                       VerticalTextAlignment="Start" 
+                                       TextColor="Black"
+                                       Font="48"/>
+            <controls:CustomStyleLabel x:Name="PmAm"
+                                       AbsoluteLayout.LayoutBounds="1,1,0.3,0.59"
+                                       AbsoluteLayout.LayoutFlags="All"
+                                       CustomStyle="Medium" 
+                                       HorizontalTextAlignment="Start" 
+                                       VerticalTextAlignment="Start" 
+                                       Font="22"
+                                       TextColor="Black"/>
+        </AbsoluteLayout>
+    </ContentView.Content>
+</ContentView>
\ No newline at end of file
diff --git a/Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml.cs b/Clock/Clock.Tizen.Mobile/Controls/GmtTimeLabel.xaml.cs
new file mode 100644 (file)
index 0000000..ddefb46
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+* Copyright 2018  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+using System.Text;
+using System.Threading.Tasks;
+using Clock.Tizen.Mobile.Tools;
+using Tizen;
+using Tizen.System;
+using Xamarin.Forms;
+
+namespace Clock.Tizen.Mobile.Controls
+{
+    public partial class GmtTimeLabel : ContentView, IVisibleAware
+    {
+        public GmtTimeLabel()
+        {
+            InitializeComponent();
+            this.SetVisibleAware(Appearing, Disappearing);
+        }
+
+        private bool _is24HourClockEnabled;
+        private void LocaleTimeFormat24HourSettingChanged(object sender, LocaleTimeFormat24HourSettingChangedEventArgs e)
+        {
+            _is24HourClockEnabled = e.Value;
+            UpdateTime();
+        }
+        #region Inner classes
+
+        class MinutesTicker
+        {
+            public event Action Tick;
+
+            public MinutesTicker()
+            {
+                int dueTime = (60 - DateTime.Now.Second) * 1000;
+                StartTimer(dueTime, 60 * 1000);
+            }
+
+            private async void StartTimer(int delay, int interval)
+            {
+                await Task.Delay(delay);
+                Device.StartTimer(TimeSpan.FromMilliseconds(interval), OnElapsed);
+            }
+
+            private bool OnElapsed()
+            {
+                Tick?.Invoke();
+                return true;
+            }
+        }
+
+        #endregion
+
+        static int timerCount = 0;
+        private static MinutesTicker _ticker = new MinutesTicker();
+
+        public int GmtMinutesOffset
+        {
+            get { return (int)GetValue(GmtMinutesOffsetProperty); }
+            set { SetValue(GmtMinutesOffsetProperty, value); }
+        }
+
+        public static readonly BindableProperty GmtMinutesOffsetProperty =
+            BindableProperty.Create(nameof(GmtMinutesOffset), typeof(int), typeof(GmtTimeLabel), default(int)
+                , BindingMode.TwoWay, propertyChanged: UpdateTimeOnChanged);
+
+
+        private static void UpdateTimeOnChanged(BindableObject bindable, object oldValue, object newValue)
+        {
+            if (bindable is GmtTimeLabel timeLabel)
+            {
+                timeLabel.UpdateTime();
+            }
+        }
+
+        public VisualState VisualState { get; set; }
+
+        private void Appearing()
+        {
+            _is24HourClockEnabled = SystemSettings.LocaleTimeFormat24HourEnabled;
+            SystemSettings.LocaleTimeFormat24HourSettingChanged += LocaleTimeFormat24HourSettingChanged;
+            UpdateTime();
+            _ticker.Tick -= UpdateTime;
+            _ticker.Tick += UpdateTime;
+        }
+
+        private void Disappearing()
+        {
+            SystemSettings.LocaleTimeFormat24HourSettingChanged -= LocaleTimeFormat24HourSettingChanged;
+            _ticker.Tick -= UpdateTime;
+        }
+
+        private void UpdateTime()
+        {
+            var time = DateTime.Now.AddMinutes(GmtMinutesOffset);
+            StringBuilder amPm = new StringBuilder();
+            amPm.Append(time.ToString("tt").ToLower());
+            amPm.Insert(1, ".");
+            amPm.Append(".");
+
+            Time.Text = time.ToString(_is24HourClockEnabled ? "H:mm" : "h:mm");
+            PmAm.Text = _is24HourClockEnabled ? "" : amPm.ToString();
+        }
+
+    }
+}
\ No newline at end of file
index 11a6b7d..d5d7e78 100644 (file)
@@ -6,12 +6,19 @@ using System.Threading;
 using System.Threading.Tasks;
 using Clock.Tizen.Mobile.Tools;
 using Tizen;
+using Tizen.System;
 using Xamarin.Forms;
 
 namespace Clock.Tizen.Mobile.Controls
 {
     public class TimeLabel : Label, IVisibleAware
     {
+        private bool _is24HourClockEnabled;
+        private void LocaleTimeFormat24HourSettingChanged(object sender, LocaleTimeFormat24HourSettingChangedEventArgs e)
+        {
+            _is24HourClockEnabled = e.Value;
+            UpdateTime();
+        }
         #region Inner classes
 
         class MinutesTicker
@@ -55,12 +62,11 @@ namespace Clock.Tizen.Mobile.Controls
 
         public static readonly BindableProperty GmtMinutesOffsetProperty =
             BindableProperty.Create(nameof(GmtMinutesOffset), typeof(int), typeof(TimeLabel), default(int)
-                , BindingMode.TwoWay, propertyChanged: OnOffsetChanged);
+                , BindingMode.TwoWay, propertyChanged: UpdateTimeOnChanged);
 
-        private static void OnOffsetChanged(BindableObject bindable, object oldValue, object newValue)
+        private static void UpdateTimeOnChanged(BindableObject bindable, object oldValue, object newValue)
         {
-            var timeLabel = bindable as TimeLabel;
-            if (timeLabel != null)
+            if (bindable is TimeLabel timeLabel)
             {
                 timeLabel.UpdateTime();
             }
@@ -70,6 +76,8 @@ namespace Clock.Tizen.Mobile.Controls
 
         private void StartTimer()
         {
+            _is24HourClockEnabled = SystemSettings.LocaleTimeFormat24HourEnabled;
+            SystemSettings.LocaleTimeFormat24HourSettingChanged += LocaleTimeFormat24HourSettingChanged;
             UpdateTime();
             _ticker.Tick -= UpdateTime;
             _ticker.Tick += UpdateTime;
@@ -77,13 +85,13 @@ namespace Clock.Tizen.Mobile.Controls
 
         private void StopTimer()
         {
+            SystemSettings.LocaleTimeFormat24HourSettingChanged -= LocaleTimeFormat24HourSettingChanged;
             _ticker.Tick -= UpdateTime;
-            Log.Debug("default", "stop Timer " + timerCount.ToString());
         }
 
         private void UpdateTime()
         {
-            Text = string.Format("{0:h:mm}", DateTime.Now.AddMinutes(GmtMinutesOffset));
+            Text = DateTime.Now.AddMinutes(GmtMinutesOffset).ToString(_is24HourClockEnabled ? "H:mm" : "h:mm tt");
         }
     }
 }
\ No newline at end of file
index ea01bf7..ef95422 100644 (file)
@@ -19,6 +19,9 @@ using Clock.Services;
 using Clock.ViewModels;
 using CommonServiceLocator;
 using Navigation.Tools.Navigation.Interfaces;
+using System;
+using Tizen;
+
 
 namespace Clock.Tizen.Mobile.Factory
 {
@@ -39,6 +42,26 @@ namespace Clock.Tizen.Mobile.Factory
                 ServiceLocator.Current.GetInstance<ISystemSettings>());
         }
 
+        public static WorldClockViewModel CreateWorldClockViewModel()
+        {
+            WorldClockViewModel result;
+            try
+            {
+                result = new WorldClockViewModel(ServiceLocator.Current.GetInstance<INavigationService>(),
+                ServiceLocator.Current.GetInstance<ITimeZonePickerService>(),
+                ServiceLocator.Current.GetInstance<ILocationsManager>(),
+                ServiceLocator.Current.GetInstance<ILogger>());
+
+            }
+            catch (Exception ex)
+            {
+                Log.Debug("clock", ex.StackTrace);
+                throw;
+            }
+
+            return result;
+        }
+
         public static AddAlarmViewModel CreateAddAlarmViewModel()
         {
             return new AddAlarmViewModel(ServiceLocator.Current.GetInstance<INavigationService>());
index effb9ff..7b704fe 100644 (file)
@@ -21,5 +21,6 @@ namespace Clock.Tizen.Mobile.Services
     public class ViewModelLocator
     {
         public object AlarmListViewModel => ViewModelFactory.CreateAlarmListPageViewModel();
+        public object WorldClockViewModel => ViewModelFactory.CreateWorldClockViewModel();
     }
 }
\ No newline at end of file
index 7d08c9c..33650e4 100644 (file)
         <pages:AlarmListPage Title="Alarm"
                              Icon="tabs/clock_tabs_ic_alarm.png" />
 
-        <ContentPage Title="World clock"
-                     Icon="tabs/clock_tabs_ic_worldclock.png">
-            <StackLayout>
-                <Label Text="World Clock Stub" />
-            </StackLayout>
-        </ContentPage>
+        <pages:WorldClockPage  Title="World clock"
+                     Icon="tabs/clock_tabs_ic_worldclock.png"/>
 
         <ContentPage Title="Stopwatch"
                      Icon="tabs/clock_tabs_ic_stopwatch.png">
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
-
-<ContentPage x:Class="Clock.Tizen.Mobile.Views.WorldClockView"
+<ContentPage x:Class="Clock.Tizen.Mobile.Views.WorldClockPage"
              xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:controls="clr-namespace:Clock.Tizen.Mobile.Controls;assembly=Clock.Tizen.Mobile"
              xmlns:converters="clr-namespace:Clock.Tools.Converters;assembly=Clock"
              xmlns:popup="clr-namespace:Clock.Tizen.Mobile.Controls.Popup"
              xmlns:mvvm="clr-namespace:Clock.Mvvm;assembly=Clock"
+             BindingContext="{Binding Path=WorldClockViewModel, Source={StaticResource ViewModelLocator}}"
              x:Name="root">
     <ContentPage.Resources>
         <ResourceDictionary>
                AbsoluteLayout.LayoutBounds="0, 1, 1, 0.38" AbsoluteLayout.LayoutFlags="All"
                VerticalTextAlignment="Center" HorizontalTextAlignment="Center" VerticalOptions="Center"
                HorizontalOptions="Center"
-               IsVisible="{Binding HandPickedPlaces, Converter={StaticResource CollectionToFalseConverter}}" />
-
-        <ListView ItemsSource="{Binding HandPickedPlaces}" AbsoluteLayout.LayoutBounds="0, 1, 1, 0.38"
+               IsVisible="{Binding Locations, Converter={StaticResource CollectionToFalseConverter}}" />
+        <ListView x:Name="LocationsList" ItemsSource="{Binding Locations}" AbsoluteLayout.LayoutBounds="0, 1, 1, 0.38"
                   AbsoluteLayout.LayoutFlags="All"
                   SelectedItem="{Binding SelectedLocation, Mode=OneWayToSource}" RowHeight="150"
-                  IsVisible="{Binding HandPickedPlaces, Converter={StaticResource CollectionToBooleanConverter}}"
-                  x:Name="listView">
-            <ListView.ItemTemplate>
-                <DataTemplate>
-                    <ViewCell>
-                        <AbsoluteLayout>
-                            <StackLayout AbsoluteLayout.LayoutBounds="0.06, 0.2, 0.24, 0.45"
-                                         AbsoluteLayout.LayoutFlags="All"
-                                         Orientation="Horizontal">
-                                <controls:TimeLabel GmtMinutesOffset="{Binding GmtMinutesOffset}" FontSize="24"
-                                                    VerticalTextAlignment="Center" HorizontalTextAlignment="End"
-                                                    VerticalOptions="EndAndExpand" />
-                                <Label Text="{Binding ., Converter={StaticResource LocationToPmDesignationConverter}}"
-                                       FontSize="18" TextColor="Black" Margin="4,0,0,4"
-                                       VerticalTextAlignment="Center" HorizontalTextAlignment="Center"
-                                       VerticalOptions="EndAndExpand" />
-                            </StackLayout>
-                            <Label AbsoluteLayout.LayoutBounds="0.06, 0.76, 0.24, 0.27"
-                                   AbsoluteLayout.LayoutFlags="All"
-                                   Text="{Binding ., Converter={StaticResource ClockLocationToDayMonthConverter}}"
-                                   FontSize="16" TextColor="Gray" />
-                            <Label AbsoluteLayout.LayoutBounds="0.91, 0.23, 0.56, 0.35"
-                                   AbsoluteLayout.LayoutFlags="All"
-                                   Text="{Binding ., Converter={StaticResource ClockLocationToPlaceConverter}}"
-                                   FontSize="24" TextColor="Black" />
-                            <Label AbsoluteLayout.LayoutBounds="0.91, 0.70, 0.56, 0.29"
-                                   AbsoluteLayout.LayoutFlags="All"
-                                   Text="{Binding ., Converter={StaticResource ClockLocationToOffsetConverter}, ConverterParameter='full'}"
-                                   FontSize="18" TextColor="Gray" />
-                        </AbsoluteLayout>
-                    </ViewCell>
-                </DataTemplate>
-            </ListView.ItemTemplate>
+                  IsVisible="{Binding Locations, Converter={StaticResource CollectionToBooleanConverter}}"
+                  ItemTemplate="{StaticResource LocationViewCellTemplate}">
         </ListView>
-
-        <controls:FloatingButton AbsoluteLayout.LayoutBounds="1, 0.93, 1, 0.11" AbsoluteLayout.LayoutFlags="All"
+        <controls:FloatingButton AbsoluteLayout.LayoutBounds="1, 0.93, 1, 0.11"
+                                 AbsoluteLayout.LayoutFlags="All"
                                  Command="{Binding AddCommand}" />
     </AbsoluteLayout>
 </ContentPage>
\ No newline at end of file
diff --git a/Clock/Clock.Tizen.Mobile/Views/WorldClockPage.xaml.cs b/Clock/Clock.Tizen.Mobile/Views/WorldClockPage.xaml.cs
new file mode 100644 (file)
index 0000000..9790d88
--- /dev/null
@@ -0,0 +1,34 @@
+using Navigation.Tools.Navigation.Interfaces;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Xamarin.Forms;
+using Tizen;
+
+namespace Clock.Tizen.Mobile.Views
+{
+    public partial class WorldClockPage : ContentPage, INavigationServiceAware
+    {
+        public WorldClockPage()
+        {
+            InitializeComponent();
+        }
+
+        public void DeInitialize()
+        {
+            (BindingContext as INavigationServiceAware)?.DeInitialize();
+        }
+
+        public void Initialize(object parameters)
+        {
+            Initialize();
+        }
+
+        public void Initialize()
+        {
+            (BindingContext as INavigationServiceAware)?.Initialize();
+        }
+    }
+}
\ No newline at end of file
diff --git a/Clock/Clock.Tizen.Mobile/Views/WorldClockView.xaml.cs b/Clock/Clock.Tizen.Mobile/Views/WorldClockView.xaml.cs
deleted file mode 100644 (file)
index 6779fd9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Xamarin.Forms;
-
-namespace Clock.Tizen.Mobile.Views
-{
-    public partial class WorldClockView : ContentPage
-    {
-        public WorldClockView()
-        {
-            InitializeComponent();
-        }
-    }
-}
\ No newline at end of file
diff --git a/Clock/Clock/ViewModels/LocationViewModel.cs b/Clock/Clock/ViewModels/LocationViewModel.cs
new file mode 100644 (file)
index 0000000..ad21492
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+* Copyright 2018  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using Clock.Model;
+using Navigation.Tools.Navigation.ViewModels;
+using System;
+using System.Text;
+
+namespace Clock.ViewModels
+{
+    /// <summary>
+    /// Location ViewModel
+    /// </summary>
+    public class LocationViewModel : ViewModelBase, IEquatable<LocationViewModel>
+    {
+        /// <summary>
+        /// Location model.
+        /// </summary>
+        public Location Model { get; }
+        /// <summary>
+        /// LocationViewModel
+        /// </summary>
+        /// <param name="model">Location model</param>
+        public LocationViewModel(Location model)
+        {
+            Model = model;
+        }
+        /// <summary>
+        /// Name
+        /// </summary>
+        public string Name
+        {
+            get => $"{Model.City}, {Model.Country}";
+        }
+        /// <summary>
+        /// Gmt minutes offset
+        /// </summary>
+        public int GmtMinutesOffset => Model.GmtMinutesOffset;
+
+        public bool Equals(LocationViewModel other)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}
index dca9dfb..265fe8a 100644 (file)
@@ -2,6 +2,7 @@
 using Clock.Model;
 using Clock.Tools;
 using Clock.Tools.Comparers;
+using Navigation.Tools.Navigation.Interfaces;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -18,7 +19,7 @@ namespace Clock.ViewModels
 {
     public delegate Task<IEnumerable<ClockLocation>> NavigateToPlaces(IEnumerable<ClockLocation> locations);
 
-    public class WorldClockViewModel : INotifyPropertyChanged
+    public class WorldClockViewModel : NavigationServiceAwareViewModel
     {
         private readonly ITimeZonePickerService _timeZoneService;
 
@@ -33,27 +34,21 @@ namespace Clock.ViewModels
         private NavigateToPlaces _navigateToReordering = null;
         private List<MenuCommand> _menuCommands = null;
         private ILogger _logger = null;
-        private ObservableCollection<ClockLocation> _handPickedPlaces = null;
+        private readonly ISystemSettings _settings;
+        private ObservableCollection<LocationViewModel> _locations = null;
 
-        public WorldClockViewModel(ITimeZonePickerService timeZoneService, ILocationsManager locationsManager, ILogger logger)
+        public WorldClockViewModel(INavigationService navigationService, ITimeZonePickerService timeZoneService, ILocationsManager locationsManager, ILogger logger)
+            :base(navigationService)
         {
             _timeZoneService = timeZoneService;
             _locationsManager = locationsManager;
             _logger = logger;
-        }
-
-        public WorldClockViewModel(IAppControl appControl, NavigateToPlaces navigateToDeleting,
-            NavigateToPlaces navigateToReordering, ILogger logger)
-        {
-            _logger = logger;
-            _appControl = appControl;
-            _navigateToDeleting = navigateToDeleting;
-            _navigateToReordering = navigateToReordering;
             _timezones = new Timezones(ClockLocation.Locations, GetInitialLocation());
             AddCommand = new Command(Add);
             MoveRightCommand = new Command(MoveTimezoneRight);
             MoveLeftCommand = new Command(MoveTimezoneLeft);
-        }
+            _locations = new ObservableCollection<LocationViewModel>();
+        }        
 
         public ICommand AddCommand { get; set; }
 
@@ -67,7 +62,7 @@ namespace Clock.ViewModels
             {
                 if (_menuCommands == null)
                 {
-                    HandPickedPlaces.CollectionChanged += (s, e) =>
+                    Locations.CollectionChanged += (s, e) =>
                     {
                         UpdateMenu();
                         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuCommands)));
@@ -91,25 +86,7 @@ namespace Clock.ViewModels
             }
         }
 
-        public ObservableCollection<ClockLocation> HandPickedPlaces
-        {
-            get
-            {
-                if (_handPickedPlaces == null)
-                {
-                    _handPickedPlaces = new ObservableCollection<ClockLocation>();
-                    _handPickedPlaces.CollectionChanged += (s, e) =>
-                    {
-                        if (IsBecomingEmptyOrNotEmpty(e.Action, _handPickedPlaces))
-                        {
-                            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HandPickedPlaces)));
-                        }
-                    };
-                }
-
-                return _handPickedPlaces;
-            }
-        }
+        public ObservableCollection<LocationViewModel> Locations => _locations;
 
         public ClockLocation Location
         {
@@ -145,31 +122,16 @@ namespace Clock.ViewModels
 
         public async Task NavigateToDeletingPlaces()
         {
-            IEnumerable<ClockLocation> locations = await _navigateToDeleting.Invoke(HandPickedPlaces);
-            if (locations != null)
-            {
-                foreach (var item in locations)
-                {
-                    HandPickedPlaces.Remove(item);
-                }
-            }
-
             _logger?.Debug("After delete");
         }
 
         public async Task NavigateToReorderingPlaces()
         {
-            await _navigateToReordering(HandPickedPlaces);
             _logger?.Debug("After reordering");
         }
 
         private void OnLocationsResult(ClockLocation location)
         {
-            Location = location;
-            if (HandPickedPlaces.Contains(location, ClockLocationEqualityComparer.Instance) == false)
-            {
-                HandPickedPlaces.Add(location);
-            }
         }
 
         private void MoveTimezoneRight()
@@ -209,11 +171,11 @@ namespace Clock.ViewModels
 
         private void UpdateMenu()
         {
-            if (HandPickedPlaces == null || HandPickedPlaces.Count() == 0)
+            if (Locations == null || Locations.Count() == 0)
             {
                 _menuCommands = SetMenuForNoPlaces();
             }
-            else if (HandPickedPlaces.Count() == 1)
+            else if (Locations.Count() == 1)
             {
                 _menuCommands = SetMenuForOnePlace();
             }
@@ -229,5 +191,18 @@ namespace Clock.ViewModels
             return collectionAction == NotifyCollectionChangedAction.Add && collection.Count() == 1
                    || collectionAction == NotifyCollectionChangedAction.Remove && collection.Count() == 0;
         }
+
+        public override void Initialize()
+        {
+            base.Initialize();
+            _locations.Clear();
+            var results = _locationsManager.GetAll().Select(x => new LocationViewModel(x));
+            foreach(var item in results)
+            {
+                _locations.Add(item);
+            }
+
+            OnPropertyChanged(nameof(Locations));
+        }
     }
 }
\ No newline at end of file
index e6e53fb..2fb0cfd 100644 (file)
@@ -39,5 +39,16 @@ namespace Navigation.Tools.Navigation.Interfaces
         /// The <see cref="Task"/>.
         /// </returns>
         Task NavigateBack();
+        /// <summary>
+        /// Navigates back and initializes previous page with its binding context.
+        /// </summary>
+        /// <returns>Task</returns>
+        Task NavigateBackAndInitialize();
+        /// <summary>
+        /// Navigates back and initializes previous page with its binding context.
+        /// </summary>
+        /// <param name="parameters">Prameters to be passed to initialization methods after back.</param>
+        /// <returns>Task</returns>
+        Task NavigateBackAndInitialize(object parameters);
     }
 }
index 265894c..0cd7603 100644 (file)
@@ -92,7 +92,26 @@ namespace Navigation.Tools.Navigation
         {
             (CurrentPage as INavigationServiceAware)?.DeInitialize();
             (CurrentPage.BindingContext as INavigationServiceAware)?.DeInitialize();
-            await this._navigation.PopAsync();
+            await _navigation.PopAsync();
+        }
+        /// <summary>
+        /// Navigate Back And Initialize
+        /// </summary>
+        /// <returns>Task</returns>
+        public async Task NavigateBackAndInitialize()
+        {
+            await NavigateBack();
+            InitializePage(CurrentPage);
+        }
+        /// <summary>
+        /// Navigate Back And Initialize
+        /// </summary>
+        /// <param name="parameters">Parameters.</param>
+        /// <returns>Task</returns>
+        public async Task NavigateBackAndInitialize(object parameters)
+        {
+            await NavigateBack();
+            InitializePage(CurrentPage, parameters);
         }
 
         /// <summary>
@@ -134,5 +153,17 @@ namespace Navigation.Tools.Navigation
             (page as INavigationServiceAware)?.Initialize(parameters);
             (page.BindingContext as INavigationServiceAware)?.Initialize(parameters);
         }
+
+        protected virtual void InitializePage(Page page, object parameters)
+        {
+            (page as INavigationServiceAware)?.Initialize(parameters);
+            (page.BindingContext as INavigationServiceAware)?.Initialize(parameters);
+        }
+
+        protected virtual void InitializePage(Page page)
+        {
+            (page as INavigationServiceAware)?.Initialize();
+           (page.BindingContext as INavigationServiceAware)?.Initialize();
+        }
     }
 }
index 9c1b825..ace72f5 100644 (file)
@@ -14,12 +14,16 @@ namespace Clock.Tools.Converters
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             StringBuilder builder = new StringBuilder();
-            var location = value as ClockLocation;
-            var time = DateTime.Now.AddMinutes(location?.GmtMinutesOffset ?? 0);
-            return string.Format("{0}, {1} {2}"
-                , time.DayOfWeek.ToString().Substring(0, 3)
-                , time.Day
-                , culture.DateTimeFormat.GetMonthName(time.Month).Substring(0, 3));
+            if(value is int gmtOffset)
+            {
+                var time = DateTime.Now.AddMinutes(gmtOffset);
+                return string.Format("{0}, {1} {2}"
+                    , time.DayOfWeek.ToString().Substring(0, 3)
+                    , time.Day
+                    , culture.DateTimeFormat.GetMonthName(time.Month).Substring(0, 3));
+            }
+
+            return string.Empty;
         }
 
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
index 604378b..3ae7911 100644 (file)
@@ -14,24 +14,28 @@ namespace Clock.Tools.Converters
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             StringBuilder builder = new StringBuilder();
-            ClockLocation location = value as ClockLocation;
-            if (location == null || location.GmtMinutesOffset == 0)
+            if(value is int gmtOffset)
             {
-                builder.Append("same as local");
-            }
-            else
-            {
-                var hours = Math.Abs(location.GmtMinutesOffset) / 60;
-                builder.Append(hours);
-                builder.Append(GetHours(hours, parameter));
-                if (location.GmtMinutesOffset - hours * 60 >= 30)
+
+                if (gmtOffset == 0)
                 {
-                    builder.Append(" 30m");
+                    builder.Append("same as local");
                 }
+                else
+                {
+                    var hours = Math.Abs(gmtOffset) / 60;
+                    builder.Append(hours);
+                    builder.Append(GetHours(hours, parameter));
+                    if (gmtOffset - hours * 60 >= 30)
+                    {
+                        builder.Append(" 30m");
+                    }
 
-                builder.Append(location.GmtMinutesOffset > 0 ? " ahead" : " behind");
+                    builder.Append(gmtOffset > 0 ? " ahead" : " behind");
+                }
             }
 
+
             return builder.ToString();
         }