コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            contactsListView         = FindViewById <ListView>(Resource.Id.ContactsListView);
            myContactsAdapter        = new MyContactsAdapter(this, myContacts);
            contactsListView.Adapter = myContactsAdapter;

            Button button = FindViewById <Button>(Resource.Id.cmdGetContacts);

            button.Click += delegate {
                // add event handler code for button
                myContacts.Clear();
                myContacts.Add(new MyContact {
                    Name = "Mike Fitzmaurice", Email = "*****@*****.**"
                });
                myContacts.Add(new MyContact {
                    Name = "Chris Sells", Email = "*****@*****.**"
                });
                myContacts.Add(new MyContact {
                    Name = "Brian Cox", Email = "*****@*****.**"
                });

                myContactsAdapter.AddAll(myContacts);
                myContactsAdapter.NotifyDataSetChanged();
            };
        }
コード例 #2
0
 private void MyContactsAdapter_OnItemClick(object sender, MyContacts_AdapterClickEventArgs adapterClickEvents)
 {
     try
     {
         var position = adapterClickEvents.Position;
         if (position >= 0)
         {
             var item = MyContactsAdapter.GetItem(position);
             if (item != null)
             {
                 Intent Int;
                 if (item.user_id != UserDetails.User_id)
                 {
                     Int = new Intent(this, typeof(User_Profile_Activity));
                     Int.PutExtra("UserId", item.user_id);
                     Int.PutExtra("UserType", "MyContacts");
                     Int.PutExtra("UserItem", JsonConvert.SerializeObject(item));
                 }
                 else
                 {
                     Int = new Intent(this, typeof(MyProfile_Activity));
                     Int.PutExtra("UserId", item.user_id);
                 }
                 StartActivity(Int);
             }
         }
     }
     catch (Exception exception)
     {
         Crashes.TrackError(exception);
     }
 }
コード例 #3
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate(bundle);
     SetContentView(Resource.Layout.Main);
     Button btnAuthenticate = FindViewById<Button>(Resource.Id.BtnAuthenticate);
     contactsListView = FindViewById<ListView>(Resource.Id.ContactsListView);
     myContactsAdapter = new MyContactsAdapter(this, myContacts);
     contactsListView.Adapter = myContactsAdapter;
     btnAuthenticate.Click += btnAuthenticate_Click;
 }
コード例 #4
0
    protected override void OnCreate(Bundle bundle) {
      base.OnCreate(bundle);

      SetContentView(Resource.Layout.Main);

      contactsListView = FindViewById<ListView>(Resource.Id.ContactsListView);
      myContactsAdapter = new MyContactsAdapter(this, myContacts);
      contactsListView.Adapter = myContactsAdapter;

      Button button = FindViewById<Button>(Resource.Id.cmdGetContacts);
      button.Click += async delegate {
        // add event handler code for button
        await Office365Service.EnsureClientCreated(this);
        myContacts = await Office365Service.GetMyContacts();
        myContactsAdapter.AddAll(myContacts);
        myContactsAdapter.NotifyDataSetChanged();
      };
    }
コード例 #5
0
    protected override void OnCreate(Bundle bundle) {
      base.OnCreate(bundle);

      SetContentView(Resource.Layout.Main);

      contactsListView = FindViewById<ListView>(Resource.Id.ContactsListView);
      myContactsAdapter = new MyContactsAdapter(this, myContacts);
      contactsListView.Adapter = myContactsAdapter;

      Button button = FindViewById<Button>(Resource.Id.cmdGetContacts);
      button.Click += delegate {
        // add event handler code for button
        myContacts.Clear();
        myContacts.Add(new MyContact { Name = "Mike Fitzmaurice", Email = "*****@*****.**" });
        myContacts.Add(new MyContact { Name = "Chris Sells", Email = "*****@*****.**" });
        myContacts.Add(new MyContact { Name = "Brian Cox", Email = "*****@*****.**" });

        myContactsAdapter.AddAll(myContacts);
        myContactsAdapter.NotifyDataSetChanged();
      };
    }
コード例 #6
0
        //Event Refresh Data Page
        private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
        {
            try
            {
                if (Type_Contacts == "Following")
                {
                    MyContactsAdapter?.Clear();
                    Get_MyContact();
                }
                else
                {
                    MyFollowersAdapter?.Clear();
                    Get_MyFollowers();
                }

                swipeRefreshLayout.Refreshing = true;
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }
コード例 #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            contactsListView         = FindViewById <ListView>(Resource.Id.ContactsListView);
            myContactsAdapter        = new MyContactsAdapter(this, myContacts);
            contactsListView.Adapter = myContactsAdapter;

            Button button = FindViewById <Button>(Resource.Id.cmdGetContacts);

            button.Click += async delegate {
                // add event handler code for button
                await Office365Service.EnsureClientCreated(this);

                myContacts = await Office365Service.GetMyContacts();

                myContactsAdapter.AddAll(myContacts);
                myContactsAdapter.NotifyDataSetChanged();
            };
        }
コード例 #8
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();
            }
        }
コード例 #9
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);
            }
        }