コード例 #1
0
        void OrganizedData(Java.Lang.Object value)
        {
            var snapshot = (QuerySnapshot)value;

            if (!snapshot.IsEmpty)
            {
                if (ListOfPost.Count > 0)
                {
                    ListOfPost.Clear();
                }

                foreach (DocumentSnapshot item in snapshot.Documents)
                {
                    Post post = new Post();
                    post.ID       = item.Id;
                    post.PostBody = item.Get("post_body") != null?item.Get("post_body").ToString() : "";

                    post.Author = item.Get("author") != null?item.Get("author").ToString() : "";

                    post.ImageId = item.Get("image_id") != null?item.Get("image_id").ToString() : "";

                    post.OwnerId = item.Get("owner_id") != null?item.Get("owner_id").ToString() : "";

                    post.DownloadUrl = item.Get("download_url") != null?item.Get("download_url").ToString() : "";

                    string datestring = item.Get("post_date") != null?item.Get("post_date").ToString() : "";

                    post.PostDate = DateTime.ParseExact(datestring, @"dd/MM/yyyy HH:mm:ss tt",
                                                        System.Globalization.CultureInfo.InvariantCulture);

                    var data = item.Get("likes") != null?item.Get("likes") : null;

                    if (data != null)
                    {
                        var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister);

                        //retrieve our own id
                        string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid;

                        //check the number of users liked the post
                        post.LikeCount = dictionaryFromHashMap.Count;

                        //verifies if we liked the post or not.
                        if (dictionaryFromHashMap.Contains(uid))
                        {
                            post.Liked = true;
                        }
                    }

                    ListOfPost.Add(post);
                }

                OnPostRetrieved?.Invoke(this, new PostEventArgs {
                    Posts = ListOfPost
                });
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public Task SaveDeviceParameter(Parameter parameter, Enum value)
        {
            return(Task.Run(async() =>
            {
                await Reconnect(throwOnError: true);
                await Unlock(throwOnError: true);


                var _parameter = parameter.ToR7();
                var _value = Convert.ToInt32(value);


                var __parameter = comms.CurrentDevice.ParameterForIdentifier(_parameter.EnumToInt());

#if IOS
                if (__parameter == null || !__parameter.Available)
                {
                    throw new InvalidOperationException($"Parameter `{parameter}` unavailable on this device");
                }
#elif ANDROID
                if (__parameter == null || !__parameter.Available.BooleanValue())
                {
                    throw new InvalidOperationException($"Parameter `{parameter}` unavailable on this device");
                }
#endif

#if IOS
                var option = __parameter.Options.SingleOrDefault(x => ((NSNumber)x.Key).Int32Value == _value);
#elif ANDROID
                var option = new Android.Runtime.JavaDictionary <int?, string>(__parameter.Options.Handle, Android.Runtime.JniHandleOwnership.DoNotRegister).ToDictionary(t => t.Key, t => t.Value).SingleOrDefault(x => x.Key == _value);
#endif

                if (option.Key == null)
                {
                    throw new InvalidOperationException($"Option `{value}` for `{parameter}` unavailable on this device");
                }


#if ANDROID
                (comms.CurrentDevice as R7GenericDevice).UpdateParameter(_parameter, _value);
#elif IOS
                comms.CurrentDevice.Update((nuint)(int)_parameter, NSData.FromArray(new byte[] { (byte)Convert.ToInt32(_value) }));
#endif

                ///Запрашиваем новое значение с устройства чтобы убедиться что оно сохранилось
                ///
#if ANDROID
                (comms.CurrentDevice as R7GenericDevice).RequestParameter(_parameter);
#elif IOS
                comms.CurrentDevice.Request(_parameter.EnumToInt());
#endif

                ///Ждем получения этого значения
                await WaitForParameterChanged(_parameter, _value, throwOnError: true);
            }));
        }
コード例 #3
0
        void OrganizeData(Java.Lang.Object Value)
        {
            var snapshot = (QuerySnapshot)Value;

            if (!snapshot.IsEmpty)
            {
                if (ListOfPost.Count > 0)
                {
                    ListOfPost.Clear();
                }

                foreach (DocumentSnapshot item in snapshot.Documents)
                {
                    Post post = new Post();
                    post.ID = item.Id;

                    post.PostBody = item.Get("post_body") != null?item.Get("post_body").ToString() : "";

                    post.Author = item.Get("author") != null?item.Get("author").ToString() : "";

                    post.ImageId = item.Get("image_id") != null?item.Get("image_id").ToString() : "";

                    post.OwnerId = item.Get("owner_id") != null?item.Get("owner_id").ToString() : "";

                    post.DownloadUrl = item.Get("download_url") != null?item.Get("download_url").ToString() : "";

                    string datestring = item.Get("post_date") != null?item.Get("post_date").ToString() : "";

                    post.PostDate = DateTime.Parse(datestring);


                    var data = item.Get("likes") != null?item.Get("likes") : null;

                    if (data != null)
                    {
                        var    dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister);
                        string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid;

                        post.LikeCount = dictionaryFromHashMap.Count;

                        if (dictionaryFromHashMap.Contains(uid))
                        {
                            post.Liked = true;
                        }
                    }

                    ListOfPost.Add(post);
                }

                OnPostRetrieved?.Invoke(this, new PostEventArgs {
                    Posts = ListOfPost
                });
            }
        }
