private async Task CommandRegistAction()
        {
            if (_bodyImageService.CheckExitTargetDayData(DateTime.Now))
            {
                var result =
                    await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                    LanguageUtils.Get(LanguageKeys.TodayDataUpdateConfirm), LanguageUtils.Get(LanguageKeys.OK),
                                                                    LanguageUtils.Get(LanguageKeys.Cancel));

                if (result)
                {
                    _bodyImageService.UpdateBodyImage(_id, _base64String);
                }
            }
            else
            {
                _bodyImageService.RegistBodyImage(_base64String);
            }

            if (_takePhotoFromCamera)
            {
                //TODO 確認のダイアログを表示する
                //TODO ViewModelCommonUtilに移動する?
                DependencyService.Get <IImageService>().DeleteImageFile(_filePath);
            }

            // ホーム画面をリロードする
            ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingHomeReload);
            ViewModelCommonUtil.DataBackPage();
        }
Exemple #2
0
        public string Analy()
        {
            var model = _basicDataService.GetBasicData();

            var currentWeight     = model.BodyWeight;
            var currentHeight     = model.Height;
            var bmi               = float.Parse(ViewModelCommonUtil.CulculateBmi(currentHeight, currentWeight).ToString("0.0000"));
            var appropriateWeight = float.Parse(CulculateAppropriate(currentHeight, currentWeight).ToString("0.0000"));
            var difference        = currentWeight - float.Parse(appropriateWeight.ToString("0.0000"));

            var sb = new StringBuilder();

            sb.AppendLine(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat1, model.Height.ToString(), appropriateWeight));
            sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat2, difference, bmi));
            sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat3));
            if (difference > 0)
            {
                sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat4));
                sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat8));
            }
            else
            {
                if (bmi < 18.5)
                {
                    sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat7));
                }
                else
                {
                    sb.Append(LanguageUtils.Get(LanguageKeys.BodyWeightAnalysisFormat5));
                }
            }

            return(sb.ToString());
        }
        /// <summary>
        /// フォトライブラリ選択アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandTakeLibraryAction()
        {
            _takePhotoFromCamera = false;

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error),
                                                                LanguageUtils.Get(LanguageKeys.PictureLibraryCanNotOpen), LanguageUtils.Get(LanguageKeys.OK));

                return;
            }
            var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
            {
                PhotoSize = PhotoSize.Medium
            });

            if (file == null)
            {
                return;
            }

            BodyImage = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return(stream);
            });

            var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream());

            _base64String = Convert.ToBase64String(imgData);
        }
        /// <summary>
        ///     体格画像のロード
        /// </summary>
        public void LoadBodyImage()
        {
            // 表示する体格画像を取得
            var bodyImageModel = BodyImageService.GetBodyImage();

            if (bodyImageModel != null)
            {
                var imageAsBytes = Convert.FromBase64String(bodyImageModel.ImageBase64String);

                BodyImage = ImageSource.FromStream(() =>
                                                   new MemoryStream(ViewModelCommonUtil.GetResizeImageBytes(imageAsBytes, 300, 425)));
                BodyImageRegistedDateString =
                    LanguageUtils.Get(LanguageKeys.RegistedDate) +
                    ViewModelCommonUtil.FormatDateString(bodyImageModel.RegistedDate);
            }
            else
            {
                // 登録されている体格画像がない場合はイメージなし用の画像を表示する
                var imageAsBytes = Convert.FromBase64String(ViewModelConst.NoImageString64);
                BodyImage = ImageSource.FromStream(() =>
                                                   new MemoryStream(ViewModelCommonUtil.GetResizeImageBytes(imageAsBytes, 300, 425)));
                BodyImageRegistedDateString =
                    LanguageUtils.Get(LanguageKeys.RegistedDate) + StringConst.Empty;
            }
        }
