예제 #1
0
        void FilterIntoEmotions()
        {
            int index = 0, sub = 0;

            DateTime now  = DateTime.Now.Date;
            DateTime date = now;

            Emotion        emotion  = Emotion.None;
            List <Emotion> emotions = DreamsAPI.GetEmotions();

            for (index = 0; index < emotions.Count; index++)
            {
                emotion = emotions[index];
                ObservableCollection <ChartDataPoint> points = new ObservableCollection <ChartDataPoint>();
                for (sub = 6; sub >= 0; sub--)
                {
                    date = now.AddDays(-sub);
                    points.Add(new ChartDataPoint(date, new List <DreamRecord>(from rec in DreamsAPI.GetRecords()
                                                                               where rec.DateRecorded.Date == date.Date && rec.Emotion == emotion
                                                                               select rec).Count));
                }

                if (_seriesData.ContainsKey(emotion))
                {
                    _seriesData[emotion] = points;
                }
                else
                {
                    _seriesData.Add(emotion, points);
                }
            }
        }
예제 #2
0
파일: dreams.cs 프로젝트: MHopke/dreams
 public App()
 {
     DreamsAPI.Initialize();
     // The root page of your application
     MainPage = new NavigationPage(new HomePage())
     {
         BarBackgroundColor = Colors.DreamBlue,
         BarTextColor       = Color.White
     };
 }
예제 #3
0
        public JournalPage()
        {
            Title = "Dream Journal";
            NavigationPage.SetBackButtonTitle(this, "Journal");

            DateTime now   = DateTime.UtcNow;
            DateTime start = DreamsAPI.InstallDate;

            _months = new ObservableCollection <JournalMonth>();

            IEnumerable <DreamRecord> records = DreamsAPI.GetRecords();

            //Console.WriteLine(start);
            while (start <= now)
            {
                Console.WriteLine($"{start}");
                JournalMonth jMonth = new JournalMonth()
                {
                    Date = start
                };
                jMonth.Records = new ObservableCollection <DreamRecord>(from rec in records
                                                                        where rec.DateRecorded.Month == start.Month && rec.DateRecorded.Year == start.Year
                                                                        select rec);
                jMonth.RecordCount = jMonth.Records.Count;
                _months.Add(jMonth);

                start = start.AddMonths(1);
            }

            ListView list = new ListView()
            {
                SeparatorVisibility = SeparatorVisibility.None
            };

            list.ItemsSource  = _months;
            list.ItemTemplate = new DataTemplate(typeof(JournalMonthCell));
            list.ItemTapped  += MonthTapped;

            StackLayout layout = new StackLayout()
            {
                Children =
                {
                    list
                }
            };

            Content = layout;
        }
예제 #4
0
파일: MonthPage.cs 프로젝트: MHopke/dreams
        SfChart CreateChart(JournalMonth month)
        {
            _points = new ObservableCollection <ChartDataPoint>();

            SfChart chart = new SfChart()
            {
                HeightRequest = 250
            };

            chart.Title.Text = "Monthly Emotion Overview";

            PieSeries series = new PieSeries()
            {
                XBindingPath = "Emotion",
                YBindingPath = "Value"
            };

            series.ColorModel.Palette      = ChartColorPalette.Custom;
            series.DataMarker              = new ChartDataMarker();
            series.DataMarkerPosition      = CircularSeriesDataMarkerPosition.OutsideExtended;
            series.DataMarker.LabelContent = LabelContent.Percentage;

            series.ColorModel.CustomBrushes.Clear();
            chart.Legend = new ChartLegend();

            Emotion        emotion  = Emotion.None;
            List <Emotion> emotions = DreamsAPI.GetEmotions();

            for (int index = 0; index < emotions.Count; index++)
            {
                emotion = emotions[index];
                List <DreamRecord> records = new List <DreamRecord>(from rec in month.Records
                                                                    where rec.Emotion == emotion
                                                                    select rec);
                _points.Add(new ChartDataPoint(emotion.ToString(), records.Count));
                series.ColorModel.CustomBrushes.Add(DreamsAPI.GetEmotionColor(emotion));
            }

            series.ItemsSource = _points;

            chart.Series.Add(series);

            return(chart);
        }
예제 #5
0
파일: SearchPage.cs 프로젝트: MHopke/dreams
        void OnSearchBarButtonPressed(object sender, EventArgs args)
        {
            SearchBar bar  = (SearchBar)sender;
            string    text = bar.Text;

            _tags = text.Split(',');

            if (_list.Count > 0)
            {
                _list.Clear();
            }

            List <DreamRecord> records = DreamsAPI.GetDreamsWithTag(text);

            for (int index = 0; index < records.Count; index++)
            {
                _list.Add(records[index]);
            }
        }
예제 #6
0
파일: dreams.cs 프로젝트: MHopke/dreams
 protected override void OnStart()
 {
     DreamsAPI.SetupInstallDate();
 }
