コード例 #1
0
ファイル: App.xaml.cs プロジェクト: KRA2008/cringebot
        public App(IBootstrapper bootstrapper, IThemeService themeService, IAppProperties dataStore)
        {
            InitializeComponent();
            _themeService = themeService;
            _dataStore    = dataStore;

            var startingPage = bootstrapper.GetStartingPage();

            _mainViewModel = (MainViewModel)((FreshBaseContentPage)((FreshNavigationContainer)startingPage).CurrentPage).BindingContext;

            MainPage = startingPage;
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: KRA2008/cringebot
        public MainViewModel(IAppProperties properties, INotificationManager notificationManager,
                             IKeyboardHelper keyboardHelper)
        {
            _properties          = properties;
            _notificationManager = notificationManager;
            _memories            = new List <Memory>();

            MessagingCenter.Subscribe <ThemeService, bool>(this, ThemeService.TOOLS_SHOULD_BE_BLACK_CHANGED, SetToolbarIcons);

            AddMemoryCommand = new Command(() =>
            {
                if (string.IsNullOrWhiteSpace(MemoryInput))
                {
                    return;
                }

                var newMemory = new Memory
                {
                    Description = MemoryInput
                };
                newMemory.Occurrences.Add(SystemTime.Now());
                _memories.Add(newMemory);
                RaisePropertyChanged(nameof(Memories));

                MemoryInput = null;

                notificationManager.SetMemories(_memories);

                CringeFlashTrigger = !CringeFlashTrigger;
            });

            AddOccurrenceCommand = new Command(arg =>
            {
                var memory = (Memory)arg;
                memory.Occurrences.Insert(0, SystemTime.Now());
                MemoryInput = "";
                keyboardHelper.HideKeyboard();
                CringeFlashTrigger = !CringeFlashTrigger;
            });

            ViewDetailsCommand = new Command(async args =>
            {
                var memory = (Memory)((ItemTappedEventArgs)args).Item;
                await ViewDetails(memory);
            });

            ViewGraphCommand = new Command(async args =>
            {
                await ViewGraph(_memories);
            });

            ViewHelpCommand = new Command(async args =>
            {
                await ViewHelp();
            });

            ViewSettingsCommand = new Command(async args =>
            {
                await ViewSettings();
            });

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName != nameof(Simulate))
                {
                    return;
                }

                if (Simulate)
                {
                    notificationManager.StartNotifications(_memories, _settings);
                    ShowSimulationExplanation();
                }
                else
                {
                    notificationManager.StopNotifications();
                }
            };
        }