コード例 #1
0
 private void Accept()
 {
     _tripRef.Child("status").SetValue("accepted");
     _tripRef.Child("driver_name").SetValue(AppDataHelper.GetFullname());
     _tripRef.Child("driver_phone").SetValue(AppDataHelper.GetPhone());
     _tripRef.Child("driver_location").Child("latitude").SetValue(_mLastlocation.Latitude);
     _tripRef.Child("driver_location").Child("longitude").SetValue(_mLastlocation.Longitude);
     _tripRef.Child("driver_id").SetValue(AppDataHelper.GetCurrentUser().Uid);
 }
コード例 #2
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            HashMap postMap = new HashMap();

            postMap.Put("author", AppDataHelper.GetFullname());
            postMap.Put("owner_id", AppDataHelper.GetFirebaseAuth().CurrentUser.Uid);

            postMap.Put("post_date", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss tt"));
            postMap.Put("post_body", postEditText.Text);

            //this will return an instance of our firestore
            //this will also generate an id
            DocumentReference newPostRef = AppDataHelper.GetFirestore().Collection("posts").Document();
            //retrieve the document ID created
            string postKey = newPostRef.Id;

            postMap.Put("image_id", postKey);

            ShowProgressDialogue("Posting..");

            // Save post image to firebase storage
            StorageReference storageReference = null;

            //check if the filebytes is not null
            if (fileBytes != null)
            {
                //This is the location where our images will be uploaded in the Firebase Storage
                //"postImages/" + "photo" is the location + imagename
                storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postKey);

                //this code will save our image file to firebase storage
                storageReference.PutBytes(fileBytes)
                .AddOnSuccessListener(taskCompletionListeners)
                .AddOnFailureListener(taskCompletionListeners);
            }
            taskCompletionListeners.Success += (obj, EventArgs args) =>
            {
                //check if storageReference is null
                if (storageReference != null)
                {
                    storageReference.DownloadUrl.AddOnSuccessListener(downloadUrlListener);
                }

                //to get hold of the URL
                downloadUrlListener.Success += (obj, args) =>
                {
                    string downloadUrl = args.Result.ToString();
                    postMap.Put("download_url", downloadUrl);

                    //Save post to Firebase Firestore
                    newPostRef.Set(postMap);

                    CloseProgressDialogue();
                    Finish();
                };
            };

            taskCompletionListeners.Failure += (obj, args) =>
            {
                Toast.MakeText(this, "Upload failed!", ToastLength.Short).Show();
                CloseProgressDialogue();
            };
        }