예제 #7
0
        SfChart CreateWeeklyChart()
        {
            FilterIntoEmotions();

            SfChart chart = new SfChart()
            {
                HeightRequest = 250
            };

            chart.Title.Text = "Your Last Seven Days";

            //Initializing Primary Axis
            DateTimeAxis primaryAxis = new DateTimeAxis()
            {
                Interval           = 1,
                IntervalType       = DateTimeIntervalType.Days,
                ShowMajorGridLines = false,
                ShowMinorGridLines = false
            };

            primaryAxis.LabelStyle.LabelFormat = "MMM dd";

            primaryAxis.Title = new ChartAxisTitle()
            {
                Text = "Day",
            };

            chart.PrimaryAxis = primaryAxis;

            //Initializing Secondary Axis
            NumericalAxis secondaryAxis = new NumericalAxis()
            {
                Interval           = 1,
                ShowMinorGridLines = false
            };

            secondaryAxis.Title = new ChartAxisTitle()
            {
                Text = "Num. Dreams",
            };

            chart.SecondaryAxis = secondaryAxis;

            chart.Legend = new ChartLegend();

            foreach (KeyValuePair <Emotion, ObservableCollection <ChartDataPoint> > pair
                     in _seriesData)
            {
                StackingColumnSeries series = new StackingColumnSeries()
                {
                    ItemsSource  = pair.Value,
                    XBindingPath = "Day",
                    YBindingPath = "Value",
                    Color        = DreamsAPI.GetEmotionColor(pair.Key),
                    Label        = pair.Key.ToString()
                };

                chart.Series.Add(series);
            }

            return(chart);
        }
예제 #8
0
        public DreamRecordPage(DreamRecord record, bool newRecord)
        {
            _previousRecord = new DreamRecord(record);

            Entry title = new Entry()
            {
                Placeholder   = "Enter title...",
                HeightRequest = 50
            };

            title.BindingContext = record;
            title.SetBinding(Entry.TextProperty, "Title");

            Label descLabel = new Label()
            {
                Text = "Description",
                HorizontalTextAlignment = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold,
            };
            Editor description = new Editor()
            {
                //HeightRequest = 250,
                BackgroundColor = Color.Gray,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            description.BindingContext = record;
            description.SetBinding(Editor.TextProperty, "Description");

            DatePicker datePicker = new DatePicker()
            {
                Format = "D"
            };

            datePicker.BindingContext = record;
            datePicker.SetBinding(DatePicker.DateProperty, "DateRecorded");

            DateTime now = DateTime.Now;

            if (newRecord)
            {
                datePicker.Date = now;
            }
            else
            {
                datePicker.Date = record.DateRecorded;
            }

            datePicker.MinimumDate = datePicker.Date.AddYears(-1);
            datePicker.MaximumDate = now;

            Picker picker = new Picker()
            {
                Title = "Emotion"
            };

            picker.SelectedIndexChanged += (object sender, EventArgs e) =>
            {
                if (picker.SelectedIndex != -1)
                {
                    record.Emotion = (Emotion)picker.SelectedIndex;
                }
            };

            List <Emotion> emotions = DreamsAPI.GetEmotions();

            for (int index = 0; index < emotions.Count; index++)
            {
                picker.Items.Add((emotions[index]).ToString());
            }

            picker.SelectedIndex = (int)record.Emotion;

            Entry tags = new Entry()
            {
                Placeholder   = "Enter comma separated tags",
                HeightRequest = 50,
            };

            tags.BindingContext = record;
            tags.SetBinding(Entry.TextProperty, "Tags");

            Button submit = new Button();

            if (newRecord)
            {
                submit.Text = ADD;
            }
            else
            {
                submit.Text = UPDATE;
            }

            submit.Clicked += async(object sender, EventArgs e) =>
            {
                if (newRecord)
                {
                    DreamsAPI.SaveRecord(record);

                    MessagingCenter.Send <DreamRecordPage, DreamRecord>(this, "NewRecord", record);
                }
                else
                {
                    try
                    {
                        DreamsAPI.SaveRecord(record);

                        if ((_previousRecord.DateRecorded != record.DateRecorded ||
                             _previousRecord.Emotion != record.Emotion) && recordUpdated != null)
                        {
                            recordUpdated(_previousRecord, record);
                        }
                    }
                    catch (Exception er)
                    {
                        Console.WriteLine(er.Message);
                    }
                }

                await Navigation.PopAsync();
            };

            StackLayout descStack = new StackLayout()
            {
                Children =
                {
                    descLabel,
                    description,
                },
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            StackLayout bottomStack = new StackLayout()
            {
                Children =
                {
                    datePicker,
                    picker,
                    tags,
                    submit
                },
                VerticalOptions = LayoutOptions.End
            };

            StackLayout layout = new StackLayout()
            {
                Children =
                {
                    title,
                    descStack,
                    bottomStack
                }
            };

            Content = layout;
        }