Beispiel #1
0
        public void Duplicates_Should_Not_Be_Added_Via_AddRange()
        {
            var target = new Classes();

            target.Add("foo");
            target.AddRange(new[] { "foo", "bar" });

            Assert.Equal(new[] { "foo", "bar" }, target);
        }
Beispiel #2
0
        internal void ReadItems()
        {
            if (items.Any())
            {
                throw new InvalidOperationException();
            }

            using (var reader = cache.CreateReader(cache.MetadataTranslator))
            {
                reader.Seek(TagClassDataPointer.Address, SeekOrigin.Begin);
                Classes.AddRange(reader.ReadEnumerable <TagClass>(TagClassCount));

                reader.Seek(TagDataPointer.Address, SeekOrigin.Begin);
                for (int i = 0; i < TagCount; i++)
                {
                    var item = reader.ReadObject(new IndexItem(cache, i));
                    if (item.ClassIndex < 0)
                    {
                        continue;
                    }

                    items.Add(i, item);

                    if (item.ClassCode != CacheFactory.ScenarioClass && CacheFactory.SystemClasses.Contains(item.ClassCode))
                    {
                        sysItems.Add(item.ClassCode, item);
                    }
                }

                // hack to redirect any play tag requests to the start of the zone tag when there is no play tag
                var play = sysItems["play"];
                if (play.MetaPointer.Value == 0)
                {
                    play.MetaPointer = new Pointer(sysItems["zone"].MetaPointer.Value + 28, cache.MetadataTranslator);
                }

                reader.Seek(cache.Header.FileTableIndexPointer.Address, SeekOrigin.Begin);
                var indices = reader.ReadEnumerable <int>(TagCount).ToArray();

                reader.Seek(cache.Header.FileTablePointer.Address, SeekOrigin.Begin);
                var decrypted = reader.ReadAesBytes(cache.Header.FileTableSize, CacheFile.FileNamesKey);
                using (var ms = new MemoryStream(decrypted))
                    using (var tempReader = new EndianReader(ms))
                    {
                        for (int i = 0; i < TagCount; i++)
                        {
                            if (indices[i] == -1)
                            {
                                Filenames.Add(i, null);
                                continue;
                            }

                            tempReader.Seek(indices[i], SeekOrigin.Begin);
                            Filenames.Add(i, tempReader.ReadNullTerminatedString());
                        }
                    }
            }

            try
            {
                sysItems[CacheFactory.ScenarioClass] = items.Values.Single(i => i.ClassCode == CacheFactory.ScenarioClass && i.FullPath == cache.Header.ScenarioName);
            }
            catch { throw Exceptions.AmbiguousScenarioReference(); }
        }
