Exemple #1
0
    private void RetrieveGroupData(string code)
    {
        FirebaseDatabase.DefaultInstance.GetReference("GROUP/" + code).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
            }
            else if (task.IsCanceled)
            {
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snap = task.Result;
                Group group       = new Group();

                if (snap.ChildrenCount == 0)
                {
                    Debug.Log("empty");
                    return;
                }

                IDictionary result = (IDictionary)snap.Value;
                Debug.Log("zaa6");
                group.name = result["name"].ToString();
                group.code = result["code"].ToString();
                //그룹의 시간표
                if (result.Contains("events_list"))
                {
                    Dictionary <string, object> evnet_list = (Dictionary <string, object>)result["events_list"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in evnet_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        int year           = Convert.ToInt32(tmp["year"].ToString());
                        int month          = Convert.ToInt32(tmp["month"].ToString());
                        int day            = Convert.ToInt32(tmp["day"].ToString());
                        int hour           = Convert.ToInt32(tmp["hour"].ToString());
                        int min            = Convert.ToInt32(tmp["min"].ToString());
                        string title       = tmp["title"].ToString();
                        string description = tmp["description"].ToString();
                        string place       = tmp["place"].ToString();
                        group.events_list.Add(key, new Events(year, month, day, hour, min, title, description, place));
                    }
                }

                if (result.Contains("feed"))
                {
                    Dictionary <string, object> feed_list = (Dictionary <string, object>)result["feed"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in feed_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        if (tmp["author"].ToString() == userID)
                        {
                            continue;
                        }
                        string title = tmp["title"].ToString();
                        string body  = tmp["body"].ToString();


                        string gcode = group.code;

                        MainController.Feed tmpFeed = new MainController.Feed();
                        tmpFeed.title     = title;
                        tmpFeed.body      = body;
                        tmpFeed.groupcode = gcode;


                        group.feed_list.Add(key, tmpFeed);
                    }
                }

                if (result.Contains("member"))
                {
                    List <object> memberlist = (List <object>)result["member"];
                    foreach (var sitem in memberlist)
                    {
                        if (!sitem.ToString().Equals(userID))
                        {
                            RetrieveMemberData(group, sitem.ToString());
                        }
                    }
                }

                //todo add groupinfo
                _controller.group_list.Add(group);
            }
        });
    }
Exemple #2
0
    public void AcceptInvite(Feed feed)
    {
        string code = feed.groupcode;

        FirebaseDatabase.DefaultInstance.GetReference("GROUP/" + code).GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
            }
            else if (task.IsCanceled)
            {
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snap = task.Result;
                Group group       = new Group();

                if (snap.ChildrenCount == 0)
                {
                    Debug.Log("empty");
                    return;
                }

                IDictionary result = (IDictionary)snap.Value;

                group.name = result["name"].ToString();
                group.code = result["code"].ToString();
                //그룹의 시간표
                if (result.Contains("events_list"))
                {
                    Dictionary <string, object> evnet_list = (Dictionary <string, object>)result["events_list"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in evnet_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        int year           = Convert.ToInt32(tmp["year"].ToString());
                        int month          = Convert.ToInt32(tmp["month"].ToString());
                        int day            = Convert.ToInt32(tmp["day"].ToString());
                        int hour           = Convert.ToInt32(tmp["hour"].ToString());
                        int min            = Convert.ToInt32(tmp["min"].ToString());
                        string title       = tmp["title"].ToString();
                        string description = tmp["description"].ToString();
                        string place       = tmp["place"].ToString();
                        group.events_list.Add(key, new Events(year, month, day, hour, min, title, description, place));
                    }
                }


                if (result.Contains("feed"))
                {
                    Dictionary <string, object> feed_list = (Dictionary <string, object>)result["feed"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in feed_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        string title = tmp["title"].ToString();
                        string body  = tmp["body"].ToString();
                        string gcode = group.code;

                        MainController.Feed tmpFeed = new MainController.Feed();
                        tmpFeed.title     = title;
                        tmpFeed.body      = body;
                        tmpFeed.groupcode = gcode;

                        group.feed_list.Add(key, tmpFeed);
                    }
                }
                DB_GROUPCODE tmpdb = new DB_GROUPCODE();
                if (result.Contains("member"))
                {
                    List <object> memberlist = (List <object>)result["member"];
                    foreach (var sitem in memberlist)
                    {
                        tmpdb.member.Add(sitem.ToString());

                        if (!sitem.ToString().Equals(userID))
                        {
                            RetrieveMemberData(group, sitem.ToString());
                        }
                    }
                }
                tmpdb.code = code;
                tmpdb.name = group.name;
                tmpdb.member.Add(userID);
                //todo add groupinfo
                _controller.group_list.Add(group);

                Debug.Log("add");

                int memberidx = _controller.group_list[_controller.group_list.Count - 1].member.Count;

                FirebaseDatabase.DefaultInstance.GetReference("GROUP/" + code).SetRawJsonValueAsync(JsonUtility.ToJson(tmpdb));
                int gidx   = _controller.group_list.Count - 1;
                GROUPDB DB = new GROUPDB();
                DB.code    = code;

                FirebaseDatabase.DefaultInstance.GetReference("USER/" + userID + "/group_list/" + gidx).SetRawJsonValueAsync(JsonUtility.ToJson(DB));
                _controller.setGroup();
            }
        });
    }
