Exemplo n.º 1
0
        private void PostAdapter_ItemLongClick(object sender, PostAdapterClickEventArgs e)
        {
            string postID  = ListOfPost[e.Position].ID;
            string ownerID = ListOfPost[e.Position].OwnerId;

            if (AppDataHelper.GetFirebaseAuth().CurrentUser.Uid == ownerID)
            {
                Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
                alert.SetTitle("Edit or Delete Post");
                alert.SetMessage("Are you sure");

                alert.SetNegativeButton("Edit Post", (o, args) =>
                {
                    EditPostFragment editPostFragment = new EditPostFragment(ListOfPost[e.Position]);
                    var trans = SupportFragmentManager.BeginTransaction();
                    editPostFragment.Show(trans, "edit");
                });

                alert.SetPositiveButton("Delete", (o, args) =>
                {
                    AppDataHelper.GetFirestore().Collection("posts").Document(postID).Delete();

                    StorageReference storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postID);
                    storageReference.Delete();
                });
                alert.Show();
            }
        }
Exemplo n.º 2
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            DocumentReference reference = AppDataHelper.GetFirestore().Collection("posts").Document(thisPost.ID);

            reference.Update("post_body", postEditText.Text);
            this.Dismiss();
        }
Exemplo n.º 3
0
 public void FetchUser()
 {
     //This will retrieve a document snapshot that is going to contain information about this particular user
     AppDataHelper.GetFirestore().Collection("users").Document(AppDataHelper.GetFirebaseAuth()
                                                               .CurrentUser.Uid).Get()
     .AddOnSuccessListener(this);
 }
Exemplo n.º 4
0
        public void FetchPost()
        {
            //Retrieve only once
            // AppDataHelper.GetFirestore().Collection("posts").Get()
            //    .AddOnSuccessListener(this);

            AppDataHelper.GetFirestore().Collection("posts").AddSnapshotListener(this);
        }
Exemplo n.º 5
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());
            postMap.Put("post_body", postEditText.Text);

            DocumentReference newPostRef = AppDataHelper.GetFirestore().Collection("posts").Document();
            string            postKey    = newPostRef.Id;

            postMap.Put("image_id", postKey);


            ShowProgressDialogue("Saving Information ...");

            // Save Post Image to Firebase Storaage
            StorageReference storageReference = null;

            if (fileBytes != null)
            {
                storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postKey);
                storageReference.PutBytes(fileBytes)
                .AddOnSuccessListener(taskCompletionListeners)
                .AddOnFailureListener(taskCompletionListeners);
            }

            // Image Upload Success Callback
            taskCompletionListeners.Sucess += (obj, args) =>
            {
                if (storageReference != null)
                {
                    storageReference.DownloadUrl.AddOnSuccessListener(downloadUrlListener);
                }
            };

            // Image Download URL Callback
            downloadUrlListener.Sucess += (obj, args) =>
            {
                string downloadUrl = args.Result.ToString();
                postMap.Put("download_url", downloadUrl);

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


            // Image Upload Failure Callback
            taskCompletionListeners.Failure += (obj, args) =>
            {
                Toast.MakeText(this, "Upload was not completed", ToastLength.Short).Show();
            };
        }
Exemplo n.º 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.register);
            fullnameText            = (TextInputLayout)FindViewById(Resource.Id.fullNameRegText);
            emailText               = (TextInputLayout)FindViewById(Resource.Id.emailRegText);
            passwordText            = (TextInputLayout)FindViewById(Resource.Id.passwordRegText);
            confirmPasswordText     = (TextInputLayout)FindViewById(Resource.Id.confirmPasswordRegText);
            clickHereToLogin        = (TextView)FindViewById(Resource.Id.clickToLogin);
            clickHereToLogin.Click += ClickHereToLogin_Click;

            registerButton        = (Button)FindViewById(Resource.Id.registerButton);
            registerButton.Click += RegisterButton_Click;
            database              = AppDataHelper.GetFirestore();
            mAuth = AppDataHelper.GetFirebaseAuth();
        }
Exemplo n.º 7
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);
                    }
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.register);

            fullnameText        = (TextInputLayout)FindViewById(Resource.Id.fullNameRegText);
            emailText           = (TextInputLayout)FindViewById(Resource.Id.emailRegText);
            passwordText        = (TextInputLayout)FindViewById(Resource.Id.passwordRegText);
            confirmPasswordText = (TextInputLayout)FindViewById(Resource.Id.confirmPasswordRegText);
            clickHereToLogin    = (TextView)FindViewById(Resource.Id.clickToLogin);

            clickHereToLogin.Click += ClickHereToLogin_Click;

            registerButton        = (Button)FindViewById(Resource.Id.registerButton);
            registerButton.Click += RegisterButton_Click;

            //whenver we call the GetFirestore() method, it will return an instance of our firebase firestore.
            database = AppDataHelper.GetFirestore();

            //Instantiate firebase authentication
            mAuth = AppDataHelper.GetFirebaseAuth();
        }
Exemplo n.º 9
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);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void RemoveListener()
        {
            var listener = AppDataHelper.GetFirestore().Collection("posts").AddSnapshotListener(this);

            listener.Remove();
        }
Exemplo n.º 11
0
 public void UnlikePost()
 {
     like = false;
     AppDataHelper.GetFirestore().Collection("posts").Document(postID).Get()
     .AddOnSuccessListener(this);
 }
Exemplo n.º 12
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();
            };
        }
Exemplo n.º 13
0
 public void FetchUser()
 {
     AppDataHelper.GetFirestore().Collection("users").Document(AppDataHelper.GetFirebaseAuth().CurrentUser.Uid).Get()
     .AddOnSuccessListener(this);
 }