コード例 #4
0
        public void OnSuccess(Java.Lang.Object result)
        {
            DocumentSnapshot snapshot = (DocumentSnapshot)result;

            if (!snapshot.Exists())
            {
                return;
            }

            DocumentReference likeReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID);

            if (like)
            {
                likeReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true);
            }
            else
            {
                //check for null
                if (snapshot.Get("likes") == null)
                {
                    return;
                }

                var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null;

                if (data != null)
                {
                    var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister);

                    //retrieve our own id
                    string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid;

                    //check if our user ID is contained inside the dictionary
                    if (dictionaryFromHashMap.Contains(uid))
                    {
                        //remove our user ID to unlike the post
                        dictionaryFromHashMap.Remove(uid);

                        //update the hashmap withour our userid included
                        likeReference.Update("likes", dictionaryFromHashMap);
                    }
                }
            }
        }
 public void Call(Java.Lang.Object retrievedAttributes)
 {
     callbackString = "";
     if (retrievedAttributes != null)
     {
         var attributesDictionary = new Android.Runtime.JavaDictionary <string, object>(retrievedAttributes.Handle, Android.Runtime.JniHandleOwnership.DoNotRegister);
         foreach (KeyValuePair <string, object> pair in attributesDictionary)
         {
             callbackString = callbackString + "[ " + pair.Key + " : " + pair.Value + " ]";
         }
     }
     else
     {
         callbackString = "GetUserAttributes callback is null.";
     }
     if (latch != null)
     {
         latch.Signal();
     }
 }
コード例 #6
0
        public void OnSuccess(Java.Lang.Object result)
        {
            DocumentSnapshot snapshot = (DocumentSnapshot)result;

            if (!snapshot.Exists())
            {
                return;
            }

            DocumentReference likesReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID);

            if (Like)
            {
                likesReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true);
            }
            else
            {
                if (snapshot.Get("likes") == null)
                {
                    return;
                }

                var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null;

                if (data != null)
                {
                    var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister);

                    string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid;

                    if (dictionaryFromHashMap.Contains(uid))
                    {
                        dictionaryFromHashMap.Remove(uid);
                        likesReference.Update("likes", dictionaryFromHashMap);
                    }
                }
            }
        }
コード例 #7
0
        public void OnSuccess(Object result)
        {
            var snapshot = (DocumentSnapshot)result;

            string fullname = snapshot.Get("full_name").ToString();
            string email    = snapshot.Get("email") != null?snapshot.Get("email").ToString() : "";

            var phone_number = snapshot.Get("phone_number") != null?snapshot.Get("phone_number") : null;

            if (phone_number != null)
            {
                var dictionFromHashMap = new Android.Runtime.JavaDictionary <string, string>(phone_number.Handle, Android.Runtime.JniHandleOwnership.DoNotRegister);

                string data_result = "full name = " + fullname + "\n ";
                data_result = data_result + "email = " + email + " \n ";
                foreach (KeyValuePair <string, string> item in dictionFromHashMap)
                {
                    data_result = data_result + item.Key + " = " + item.Value + " \n ";
                }

                resultTextView.Text = data_result;
            }
        }