예제 #1
0
        protected void InitEvents()
        {
            mSwipeRefreshLayout.SetOnRefreshListener(this);

            //var viewOnGestureListener = new RecyclerViewItemOnGestureListener(mRecyclerView, this);
            //mRecyclerView.AddOnItemTouchListener(new RecyclerViewItemOnItemTouchListener(mRecyclerView, viewOnGestureListener));

            // 加载更多
            var onScrollListener = new XamarinRecyclerViewOnScrollListener(linearLayoutManager);

            onScrollListener.LoadMoreEvent += (object sender, EventArgs e) =>
            {
                if (totalCount > this.sumList.Count)
                {
                    if (!loadingData)
                    {
                        loadingData = true;
                        BindData();
                    }
                }
                else if (totalCount == this.sumList.Count)
                {
                    Toast.MakeText(this.CurrContext, "没有更多了", ToastLength.Short).Show();
                }
            };
            mRecyclerView.AddOnScrollListener(onScrollListener);
        }
예제 #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            var view = this.BindingInflate(Resource.Layout.ExploreLayout, null);

            var recyclerView = view.FindViewById <MvxRecyclerView>(Resource.Id.series_list);

            if (recyclerView != null)
            {
                recyclerView.HasFixedSize = true;

                var layoutManager = new LinearLayoutManager(view.Context);

                var onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager);
                onScrollListener.LoadMoreEvent += async(s, e) =>
                {
                    await ViewModel.LoadMoreAsync();
                };

                recyclerView.AddOnScrollListener(onScrollListener);

                recyclerView.SetLayoutManager(layoutManager);

                recyclerView.GetRecycledViewPool().Clear();
            }

            return(view);
        }
        public void LoadContacts(int afterContact = 0)
        {
            try
            {
                var dbDatabase = new SqLiteDatabase();
                var localList  = dbDatabase.Get_MyContact(afterContact, 100);
                if (localList?.Count > 0)
                {
                    RunOnUiThread(() =>
                    {
                        var listNew = localList?.Where(c => !CallAdapter.mCallUserContacts.Select(fc => fc.UserId).Contains(c.UserId)).ToList();
                        if (listNew.Count > 0)
                        {
                            Classes.AddRange(CallAdapter.mCallUserContacts, localList);
                            var lastCountItem = CallAdapter.ItemCount;
                            CallAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                            CallAdapter.BindEnd();
                        }
                        else
                        {
                            Get_Contacts_APi();
                        }
                    });
                }
                else
                {
                    Get_Contacts_APi();
                }

                RunOnUiThread(() =>
                {
                    //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;
                    }
                });

                dbDatabase.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                LoadContacts(afterContact);
            }
        }
예제 #4
0
        private void SetUpRecyclerView(RecyclerView _recyclerView)
        {
            //Create our layout manager

            recyclerView.HasFixedSize = true;
            var layoutManager = new LinearLayoutManager(Activity);

            onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager);
            onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync;
            onScrollListener.OnHide        += OnScrollListener_OnHide;
            onScrollListener.OnShow        += OnScrollListener_OnShow;
            recyclerView.AddOnScrollListener(onScrollListener);
            recyclerView.SetLayoutManager(layoutManager);
        }
예제 #5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.Read_Fragment, container, false);

            HasOptionsMenu         = true;
            paginationModel.Status = 1; // 0 = WishList ,  1 = Read , 2 = All
            mRecyclerView          = view.FindViewById <RecyclerView>(Resource.Id.ReadBookList);
            if (mRecyclerView != null)
            {
                mRecyclerView.HasFixedSize = true;
                var layoutManager    = new LinearLayoutManager(this.Context);
                var onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager);
                onScrollListener.LoadMoreEvent += (object sender, bool loadCalled) =>
                {
                    if (loadCalled)
                    {
                        if (loadList && !(BookList.Count < 30))
                        {
                            Toast.MakeText(this.Context, "Loading More Books...", ToastLength.Long).Show();
                            if (InternetConnectivityModel.CheckConnection(this.Context))
                            {
                                LoadMoreBooks();
                            }
                            else
                            {
                                LoadMoreBooksOffline();
                            }
                        }
                    }
                };
                mRecyclerView.AddOnScrollListener(onScrollListener);
                mRecyclerView.SetLayoutManager(layoutManager);
            }
            paginationModel.SkipRecords = 0;
            mRecyclerView.Click        += MRecyclerView_Click;
            FloatingActionButton fabAddBook = view.FindViewById <FloatingActionButton>(Resource.Id.fabAddBook);

            fabAddBook.Click += FabAddBook_Click;
            if (InternetConnectivityModel.CheckConnection(this.Context))
            {
                LoadServerBooks();
            }
            else
            {
                paginationModel.SkipRecords = 0;
                paginationModel.TakeRecords = 30;
                loadBookAdapter();
            }
            return(view);
        }
