예제 #1
0
        public async void refreshData(int whatData)
        {
            switch (whatData)
            {
            case 1:
                projects    = null;
                projectJson = null;
                pServer     = null;
                checkDataAsync(PROJECT_DATA);
                break;

            case 2:
                tasks = null;
                projectsWithTasks.Clear();
                taskJson.Clear();
                checkDataAsync(TASKS_DATA);
                break;

            case 3:
                timesheetPeriods = null;
                checkDataAsync(TIMESHEET_DATA);
                break;

            case 4:
                enterpriseResources = null;
                checkDataAsync(RESOURCES_DATA);
                break;

            case 5:
                clearFragment();
                oldFragment        = null;
                willSwitch         = false;
                refresh.Refreshing = true;

                offline = null;
                offline = await service.pullData(true, userName.Text);

                int count = 0;
                foreach (var item in offline)
                {
                    count++;
                }
                if (count != 0)
                {
                    switchFragment(savedTimesheetFragment);
                }
                else
                {
                    mText = "You don't have any timesheet saved";
                    switchFragment(new OfflineFragment());
                    fab.SetVisibility(ViewStates.Gone);
                }
                refresh.Refreshing = false;
                willSwitch         = true;
                break;
            }
        }
예제 #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.empty_recycleview, container, false);

            main        = (Activity as MainActivity);
            core        = main.getCore();
            periodList  = main.getTimesheetPeriods();
            oldPosition = -1;

            periodTemp.Clear();
            TimeSpan span;

            for (int i = 0; i < periodList.D.Results.Count; i++)
            {
                periodTemp.Add(periodList.D.Results[i].Name + ": " + periodList.D.Results[i].Start.ToShortDateString() + " - " + periodList.D.Results[i].End.ToShortDateString());
                span = periodList.D.Results[i].End.Subtract(periodList.D.Results[i].Start);
                for (int j = 0; j <= span.Days; j++)
                {
                    if (periodList.D.Results[i].Start.Date.AddDays(j).Equals(DateTime.Now.Date))
                    {
                        currentDayPosition = i;
                        break;
                    }
                }
            }

            mRecyclerView  = view.FindViewById <RecyclerView>(Resource.Id.recyclerView);
            mLayoutManager = new LinearLayoutManager(view.Context);
            mRecyclerView.SetLayoutManager(mLayoutManager);

            mPeriodz = new TimesheetPeriodz();
            mPeriodz.addPeriod(periodTemp, currentDayPosition);

            mPeriozAdapter            = new TimesheetPeriodAdapter(mPeriodz, main, this);
            mPeriozAdapter.itemClick += Adapter_ItemClick;
            mRecyclerView.SetAdapter(mPeriozAdapter);
            return(view);
        }
예제 #3
0
        public void fillDataAsync(int whatData)
        {
            clearFragment();
            oldFragment        = null;
            willSwitch         = false;
            refresh.Refreshing = true;
            //1 for projects
            //2 for tasks
            //3 for timesheet
            //4 for enterprise resources
            switch (whatData)
            {
            case 1:


                ThreadPool.QueueUserWorkItem(async state =>
                {
                    projectJson = await core.GetProjects();
                    var temp    = await core.GetProjectServer();
                    projects    = JsonConvert.DeserializeObject <ProjectModel.RootObject>(projectJson);
                    pServer     = JsonConvert.DeserializeObject <ProjectData.RootObject>(temp);
                    if (projects.D.Results.Count == 0 && pServer.D.Results.Count == 0)
                    {
                        projects = null;
                        pServer  = null;
                        mText    = "There are no projects in this site";
                        RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                    }
                    else
                    {
                        RunOnUiThread(() => { switchFragment(projectFragment); refresh.Refreshing = false; willSwitch = true; });
                    }
                    //CancellationToken tok = (CancellationToken)state;
                    //if (tok.IsCancellationRequested)
                    //{
                    //    projects = null;
                    //    pServer = null;
                    //    return;
                    //}
                });
                break;

            case 2:

                tasks = new List <Taskmodel.RootObject> {
                };
                tasksWithResource.Clear();
                if (pServer == null && projects == null)
                {
                    tasks = null;
                    mText = "There are no tasks assigned to you";
                    RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(async state =>
                    {
                        for (int i = 0; i < pServer.D.Results.Count; i++)
                        {
                            string data  = await core.GetTasks(pServer.D.Results[i].Id);
                            string data2 = await core.GetResourceAssignment(pServer.D.Results[i].Id, userName.Text);
                            if (data.Length > 20)
                            {
                                taskJson.Add(data);
                                projectsWithTasks.Add(pServer.D.Results[i].Name);
                            }
                            if (data2.Length > 20)
                            {
                                var insides = JsonConvert.DeserializeObject <ProjectResourceAssignments.RootObject>(data2);
                                foreach (var item in insides.D.Results)
                                {
                                    if (item.ResourceName.Equals(userName.Text))
                                    {
                                        tasksWithResource.Add(item.TaskName);
                                    }
                                }
                            }
                        }

                        for (int i = 0; i < taskJson.Count; i++)
                        {
                            tasks.Add(JsonConvert.DeserializeObject <Taskmodel.RootObject>(taskJson[i]));
                        }

                        if (tasks.Count > 0 && tasksWithResource.Count > 0)
                        {
                            RunOnUiThread(() => { switchFragment(taskFragment); refresh.Refreshing = false; willSwitch = true; });
                        }
                        else
                        {
                            tasks = null;
                            mText = "There are no tasks assigned to you";
                            RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                        }
                    }, cts.Token);
                }
                break;

            case 3:

                ThreadPool.QueueUserWorkItem(async state =>
                {
                    var data         = await core.GetTimesheetPeriods();
                    timesheetPeriods = JsonConvert.DeserializeObject <TimesheetPeriod.RootObject>(data);
                    RunOnUiThread(() => {
                        switchFragment(timesheetFragment);
                        refresh.Refreshing = false;
                        willSwitch         = true;
                    });
                }, cts.Token);
                break;

            case 4:

                ThreadPool.QueueUserWorkItem(async state =>
                {
                    var data            = await core.GetEnterpriseResources();
                    enterpriseResources = JsonConvert.DeserializeObject <EnterpriseResources.RootObject>(data);
                    RunOnUiThread(() => {
                        switchFragment(enterpriseResourceFragment);
                        refresh.Refreshing = false;
                        willSwitch         = true;
                    });
                });

                break;
            }
        }