Beispiel #1
0
        void Connect(Provider provider, Data data = null, Credential?credential = null)
        {
            if (credential == null && provider.TryGetModule <Auth>(out var auth))
            {
                var content   = transform.Find("Content");
                var authPanel = content.Find("Auth");
                OpenPanel(authPanel.gameObject);

                var btn = authPanel.Find("Login").GetComponent <Button>();
                btn.onClick.RemoveAllListeners();
                btn.onClick.AddListener(() =>
                {
                    credential = new Credential(authPanel.Find("ID").GetComponent <InputField>().text, authPanel.Find("Password").GetComponent <InputField>().text);
                    StartCoroutine(auth.Connect(credential.Value, () =>
                    {
                        bool dataIsNull = data == null;
                        if (dataIsNull)
                        {
                            data = CreateData();
                        }

                        UpdateCredentials(data.ID, credential.Value);

                        if (dataIsNull)
                        {
                            Manager.Data = data;
                            StartCoroutine(provider.GetInfos(data, Complete));
                        }
                        else
                        {
                            Complete(data);
                        }
                    }, (error) => authPanel.Find("Error").GetComponent <Text>().text = error));
                });
                OpenPanel(authPanel.gameObject);
            }
            else if (data == null)
            {
                StartCoroutine(provider.GetInfos(CreateData(), Complete));
            }
            else
            {
                Complete(data);
            }

            Data CreateData() => new Data
            {
                ID = System.Guid.NewGuid().ToString("D"), Provider = provider.GetType().Name
            };
            void Complete(Data d)
            {
                d.LastLogin      = System.DateTime.UtcNow;
                Manager.Data     = d;
                Manager.provider = provider;
                Manager.instance.Menu.sideMenu.handle.SetActive(true);
                Menu.SelectChild();
                Manager.OpenModule(Manager.instance.Home.gameObject);
            }
        }
Beispiel #2
0
 public void OnEnable()
 {
     language = LangueAPI.Culture;
     if (!Manager.isReady)
     {
         gameObject.SetActive(false); return;
     }
     Initialise(periodStart, defaultAction);
     Manager.OpenModule(gameObject);
 }
Beispiel #3
0
 public void OnEnable()
 {
     if (!Manager.isReady)
     {
         gameObject.SetActive(false); return;
     }
     if (periodIndex == 0)
     {
         Initialise();
     }
     else
     {
         Manager.OpenModule(gameObject);
     }
 }
Beispiel #4
0
        public void Initialise()
        {
            if (!Manager.provider.TryGetModule(out Integrations.Homeworks module))
            {
                gameObject.SetActive(false); return;
            }

            if (periodsMethod == null)
            {
                periodsMethod = module.DiaryPeriods();
            }
            var period = periods.ElementAtOrDefault(periodIndex);

            if (period != null)
            {
                Void();
            }
            else if (periodIndex >= 0)
            {
                LoadNext((p) => { period = p; Void(); });
            }


            void Void()
            {
                Action <List <Homework> > action = (homeworks) =>
                {
                    ProviderExtension.GenerateSubjectColors();
                    Refresh(homeworks.OrderBy(h => h.forThe), period);
                    Manager.OpenModule(gameObject);
                };

                List <Homework> GetHomeworks() => Manager.Data.ActiveChild.Homeworks?.Where(h => h.periodID != null ? h.periodID == period.id : period.timeRange.Contains(h.forThe)).ToList();

                var _homeworks = GetHomeworks();

                if (_homeworks?.Count > 0)
                {
                    action(_homeworks);
                }
                else
                {
                    StartCoroutine(module.GetHomeworks(period, () => action(GetHomeworks())));
                }
            }
        }