Exemple #5
0
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // ViewModel Logic
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/

        #region ViewModel Logic

        private void InitImageStackLayout()
        {
            ImageStack.Clear();
            var target = (from a in _bodyImageList
                          select a).Skip(NowPage * PageSize).Take(PageSize);

            foreach (var value in target)
            {
                var childStackLayout = new StackLayout();
                var imageAsBytes     = Convert.FromBase64String(value.ImageBase64String);
                var bodyImage        = new Image
                {
                    Source = ImageSource.FromStream(() =>
                                                    new MemoryStream(ViewModelCommonUtil.GetResizeImageBytes(imageAsBytes, 500, 625)))
                };
                childStackLayout.Children.Add(bodyImage);

                var registedDateLabel = new Label
                {
                    Text = value.RegistedDate.ToString(ViewModelCommonUtil.DateTimeFormatString),
                    HorizontalOptions = LayoutOptions.Center
                };
                childStackLayout.Children.Add(registedDateLabel);
                ImageStack.Add(childStackLayout);
            }
        }
Exemple #6
0
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // ViewModel Logic
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region ViewModel Logic

        public void LoadList()
        {
            Items.Clear();
            _weekList = new List <WeekEnum>();
            foreach (var week in Enum.GetValues(typeof(WeekEnum)))
            {
                _weekList.Add((WeekEnum)week);
                Items.Add(ViewModelCommonUtil.CreateTrainingScheduleSViewtructure((WeekEnum)week));
            }
        }