Beispiel #3
0
        internal void ReadItems()
        {
            if (items.Any())
            {
                throw new InvalidOperationException();
            }

            using (var reader = cache.CreateReader(cache.MetadataTranslator, cache.PointerExpander))
            {
                reader.Seek(TagClassDataPointer.Address, SeekOrigin.Begin);
                Classes.AddRange(reader.ReadEnumerable <TagClass>(TagClassCount));

                reader.Seek(TagDataPointer.Address, SeekOrigin.Begin);
                for (int i = 0; i < TagCount; i++)
                {
                    var item = reader.ReadObject(new IndexItem(cache, i));
                    if (item.ClassIndex < 0)
                    {
                        continue;
                    }

                    items.Add(i, item);

                    if (item.ClassCode != CacheFactory.ScenarioClass && CacheFactory.SystemClasses.Contains(item.ClassCode))
                    {
                        sysItems.Add(item.ClassCode, item);
                    }
                }

                var play = sysItems["play"];
                if (play.MetaPointer.Value == 0)
                {
                    play.MetaPointer = new Pointer(sysItems["zone"].MetaPointer.Value + 28, cache.MetadataTranslator);
                }

                reader.Seek(cache.Header.FileTableIndexPointer.Address, SeekOrigin.Begin);
                var indices = reader.ReadEnumerable <int>(TagCount).ToArray();

                reader.Seek(cache.Header.FileTablePointer.Address, SeekOrigin.Begin);
                using (var tempReader = reader.CreateVirtualReader())
                {
                    for (int i = 0; i < TagCount; i++)
                    {
                        if (indices[i] == -1)
                        {
                            Filenames.Add(i, null);
                            continue;
                        }

                        tempReader.Seek(indices[i], SeekOrigin.Begin);
                        Filenames.Add(i, tempReader.ReadNullTerminatedString());
                    }
                }
            }

            try
            {
                sysItems[CacheFactory.ScenarioClass] = items.Values.Single(i => i.ClassCode == CacheFactory.ScenarioClass && i.FullPath == cache.Header.ScenarioName);
            }
            catch { throw Exceptions.AmbiguousScenarioReference(); }
        }
        //Get Search Api
        public async void GetSearch_Result(string key, string user_offset = "", string group_offset = "",
                                           string page_offset             = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        if (user_offset == "" && group_offset == "" && page_offset == "")
                        {
                            AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading));
                        }
                    });

                    var(api_status, respond) = await Client.Global.Get_Search(UserDetails.User_id, key, "35",
                                                                              user_offset, group_offset, page_offset, Filter_gender);

                    if (api_status == 200)
                    {
                        if (respond is Get_Search_Object result)
                        {
                            if (result.Users.Count <= 0 && result.Groups.Count <= 0 && result.Pages.Count <= 0)
                            {
                                return;
                            }

                            RunOnUiThread(() =>
                            {
                                //Add result users
                                //*===========================================*
                                if (result.Users.Count > 0 && result.Users.Count != 0)
                                {
                                    if (SearchUser_Tab.mSearchAdapter.mSearchUserList.Count <= 0)
                                    {
                                        SearchUser_Tab.mSearchAdapter.mSearchUserList =
                                            new ObservableCollection <Get_Search_Object.User>(result.Users);
                                        SearchUser_Tab.mSearchAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.Users?.Where(c =>
                                                                          !SearchUser_Tab.mSearchAdapter.mSearchUserList.Select(fc => fc.UserId)
                                                                          .Contains(c.UserId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = SearchUser_Tab.mSearchAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(SearchUser_Tab.mSearchAdapter.mSearchUserList, listNew);
                                            SearchUser_Tab.mSearchAdapter.NotifyItemRangeInserted(lastCountItem,
                                                                                                  listNew.Count);
                                        }
                                    }
                                }

                                //Add result pages
                                //*===========================================*
                                if (result.Pages.Count > 0 && result.Pages.Count != 0)
                                {
                                    if (SearchPages_Tab.mSaerchPageAdapter.mSearchPageList.Count <= 0)
                                    {
                                        SearchPages_Tab.mSaerchPageAdapter.mSearchPageList =
                                            new ObservableCollection <Get_Search_Object.Page>(result.Pages);
                                        //SearchPages_Tab.mSaerchPageAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.Pages?.Where(c =>
                                                                          !SearchPages_Tab.mSaerchPageAdapter.mSearchPageList.Select(fc => fc.PageId)
                                                                          .Contains(c.PageId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = SearchPages_Tab.mSaerchPageAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(SearchPages_Tab.mSaerchPageAdapter.mSearchPageList,
                                                             listNew);
                                            SearchPages_Tab.mSaerchPageAdapter.NotifyItemRangeInserted(lastCountItem,
                                                                                                       listNew.Count);
                                        }
                                    }
                                }

                                //Add result groups
                                //*===========================================*
                                if (result.Groups.Count > 0 && result.Groups.Count != 0)
                                {
                                    if (SearchGroups_Tab.mSaerchGroupAdapter.mSearchGroupList.Count <= 0)
                                    {
                                        SearchGroups_Tab.mSaerchGroupAdapter.mSearchGroupList =
                                            new ObservableCollection <Get_Search_Object.Group>(result.Groups);
                                        //SearchGroups_Tab.mSaerchGroupAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.Groups?.Where(c =>
                                                                           !SearchGroups_Tab.mSaerchGroupAdapter.mSearchGroupList
                                                                           .Select(fc => fc.GroupId).Contains(c.GroupId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = SearchGroups_Tab.mSaerchGroupAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(SearchGroups_Tab.mSaerchGroupAdapter.mSearchGroupList,
                                                             listNew);
                                            SearchGroups_Tab.mSaerchGroupAdapter.NotifyItemRangeInserted(lastCountItem,
                                                                                                         listNew.Count);
                                        }
                                    }
                                }
                            });
                        }
                    }
                    else if (api_status == 400)
                    {
                        if (respond is Error_Object error)
                        {
                            var errorText = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errorText.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (api_status == 404)
                    {
                        var error = respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }

                    RunOnUiThread(() =>
                    {
                        //Show Empty Page
                        //===========================================
                        if (SearchUser_Tab.mSearchAdapter.mSearchUserList.Count > 0)
                        {
                            SearchUser_Tab.Search_Recyler.Visibility = ViewStates.Visible;
                            SearchUser_Tab.Search_Empty.Visibility   = ViewStates.Gone;
                        }
                        else
                        {
                            SearchUser_Tab.Search_Recyler.Visibility = ViewStates.Gone;
                            SearchUser_Tab.Search_Empty.Visibility   = ViewStates.Visible;
                        }

                        //Set Event Scroll >> Users
                        if (User_OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(SearchUser_Tab.mSearchLayoutManager);
                            User_OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            User_OnMainScrolEvent.LoadMoreEvent += LastUsers_OnScroll_OnLoadMoreEvent;
                            SearchUser_Tab.Search_Recyler.AddOnScrollListener(User_OnMainScrolEvent);
                            SearchUser_Tab.Search_Recyler.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            User_OnMainScrolEvent.IsLoading = false;
                        }

                        //Show Empty Page
                        //===========================================
                        if (SearchGroups_Tab.mSaerchGroupAdapter.mSearchGroupList.Count > 0)
                        {
                            SearchGroups_Tab.SearchGroup_Recyler.Visibility = ViewStates.Visible;
                            SearchGroups_Tab.SearchGroup_Empty.Visibility   = ViewStates.Gone;
                        }
                        else
                        {
                            SearchGroups_Tab.SearchGroup_Recyler.Visibility = ViewStates.Gone;
                            SearchGroups_Tab.SearchGroup_Empty.Visibility   = ViewStates.Visible;
                        }

                        //Set Event Scroll >> Groups
                        if (Group_OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(SearchGroups_Tab.mSearchLayoutManager);
                            Group_OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            Group_OnMainScrolEvent.LoadMoreEvent += LastGroups_OnScroll_OnLoadMoreEvent;
                            SearchGroups_Tab.SearchGroup_Recyler.AddOnScrollListener(Group_OnMainScrolEvent);
                            SearchGroups_Tab.SearchGroup_Recyler.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            Group_OnMainScrolEvent.IsLoading = false;
                        }

                        //Show Empty Page
                        //===========================================
                        if (SearchPages_Tab.mSaerchPageAdapter.mSearchPageList.Count > 0)
                        {
                            SearchPages_Tab.SearchPage_Recyler.Visibility = ViewStates.Visible;
                            SearchPages_Tab.SearchPage_Empty.Visibility   = ViewStates.Gone;
                        }
                        else
                        {
                            SearchPages_Tab.SearchPage_Recyler.Visibility = ViewStates.Gone;
                            SearchPages_Tab.SearchPage_Empty.Visibility   = ViewStates.Visible;
                        }

                        //Set Event Scroll >> Pages
                        if (Page_OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(SearchPages_Tab.mSearchLayoutManager);
                            Page_OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            Page_OnMainScrolEvent.LoadMoreEvent += LastPage_OnScroll_OnLoadMoreEvent;
                            SearchPages_Tab.SearchPage_Recyler.AddOnScrollListener(Page_OnMainScrolEvent);
                            SearchPages_Tab.SearchPage_Recyler.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            Page_OnMainScrolEvent.IsLoading = false;
                        }

                        _SearchView.ClearFocus();
                        AndHUD.Shared.Dismiss(this);
                    });
                }
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
                GetSearch_Result(search_key, LastUserid, LastGroupid, LastPageid);
            }
        }
        //Get Data Market Using API >> My Products
        public async void Get_MyDataMarket_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    var(Api_status, Respond) = await Client.Market.Get_Products(UserDetails.User_id, "35", offset);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Products_Object result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                if (result.products.Length <= 0)
                                {
                                    if (swipeRefreshLayout.Refreshing)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.products.Length > 0)
                                {
                                    if (MMyProductsAdapter.MyProductsList.Count <= 0)
                                    {
                                        MMyProductsAdapter.MyProductsList =
                                            new ObservableCollection <Get_Products_Object.Product>(result.products);
                                        MMyProductsAdapter.BindEnd();

                                        var animation = AnimationUtils.LoadAnimation(Activity,
                                                                                     Resource.Animation.slideUpAnim);
                                        MainRecyclerView.StartAnimation(animation);
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listnew = result.products?.Where(c =>
                                                                             !MMyProductsAdapter.MyProductsList.Select(fc => fc.id).Contains(c.id))
                                                      .ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = MMyProductsAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MMyProductsAdapter.MyProductsList, listnew);
                                            MMyProductsAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count);
                                        }

                                        if (swipeRefreshLayout.Refreshing)
                                        {
                                            swipeRefreshLayout.Refreshing = false;
                                        }
                                    }
                                }
                            });
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is Error_Object error)
                        {
                            var errortext = error._errors.Error_text;
                            //Toast.MakeText(this.Activity, errortext, ToastLength.Short).Show();

                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(Activity);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                        //Toast.MakeText(this.Activity, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                Activity.RunOnUiThread(() =>
                {
                    if (MMyProductsAdapter.MyProductsList.Count > 0)
                    {
                        if (MainRecyclerView.Visibility == ViewStates.Gone)
                        {
                            MainRecyclerView.Visibility = ViewStates.Visible;
                        }

                        if (MyProducts_Empty.Visibility == ViewStates.Visible)
                        {
                            MyProducts_Empty.Visibility = ViewStates.Gone;
                        }
                    }
                    else
                    {
                        MainRecyclerView.Visibility = ViewStates.Gone;
                        MyProducts_Empty.Visibility = ViewStates.Visible;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (MarketMyProductScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                        MarketMyProductScrolEvent = xamarinRecyclerViewOnScrollListener;
                        MarketMyProductScrolEvent.LoadMoreEvent += MyProductsOnScroll_OnLoadMoreEvent;
                        MainRecyclerView.AddOnScrollListener(MarketMyProductScrolEvent);
                        MainRecyclerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        MarketMyProductScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_MyDataMarket_Api(offset);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Erstellt eine Datenbank mit Musterdaten. Ist die Datenbank schon vorhanden, werden keine
        /// Änderungen daran durchgeführt.
        /// </summary>
        /// <param name="deleteDb">Gibt ab, ob eine vorhandene Datenbank gelöscht werden soll.</param>
        public void CreateDatabase(bool deleteDb = false)
        {
            if (deleteDb)
            {
                Database.EnsureDeleted();
            }
            if (!Database.EnsureCreated())
            {
                return;
            }

            // Damit bei jedem Programmstart die gleichen Daten generiert werden, wird der
            // Zufallsgenerator mit einem fixen Wert initialisiert. Das ist wichtig, um Fehler
            // reproduzieren zu können.
            Randomizer.Seed = new Random(16030829);
            Randomizer rnd = new Randomizer();

            // Die Geschlechter in die DB schreiben.
            var genders = new List <Gender>
            {
                new Gender {
                    GenderNr = 1, Name = "Male"
                },
                new Gender {
                    GenderNr = 2, Name = "Female"
                },
            };

            Genders.AddRange(genders);
            SaveChanges();

            // 20 Lehrer erzeugen.
            int teacherNr = 1000;
            var teachers  = new Faker <Teacher>()
                            .RuleFor(t => t.Firstname, f => f.Name.FirstName())
                            .RuleFor(t => t.Lastname, f => f.Name.LastName())
                            .RuleFor(t => t.TeacherNr, (f, t) => $"{t.Lastname.Substring(0, 3).ToUpper()}{teacherNr++}")
                            .RuleFor(t => t.Email, (f, t) => t.TeacherNr.ToLower() + "@spengergasse.at")
                            .Generate(20);

            Teachers.AddRange(teachers);
            SaveChanges();

            // Die Klassen 1AHIF - 5AHIF erzeugen.
            var classes = Enumerable.Range(1, 5)
                          .Select(i => new Schoolclass
            {
                ClassNr = i.ToString() + "AHIF",
                Room    = $"{rnd.String2(1, "ABC")}{rnd.String2(1, "1234")}.{rnd.String2(1, "01")}{rnd.String2(1, "123456789")}",
                KV      = rnd.ListItem(teachers)
            }).ToList();

            Classes.AddRange(classes);
            SaveChanges();

            // 50 Schüler erzeugen und in eine zufällige Klasse setzen.
            var pupils = new Faker <Pupil>()
                         .RuleFor(p => p.Gender, f => f.Random.ListItem(genders))
                         .RuleFor(p => p.Lastname, f => f.Name.LastName())
                         .RuleFor(p => p.Firstname, (f, p) => f.Name.FirstName((Bogus.DataSets.Name.Gender)(p.Gender.GenderNr - 1)))
                         .RuleFor(p => p.Schoolclass, f => f.Random.ListItem(classes))
                         // Bei nullable Werten erzeugen wir 20 % NULL werten. In diesem Fall wird das Geburtsdatum
                         // nicht bei jedem Schüler eingetragen.
                         .RuleFor(p => p.DateOfBirth, (f, p) =>
                                  f.Date.Between(
                                      new DateTime(2006 - int.Parse(p.Schoolclass.ClassNr.Substring(0, 1)), 9, 1),
                                      new DateTime(2007 - int.Parse(p.Schoolclass.ClassNr.Substring(0, 1)), 9, 1)).Date.OrNull(f, 0.2f))
                         .Generate(50);

            Pupils.AddRange(pupils);
            SaveChanges();

            // Generator für Prüfungen erzeugen.
            var examFaker = new Faker <Exam>()
                            .RuleFor(e => e.Subject, f => f.Random.ListItem(new string[] { "AM", "D", "E", "POS", "DBI" }))
                            .RuleFor(e => e.Date, f => f.Date.Between(new DateTime(2019, 9, 1), new DateTime(2020, 7, 1)).Date)
                            .RuleFor(e => e.Examiner, f => f.Random.ListItem(teachers))
                            .RuleFor(e => e.Grade, f => f.Random.Int(1, 5).OrNull(f, 0.2f));

            // 3 - 5 Prüfungen für jeden Schüler erzeugen und die Liste der Prüfungen des Schülers
            // setzen.
            foreach (var p in pupils)
            {
                int examCount = rnd.Int(3, 5);
                // Der Schüler wird erst jetzt zugewiesen, da wir für jeden Schüler Prüfungen
                // generieren wollen.
                Exams.AddRange(examFaker.RuleFor(e => e.Pupil, f => p).Generate(examCount));
            }
            SaveChanges();
        }
        public void Should_Not_Be_Able_To_Add_Pseudoclasses_Via_AddRange()
        {
            var target = new Classes();

            Assert.Throws <ArgumentException>(() => target.AddRange(new[] { "foo", ":bar" }));
        }
        //Api
        public async void Get_Contacts_APi()
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });
                    Toast.MakeText(this, GetString(Resource.String.Lbl_Error_check_internet_connection),
                                   ToastLength.Short)
                    .Show();
                }
                else
                {
                    var lastIdUser = CallAdapter.mCallUserContacts?.LastOrDefault()?.UserId ?? "0";

                    var(api_status, respond) = await API_Request.Get_users_friends_Async(lastIdUser);

                    if (api_status == 200)
                    {
                        if (respond is Classes.UserContacts result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.Users.Count <= 0)
                                {
                                }
                                else if (result.Users.Count > 0)
                                {
                                    var listNew = result.Users?.Where(c => !CallAdapter.mCallUserContacts.Select(fc => fc.UserId).Contains(c.UserId)).ToList();
                                    if (listNew.Count > 0)
                                    {
                                        Classes.AddRange(CallAdapter.mCallUserContacts, listNew);

                                        var lastCountItem = CallAdapter.ItemCount;
                                        CallAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                        CallAdapter.BindEnd();
                                        CallAdapter.NotifyItemChanged(0);

                                        //Insert Or Update All data UsersContact to database
                                        var dbDatabase = new SqLiteDatabase();
                                        dbDatabase.Insert_Or_Replace_MyContactTable(CallAdapter.mCallUserContacts);
                                        dbDatabase.Dispose();
                                    }

                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                            });
                        }
                    }
                    else if (api_status == 400)
                    {
                        if (respond is ErrorObject error)
                        {
                            var errortext = error._errors.Error_text;


                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (api_status == 404)
                    {
                        var error = respond.ToString();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                RunOnUiThread(() =>
                {
                    if (CallAdapter.mCallUserContacts?.Count > 0)
                    {
                        Calluser_Empty.Visibility      = ViewStates.Gone;
                        CalluserRecylerView.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        Calluser_Empty.Visibility      = ViewStates.Visible;
                        CalluserRecylerView.Visibility = ViewStates.Gone;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (OnMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener = new XamarinRecyclerViewOnScrollListener(ContactsLayoutManager);
                        OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMainScrolEvent.LoadMoreEvent += MyContact_OnScroll_OnLoadMoreEvent;
                        CalluserRecylerView.AddOnScrollListener(OnMainScrolEvent);
                        CalluserRecylerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Get_Contacts_APi();
            }
        }
        public void Get_MyContact(int lastId = 0)
        {
            try
            {
                RunOnUiThread(() =>
                {
                    if (Settings.ConnectivitySystem == "1") // Following
                    {
                        SupportActionBar.Title = GetText(Resource.String.Lbl_Following);
                    }
                    else // Friend
                    {
                        SupportActionBar.Title = GetText(Resource.String.Lbl_Friends);
                    }
                });

                //Get All User From Database
                var dbDatabase = new SqLiteDatabase();
                var localList  = dbDatabase.Get_MyContact(lastId, 25);
                if (localList != null)
                {
                    RunOnUiThread(() =>
                    {
                        var list = new JavaList <Classes.UserContacts.User>(localList);
                        if (list.Count > 0)
                        {
                            var listNew = list?.Where(c => !UserContactsList.Select(fc => fc.user_id).Contains(c.user_id)).ToList();
                            if (listNew.Count > 0)
                            {
                                Classes.AddRange(UserContactsList, listNew);

                                var listOrder = new JavaList <Classes.UserContacts.User>(UserContactsList.OrderBy(a => a.name));
                                if (MyContactsAdapter == null)
                                {
                                    //Results differ
                                    MyContactsAdapter = new MyContacts_Adapter(this, listOrder, ContactsRecyler);
                                    ContactsRecyler.SetAdapter(MyContactsAdapter);
                                    MyContactsAdapter.ItemClick += MyContactsAdapter_OnItemClick;

                                    var lastCountItem = MyContactsAdapter.ItemCount;
                                    MyContactsAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                }
                                else
                                {
                                    MyContactsAdapter.mMyContactsList = new JavaList <Classes.UserContacts.User>(listOrder);

                                    var lastCountItem = MyContactsAdapter.ItemCount;
                                    MyContactsAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                }
                            }
                            else
                            {
                                if (ShowSnackbar)
                                {
                                    Snackbar.Make(ContactsRecyler, GetText(Resource.String.Lbl_Loading_From_Server), Snackbar.LengthLong).Show();
                                    ShowSnackbar = false;
                                }
                                Get_Contacts_APi();
                            }

                            if (swipeRefreshLayout != null)
                            {
                                swipeRefreshLayout.Refreshing = false;
                            }
                        }
                        else
                        {
                            if (ShowSnackbar)
                            {
                                Snackbar.Make(ContactsRecyler, GetText(Resource.String.Lbl_Loading_From_Server), Snackbar.LengthLong).Show();
                                ShowSnackbar = false;
                            }
                            Get_Contacts_APi();
                        }

                        //Set Event Scroll
                        if (OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(ContactsLayoutManager, swipeRefreshLayout);
                            OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            OnMainScrolEvent.LoadMoreEvent += MyContact_OnScroll_OnLoadMoreEvent;
                            ContactsRecyler.AddOnScrollListener(OnMainScrolEvent);
                            ContactsRecyler.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            OnMainScrolEvent.IsLoading = false;
                        }
                    });
                }
                else
                {
                    if (ShowSnackbar)
                    {
                        Snackbar.Make(ContactsRecyler, GetText(Resource.String.Lbl_Loading_From_Server), Snackbar.LengthLong).Show();
                        ShowSnackbar = false;
                    }
                    Get_Contacts_APi();
                }

                dbDatabase.Dispose();

                if (UserContactsList?.Count <= 24 || UserContactsList?.Count == 0)
                {
                    swipeRefreshLayout.Refreshing = true;
                    Get_Contacts_APi();
                }
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
        //Get Search Api
        public async void GetSearch_Result(string key, string user_offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Toast.MakeText(this, GetString(Resource.String.Lbl_Error_check_internet_connection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        if (user_offset == "")
                        {
                            swipeRefreshLayout.Refreshing = true;
                            swipeRefreshLayout.Enabled    = true;
                        }
                    });

                    var(api_status, respond) = await Global.Get_Search(UserDetails.User_id, key, "35", user_offset, "", "", Filter_gender);

                    if (api_status == 200)
                    {
                        if (respond is GetSearchObject result)
                        {
                            if (result.Users.Count <= 0 && result.Groups.Count <= 0 && result.Pages.Count <= 0)
                            {
                                return;
                            }

                            RunOnUiThread(() =>
                            {
                                //Add result users
                                //*===========================================*
                                if (result.Users.Count > 0 && result.Users.Count != 0)
                                {
                                    if (mAdapter.mSearchUserList.Count <= 0)
                                    {
                                        mAdapter.mSearchUserList = new ObservableCollection <GetSearchObject.User>(result.Users);
                                        mAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.Users?.Where(c => !mAdapter.mSearchUserList.Select(fc => fc.UserId).Contains(c.UserId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = mAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(mAdapter.mSearchUserList, listNew);
                                            mAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                        }
                                    }
                                }
                            });
                        }
                    }
                    else if (api_status == 400)
                    {
                        if (respond is ErrorObject error)
                        {
                            var errorText = error._errors.Error_text;


                            if (errorText.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (api_status == 404)
                    {
                        var error = respond.ToString();
                    }

                    RunOnUiThread(() =>
                    {
                        //Show Empty Page
                        //===========================================
                        if (mAdapter.mSearchUserList.Count > 0)
                        {
                            SearchRecyler.Visibility      = ViewStates.Visible;
                            OnlineSearch_Empty.Visibility = ViewStates.Gone;
                        }
                        else
                        {
                            SearchRecyler.Visibility      = ViewStates.Gone;
                            OnlineSearch_Empty.Visibility = ViewStates.Visible;
                        }

                        //Set Event Scroll >> Users
                        if (User_OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(mLayoutManager);
                            User_OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            User_OnMainScrolEvent.LoadMoreEvent += LastUsers_OnScroll_OnLoadMoreEvent;
                            SearchRecyler.AddOnScrollListener(User_OnMainScrolEvent);
                            SearchRecyler.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            User_OnMainScrolEvent.IsLoading = false;
                        }

                        _SearchView.ClearFocus();
                        swipeRefreshLayout.Refreshing = false;
                    });
                }
                RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                GetSearch_Result(search_key, LastUserid);
                RunOnUiThread(() =>
                {
                    swipeRefreshLayout.Refreshing = false;
                    if (mAdapter.mSearchUserList.Count > 0)
                    {
                        SearchRecyler.Visibility      = ViewStates.Visible;
                        OnlineSearch_Empty.Visibility = ViewStates.Gone;
                    }
                    else
                    {
                        SearchRecyler.Visibility      = ViewStates.Gone;
                        OnlineSearch_Empty.Visibility = ViewStates.Visible;
                    }
                });
            }
        }
Beispiel #11
0
        public async void Get_BlockedList_API()
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    swipeRefreshLayout.Refreshing = false;
                    Toast.MakeText(this, GetString(Resource.String.Lbl_Error_check_internet_connection),
                                   ToastLength.Short)
                    .Show();
                }
                else
                {
                    var(Api_status, Respond) = await Global.Get_Blocked_Users();

                    if (Api_status == 200)
                    {
                        if (Respond is GetBlockedUsersObject result)
                        {
                            if (result.blocked_users.Length <= 0)
                            {
                                swipeRefreshLayout.Refreshing = false;
                            }

                            var dbDatabase = new SqLiteDatabase();
                            if (mAdapter.mBlockedUsers.Count > 0)
                            {
                                //Bring new users
                                var listnew = result.blocked_users.Where(c =>
                                                                         !mAdapter.mBlockedUsers.Select(fc => fc.user_id).Contains(c.user_id)).ToList();
                                if (listnew.Count > 0)
                                {
                                    //Results differ
                                    Classes.AddRange(mAdapter.mBlockedUsers, listnew);

                                    //Insert Or Replace Just New Data To Database
                                    dbDatabase.Insert_Or_Replace_BlockedUsersTable(
                                        new ObservableCollection <GetBlockedUsersObject.BlockedUsers>(listnew));
                                }
                            }
                            else
                            {
                                mAdapter.mBlockedUsers =
                                    new ObservableCollection <GetBlockedUsersObject.BlockedUsers>(
                                        result.blocked_users);
                                mAdapter.BindEnd();

                                //Insert Or Replace Data To Database
                                dbDatabase.Insert_Or_Replace_BlockedUsersTable(mAdapter.mBlockedUsers);
                            }

                            dbDatabase.Dispose();
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is ErrorObject error)
                        {
                            var errortext = error._errors.Error_text;


                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                if (mAdapter.mBlockedUsers.Count > 0)
                {
                    BlockedUsersRecyler.Visibility = ViewStates.Visible;
                    BlockedUsers_Empty.Visibility  = ViewStates.Gone;
                }
                else
                {
                    BlockedUsersRecyler.Visibility = ViewStates.Gone;
                    BlockedUsers_Empty.Visibility  = ViewStates.Visible;
                }

                swipeRefreshLayout.Refreshing = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Get_BlockedList_API();
            }
        }
Beispiel #12
0
        //Get Articles API
        public async void Get_Articles_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });

                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    var(Api_status, Respond) = await Client.Article.Get_Articles("25", offset);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Users_Articles_Object result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.articles.Length <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.articles.Length > 0)
                                {
                                    if (ArticlesAdapter.ArticlesList.Count <= 0)
                                    {
                                        ArticlesAdapter.ArticlesList =
                                            new ObservableCollection <Get_Users_Articles_Object.Article>(
                                                result.articles);
                                        ArticlesAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listnew = result.articles?.Where(c =>
                                                                             !ArticlesAdapter.ArticlesList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = ArticlesAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(ArticlesAdapter.ArticlesList, listnew);
                                            ArticlesAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count);
                                        }

                                        if (swipeRefreshLayout.Refreshing)
                                        {
                                            swipeRefreshLayout.Refreshing = false;
                                        }
                                    }
                                }
                            });
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is Error_Object error)
                        {
                            var errortext = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }

                    //Show Empty Page
                    //===========================================
                    RunOnUiThread(() =>
                    {
                        if (ArticlesAdapter.ArticlesList.Count > 0)
                        {
                            Articls_Empty.Visibility      = ViewStates.Gone;
                            ArticlsRecylerView.Visibility = ViewStates.Visible;
                        }
                        else
                        {
                            Articls_Empty.Visibility      = ViewStates.Visible;
                            ArticlsRecylerView.Visibility = ViewStates.Gone;
                        }

                        swipeRefreshLayout.Refreshing = false;

                        //Set Event Scroll
                        if (OnMainScrolEvent == null)
                        {
                            var xamarinRecyclerViewOnScrollListener =
                                new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                            OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                            OnMainScrolEvent.LoadMoreEvent += Article_OnScroll_OnLoadMoreEvent;
                            ArticlsRecylerView.AddOnScrollListener(OnMainScrolEvent);
                            ArticlsRecylerView.AddOnScrollListener(new ScrollDownDetector());
                        }
                        else
                        {
                            OnMainScrolEvent.IsLoading = false;
                        }
                    });
                }
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_Articles_Api(offset);
            }
        }
