Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        provider    = GlobalContentProvider.Instance;
        foodManager = provider.GetCurrentFoodManager();
        foodKey     = foodManager.GetFoodKey();

        canvas = GameObject.Find("ReviewCanvas");
        detail = canvas.transform.Find("ScrollView_5/ScrollRect/Content");

        //get ref to comment and username input
        commentInput  = detail.Find("CommentField").GetComponent <InputField>();
        usernameInput = detail.Find("Username").GetComponent <InputField>();

        //add listener for button
        detail.Find("Submit").GetComponent <Button>().onClick.AddListener(OnSubmitClick);
        detail.Find("Share").GetComponent <Button>().onClick.AddListener(OnShareClick);

        //get ref to rating
        rating = detail.Find("Rating").Find("Score").GetComponent <Slider>();

        //get toast
        toast = detail.Find("Toast").GetComponent <Toast>();

        //get back btn
        backBtn = canvas.transform.Find("Title/BackBtn").GetComponent <Button>();
        backBtn.onClick.AddListener(OnBackClick);

        // Set up the Editor before calling into the realtime database.
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://armenu-2220c.firebaseio.com/");

        // Get the reference for comment
        commentsRef = FirebaseDatabase.DefaultInstance
                      .GetReference("Meal/" + foodKey + "/Comments");
        // Get the reference for rating
        ratingRef = FirebaseDatabase.DefaultInstance
                    .GetReference("Meal/" + foodKey + "/Rating");

        // // Try to get the rating key
        // GlobalContentProvider.Instance.ratings.TryGetValue(foodKey, out ratingKey);
        // // if there is no rating key associated with this meal in this session -> push new one
        // if (ratingKey == "" || ratingKey == null) {
        //  currentRatingRef = ratingRef.Push();
        //  ratingKey = currentRatingRef.Key;
        //  GlobalContentProvider.Instance.ratings.Add(foodKey, ratingKey);
        // } else {
        //  currentRatingRef = ratingRef.Child(ratingKey);
        // }

        setContent();
    }
Esempio n. 2
0
    void InvokeDatabase()
    {
        FirebaseDatabase.DefaultInstance
        .GetReference("Meal/" + foodManager.GetFoodKey() + "/AveRating/Rate")
        .GetValueAsync().ContinueWith(task => {
            if (task.IsFaulted)
            {
                //handle error
            }
            else if (task.IsCompleted)
            {
                DataSnapshot rating = task.Result;
                SetRating((double)rating.Value);
            }
        });

        FirebaseDatabase.DefaultInstance
        .GetReference("Meal/" + foodManager.GetFoodKey() + "/Comments")
        .GetValueAsync().ContinueWith(task => {
            if (task.IsFaulted)
            {
                //handle error
            }
            else if (task.IsCompleted)
            {
                DataSnapshot commentsSnap = task.Result;
                foreach (DataSnapshot comment in commentsSnap.Children)
                {
                    content.comments.Add(new Tuple <string, string>(
                                             (string)comment.Child("username").Value,
                                             (string)comment.Child("content").Value));
                }

                SetComments();
            }
        });
    }