Exemple #1
0
        /// <summary>
        /// This function checks that if network is available or not. if its available, it hits Knowledge api and store api's data into local db, if not available then it just get data from local db
        /// </summary>
        /// <returns></returns>
        public async Task <List <Category> > DatabaseOperation()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                var appActivityService = new AppActivityService();
                var activity           = await appActivityService.FetchAppActivityAsync();

                LastUpdateKB lastUpdateKBDate = DatabaseHelper.GetInstance().GetLastUpdateKBDate();

                if (lastUpdateKBDate == null || lastUpdateKBDate.KnowledgBaseLastUpdateDate != activity.First().knowledge_activity.last_updated)
                {
                    List <KnowledgeBaseModel> items = await FetchAllKnowledgeBaseData();

                    databaseHelper.AddKnowledgeBase(items);
                    DatabaseHelper.GetInstance().SaveLastUpdateKBDate(activity.First().knowledge_activity.last_updated);
                    return(FetchAllKnowledgeBaseCategories());
                }
                else
                {
                    return(FetchAllKnowledgeBaseCategories());
                }
            }
            else
            {
                return(FetchAllKnowledgeBaseCategories());
            }
        }
Exemple #2
0
        /// <summary>
        /// This function checks that if network is available or not. if its available, it hits Meditation api and store api's data into local db, if not available then it just get data from local db
        /// </summary>
        /// <returns></returns>
        public async Task <List <Category> > DatabaseOperation()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                var appActivityService = new AppActivityService();
                var activity           = await appActivityService.FetchAppActivityAsync();

                LastUpdateMeditation lastUpdateMeditationDate = DatabaseHelper.GetInstance().GetLastMeditationDate();

                if (lastUpdateMeditationDate == null || lastUpdateMeditationDate.MeditationLastUpdateDate != activity.First().meditation_activity.last_updated)
                {
                    List <MeditationModel> items = await FetchAllMeditationData();

                    databaseHelper.AddMeditation(items);
                    DatabaseHelper.GetInstance().SaveLastMeditationDate(activity.First().meditation_activity.last_updated);
                    return(FetchAllMeditationCategories());
                }
                else
                {
                    return(FetchAllMeditationCategories());
                }
            }
            else
            {
                return(FetchAllMeditationCategories());
            }
        }
Exemple #3
0
        /// <summary>
        /// This function checks that if network is available or not. if its available, it hits DailyDigest api and store api's data into local db, if not available then it just get data from local db
        /// </summary>
        /// <returns></returns>
        public async Task <List <DailyDigest> > DatabaseOperation()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                var appActivityService = new AppActivityService();
                var activity           = await appActivityService.FetchAppActivityAsync();

                LastUpdateDailyDigest lastUpdateDailyDigestDate = DatabaseHelper.GetInstance().GetLastDailyDigestDate();
                if (lastUpdateDailyDigestDate == null || lastUpdateDailyDigestDate.DailyDigestLastUpdateDate != activity.First().digest_activity.last_updated)
                {
                    List <DailyDigestModel> items = await FetchAllDigestItems();

                    databaseHelper.AddDailyDigest(items);
                    var dailyDigestLocalData = databaseHelper.GetDailyDigest();
                    DatabaseHelper.GetInstance().SaveLastUpdateDailyDigestDate(activity.First().digest_activity.last_updated);
                    return(dailyDigestLocalData);
                }
                else
                {
                    var dailyDigestLocalData = databaseHelper.GetDailyDigest();
                    if (dailyDigestLocalData != null)
                    {
                        return(dailyDigestLocalData);
                    }
                    else
                    {
                        Debug.WriteLine("DailyDigest local data is empty on DailyDigestItemPage");
                        return(null);
                    }
                }
                //if (Settings.DailyDigest_LastUpdate != activity.First().digest_activity.last_updated)
                //{
                //    List<DailyDigestModel> items = await FetchAllDigestItems();
                //    databaseHelper.AddDailyDigest(items);
                //    var dailyDigestLocalData = databaseHelper.GetDailyDigest();
                //    Settings.DailyDigest_LastUpdate = activity.First().digest_activity.last_updated;
                //    return dailyDigestLocalData;
                //}
                //else
                //{
                //    var dailyDigestLocalData = databaseHelper.GetDailyDigest();
                //    if (dailyDigestLocalData != null)
                //    {
                //        return dailyDigestLocalData;
                //    }
                //    else
                //    {
                //        Debug.WriteLine("DailyDigest local data is empty on DailyDigestItemPage");
                //        return null;
                //    }
                //}
            }
            else
            {
                var dailyDigestLocalData = databaseHelper.GetDailyDigest();
                if (dailyDigestLocalData != null)
                {
                    return(dailyDigestLocalData);
                }
                else
                {
                    Debug.WriteLine("DailyDigest local data is empty on DailyDigestItemPage");
                    return(null);
                }
            }
        }