public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var snapshotQuery = (QuerySnapshot)value; if (!snapshotQuery.IsEmpty) { foreach (DocumentSnapshot snap in snapshotQuery.Documents) { friendId = snap.Id.ToString(); DocumentReference documentReference = FirebaseBackend.FirebaseBackend .GetFireStore() .Collection("invitations") .Document(friendId); documentReference.Update(currentUserID, true) .AddOnSuccessListener(this) .AddOnFailureListener(this); } } else { OnResult?.Invoke(this, new ResultEventArgs { Result = "No user with such email" }); } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { if (error != null) { Toast.MakeText(this, error.ToString(), ToastLength.Long).Show(); } else { if (value != null) { if (value.GetType() == typeof(QuerySnapshot)) { var snapshot = (QuerySnapshot)value; if (snapshot != null && !snapshot.Metadata.IsFromCache && snapshot.DocumentChanges != null && snapshot.DocumentChanges.Count() > 0) { var changes = snapshot.DocumentChanges.ToList(); foreach (var change in changes) { System.Diagnostics.Debug.WriteLine("Changed DocumentId: " + change.Document.Id); var changedDocumentData = change.Document.Data; } } } } } }
//void FetchAndListenExpensesTable() //{ // CollectionReference monthyearRef = database.Collection("ExpenseTable"); // Query query = monthyearRef.WhereEqualTo("DateYear", YearSelected).WhereEqualTo("DateMonth", MonthSelected).WhereEqualTo("UserUid", CurrentUserUid).OrderBy("DateDay", Query.Direction.Descending); // query.Get().AddOnSuccessListener(this).AddOnFailureListener(this); //} public void OnEvent(Java.Lang.Object obj, FirebaseFirestoreException error) { TotalExpenseValue = new List <string>(); var snapshot = (QuerySnapshot)obj; parentObjects = new List <IParentObject>(); GlobalchildList = new List <object>(); if (!snapshot.IsEmpty) { var documents = snapshot.Documents; foreach (DocumentSnapshot docitem in documents) { TotalExpenseValue.Add(docitem.Get("Amount").ToString()); expenseitem = new ExpenseItemParent(); var childList = new List <Object>(); childList.Add(new ExpenseItemChild(docitem.Get("Description").ToString(), docitem.Id.ToString(), docitem.Get("Date").ToString(), docitem.Get("ItemName").ToString(), docitem.Get("Amount").ToString())); // GlobalchildList.Add(childList); expenseitem = new ExpenseItemParent() { ExpenseItem = docitem.Get("ItemName").ToString(), ExpenseItemAmount = docitem.Get("Amount").ToString() }; expenseitem.ChildObjectList = childList; GlobalchildList.Add(expenseitem.ChildObjectList[0]); parentObjects.Add(expenseitem); } // GlobalchildList = expenseitem.ChildObjectList; SetupVerticalRecyclerView(); //if(expenseadapter!=null) //{ // expenseadapter.NotifyDataSetChanged(); //} } }
public void OnEvent(Java.Lang.Object obj, FirebaseFirestoreException error) { var snapshot = (QuerySnapshot)obj; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; displayproducts.Clear(); foreach (DocumentSnapshot item in documents) { Product product = new Product(); product.ID = item.Id; product.productname = item.Get("productname").ToString(); product.category = item.Get("category") != null?item.Get("category").ToString() : ""; product.amount = item.GetLong("amount").IntValue() != 0 ? item.GetLong("amount").IntValue() : 1; //item.Get("amount") != 0 ? item.Get("amount") : 1; //user.ProfileImage = item.Get("profileimage") != null ? item.Get("profileimage").ToString() : ""; displayproducts.Add(product); } if (dataAdapter != null) { dataAdapter.NotifyDataSetChanged(); } } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var snapshot = (QuerySnapshot)value; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; cartresult.Clear(); foreach (DocumentSnapshot item in documents) { Cart product = new Cart(); product.ID = item.Id; product.productname = item.Get("productname").ToString(); product.productimgurl = item.Get("imageurl") != null?item.Get("imageurl").ToString() : ""; product.unitprice = item.GetLong("unitprice").IntValue() != 0 ? item.GetLong("unitprice").IntValue() : 1; //item.Get("amount") != 0 ? item.Get("amount") : 1; //user.ProfileImage = item.Get("profileimage") != null ? item.Get("profileimage").ToString() : ""; cartresult.Add(product); } if (cartadapter != null) { cartadapter.NotifyDataSetChanged(); } } }
/// <summary> /// Listener for FetchUserDetails /// </summary> /// <param name="value"></param> /// <param name="error"></param> public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { if (error != null) { Toast.MakeText(this, "Failed to fetch user details", ToastLength.Long).Show(); return; } var snapshot = (QuerySnapshot)value; if (snapshot.Documents.Count == 1) { var dictionary = snapshot.Documents.First().Data; //Update global variables Global.FName = dictionary.ContainsKey("FName") ? (string)dictionary["FName"] : string.Empty; Global.LName = dictionary.ContainsKey("LName") ? (string)dictionary["LName"] : string.Empty; Global.PhotoUrl = dictionary.ContainsKey("PhotoUrl") ? (string)dictionary["PhotoUrl"] : string.Empty; Global.Phone = dictionary.ContainsKey("Phone") ? (string)dictionary["Phone"] : string.Empty; Global.UserType = dictionary.ContainsKey("Type") ? (string)dictionary["Type"] : "customer"; UpdateUI(); } else { Toast.MakeText(this, "There was an error fetching user details", ToastLength.Long).Show(); } }
/// <summary> /// Snapshot listener that is trigger by DB changes (added, modified, deleted) /// </summary> /// <param name="value">New Snapshot</param> /// <param name="error">Firebase exception object</param> public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { if (error != null) { //Log.w("TAG", "listen:error", error); return; } int count = 1; var snapshots = (QuerySnapshot)value; foreach (DocumentChange dc in snapshots.DocumentChanges) { var dictionary = dc.Document.Data; dictionary.Add("Id", dc.Document.Id); var vendor = ToObject(dictionary); switch (dc.GetType().ToString()) { case "ADDED": //Log.d("TAG", "New Msg: " + dc.getDocument().toObject(Message.class)); vendors.Add(vendor); break; case "MODIFIED": //find modified item and replace with new document int index = vendors.FindIndex(x => x.Id == vendor.Id); vendors.RemoveAt(index); vendors.Insert(index, vendor); break; case "REMOVED": //delete vendor break; } } swipeRefreshLayout.Post(() => { swipeRefreshLayout.Refreshing = false; recyclerView.Clickable = true; }); if (reload) { vendorAdapter.NotifyDataSetChanged(); //for updating adapter reload = false; } else { //make toast Toast toast = Toast.MakeText(this, "new vendors added", ToastLength.Long); toast.SetGravity(GravityFlags.Center, 0, 0); toast.Show(); } }
public void OnEvent(Object value, FirebaseFirestoreException error) { if (value != null) { _action(value); } if (error != null) { _errorAction(error); } }
public void OnEvent(Java.Lang.Object obj, FirebaseFirestoreException error) { var snapshot = (QuerySnapshot)obj; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; searchproducts.Clear(); foreach (DocumentSnapshot item in documents) { Product product = new Product(); product.ID = item.Id; product.productname = item.Get("productname").ToString(); product.category = item.Get("category") != null?item.Get("category").ToString() : ""; product.imageurl = item.Get("imageurl") != null?item.Get("imageurl").ToString() : ""; product.amount = item.GetLong("amount").IntValue() != 0 ? item.GetLong("amount").IntValue() : 1; //item.Get("amount") != 0 ? item.Get("amount") : 1; //user.ProfileImage = item.Get("profileimage") != null ? item.Get("profileimage").ToString() : ""; searchproducts.Add(product); buyinguser = SecondPageActivity.loggedinuser; username = buyinguser.Fullname; //imagelist.Add($"{product.productname}_image.jpg"); //StorageReference ppref = FirebaseStorage.Instance.GetReference($"users/{username}_image"); //ppref.GetDownloadUrl().AddOnSuccessListener(this, this); } if (searchadapter != null) { searchadapter.NotifyDataSetChanged(); } } }
public async void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { try { var snapshot = (QuerySnapshot)value; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; listOfPersons.Clear(); listOfPersons = documents.ToList().ConvertAll(new Converter <DocumentSnapshot, Persons>(DocumentSnapshotToPersons)); } MainPage.updateListView(listOfPersons); } catch (System.Exception ex) { string msg = ex.Message; } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { DocumentSnapshot ds = (DocumentSnapshot)value; string opponentName = string.Empty; if (isInGame) { Finish(); } else if (ds != null) { if ((bool)ds.Get(Constants.ISLIVE_GAME)) { //stop loading and begin game pd.Dismiss(); opponentName = (string)ds.Get(Constants.PLAYER_GAME); StartGame((string)ds.Get(Constants.GAMENUM), opponentName, game.Subject); } } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var querySnapshot = (DocumentSnapshot)value; if (querySnapshot.Exists()) { if (messageList.Count > 0) { messageList.Clear(); } foreach (KeyValuePair <string, Java.Lang.Object> pair in querySnapshot.Data) { string id = pair.Key.ToString(); //Field id if (querySnapshot.Get(id + ".message_date") != null) { string image_url = querySnapshot.Get(id + ".from_image_id") != null?querySnapshot.Get(id + ".from_image_id").ToString() : ""; string messageDate = querySnapshot.Get(id + ".message_date") != null?querySnapshot.Get(id + ".message_date").ToString() : ""; BaseMessage message = new BaseMessage { ProfileImageId = image_url, ProfileFromId = querySnapshot.Get(id + ".from") != null?querySnapshot.Get(id + ".from").ToString() : "", ProfileFromName = querySnapshot.Get(id + ".from_fullname") != null?querySnapshot.Get(id + ".from_fullname").ToString() : "", ProfileToId = querySnapshot.Get(id + ".to") != null?querySnapshot.Get(id + ".to").ToString() : "", MessageBody = querySnapshot.Get(id + ".message_body") != null?querySnapshot.Get(id + ".message_body").ToString() : "", //MessageDateTime = DateTime.ParseExact(messageDate, format, null) }; message.MessageDateTime = DateTime.ParseExact(messageDate, "dd MM yyyy HH:mm:ss", CultureInfo.InvariantCulture); messageList.Add(message); } } OnMessageRetrieved?.Invoke(this, new MessagesEventArgs { MessageList = messageList }); } }
/// <summary> /// gets the collection and placed the documents data in the score list /// </summary> /// <param name="value">the snapshot</param> /// <param name="error">an error</param> public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var snapshot = (QuerySnapshot)value; if (!snapshot.IsEmpty) { var documents = snapshot.Documents; scoreList.Clear(); foreach (DocumentSnapshot item in documents) { Score score = new Score(); score.Name = item.Get(Constants.NAME).ToString(); score.HighestValue = int.Parse(item.Get(Constants.SCORE).ToString()); score.Key = int.Parse(item.Get(Constants.KEY).ToString()); if (score.Key == currentScore.Key) { btnUpload.Text = removeText; } AddToList(score); } } }
public void OnEvent(Java.Lang.Object obj, FirebaseFirestoreException exception) => _eventAction(obj, exception);
/// <summary> /// Handles callbacks from firestore, when certain values are changed, responsible for most of the game logic (when to show question/answer and when to change ect) /// </summary> /// <param name="value">value from firestore</param> /// <param name="error">exception</param> public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { DocumentSnapshot ds = (DocumentSnapshot)value; if (!isHost && ds.Get(Constants.CURRENT_Q_INDEX) != null && lastIndex != (int)ds.Get(Constants.CURRENT_Q_INDEX) && !isGameOver) { isInRest = true; gameHashMap = SetHashMap(ds, gameHashMap); //reset the views before next question tvMyAnswer.Text = 0.ToString(); tvOpponentAnswer.Text = 0.ToString(); tvAnswer.Text = "תשובה"; gameHashMap = SetHashMap(ds, gameHashMap); int index = (int)ds.Get(Constants.CURRENT_Q_INDEX); lastIndex = index; PresentQuestion(index); } if (ds.Get(Constants.IS_RESTING_TIME) != null && (bool)ds.Get(Constants.IS_RESTING_TIME) && isInRest && !isGameOver)// if the question is done, we go to rest { gameHashMap = SetHashMap(ds, gameHashMap); isInRest = false; //check answers CheckAnsAndUpdate(ds); gameStatus = HasWon(); //if host wins = 1, if player wins = 2, if tie = 0, if not won at all = -1 tvAnswer.Text = questions[(int)ds.Get(Constants.CURRENT_Q_INDEX)].Ans.ToString(); if (gameStatus != Constants.NOT_WON) //if the game is over, we show the ending dialog { isGameOver = true; ShowGameEndDialog(gameStatus); } else if (!isGameOver)//else, we keep the game going { if (isHost) { isNewQuestion = true; gameHashMap.Put(Constants.IS_NEW_QUESTION, false); gameHashMap.Put(Constants.HOST_ANSWER, 0); gameHashMap.Put(Constants.PLAYER_ANSWER, 0); fd.AddDocumentToCollection(Constants.GAMES_COL, game.GameNum, gameHashMap); } StartTimer(Constants.RESTING_TIME);//resting time after the answer is presented //put the rest that is down there here after game is finished! } //we reset the answers of both players to 0, so we don't have them set for next round } if (isHost && ds.Get(Constants.IS_NEW_QUESTION) != null && (bool)ds.Get(Constants.IS_NEW_QUESTION) && isNewQuestion && !isGameOver)//host picks new question when resting is over { gameHashMap = SetHashMap(ds, gameHashMap); isInRest = true; isNewQuestion = false;//to not go in this condition many times at once...(bug) //reset the views before next question tvMyAnswer.Text = 0.ToString(); tvOpponentAnswer.Text = 0.ToString(); tvAnswer.Text = "תשובה"; gameHashMap.Put(Constants.CURRENT_Q_INDEX, RandomNumber()); gameHashMap.Put(Constants.IS_NEW_QUESTION, false); fd.AddDocumentToCollection(Constants.GAMES_COL, game.GameNum, gameHashMap); fd.AddSnapShotListenerToDocument(Constants.GAMES_COL, game.GameNum, this); PresentQuestion(rand); } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { var snapshotQuery = (QuerySnapshot)value; if (!snapshotQuery.IsEmpty) { if (Conversations.Count > 0) { Conversations.Clear(); } foreach (DocumentSnapshot snapshot in snapshotQuery.Documents) { if (snapshot.Id.Contains(Helpers.Helper.GetUserId())) { if (snapshot.Exists()) { string chatId = snapshot.Id; string lastMessage = ""; string userId = ""; string userImgUrl = ""; DateTime messageDate = DateTime.Parse("01/01/2000"); string userFullName = ""; foreach (KeyValuePair <string, Java.Lang.Object> pair in snapshot.Data) { string id = pair.Key.ToString(); //Field id if (snapshot.Get(id + ".message_date") != null) { string latestMessageTemp = snapshot.Get(id + ".message_body") != null?snapshot.Get(id + ".message_body").ToString() : ""; string userIdTemp = snapshot.Get(id + ".from") != null?snapshot.Get(id + ".from").ToString() : ""; string userImageUrlTemp = snapshot.Get(id + ".from_image_id") != null?snapshot.Get(id + ".from_image_id").ToString() : ""; string userNameTemp = snapshot.Get(id + ".from_fullname") != null?snapshot.Get(id + ".from_fullname").ToString() : ""; string messageDateTemp = snapshot.Get(id + ".message_date") != null?snapshot.Get(id + ".message_date").ToString() : ""; string userIdTarget = snapshot.Get(id + ".to") != null?snapshot.Get(id + ".to").ToString() : ""; string userNameTarget = snapshot.Get(id + ".to_fullname") != null?snapshot.Get(id + ".to_fullname").ToString() : ""; string userImageUrlTarget = snapshot.Get(id + ".to_image_id") != null?snapshot.Get(id + ".to_image_id").ToString() : ""; DateTime temp = DateTime.ParseExact(messageDateTemp, "dd MM yyyy HH:mm:ss", CultureInfo.InvariantCulture); if (Helpers.Helper.GetUserId() != userIdTemp) { userId = userIdTemp; userImgUrl = userImageUrlTemp; userFullName = userNameTemp; } else if (Helpers.Helper.GetUserId() == userIdTemp) { userId = userIdTarget; userImgUrl = userImageUrlTarget; userFullName = userNameTarget; latestMessageTemp = "You: " + latestMessageTemp; } if (DateTime.Compare(messageDate, temp) < 0) { messageDate = temp; lastMessage = latestMessageTemp; } } } Conversations.Add(new Conversation { ProfileImageUrl = userImgUrl, LastMessageDate = messageDate, UserId = userId, ChatId = chatId, LastMessagePreview = lastMessage, ProfileName = userFullName }); } } } OnConversationRetrieved?.Invoke(this, new ConversationArgs { ConversationChat = Conversations }); } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { OrganizeData(value); }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { _handler?.Invoke(value.JavaCast <T>(), error); }