Exemple #3
0
    private void RetrieveUserData(string uid)
    {
        Debug.Log("retrieveUserData");

        User user = new User();

        FirebaseDatabase.DefaultInstance.GetReference("USER/" + uid).GetValueAsync().ContinueWith(userbasicdata =>
        {
            if (userbasicdata.IsFaulted)
            {
            }
            else if (userbasicdata.IsCanceled)
            {
            }
            else if (userbasicdata.IsCompleted)
            {
                DataSnapshot snap = userbasicdata.Result;

                if (snap.ChildrenCount == 0)
                {
                    Debug.Log("empty");
                    return;
                }

                IDictionary result = (IDictionary)snap.Value;

                user.deviceID         = result["deviceID"].ToString();
                user.isAlarmOn        = Convert.ToBoolean(result["isAlarmOn"].ToString());
                user.default_calendar = result["default_calendar"].ToString();
                user.nickname         = result["nickname"].ToString();
                user.email            = result["email"].ToString();

                if (result.Contains("dDay_list"))
                {
                    List <object> dday_list = (List <object>)result["dDay_list"];

                    foreach (var ddayitem in dday_list)
                    {
                        IDictionary tmp    = (IDictionary)ddayitem;
                        int year           = Convert.ToInt32(tmp["year"].ToString());
                        int month          = Convert.ToInt32(tmp["month"].ToString());
                        int day            = Convert.ToInt32(tmp["day"].ToString());
                        int hour           = Convert.ToInt32(tmp["hour"].ToString());
                        int min            = Convert.ToInt32(tmp["min"].ToString());
                        string description = tmp["description"].ToString();

                        user.dDay_list.Add(new Dday(year, month, day, hour, min, description));
                    }
                }

                if (result.Contains("events_list"))
                {
                    Dictionary <string, object> evnet_list = (Dictionary <string, object>)result["events_list"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in evnet_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        int year           = Convert.ToInt32(tmp["year"].ToString());
                        int month          = Convert.ToInt32(tmp["month"].ToString());
                        int day            = Convert.ToInt32(tmp["day"].ToString());
                        int hour           = Convert.ToInt32(tmp["hour"].ToString());
                        int min            = Convert.ToInt32(tmp["min"].ToString());
                        string title       = tmp["title"].ToString();
                        string description = tmp["description"].ToString();
                        string place       = tmp["place"].ToString();
                        user.events_list.Add(key, new Events(year, month, day, hour, min, title, description, place));
                    }
                }

                if (result.Contains("feed"))
                {
                    Dictionary <string, object> feed_list = (Dictionary <string, object>)result["feed"];

                    //List<object> evnet_list = (List<object>)result["events_list"];
                    foreach (var eitem in feed_list)
                    {
                        string key      = eitem.Key;
                        IDictionary tmp = (IDictionary)eitem.Value;

                        string title = tmp["title"].ToString();
                        string body  = tmp["body"].ToString();
                        string gcode = tmp["groupcode"].ToString();

                        MainController.Feed tmpFeed = new MainController.Feed();
                        tmpFeed.title     = title;
                        tmpFeed.body      = body;
                        tmpFeed.groupcode = gcode;

                        user.feed_list.Add(key, tmpFeed);
                    }
                }
                if (result.Contains("schedule_list"))
                {
                    Debug.Log("zaa");
                    Dictionary <string, object> schedule_list = (Dictionary <string, object>)result["schedule_list"];
                    //List<object> schedule_list = (List<object>)result["schedule_list"];

                    foreach (var sitem in schedule_list)
                    {
                        Debug.Log("zaa2");
                        Schedule tmpSch    = new Schedule();
                        IDictionary tmp    = (IDictionary)sitem.Value;
                        tmpSch.day1        = tmp["day1"].ToString();
                        tmpSch.start1      = tmp["start1"].ToString();
                        tmpSch.finish1     = tmp["finish1"].ToString();
                        tmpSch.description = tmp["description"].ToString();

                        Debug.Log(tmp.Count);
                        if (tmp.Count > 5)
                        {
                            tmpSch.day2    = tmp["day2"].ToString();
                            tmpSch.start2  = tmp["start2"].ToString();
                            tmpSch.finish2 = tmp["finish2"].ToString();
                        }
                        Debug.Log("a!");
                        user.schedule_list.Add(sitem.Key, tmpSch);
                    }
                }
                Debug.Log("zaa3");
                if (result.Contains("todo_list"))
                {
                    Dictionary <string, object> todo_list = (Dictionary <string, object>)result["todo_list"];
                    Debug.Log("zaa3");
                    foreach (var items in todo_list)
                    {
                        string key         = items.Key;
                        string description = items.Value.ToString();

                        IDictionary tmp  = (IDictionary)items.Value;
                        string text      = tmp["description"].ToString();
                        bool iscomplete  = Convert.ToBoolean(tmp["isComplete"].ToString());
                        Todo todo        = new Todo();
                        todo.description = text;
                        todo.isComplete  = iscomplete;
                        user.todo_list.Add(key, todo);
                        Debug.Log("add :" + key + "." + text);
                    }
                }
                Debug.Log("zaa4");
                if (result.Contains("group_list"))
                {
                    List <object> group_list = (List <object>)result["group_list"];
                    Debug.Log("zaa5");
                    foreach (var gitem in group_list)
                    {
                        IDictionary tmp = (IDictionary)gitem;
                        string code     = tmp["code"].ToString();
                        RetrieveGroupData(code);

                        //FirebaseDatabase.DefaultInstance.GetReference("GROUP/" + code + "/events_list/").ValueChanged += HandleValueChanged;
                    }
                    Debug.Log("finish getting data from firebase");
                    // Debug.Log(_controller);

                    _controller._user = user;
                    Debug.Log(_controller._user.todo_list.Count);
                    Debug.Log("add333");
                    SceneManager.LoadScene(1);
                    _controller.OffProgressBar();
                }
                else
                {
                    Debug.Log("finish getting data from firebase");
                    // Debug.Log(_controller);

                    _controller._user = user;
                    Debug.Log(_controller._user.todo_list.Count);
                    Debug.Log("add333");
                    SceneManager.LoadScene(1);
                    _controller.OffProgressBar();
                }
            }
        });
    }