Exemple #7
0
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // ViewModel Logic
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region ViewModel Logic


        /// <summary>
        /// データチャートに使用するエントリーを生成
        /// </summary>
        /// <param name="value"></param>
        /// <param name="registedDateTime"></param>
        /// <returns></returns>
        protected virtual Entry CreateNewEntry(float value, DateTime registedDateTime)
        {
            return(new Entry(value)
            {
                // TODO 色を決定
                Color = SKColor.Parse("#00CED1"),
                Label = ViewModelCommonUtil.FormatDateString(registedDateTime),
                ValueLabel = value.ToString()
            });
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Constractor
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Constractor

        public TrainingViewModel()
        {
            InitCommands();
            _pageOpenDateTime = DateTime.Now;
            var week = (int)DateTime.Now.DayOfWeek;

            _timer       = new Timer(TimeSpan.FromSeconds(1), CountDown);
            TotalSeconds = _totalSeconds;
            _trainingScheduleSViewtructure = ViewModelCommonUtil.CreateTrainingScheduleSViewtructure((WeekEnum)week);
            TrainingMenu = _trainingScheduleSViewtructure.ToString();
            Items        = _trainingScheduleSViewtructure.TrainingContentList;
            WeekLabel    = _trainingScheduleSViewtructure.WeekName;
            TrainingStartButtonVisible = true;
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        /// カメラ撮影アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandTakeCameraAction()
        {
            _takePhotoFromCamera = true;

            try
            {
                // カメラが有効であるか判定
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error),
                                                                    LanguageUtils.Get(LanguageKeys.CameraNotAvailable), LanguageUtils.Get(LanguageKeys.OK));

                    return;
                }

                // 画像ファイルの名前を決定
                var fileName = BodyImageNameHead + ViewModelCommonUtil.FormatDateStringWithoutSymbol(DateTime.Now) +
                               BodyImageExtension;
                var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    PhotoSize   = PhotoSize.Medium,
                    Directory   = BodyImageFileDirectory,
                    Name        = fileName,
                    SaveToAlbum = false
                });

                if (file == null)
                {
                    return;
                }

                _filePath = file.Path;

                BodyImage = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return(stream);
                });

                var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream());
                _base64String = Convert.ToBase64String(imgData);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
        }
        private async Task CommandCompleteTrainingAction()
        {
            PauseTimer();

            var result =
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                LanguageUtils.Get(LanguageKeys.IsDoneTraining), LanguageUtils.Get(LanguageKeys.OK),
                                                                LanguageUtils.Get(LanguageKeys.Cancel));

            if (result)
            {
                _trainingEndDateTime = DateTime.Now;
                TrainingResultService.RegistTrainingResult(trainingContent: JsonConvert.SerializeObject(_trainingScheduleSViewtructure), weather: null,
                                                           targetDate: _pageOpenDateTime, startDate: _trainingStartDateTime, endDate: _trainingEndDateTime);

                // 遷移元画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingHomeReload);
                await ViewModelConst.TrainingPageNavigation.PopAsync();
            }
            else
            {
                _timer.Start();
            }
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        public void CommandCancelAction()
        {
            // 遷移元画面をリロードする
            ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingHomeReload);
            ViewModelConst.TrainingPageNavigation.PopAsync();
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        ///     トレーニング保存アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandSaveAction()
        {
            try
            {
                if (!ValidationInputData(TrainingName))
                {
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll);
                    return;
                }

                IsLoading = true;

                var partStructureList = new List <PartStructure>();
                PartStack.Children.ForEach(child =>
                {
                    var stack        = (StackLayout)child;
                    var partModel    = ((PartModel)((Picker)stack.Children[0]).SelectedItem);
                    var subPartModel = ((SubPartModel)((Picker)stack.Children[1]).SelectedItem);

                    if (!partStructureList.Any(
                            data => data.Part.Id == partModel.Id && data.SubPart.Id == subPartModel.Id))
                    {
                        partStructureList.Add(new PartStructure
                        {
                            Part    = partModel,
                            SubPart = subPartModel
                        });
                    }
                });

                var loadList = new List <LoadModel>();
                LoadStack.Children.ForEach(child =>
                {
                    var stack     = (StackLayout)child;
                    var loadModel = ((LoadModel)((Picker)stack.Children[0]).SelectedItem);
                    if (loadList.All(data => data.Id != loadModel.Id))
                    {
                        loadList.Add(loadModel);
                    }
                });

                var loadStructure = new LoadStructure {
                    LoadList = loadList
                };

                if (_targetTrainingMasterModel != null)
                {
                    TrainingMasterService.UpdateTrainingMaster(
                        _targetTrainingMasterModel.Id,
                        TrainingName,
                        JsonConvert.SerializeObject(loadStructure),
                        JsonConvert.SerializeObject(partStructureList));
                }
                else
                {
                    TrainingMasterService.RegistTrainingMaster(
                        TrainingName,
                        JsonConvert.SerializeObject(loadStructure),
                        JsonConvert.SerializeObject(partStructureList));
                }

                IsLoading = false;

                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                // ホーム画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload);
                ViewModelCommonUtil.TrainingBackPage();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
        private async Task CommandSaveAction()
        {
            try
            {
                if (!Validate())
                {
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingSelfScroll);
                    return;
                }

                IsLoading = true;
                var trainingContentList = new List <TrainingListStructure>();

                if (!Off)
                {
                    // トレーニング一覧
                    var trainingStack = TrainingStack.Children;
                    foreach (var training in trainingStack)
                    {
                        var insert     = new TrainingListStructure();
                        var trainingId =
                            ((TrainingMasterModel)((Picker)((StackLayout)training).Children[1]).SelectedItem).Id;
                        var trainingseCount = ((Entry)((StackLayout)training).Children[3]).Text;

                        var loadContentList = new List <LoadContentStructure>();
                        var loadStack       = ((StackLayout)((StackLayout)training).Children[4]).Children;
                        foreach (var load in loadStack)
                        {
                            var insertload = new LoadContentStructure();
                            var subLoad    = ((StackLayout)load).Children[1];
                            var loadId     = ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem)
                                             .LoadId;
                            var nums       = ((Entry)((StackLayout)subLoad).Children[0]).Text;
                            var loadUnitId =
                                ((LoadUnitModel)((Picker)((StackLayout)subLoad).Children[1]).SelectedItem).Id;
                            insertload.LoadId     = loadId;
                            insertload.LoadUnitId = loadUnitId;
                            insertload.Nums       = float.Parse(nums);
                            loadContentList.Add(insertload);
                        }

                        insert.LoadContentList  = loadContentList;
                        insert.TrainingId       = trainingId;
                        insert.TrainingSetCount = int.Parse(trainingseCount);
                        trainingContentList.Add(insert);
                    }
                }

                var trainingScheduleStructure =
                    new TrainingScheduleStructure
                {
                    TrainingContentList = trainingContentList,
                    Off  = Off,
                    Week = _week
                };

                var trainingScheduleStructureJson = JsonConvert.SerializeObject(trainingScheduleStructure);

                if (_isUpdate)
                {
                    TrainingScheduleService.UpdateTrainingSchedule(_id, trainingScheduleStructureJson,
                                                                   _week);
                }
                else
                {
                    TrainingScheduleService.RegistTrainingSchedule(trainingScheduleStructureJson,
                                                                   _week);
                }

                IsLoading = false;

                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                // ホーム画面をリロードする
                ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingTrainingPrevPageReload);
                ViewModelCommonUtil.TrainingBackPage();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Exemple #14