Beispiel #13
0
        // Get List Page Using API
        public async void Get_CommunitiesList_Page_API()
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    swipeRefreshLayout.Refreshing = false;
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    Settings st = new Settings();
                    var(Api_status, Respond) = await Client.Global.Get_Community(st, UserID);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Community_Object result)
                        {
                            if (result.Groups.Count <= 0 && result.likedPages.Count <= 0 && result.Pages.Count <= 0)
                            {
                                swipeRefreshLayout.Refreshing = false;
                            }

                            var dbDatabase = new SqLiteDatabase();

                            //Add Data
                            //=======================================
                            if (PagesManage_Type == "Manage_UserPages")
                            {
                                // pages
                                if (result.Pages.Count > 0)
                                {
                                    PageAdapter.mPageList =
                                        new ObservableCollection <Get_Community_Object.Page>(result.Pages);
                                }


                                if (result.likedPages.Count > 0)
                                {
                                    var likedPagesList =
                                        new ObservableCollection <Get_Community_Object.LikedPages>(result.likedPages);
                                    var list = likedPagesList.Select(page => new Get_Community_Object.Page
                                    {
                                        PageId          = page.PageId,
                                        UserId          = page.UserId,
                                        PageName        = page.PageName,
                                        PageTitle       = page.PageTitle,
                                        PageDescription = page.PageDescription,
                                        Avatar          = page.Avatar,
                                        Cover           = page.Cover,
                                        PageCategory    = page.PageCategory,
                                        Website         = page.Website,
                                        Facebook        = page.Facebook,
                                        Google          = page.Google,
                                        Vk                    = page.Vk,
                                        Twitter               = page.Twitter,
                                        Linkedin              = page.Linkedin,
                                        Company               = page.Company,
                                        Phone                 = page.Phone,
                                        Address               = page.Address,
                                        CallActionType        = page.CallActionType,
                                        CallActionTypeUrl     = page.CallActionTypeUrl,
                                        BackgroundImage       = page.BackgroundImage,
                                        BackgroundImageStatus = page.BackgroundImageStatus,
                                        Instgram              = page.Instgram,
                                        Youtube               = page.Youtube,
                                        Verified              = page.Verified,
                                        Registered            = page.Registered,
                                        Boosted               = page.Boosted,
                                        About                 = page.About,
                                        Id                    = page.Id,
                                        Type                  = page.Type,
                                        Url                   = page.Url,
                                        Name                  = page.Name,
                                        //Rating = page.Rating,
                                        Category    = page.Category,
                                        IsPageOnwer = page.IsPageOnwer,
                                        Username    = page.Username
                                    }).ToList();

                                    //Bring new item
                                    var listnew = list?.Where(c =>
                                                              !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId)).ToList();
                                    if (listnew.Count > 0)
                                    {
                                        var lastCountItem = PageAdapter.ItemCount;
                                        //Results differ
                                        Classes.AddRange(PageAdapter.mPageList, listnew);
                                    }
                                }

                                PageAdapter.BindEnd();
                            }
                            else if (PagesManage_Type == "Manage_MyPages")
                            {
                                // likedPages
                                if (result.likedPages.Count > 0)
                                {
                                    var likedPagesList =
                                        new ObservableCollection <Get_Community_Object.LikedPages>(result.likedPages);

                                    //Update All Data To Database
                                    if (UserID == UserDetails.User_id)
                                    {
                                        var list = likedPagesList.Select(page => new Get_Community_Object.Page
                                        {
                                            PageId          = page.PageId,
                                            UserId          = page.UserId,
                                            PageName        = page.PageName,
                                            PageTitle       = page.PageTitle,
                                            PageDescription = page.PageDescription,
                                            Avatar          = page.Avatar,
                                            Cover           = page.Cover,
                                            PageCategory    = page.PageCategory,
                                            Website         = page.Website,
                                            Facebook        = page.Facebook,
                                            Google          = page.Google,
                                            Vk                    = page.Vk,
                                            Twitter               = page.Twitter,
                                            Linkedin              = page.Linkedin,
                                            Company               = page.Company,
                                            Phone                 = page.Phone,
                                            Address               = page.Address,
                                            CallActionType        = page.CallActionType,
                                            CallActionTypeUrl     = page.CallActionTypeUrl,
                                            BackgroundImage       = page.BackgroundImage,
                                            BackgroundImageStatus = page.BackgroundImageStatus,
                                            Instgram              = page.Instgram,
                                            Youtube               = page.Youtube,
                                            Verified              = page.Verified,
                                            Registered            = page.Registered,
                                            Boosted               = page.Boosted,
                                            About                 = page.About,
                                            Id                    = page.Id,
                                            Type                  = page.Type,
                                            Url                   = page.Url,
                                            Name                  = page.Name,
                                            //Rating = page.Rating,
                                            Category    = page.Category,
                                            IsPageOnwer = page.IsPageOnwer,
                                            Username    = page.Username
                                        }).ToList();

                                        // pages
                                        if (PageAdapter.mPageList.Count > 0)
                                        {
                                            //Bring new pages
                                            var listNew = list.Where(c =>
                                                                     !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId))
                                                          .ToList();
                                            if (listNew.Count > 0)
                                            {
                                                var chkList = listNew.Where(a => a.UserId != UserDetails.User_id)
                                                              .ToList();
                                                if (chkList.Count > 0)
                                                {
                                                    //Results differ
                                                    Classes.AddRange(PageAdapter.mPageList, chkList);
                                                    PageAdapter.BindEnd();

                                                    //Insert Or Replace Just New Data To Database
                                                    if (UserID == UserDetails.User_id)
                                                    {
                                                        dbDatabase.Insert_Or_Replace_PagesTable(
                                                            new ObservableCollection <Get_Community_Object.Page>(
                                                                chkList));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var chkList = list.Where(a => a.UserId != UserDetails.User_id).ToList();
                                            if (chkList.Count > 0)
                                            {
                                                PageAdapter.mPageList =
                                                    new ObservableCollection <Get_Community_Object.Page>(chkList);
                                                PageAdapter.BindEnd();

                                                //Insert Or Replace Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.Insert_Or_Replace_PagesTable(PageAdapter.mPageList);
                                                }
                                            }
                                        }

                                        dbDatabase.Insert_Or_Replace_PagesTable(
                                            new ObservableCollection <Get_Community_Object.Page>(list));
                                    }
                                }

                                //====================================

                                if (result.Pages.Count > 0)
                                {
                                    // pages
                                    if (PageAdapter.mPageList.Count > 0)
                                    {
                                        //Bring new pages
                                        var listNew = result.Pages.Where(c =>
                                                                         !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var chkList = listNew.Where(a => a.UserId != UserDetails.User_id).ToList();
                                            if (chkList.Count > 0)
                                            {
                                                //Results differ
                                                Classes.AddRange(PageAdapter.mPageList, chkList);
                                                PageAdapter.BindEnd();

                                                //Insert Or Replace Just New Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.Insert_Or_Replace_PagesTable(
                                                        new ObservableCollection <Get_Community_Object.Page>(chkList));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var chkList = result.Pages?.Where(a => a.UserId != UserDetails.User_id)
                                                      .ToList();
                                        if (chkList.Count > 0)
                                        {
                                            PageAdapter.mPageList =
                                                new ObservableCollection <Get_Community_Object.Page>(chkList);
                                            PageAdapter.BindEnd();

                                            //Insert Or Replace Data To Database
                                            if (UserID == UserDetails.User_id)
                                            {
                                                dbDatabase.Insert_Or_Replace_PagesTable(PageAdapter.mPageList);
                                            }
                                        }
                                    }

                                    //Manage
                                    if (ManagePagesAdapter.mAllUserPagesList.Count > 0)
                                    {
                                        var chkListManage = result.Pages.Where(a => a.UserId == UserDetails.User_id)
                                                            .ToList();
                                        if (chkListManage.Count > 0)
                                        {
                                            //Bring new page
                                            var listNew = chkListManage.Where(c =>
                                                                              !ManagePagesAdapter.mAllUserPagesList.Select(fc => fc.page_id)
                                                                              .Contains(c.PageId)).ToList();
                                            if (listNew.Count > 0)
                                            {
                                                var list = listNew.Select(page => new Get_User_Data_Object.Liked_Pages
                                                {
                                                    page_id          = page.PageId,
                                                    user_id          = page.UserId,
                                                    page_name        = page.PageName,
                                                    page_title       = page.PageTitle,
                                                    page_description = page.PageDescription,
                                                    avatar           = page.Avatar,
                                                    cover            = page.Cover,
                                                    page_category    = page.PageCategory,
                                                    website          = page.Website,
                                                    facebook         = page.Facebook,
                                                    google           = page.Google,
                                                    vk                      = page.Vk,
                                                    twitter                 = page.Twitter,
                                                    linkedin                = page.Linkedin,
                                                    company                 = page.Company,
                                                    phone                   = page.Phone,
                                                    address                 = page.Address,
                                                    call_action_type        = page.CallActionType,
                                                    call_action_type_url    = page.CallActionTypeUrl,
                                                    background_image        = page.BackgroundImage,
                                                    background_image_status = page.BackgroundImageStatus,
                                                    instgram                = page.Instgram,
                                                    youtube                 = page.Youtube,
                                                    verified                = page.Verified,
                                                    registered              = page.Registered,
                                                    boosted                 = page.Boosted,
                                                    about                   = page.About,
                                                    id                      = page.Id,
                                                    type                    = page.Type,
                                                    url                     = page.Url,
                                                    name                    = page.Name,
                                                    //rating = page.Rating,
                                                    category      = page.Category,
                                                    is_page_onwer = page.IsPageOnwer,
                                                    username      = page.Username
                                                }).ToList();

                                                //Results differ
                                                Classes.AddRange(ManagePagesAdapter.mAllUserPagesList, list);
                                                ManagePagesAdapter.BindEnd();

                                                //Insert Or Replace Just New Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.InsertOrReplace_ManagePagesTable(
                                                        new ObservableCollection <Get_User_Data_Object.Liked_Pages>(
                                                            list));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var chkListManage = result.Pages.Where(a => a.UserId == UserDetails.User_id)
                                                            .ToList();
                                        if (chkListManage.Count > 0)
                                        {
                                            var list = chkListManage.Select(page => new Get_User_Data_Object.Liked_Pages
                                            {
                                                page_id          = page.PageId,
                                                user_id          = page.UserId,
                                                page_name        = page.PageName,
                                                page_title       = page.PageTitle,
                                                page_description = page.PageDescription,
                                                avatar           = page.Avatar,
                                                cover            = page.Cover,
                                                page_category    = page.PageCategory,
                                                website          = page.Website,
                                                facebook         = page.Facebook,
                                                google           = page.Google,
                                                vk                      = page.Vk,
                                                twitter                 = page.Twitter,
                                                linkedin                = page.Linkedin,
                                                company                 = page.Company,
                                                phone                   = page.Phone,
                                                address                 = page.Address,
                                                call_action_type        = page.CallActionType,
                                                call_action_type_url    = page.CallActionTypeUrl,
                                                background_image        = page.BackgroundImage,
                                                background_image_status = page.BackgroundImageStatus,
                                                instgram                = page.Instgram,
                                                youtube                 = page.Youtube,
                                                verified                = page.Verified,
                                                registered              = page.Registered,
                                                boosted                 = page.Boosted,
                                                about                   = page.About,
                                                id                      = page.Id,
                                                type                    = page.Type,
                                                url                     = page.Url,
                                                name                    = page.Name,
                                                //rating = page.Rating,
                                                category      = page.Category,
                                                is_page_onwer = page.IsPageOnwer,
                                                username      = page.Username
                                            }).ToList();

                                            ManagePagesAdapter.mAllUserPagesList =
                                                new ObservableCollection <Get_User_Data_Object.Liked_Pages>(list);
                                            ManagePagesAdapter.BindEnd();

                                            //Insert Or Replace Just New Data To Database
                                            if (UserID == UserDetails.User_id)
                                            {
                                                dbDatabase.InsertOrReplace_ManagePagesTable(
                                                    new ObservableCollection <Get_User_Data_Object.Liked_Pages>(list));
                                            }
                                        }
                                    }
                                }

                                //====================================

                                // groups
                                if (result.Groups.Count > 0)
                                {
                                    var groupsList =
                                        new ObservableCollection <Get_Community_Object.Group>(result.Groups);

                                    //Update All Data To Database
                                    if (UserID == UserDetails.User_id)
                                    {
                                        dbDatabase.Insert_Or_Replace_GroupsTable(groupsList);
                                    }
                                }
                            }

                            dbDatabase.Dispose();
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is Error_Object error)
                        {
                            var errorText = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errorText.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================

                if (PagesManage_Type == "Manage_UserPages")
                {
                    if (PageAdapter.mPageList.Count > 0)
                    {
                        PagesSection.Visibility          = ViewStates.Visible;
                        LikedPagesRecylerView.Visibility = ViewStates.Visible;
                        Page_Empty.Visibility            = ViewStates.Gone;
                    }
                    else
                    {
                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                        Page_Empty.Visibility            = ViewStates.Visible;
                    }
                }
                else if (PagesManage_Type == "Manage_MyPages")
                {
                    //if Manage_MyPages list count == 0 >> show empty page
                    if (ManagePagesAdapter.mAllUserPagesList.Count > 0)
                    {
                        Txt_Count_ManagePages.Text = ManagePagesAdapter.mAllUserPagesList.Count.ToString();

                        ManagePagesSection.Visibility     = ViewStates.Visible;
                        ManagePagesRecylerView.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        Txt_Count_ManagePages.Text = "0";

                        ManagePagesSection.Visibility     = ViewStates.Gone;
                        ManagePagesRecylerView.Visibility = ViewStates.Gone;
                    }

                    if (PageAdapter.mPageList.Count > 0)
                    {
                        PagesSection.Visibility          = ViewStates.Visible;
                        LikedPagesRecylerView.Visibility = ViewStates.Visible;
                        Page_Empty.Visibility            = ViewStates.Gone;
                    }
                    else
                    {
                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                        Page_Empty.Visibility            = ViewStates.Visible;
                    }

                    if (PageAdapter.mPageList.Count == 0 && ManagePagesAdapter.mAllUserPagesList.Count == 0)
                    {
                        Page_Empty.Visibility = ViewStates.Visible;

                        ManagePagesSection.Visibility     = ViewStates.Gone;
                        ManagePagesRecylerView.Visibility = ViewStates.Gone;

                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                    }
                    else
                    {
                        Page_Empty.Visibility = ViewStates.Gone;
                    }
                }

                swipeRefreshLayout.Refreshing = false;
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_CommunitiesList_Page_API();
            }
        }
Beispiel #14
0
        public async void Get_GifData_Api(string key, string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    if (offset == "")
                    {
                        RunOnUiThread(() => { GifAdapter.Clear(); });
                    }

                    var result = await API_Request.Search_Gifs_Web(key, offset);

                    if (result.Count > 0)
                    {
                        RunOnUiThread(() =>
                        {
                            if (GifAdapter.GifList.Count == 0)
                            {
                                GifAdapter.GifList = new ObservableCollection <GifGiphyClass.Datum>(result);
                                GifRecylerView.SetAdapter(GifAdapter);
                            }
                            else
                            {
                                //Bring new item
                                var listnew = result?.Where(c => !GifAdapter.GifList.Select(fc => fc.id).Contains(c.id))
                                              .ToList();
                                if (listnew.Count > 0)
                                {
                                    var lastCountItem = GifAdapter.ItemCount;

                                    //Results differ
                                    Classes.AddRange(GifAdapter.GifList, listnew);
                                    GifAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count);
                                }
                            }

                            swipeRefreshLayout.Refreshing = false;

                            //Set Event Scroll
                            if (OnMainScrolEvent == null)
                            {
                                var xamarinRecyclerViewOnScrollListener =
                                    new XamarinRecyclerViewOnScrollListener(MLayoutManager, swipeRefreshLayout);
                                OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                                OnMainScrolEvent.LoadMoreEvent += Gif_OnScroll_OnLoadMoreEvent;
                                GifRecylerView.AddOnScrollListener(OnMainScrolEvent);
                                GifRecylerView.AddOnScrollListener(new ScrollDownDetector());
                            }
                            else
                            {
                                OnMainScrolEvent.IsLoading = false;
                            }
                        });
                    }
                }

                if (swipeRefreshLayout.Refreshing)
                {
                    swipeRefreshLayout.Refreshing = false;
                }
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_GifData_Api(search_key, offset);
            }
        }
        //Api
        public async void Get_Contacts_APi()
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    var lastIdUser = UserContactsList?.LastOrDefault()?.user_id ?? "0";

                    var(api_status, respond) = await API_Request.Get_users_friends_Async(lastIdUser);

                    if (api_status == 200)
                    {
                        if (respond is Classes.UserContacts.Rootobject result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.users.Length <= 0)
                                {
                                }
                                else if (result.users.Length > 0)
                                {
                                    var listNew = result.users?.Where(c => !UserContactsList.Select(fc => fc.user_id).Contains(c.user_id)).ToList();
                                    if (listNew.Count > 0)
                                    {
                                        Classes.AddRange(UserContactsList, listNew);

                                        var listOrder = new JavaList <Classes.UserContacts.User>(UserContactsList.OrderBy(a => a.name));
                                        if (MyContactsAdapter == null)
                                        {
                                            //Results differ
                                            MyContactsAdapter = new MyContacts_Adapter(this, listOrder, ContactsRecyler);
                                            ContactsRecyler.SetAdapter(MyContactsAdapter);
                                            MyContactsAdapter.ItemClick += MyContactsAdapter_OnItemClick;

                                            var lastCountItem = MyContactsAdapter.ItemCount;
                                            MyContactsAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                        }
                                        else
                                        {
                                            MyContactsAdapter.mMyContactsList = new JavaList <Classes.UserContacts.User>(listOrder);

                                            var lastCountItem = MyContactsAdapter.ItemCount;
                                            MyContactsAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                        }

                                        //Insert Or Update All data UsersContact to database
                                        var dbDatabase = new SqLiteDatabase();
                                        dbDatabase.Insert_Or_Replace_MyContactTable(UserContactsList);
                                        dbDatabase.Dispose();
                                    }
                                    else
                                    {
                                        if (ShowSnackbarNoMore)
                                        {
                                            Snackbar.Make(ContactsRecyler, GetText(Resource.String.Lbl_No_have_more_users), Snackbar.LengthLong).Show();
                                            ShowSnackbarNoMore = false;
                                        }
                                    }

                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                            });
                        }
                    }
                    else if (api_status == 400)
                    {
                        if (respond is Error_Object error)
                        {
                            var errortext = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errortext.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (api_status == 404)
                    {
                        var error = respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                RunOnUiThread(() =>
                {
                    if (UserContactsList?.Count > 0)
                    {
                        Contacts_Empty.Visibility  = ViewStates.Gone;
                        ContactsRecyler.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        Contacts_Empty.Visibility  = ViewStates.Visible;
                        ContactsRecyler.Visibility = ViewStates.Gone;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (OnMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(ContactsLayoutManager, swipeRefreshLayout);
                        OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMainScrolEvent.LoadMoreEvent += MyContact_OnScroll_OnLoadMoreEvent;
                        ContactsRecyler.AddOnScrollListener(OnMainScrolEvent);
                        ContactsRecyler.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_Contacts_APi();
            }
        }
Beispiel #16
0
        public void Should_Not_Be_Able_To_Add_Pseudoclasses_Via_AddRange()
        {
            var target = new Classes();

            Assert.Throws<ArgumentException>(() => target.AddRange(new[] { "foo", ":bar" }));
        }
        //Get Photo API
        public async void Get_AlbumUser_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });

                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                    ImagesRecylerView.Visibility = ViewStates.Visible;
                    photos_Empty.Visibility      = ViewStates.Gone;
                }
                else
                {
                    var(Api_status, Respond) = await Client.Album.Get_User_Albums(S_UserId, "35", offset);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_User_Albums_Object result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.albums.Count <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.albums.Count > 0)
                                {
                                    //Bring new groups
                                    var listNew = result.albums.Where(c =>
                                                                      !photosAdapter.mMyAlbumsList.Select(fc => fc.group_id).Contains(c.group_id))
                                                  .ToList();
                                    if (listNew.Count > 0)
                                    {
                                        //Results differ
                                        Classes.AddRange(photosAdapter.mMyAlbumsList, listNew);
                                        photosAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        photosAdapter.mMyAlbumsList =
                                            new ObservableCollection <Get_User_Albums_Object.Album>(result.albums);
                                        photosAdapter.BindEnd();
                                    }
                                }
                            });
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is Error_Object error)
                        {
                            var errorText = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errorText.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================
                RunOnUiThread(() =>
                {
                    if (photosAdapter.mMyAlbumsList.Count > 0)
                    {
                        ImagesRecylerView.Visibility = ViewStates.Visible;
                        photos_Empty.Visibility      = ViewStates.Gone;
                    }
                    else
                    {
                        ImagesRecylerView.Visibility = ViewStates.Gone;
                        photos_Empty.Visibility      = ViewStates.Visible;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (OnMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                        OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMainScrolEvent.LoadMoreEvent += MyAlbums_OnScroll_OnLoadMoreEvent;
                        ImagesRecylerView.AddOnScrollListener(OnMainScrolEvent);
                        ImagesRecylerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_AlbumUser_Api(offset);
            }
        }