protected override IMvxListItemView CreateBindableView(object dataContext, int templateId) { var view = base.CreateBindableView(dataContext, templateId) as MvxListItemView; var name = view.FindViewById <TextView>(Resource.Id.label_medication_name); var dosage = view.FindViewById <TextView>(Resource.Id.label_medication_dosage); var ordination = view.FindViewById <TextView>(Resource.Id.label_medication_ordination); var medication = dataContext as MedicationDosage; name.Text = medication.Name; dosage.Text = medication.Dosage; ordination.Text = $"{new DaysOfWeekConverter().Convert(medication.Days,typeof(string),null,System.Globalization.CultureInfo.CurrentCulture).ToString()}: {medication.Hours}"; if (medication?.ThumbnailName != null) { try { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); thumbnail.SetImageBitmap(BitmapFactory.DecodeByteArray(array, 0, array.Length)); } catch { } } else { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); thumbnail.SetImageBitmap(BitmapFactory.DecodeResource(this.Context.Resources, Resource.Drawable.pillThumb)); } return(view); }
public async void Init(MedicationDosageNavigation nav) { if (nav.MedicationDosageId != MedicationDosageNavigation.NewRecord) { isNew = false; Data.MedicationDosage item = await storage.GetAsync <Data.MedicationDosage>(nav.MedicationDosageId); Id = item.Id; MedicationName = item.Name; MedicationDosage = item.Dosage; Monday = item.Days.HasFlag(DaysOfWeek.Monday); Tuesday = item.Days.HasFlag(DaysOfWeek.Tuesday); Wednesday = item.Days.HasFlag(DaysOfWeek.Wednesday); Thursday = item.Days.HasFlag(DaysOfWeek.Thursday); Friday = item.Days.HasFlag(DaysOfWeek.Friday); Saturday = item.Days.HasFlag(DaysOfWeek.Saturday); Sunday = item.Days.HasFlag(DaysOfWeek.Sunday); DosageHours = new RxUI.ReactiveList <TimeSpan>(item.DosageHours); if (!string.IsNullOrEmpty(item.ImageName)) { Bytes = imageLoader.LoadImage(item.ImageName); } } else { isNew = true; } }
public async void Init(MedicationDosageNavigation nav) { if (nav.MedicationDosageId != MedicationDosageNavigation.NewRecord) { isNew = false; MedicationDosage item = await storage.GetAsync <Data.MedicationDosage>(nav.MedicationDosageId); Id = item.Id; MedicationName = item.Name; StartDate = item.From; EndDate = item.To; MedicationDosage = item.Dosage; Monday = item.Days.HasFlag(DaysOfWeek.Monday); Tuesday = item.Days.HasFlag(DaysOfWeek.Tuesday); Wednesday = item.Days.HasFlag(DaysOfWeek.Wednesday); Thursday = item.Days.HasFlag(DaysOfWeek.Thursday); Friday = item.Days.HasFlag(DaysOfWeek.Friday); Saturday = item.Days.HasFlag(DaysOfWeek.Saturday); Sunday = item.Days.HasFlag(DaysOfWeek.Sunday); DosageHours = new List <TimeSpan>(item.DosageHours); HoursLabel = item.Hours; RingUri = item.RingUri; if (!string.IsNullOrEmpty(item.ImageName)) { Bytes = imageLoader.LoadImage(item.ImageName); } } else { isNew = true; selectAllDays(); } loadSettings(); }
public static Notification GetNotification(Context context, MedicationDosage medication, DateTime occurrenceDate, Intent notificationIntent) { var builder = new NotificationCompat.Builder(context); builder.SetContentTitle(medication.Name); builder.SetTicker($"[PILLER] {medication.Name}"); builder.SetSmallIcon(Resource.Drawable.pill64x64); builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm)); builder.SetPriority((int)NotificationPriority.High); builder.SetVisibility((int)NotificationVisibility.Public); // visible on locked screen RemoteViews contentView = new RemoteViews(context.PackageName, Resource.Layout.customNotification); contentView.SetTextViewText(Resource.Id.titleTextView, medication.Name); contentView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate)); if (medication?.ThumbnailName == null) { contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); } else { ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } RemoteViews contentBigView = new RemoteViews(context.PackageName, Resource.Layout.customBigNotification); contentBigView.SetTextViewText(Resource.Id.titleTextView, medication.Name); contentBigView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate)); PendingIntent intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.okButton, intent); intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.noButton, intent); intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.laterButton, intent); if (medication?.ThumbnailName == null) { contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); } else { ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } builder.SetCustomContentView(contentView); builder.SetCustomBigContentView(contentBigView); return(builder.Build()); }
protected override IMvxListItemView CreateBindableView(object dataContext, int templateId) { var view = base.CreateBindableView(dataContext, templateId) as MvxListItemView; var name = view.FindViewById <TextView>(Resource.Id.label_medication_name); var time = view.FindViewById <TextView>(Resource.Id.label_medication_time); var daysOfWeek = view.FindViewById <TextView>(Resource.Id.label_medication_days_of_week); var bset = view.CreateBindingSet <MvxListItemView, MedicationDosage>(); bset.Bind(name) .To(x => x.Name); // Konwertery to specyficzny dla MvvmCross'a sposób translacji danych z view modelu do danych z których potrafi skorzystać widok. // Zazwyczaj nie są one potrzebne, np. kiedy pokazujemy tekst, ale jeśli zachodzi potrzeba pokazania np. listy w jednej linii musimy użyć konwertera. // TextView jest domyślnie bindowane do property Text, więc nie trzeba jej wprost wskazywać bset.Bind(time) .To(x => x.DosageHours) .WithConversion(new DosageHoursConverter()); // jeśli bind ma być do innej property to wskazuje się tak jak poniżej (metoda .For) bset.Bind(time) .To(x => x.DosageHours) .For(v => v.Visibility) .WithConversion(new InlineValueConverter <IEnumerable <TimeSpan>, ViewStates>(dosageHours => dosageHours.Any() ? ViewStates.Visible : ViewStates.Gone)); bset.Bind(daysOfWeek) .To(x => x.Days) .WithConversion(new DaysOfWeekConverter()); bset.Bind(daysOfWeek) .To(x => x.Days) .For(v => v.Visibility) .WithConversion(new InlineValueConverter <DaysOfWeek, ViewStates>(dosageHours => dosageHours == DaysOfWeek.None ? ViewStates.Gone : ViewStates.Visible)); bset.Apply(); var medication = dataContext as MedicationDosage; if (medication?.ThumbnailName != null) { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); thumbnail.SetImageBitmap(BitmapFactory.DecodeByteArray(array, 0, array.Length)); } else { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); thumbnail.SetImageBitmap(BitmapFactory.DecodeResource(this.Context.Resources, Resource.Drawable.pill64x64)); } return(view); }
protected override IMvxListItemView CreateBindableView(object dataContext, int templateId) { var view = base.CreateBindableView(dataContext, templateId) as MvxListItemView; var name = view.FindViewById <TextView>(Resource.Id.label_nearest_name); var dosage = view.FindViewById <TextView>(Resource.Id.label_nearest_dosage); var time = view.FindViewById <TextView>(Resource.Id.label_nearest_time); var bset = view.CreateBindingSet <MvxListItemView, NotificationOccurrence>(); var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); var del_nearest_not_button = view.FindViewById <ImageView>(Resource.Id.del_nearest_not_button); del_nearest_not_button.Click += (sender, e) => DeleteRequested.Execute((NotificationOccurrence)dataContext).Subscribe(); bset.Bind(name) .To(x => x.Name); bset.Bind(dosage) .To(x => x.Dosage); bset.Bind(time) .To(x => x.OccurrenceDateTime) .WithConversion(new InlineValueConverter <DateTime, string>(dt => dt.ToShortTimeString())); bset.Bind(thumbnail) .To(x => x.ThumbnailImage) .For("Bitmap") .WithConversion(new InlineValueConverter <string, Bitmap>(file => { if (file != null) { byte[] array = imageLoader.LoadImage(file); return(BitmapFactory.DecodeByteArray(array, 0, array.Length)); } else { return(BitmapFactory.DecodeResource(this.Context.Resources, Resource.Drawable.pillThumb)); } })); bset.Apply(); return(view); }
public static Notification GetNotification(Context context, MedicationDosage medication, NotificationOccurrence notificationOccurrence, Intent notificationIntent) { var builder = new NotificationCompat.Builder(context); builder.SetContentTitle(medication.Name); builder.SetTicker($"[PILLER] {medication.Name}"); builder.SetSmallIcon(Resource.Drawable.pill64x64); var data = JsonConvert.DeserializeObject <SettingsData>(Mvx.Resolve <ISettings>().GetValue <string>(SettingsData.Key)); Android.Net.Uri ring = Android.Net.Uri.Parse(data.RingUri); builder.SetSound(ring); builder.SetPriority((int)NotificationPriority.High); builder.SetVisibility((int)NotificationVisibility.Public); // visible on locked screen RemoteViews contentView = new RemoteViews(context.PackageName, Resource.Layout.customNotification); contentView.SetTextViewText(Resource.Id.titleTextView, medication.Name + " " + medication.Dosage); contentView.SetTextViewText(Resource.Id.descTextView, FormatOccurrence(notificationOccurrence.OccurrenceDateTime)); //contentView.SetImageViewBitmap(Resource.Id.iconView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); RemoteViews contentBigView = new RemoteViews(context.PackageName, Resource.Layout.customBigNotification); contentBigView.SetTextViewText(Resource.Id.titleTextView, medication.Name + " " + medication.Dosage); contentBigView.SetTextViewText(Resource.Id.descTextView, FormatOccurrence(notificationOccurrence.OccurrenceDateTime)); if (medication?.ThumbnailName == null) { var roundedImage = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64); contentView.SetImageViewBitmap(Resource.Id.imageView, roundedImage); contentBigView.SetImageViewBitmap(Resource.Id.iconView, roundedImage); } else { var imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } var medicationId = medication.Id.Value; var notificationId = notificationOccurrence.Id.Value; System.Diagnostics.Debug.Write(notificationId); Intent okIntent = new Intent(notificationIntent); Intent noIntent = new Intent(notificationIntent); Intent laterIntent = new Intent(notificationIntent); notificationIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); okIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); noIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); laterIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); okIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); noIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); laterIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); okIntent.SetAction("OK"); noIntent.SetAction("LATER"); //laterIntent.SetAction("LATER"); PendingIntent ok_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, okIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.okButton, ok_intent); PendingIntent no_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, noIntent, 0); contentBigView.SetOnClickPendingIntent(Resource.Id.noButton, no_intent); //PendingIntent later_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, laterIntent, 0); //contentBigView.SetOnClickPendingIntent(Resource.Id.laterButton, later_intent); //contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); if (medication?.ThumbnailName == null) { contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64)); } else { ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>(); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length)); } builder.SetCustomContentView(contentView); builder.SetCustomBigContentView(contentBigView); var notification = builder.Build(); // action upon notification click var notificationMainAction = new Intent(context, typeof(NotificationPublisher)); notificationMainAction.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); notificationMainAction.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); notificationMainAction.SetAction("GO_TO_MEDICATION"); var flags = (PendingIntentFlags)((int)PendingIntentFlags.CancelCurrent | (int)NotificationFlags.AutoCancel); notification.ContentIntent = PendingIntent.GetBroadcast(context, notificationId, notificationMainAction, flags); // action upon notification dismiss var notificationDismissAction = new Intent(context, typeof(NotificationPublisher)); notificationDismissAction.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId); notificationDismissAction.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); notificationDismissAction.SetAction("NOTIFCATION_DISMISS"); //var flags = (PendingIntentFlags)((int)PendingIntentFlags.CancelCurrent | (int)NotificationFlags.AutoCancel); notification.DeleteIntent = PendingIntent.GetBroadcast(context, notificationId, notificationDismissAction, flags); return(notification); }
protected override IMvxListItemView CreateBindableView(object dataContext, int templateId) { var view = base.CreateBindableView(dataContext, templateId) as MvxListItemView; var name = view.FindViewById <TextView>(Resource.Id.name); var dosage = view.FindViewById <TextView>(Resource.Id.dosage); var bset = view.CreateBindingSet <MvxListItemView, MedicationDosage>(); bset.Bind(name) .To(x => x.NameLabel); // Konwertery to specyficzny dla MvvmCross'a sposób translacji danych z view modelu do danych z których potrafi skorzystać widok. // Zazwyczaj nie są one potrzebne, np. kiedy pokazujemy tekst, ale jeśli zachodzi potrzeba pokazania np. listy w jednej linii musimy użyć konwertera. // TextView jest domyślnie bindowane do property Text, więc nie trzeba jej wprost wskazywać bset.Apply(); var medication = dataContext as MedicationDosage; if (medication?.ThumbnailName != null) { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); byte[] array = imageLoader.LoadImage(medication.ThumbnailName); thumbnail.SetImageBitmap(BitmapFactory.DecodeByteArray(array, 0, array.Length)); } else { var thumbnail = view.FindViewById <ImageView>(Resource.Id.list_thumbnail); thumbnail.SetImageBitmap(BitmapFactory.DecodeResource(this.Context.Resources, Resource.Drawable.pillThumb)); } int amount = 0; foreach (var hour in medication.HoursEncoded.Split(';')) { amount++; } int days = 0; DateTime date1; DateTime date2; if (!string.IsNullOrEmpty(medication.From) && DateTime.Parse(medication.From).Date > DateTime.Parse(from).Date) { date1 = DateTime.Parse(medication.From).Date; } else { date1 = DateTime.Parse(from).Date; } if (!string.IsNullOrEmpty(medication.To) && DateTime.Parse(medication.To).Date < DateTime.Parse(to).Date) { date2 = DateTime.Parse(medication.To).Date; } else { date2 = DateTime.Parse(to).Date; } for (DateTime date = date1; date.Date <= date2; date = date.AddDays(1)) { foreach (var day in medication.Days.GetSelected()) { if (date.DayOfWeek.EqualsDaysOfWeek(day)) { days++; } } } dosage.Text = (amount * days).ToString(); if (amount * days == 0) { //sth what hide item } return(view); }