예제 #6
0
        private void SetUpRecyclerView(RecyclerView _recyclerView)
        {
            //Create our layout manager

            _recyclerView.HasFixedSize = true;
            var layoutManager = new LinearLayoutManager(this);

            onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager);
            onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync;
            onScrollListener.OnHide        += OnScrollListener_OnHide;
            onScrollListener.OnShow        += OnScrollListener_OnShow;
            _recyclerView.AddOnScrollListener(onScrollListener);
            _recyclerView.SetLayoutManager(layoutManager);

            _recyclerView.AddItemDecoration(horizontalDecoration);
        }
예제 #7
0
        //Get Messages Local Or Api
        private void Get_Messages()
        {
            try
            {
                BeforeMessageId = 0;
                MAdapter.MessageList.Clear();
                MAdapter.NotifyDataSetChanged();

                SqLiteDatabase dbDatabase = new SqLiteDatabase();
                var            localList  = dbDatabase.GetMessagesList(UserDetails.UserId, Userid, BeforeMessageId);
                if (localList == "1") //Database.. Get Messages Local
                {
                    MAdapter.NotifyDataSetChanged();

                    //Scroll Down >>
                    ChatBoxRecyclerView.ScrollToPosition(MAdapter.MessageList.Count - 1);
                    SwipeRefreshLayout.Refreshing = false;
                    SwipeRefreshLayout.Enabled    = false;
                }
                else //Or server.. Get Messages Api
                {
                    SwipeRefreshLayout.Refreshing = true;
                    SwipeRefreshLayout.Enabled    = true;
                    GetMessages_API();
                }

                //Set Event Scroll
                XamarinRecyclerViewOnScrollListener onScrollListener = new XamarinRecyclerViewOnScrollListener(MLayoutManager, SwipeRefreshLayout);
                onScrollListener.LoadMoreEvent += Messages_OnScroll_OnLoadMoreEvent;
                ChatBoxRecyclerView.AddOnScrollListener(onScrollListener);
                TaskWork = "Working";

                //Run timer
                Timer = new Timer {
                    Interval = AppSettings.MessageRequestSpeed, Enabled = true
                };
                Timer.Elapsed += TimerOnElapsed_MessageUpdater;
                Timer.Start();

                dbDatabase.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #8
0
        protected override void InitEvents()
        {
            // 返回
            FindViewById <ImageButton>(Resource.Id.imgBtn_back).Click += (sender, e) =>
            {
                CurrActivity.Finish();
                OverridePendingTransition(Resource.Animation.left_in, Resource.Animation.right_out);
            };

            llAdd.Click += (sender, e) =>
            {
                Intent intent = new Intent(CurrActivity, typeof(TeacherAddActivity));
                intent.PutExtra("scopeName", scopeName);
                StartActivity(intent);
                OverridePendingTransition(Resource.Animation.right_in, Resource.Animation.left_out);
            };

            mSwipeRefreshLayout.SetOnRefreshListener(this);

            RecyclerViewItemOnGestureListener viewOnGestureListener = new RecyclerViewItemOnGestureListener(mRecyclerView, this);

            mRecyclerView.AddOnItemTouchListener(new RecyclerViewItemOnItemTouchListener(mRecyclerView, viewOnGestureListener));

            // 加载更多
            var onScrollListener = new XamarinRecyclerViewOnScrollListener(linearLayoutManager);

            onScrollListener.LoadMoreEvent += (object sender, EventArgs e) =>
            {
                if (totalCount > teacherList.Count)
                {
                    if (!loadingData)
                    {
                        loadingData = true;
                        GetTeacherListByScope();
                    }
                }
                else if (totalCount == teacherList.Count)
                {
                    Toast.MakeText(this, "没有更多了", ToastLength.Short).Show();
                }
            };
            mRecyclerView.AddOnScrollListener(onScrollListener);
        }
예제 #9
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = base.OnCreateView(inflater, container, savedInstanceState);

            TournamentsAdapter            = new TournamentsAdapter(ViewModel.Tournaments);
            TournamentsAdapter.ItemClick += OnItemClick;

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

            addTournament.Click += ShowAddTournamentDialog;

            TournamentsRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.tournamentsrecyclerview);
            var layoutManager    = new LinearLayoutManager(this.Activity);
            var onScrollListener = new XamarinRecyclerViewOnScrollListener(layoutManager)
            {
                FloatingButton = addTournament
            };

            TournamentsRecyclerView.AddOnScrollListener(onScrollListener);
            TournamentsRecyclerView.SetLayoutManager(layoutManager);
            TournamentsRecyclerView.SetAdapter(TournamentsAdapter);
            return(view);
        }
        //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
                {
                    if (TimerWork == "Working")
                    {
                        TimerWork = "Stop";
                        var lastIdUser = UserContactsList?.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 => !UserContactsList.Select(fc => fc.UserId).Contains(c.UserId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            Classes.AddRange(UserContactsList, listNew);

                                            var listOrder = new JavaList <Classes.UserContacts.User>(UserContactsList.OrderBy(a => a.Name));

                                            ContactAdapter.mMyContactsList = new JavaList <Classes.UserContacts.User>(listOrder);
                                            ContactAdapter.ItemClick      += ContactAdapter_OnItemClick;
                                            ContactAdapter.NotifyDataSetChanged();

                                            var dbDatabase = new SqLiteDatabase();
                                            dbDatabase.Insert_Or_Replace_MyContactTable(UserContactsList);
                                            dbDatabase.Dispose();
                                        }
                                        else
                                        {
                                            if (ShowSnackbarNoMore)
                                            {
                                                ShowSnackbarNoMore = false;
                                            }
                                        }

                                        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();
                        }
                    }
                    TimerWork = "Working";
                }

                //Show Empty Page >>
                //===============================================================
                RunOnUiThread(() =>
                {
                    if (UserContactsList?.Count > 0)
                    {
                        usercontacts_Empty.Visibility = ViewStates.Gone;
                        ContactsRecyler.Visibility    = ViewStates.Visible;
                    }
                    else
                    {
                        usercontacts_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)
            {
                Console.WriteLine(e);
                TimerWork = "Working";
                Get_Contacts_APi();
            }
        }
        public void Get_MyContact(int lastId = 0)
        {
            try
            {
                RunOnUiThread(() =>
                {
                    if (AppSettings.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.UserId).Contains(c.UserId)).ToList();
                            if (listNew.Count > 0)
                            {
                                Classes.AddRange(UserContactsList, listNew);
                                var listOrder = new JavaList <Classes.UserContacts.User>(UserContactsList.OrderBy(a => a.Name));


                                ContactAdapter.mMyContactsList = new JavaList <Classes.UserContacts.User>(listOrder);
                                ContactAdapter.ItemClick      += ContactAdapter_OnItemClick;


                                ContactAdapter.NotifyDataSetChanged();
                            }
                            else
                            {
                                if (ShowSnackbar)
                                {
                                    ShowSnackbar = false;
                                }

                                Get_Contacts_APi();
                            }

                            if (swipeRefreshLayout != null)
                            {
                                swipeRefreshLayout.Refreshing = false;
                            }
                        }
                        else
                        {
                            if (ShowSnackbar)
                            {
                                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
                {
                    Get_Contacts_APi();
                }

                dbDatabase.Dispose();

                if (UserContactsList?.Count <= 24 || UserContactsList?.Count == 0)
                {
                    Get_Contacts_APi();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #12
0
        private void ChangeLayout(RecyclerView _recyclerView)
        {
            if (mAdapter != null && mAdapter.ItemCount > 0)
            {
                int scrollPosition = 0;
                LinearLayoutManager mLayoutManager;
                // If a layout manager has already been set, get current scroll position.
                if (_recyclerView.GetLayoutManager() != null)
                {
                    scrollPosition = ((LinearLayoutManager)_recyclerView.GetLayoutManager())
                                     .FindFirstCompletelyVisibleItemPosition();
                }

                switch (mCurrentLayoutManagerType)
                {
                case MyEnum.ListView:
                    mLayoutManager            = new LinearLayoutManager(this);
                    mCurrentLayoutManagerType = MyEnum.Thumbnail;
                    ChangeMenuIconToThumbnail();
                    _recyclerView.SetLayoutManager(mLayoutManager);
                    onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager);
                    break;

                case MyEnum.Thumbnail:
                    var mGridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.Vertical, false);
                    mCurrentLayoutManagerType = MyEnum.GridView;
                    ChangeMenuIconToList();
                    _recyclerView.SetLayoutManager(mGridLayoutManager);
                    onScrollListener = new XamarinRecyclerViewOnScrollListener(mGridLayoutManager);
                    break;

                case MyEnum.GridView:
                    mLayoutManager            = new LinearLayoutManager(this);
                    mCurrentLayoutManagerType = MyEnum.ListView;
                    ChangeMenuIconToList();
                    _recyclerView.SetLayoutManager(mLayoutManager);
                    onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager);
                    break;

                default:
                    mLayoutManager            = new LinearLayoutManager(this);
                    mCurrentLayoutManagerType = MyEnum.ListView;
                    ChangeMenuIconToList();
                    _recyclerView.SetLayoutManager(mLayoutManager);
                    onScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager);
                    break;
                }

                mAdapter = new Wishlist_Adapter(this, mAdapter.Product, this);
                mAdapter.SetLayoutManager(mCurrentLayoutManagerType);

                _recyclerView.SetAdapter(mAdapter);
                _recyclerView.ScrollToPosition(scrollPosition);
                recyclerView.RemoveOnScrollListener(onScrollListener);


                onScrollListener.LoadMoreEvent += OnScrollListener_LoadMoreEventAsync;
                onScrollListener.OnHide        += OnScrollListener_OnHide;
                onScrollListener.OnShow        += OnScrollListener_OnShow;
                recyclerView.AddOnScrollListener(onScrollListener);

                //Decorate Recyclerview
                if (mCurrentLayoutManagerType == MyEnum.GridView)
                {
                    _recyclerView.AddItemDecoration(verticalDecoration);
                }
                else
                {
                    _recyclerView.AddItemDecoration(verticalDecoration);
                }
            }
        }
예제 #13
0
        //Get Data Movies Using Api
        public async void Get_MoviesList_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.Movies.Get_Movies("10", offset);

                    if (api_status == 200)
                    {
                        if (respond is Get_Movies_Object result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.movies.Length <= 0)
                                {
                                    if (swipeRefreshLayout.Refreshing)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.movies.Length > 0)
                                {
                                    if (MoviesAdapter.mMoviesList.Count > 0)
                                    {
                                        //Bring new users
                                        var listnew = result.movies.Where(c =>
                                                                          !MoviesAdapter.mMoviesList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            Classes.AddRange(MoviesAdapter.mMoviesList, listnew);
                                        }
                                    }
                                    else
                                    {
                                        MoviesAdapter.mMoviesList =
                                            new ObservableCollection <Get_Movies_Object.Movie>(result.movies);
                                        MoviesAdapter.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 (MoviesAdapter.mMoviesList.Count > 0)
                    {
                        MoviesRecyler.Visibility = ViewStates.Visible;
                        Movies_Empty.Visibility  = ViewStates.Gone;
                    }
                    else
                    {
                        MoviesRecyler.Visibility = ViewStates.Gone;
                        Movies_Empty.Visibility  = ViewStates.Visible;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (OnMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                        OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMainScrolEvent.LoadMoreEvent += Movies_OnScroll_OnLoadMoreEvent;
                        MoviesRecyler.AddOnScrollListener(OnMainScrolEvent);
                        MoviesRecyler.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_MoviesList_API(offset);
            }
        }
예제 #14
0
        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);
            }
        }
예제 #15
0
        public async void Get_NearByList_API(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    swipeRefreshLayout.Refreshing = false;
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    XamarinRecyclerViewOnScrollListener.IsLoading = true;

                    await GetPosition();

                    var dictionary = new Dictionary <string, string>
                    {
                        { "limit", "25" },
                        { "offset", offset },
                        { "gender", Filter_gender },
                        { "keyword", "" },
                        { "status", Filter_status },
                        { "distance", Filter_Distance },
                        { "lat", UserDetails.Lat },
                        { "lng", UserDetails.Lng }
                    };


                    var(Api_status, Respond) = await Client.Nearby.Get_Nearby_Users(dictionary);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Nearby_Users_Object result)
                        {
                            RunOnUiThread(() =>
                            {
                                if (result.nearby_users.Length <= 0)
                                {
                                    if (swipeRefreshLayout.Refreshing)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }

                                    if (NearByAdapter.mNearByList.Count > 0)
                                    {
                                        Snackbar.Make(NearByRecylerView, GetText(Resource.String.Lbl_No_more_users),
                                                      Snackbar.LengthLong).Show();
                                    }
                                }
                                else if (result.nearby_users.Length > 0)
                                {
                                    if (NearByAdapter.mNearByList.Count <= 0)
                                    {
                                        NearByAdapter.mNearByList =
                                            new ObservableCollection <Get_Nearby_Users_Object.Nearby_Users>(
                                                result.nearby_users);
                                        NearByAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listnew = result.nearby_users?.Where(c =>
                                                                                 !NearByAdapter.mNearByList.Select(fc => fc.user_id).Contains(c.user_id))
                                                      .ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = NearByAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(NearByAdapter.mNearByList, listnew);
                                            NearByAdapter.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 (NearByAdapter.mNearByList.Count > 0)
                    {
                        NearByRecylerView.Visibility = ViewStates.Visible;
                        NearBy_Empty.Visibility      = ViewStates.Gone;
                    }
                    else
                    {
                        NearByRecylerView.Visibility = ViewStates.Gone;
                        NearBy_Empty.Visibility      = ViewStates.Visible;
                    }

                    swipeRefreshLayout.Refreshing = false;

                    //Set Event Scroll
                    if (OnMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                        OnMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMainScrolEvent.LoadMoreEvent += NearBy_OnScroll_OnLoadMoreEvent;
                        NearByRecylerView.AddOnScrollListener(OnMainScrolEvent);
                        NearByRecylerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        XamarinRecyclerViewOnScrollListener.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_NearByList_API(offset);
            }
        }
        //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();
            }
        }
예제 #17
0
        //Get Data My Event Using API
        public async void Get_MyEvent_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Activity.RunOnUiThread(() =>
                    {
                        if (swipeRefreshLayout != null)
                        {
                            swipeRefreshLayout.Refreshing = false;
                        }
                    });
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    var(api_status, respond) = await Client.Event.Get_MyEvents("20", "", offset);

                    if (api_status == 200)
                    {
                        if (respond is Get_MyEvent_object result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                if (result.my_events.Length <= 0)
                                {
                                    if (swipeRefreshLayout != null)
                                    {
                                        swipeRefreshLayout.Refreshing = false;
                                    }
                                }
                                else if (result.my_events.Length > 0)
                                {
                                    if (MyEventAdapter.mMyEventList.Count <= 0)
                                    {
                                        MyEventAdapter.mMyEventList =
                                            new ObservableCollection <Get_MyEvent_object.My_Events>(result.my_events);
                                        MyEventAdapter.BindEnd();
                                    }
                                    else
                                    {
                                        //Bring new item
                                        var listNew = result.my_events?.Where(c =>
                                                                              !MyEventAdapter.mMyEventList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var lastCountItem = MyEventAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MyEventAdapter.mMyEventList, listNew);
                                            MyEventAdapter.NotifyItemRangeInserted(lastCountItem, listNew.Count);
                                        }

                                        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.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 (MyEventAdapter.mMyEventList.Count > 0)
                    {
                        MyEventRecyclerView.Visibility = ViewStates.Visible;
                        MyEvent_Empty.Visibility       = ViewStates.Gone;
                    }
                    else
                    {
                        MyEventRecyclerView.Visibility = ViewStates.Gone;
                        MyEvent_Empty.Visibility       = ViewStates.Visible;
                    }

                    if (swipeRefreshLayout != null)
                    {
                        swipeRefreshLayout.Refreshing = false;
                    }

                    //Set Event Scroll
                    if (OnMyEventScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(MLayoutManager, swipeRefreshLayout);
                        OnMyEventScrolEvent = xamarinRecyclerViewOnScrollListener;
                        OnMyEventScrolEvent.LoadMoreEvent += MyEventOnScroll_OnLoadMoreEvent;
                        MyEventRecyclerView.AddOnScrollListener(OnMyEventScrolEvent);
                        MyEventRecyclerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        OnMyEventScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_MyEvent_Api(offset);
            }
        }
        //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);
            }
        }
예제 #19
0
        //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();
            }
        }
예제 #20
0
        //Get Data Market Using API
        public async void Get_DataMarket_Api(string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Activity.RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; });
                    Toast.MakeText(Activity, Activity.GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                   ToastLength.Short).Show();
                }
                else
                {
                    var(Api_status, Respond) = await Client.Market.Get_Products("", "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 (MMarketAdapter.MarketList.Count <= 0)
                                    {
                                        MMarketAdapter.MarketList =
                                            new ObservableCollection <Get_Products_Object.Product>(result.products);
                                        MMarketAdapter.BindEnd();

                                        var animation = AnimationUtils.LoadAnimation(Activity,
                                                                                     Resource.Animation.slideUpAnim);
                                        MainRecyclerView.StartAnimation(animation);
                                    }
                                    else
                                    {
                                        //Bring new item
                                        //var exceptList = result.products?.ToList().Except(MMarketAdapter?.MarketList).ToList();

                                        var listnew = result.products?.Where(c =>
                                                                             !MMarketAdapter.MarketList.Select(fc => fc.id).Contains(c.id)).ToList();
                                        if (listnew.Count > 0)
                                        {
                                            var lastCountItem = MMarketAdapter.ItemCount;

                                            //Results differ
                                            Classes.AddRange(MMarketAdapter.MarketList, listnew);
                                            MMarketAdapter.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(() =>
                {
                    swipeRefreshLayout.Refreshing = false;

                    if (MMarketAdapter.MarketList.Count > 0)
                    {
                        if (MainRecyclerView.Visibility == ViewStates.Gone)
                        {
                            MainRecyclerView.Visibility = ViewStates.Visible;
                        }

                        if (Market_Empty.Visibility == ViewStates.Visible)
                        {
                            Market_Empty.Visibility = ViewStates.Gone;
                        }
                    }
                    else if (MMarketAdapter.MarketList.Count <= 0)
                    {
                        MainRecyclerView.Visibility = ViewStates.Gone;
                        Market_Empty.Visibility     = ViewStates.Visible;
                    }

                    //Set Event Scroll
                    if (MarketMainScrolEvent == null)
                    {
                        var xamarinRecyclerViewOnScrollListener =
                            new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout);
                        MarketMainScrolEvent = xamarinRecyclerViewOnScrollListener;
                        MarketMainScrolEvent.LoadMoreEvent += Market_FragmentOnScroll_OnLoadMoreEvent;
                        MainRecyclerView.AddOnScrollListener(MarketMainScrolEvent);
                        MainRecyclerView.AddOnScrollListener(new ScrollDownDetector());
                    }
                    else
                    {
                        MarketMainScrolEvent.IsLoading = false;
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_DataMarket_Api(offset);
            }
        }
예제 #21
0
        public async void Get_GifData_Api(string key, string offset = "")
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    Toast.MakeText(this, GetString(Resource.String.Lbl_Error_check_internet_connection), 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)
            {
                Console.WriteLine(e);
                Get_GifData_Api(search_key, offset);
            }
        }
        //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;
                    }
                });
            }
        }