Exemplo n.º 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.checklist_fragment, null);

            checklist1Button = view.FindViewById <Button>(Resource.Id.checklist1Button);
            checklist2Button = view.FindViewById <Button>(Resource.Id.checklist2Button);
            checklist3Button = view.FindViewById <Button>(Resource.Id.checklist3Button);
            checklist4Button = view.FindViewById <Button>(Resource.Id.checklist4Button);
            checklist5Button = view.FindViewById <Button>(Resource.Id.checklist5Button);

            addFloatingActionButton = view.FindViewById <FloatingActionButton>(Resource.Id.addFloatingActionButton);

            checklist1Button.Click += async(s, e) => { fragmentDefconStatus = 1; SetButtonColors(1); await ReloadCheckList(1); };
            checklist2Button.Click += async(s, e) => { fragmentDefconStatus = 2; SetButtonColors(2); await ReloadCheckList(2); };
            checklist3Button.Click += async(s, e) => { fragmentDefconStatus = 3; SetButtonColors(3); await ReloadCheckList(3); };
            checklist4Button.Click += async(s, e) => { fragmentDefconStatus = 4; SetButtonColors(4); await ReloadCheckList(4); };
            checklist5Button.Click += async(s, e) => { fragmentDefconStatus = 5; SetButtonColors(5); await ReloadCheckList(5); };

            addFloatingActionButton.Click += async(s, e) =>
            {
                _onCreateView.PerformHapticFeedback(FeedbackConstants.VirtualKey, FeedbackFlags.IgnoreGlobalSetting);
                var checkListEntry = new CheckListEntry()
                {
                    DefconStatus = fragmentDefconStatus, UnixTimeStampCreated = DateTimeOffset.Now.ToUnixTimeMilliseconds(), FontSize = 26
                };
                _checkList.Add(checkListEntry);
                await _sqLiteAsyncConnection.InsertAsync(checkListEntry);

                _checklistRecyclerViewAdapter.NotifyDataSetChanged();
                await SetCounter();
            };

            itemsCounter1 = view.FindViewById <TextView>(Resource.Id.counterOne);
            itemsCounter2 = view.FindViewById <TextView>(Resource.Id.counterTwo);
            itemsCounter3 = view.FindViewById <TextView>(Resource.Id.counterThree);
            itemsCounter4 = view.FindViewById <TextView>(Resource.Id.counterFour);
            itemsCounter5 = view.FindViewById <TextView>(Resource.Id.counterFife);

            _onCreateView = view;
            return(view);
        }
 private async Task UpdateDatabase(Task <string> task)
 {
     try
     {
         var checkListEntries = JsonConvert.DeserializeObject <List <CheckListEntry> >(task.Result);
         foreach (var checkListEntry in checkListEntries)
         {
             CheckListEntry foundCheckListEntry = (await _sqLiteAsyncConnection.FindAsync <CheckListEntry>(c => c.UnixTimeStampCreated == checkListEntry.UnixTimeStampCreated));
             if (foundCheckListEntry != null)
             {
                 if (foundCheckListEntry.Deleted != checkListEntry.Deleted)
                 {
                     foundCheckListEntry.Deleted    = checkListEntry.Deleted;
                     foundCheckListEntry.Visibility = checkListEntry.Visibility;
                     foundCheckListEntry.Checked    = true;
                     await _sqLiteAsyncConnection?.UpdateAsync(foundCheckListEntry);
                 }
                 else if (foundCheckListEntry.UnixTimeStampUpdated != checkListEntry.UnixTimeStampUpdated)
                 {
                     foundCheckListEntry.Item       = checkListEntry.Item;
                     foundCheckListEntry.Checked    = checkListEntry.Checked;
                     foundCheckListEntry.FontSize   = checkListEntry.FontSize;
                     foundCheckListEntry.Width      = checkListEntry.Width;
                     foundCheckListEntry.Visibility = checkListEntry.Visibility;
                     await _sqLiteAsyncConnection?.UpdateAsync(foundCheckListEntry);
                 }
             }
             else if (foundCheckListEntry == null)
             {
                 await _sqLiteAsyncConnection.InsertAsync(checkListEntry);
             }
         }
         _eventService.OnChecklistUpdatedEvent(new EventArgs());
         //Toast.MakeText(_context, "New Checklist Update received...", ToastLength.Short).Show();
     }
     catch { }
     _isAlreadyConnected = false;
 }