</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>
<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
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;
{
private UnityContainer _ioCContainer;
- public const string Tag = "d";
+ public const string Tag = "clock";
public string ApplicationId { get; set; }
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),
_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),
--- /dev/null
+<?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
--- /dev/null
+/*
+* 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
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
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();
}
private void StartTimer()
{
+ _is24HourClockEnabled = SystemSettings.LocaleTimeFormat24HourEnabled;
+ SystemSettings.LocaleTimeFormat24HourSettingChanged += LocaleTimeFormat24HourSettingChanged;
UpdateTime();
_ticker.Tick -= UpdateTime;
_ticker.Tick += UpdateTime;
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
using Clock.ViewModels;
using CommonServiceLocator;
using Navigation.Tools.Navigation.Interfaces;
+using System;
+using Tizen;
+
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>());
public class ViewModelLocator
{
public object AlarmListViewModel => ViewModelFactory.CreateAlarmListPageViewModel();
+ public object WorldClockViewModel => ViewModelFactory.CreateWorldClockViewModel();
}
}
\ No newline at end of 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">
<?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
--- /dev/null
+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
+++ /dev/null
-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
--- /dev/null
+/*
+* 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();
+ }
+ }
+}
using Clock.Model;
using Clock.Tools;
using Clock.Tools.Comparers;
+using Navigation.Tools.Navigation.Interfaces;
using System;
using System.Collections;
using System.Collections.Generic;
{
public delegate Task<IEnumerable<ClockLocation>> NavigateToPlaces(IEnumerable<ClockLocation> locations);
- public class WorldClockViewModel : INotifyPropertyChanged
+ public class WorldClockViewModel : NavigationServiceAwareViewModel
{
private readonly ITimeZonePickerService _timeZoneService;
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; }
{
if (_menuCommands == null)
{
- HandPickedPlaces.CollectionChanged += (s, e) =>
+ Locations.CollectionChanged += (s, e) =>
{
UpdateMenu();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuCommands)));
}
}
- 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
{
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()
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();
}
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
/// 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);
}
}
{
(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>
(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();
+ }
}
}
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)
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();
}