protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_history); ensureRepo = new EnsureRepository(this); #region RvSetup // Create your application here var mLayoutManager = new LinearLayoutManager(this); // Logs recycler view (almost the same as ListView, but you can swipe out items) logsRv = FindViewById <RecyclerView>(Resource.Id.EnsuresRv); logsRv.SetLayoutManager(mLayoutManager); // Data adapter ensuresRvAdapter = new EnsureRecyclerAdapter(ensures); logsRv.SetAdapter(ensuresRvAdapter); logsRvTouchHelper = new EnsureLogTouchHelper(); logsRvTouchHelper.OnItemRecycled += LogsRv_ItemSwiped; // Touch helper (to handle item swipes) ItemTouchHelper itemTouchHelper = new ItemTouchHelper(logsRvTouchHelper); itemTouchHelper.AttachToRecyclerView(logsRv); #endregion prevBtn = FindViewById <Button>(Resource.Id.HistoryPrevBtn); prevBtn.Click += PrevBtn_Click; nextBtn = FindViewById <Button>(Resource.Id.HistoryNextBtn); nextBtn.Click += NextBtn_Click; displayedDateTv = FindViewById <TextView>(Resource.Id.DisplayedDateHistory); emptyListMessage = FindViewById <TextView>(Resource.Id.NothingMessageHistory); topLoadingProgress = FindViewById <ProgressBar>(Resource.Id.HistoryActivityTopProgress); ensureRepo = new EnsureRepository(this); // show top back button SupportActionBar.SetDisplayHomeAsUpEnabled(true); await UpdateDate(DateTime.Today); }
/// <summary> /// Handles the notification receiver broadcasts /// </summary> public async Task HandleNotificationBroadcastAsync(Intent intent) { // Stage 1: update information from server var ensureRepository = new EnsureRepository(context); var userSvc = new UserService(context); if (!userSvc.IsUserLoggedIn) { userSvc.LoadUserInfoFromSp(); // Load from SP all the user's info. We may call this after boot! } var userInfo = await userSvc.RefreshInfo(); var progress = (await ensureRepository.GetLogs(DateTime.MinValue)).Count; if (userInfo is null || progress < 0) // error has occured during information updating - stop. { LogHelper.Error("An error has occured while refreshing user info and log count in notification handler."); return; } LogHelper.Info($"Notification Service Got info from server: {progress}/{userInfo.DailyTarget}"); if (!context.IsAppForeground() && !intent.GetBooleanExtra("withoutNotification", false)) // only if user is NOT using the app, and there was no request (int the intent) to prevent showing notifications { // Stage 2: Notify user to drink if should (Target > Progress) if (userInfo.DailyTarget > progress) { NotifyEnsure(progress, userInfo); } } // Stage 3: schedule next check DateTime nextNotificationSchedule = GetNextSchedule(progress, userInfo); ScheduleEnsureCheckNotification(nextNotificationSchedule, false); }