0
 /// <summary>
 ///  キャンセルアクション
 /// </summary>
 public void CommandCancelAction()
 {
     // ホーム画面をリロードする
     ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingHomeReload);
     ViewModelCommonUtil.DataBackPage();
 }
Exemple #15
0
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        //
        // Command Actions
        //
        /*----------------------------------------------------------------------------------------------------------------------------------------*/
        #region Command Actions

        /// <summary>
        ///  基本データ保存アクション
        /// </summary>
        /// <returns></returns>
        private async Task CommandSaveAction()
        {
            try
            {
                if (!ValidationInputData(Name, Gender, Height,
                                         BodyWeight, BodyFatPercentage,
                                         MaxBloodPressure,
                                         MinBloodPressure, BasalMetabolism))
                {
                    ScrollRequest = ScrollRequest.SendScrollRequest(ScrollRequestType.RequestTypeToTop);
                    return;
                }

                IsLoading = true;
                if (_basicDataService.CheckExitTargetDayData(DateTime.Now))
                {
                    var result =
                        await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Confirm),
                                                                        LanguageUtils.Get(LanguageKeys.TodayDataUpdateConfirm), LanguageUtils.Get(LanguageKeys.OK),
                                                                        LanguageUtils.Get(LanguageKeys.Cancel));

                    if (result)
                    {
                        _basicDataService.UpdateBasicData(_id, Name, 1, Gender, height: Height, birthday: Birthday,
                                                          bodyWeight: BodyWeight, bodyFatPercentage: BodyFatPercentage,
                                                          maxBloodPressure: MaxBloodPressure,
                                                          minBloodPressure: MinBloodPressure, basalMetabolism: BasalMetabolism);
                    }
                    else
                    {
                        IsLoading = false;
                        return;
                    }
                }
                else
                {
                    _basicDataService.RegistBasicData(Name, 1, Gender, height: Height, birthday: Birthday,
                                                      bodyWeight: BodyWeight, bodyFatPercentage: BodyFatPercentage,
                                                      maxBloodPressure: MaxBloodPressure,
                                                      minBloodPressure: MinBloodPressure, basalMetabolism: BasalMetabolism);
                }

                IsLoading = false;
                await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Complete),
                                                                LanguageUtils.Get(LanguageKeys.SaveComplete), LanguageUtils.Get(LanguageKeys.OK));

                if (_isUpdate)
                {
                    // ホーム画面をリロードする
                    ViewModelCommonUtil.SendMessage(ViewModelConst.MessagingHomeReload);
                    ViewModelCommonUtil.DataBackPage();
                }
                else
                {
                    ViewModelCommonUtil.BackHome();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }