| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading.Tasks;
- using comal.timesheets.Tasks;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI;
- using XF.Material.Forms.UI.Dialogs;
- using System.Threading;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class TasksList
- {
- Color color = Color.FromHex("#15C7C1");
- int currentCategory = 0;
- bool searching = false;
- bool firstLoad = true;
- bool tapping = false;
- bool doubleTap = false;
- public TasksList()
- {
- InitializeComponent();
- LoadPreferences();
- searchEnt.IsEnabled = false;
- App.Data.Kanbans.Refresh(
- false,
- () => Device.BeginInvokeOnMainThread(DisplayList)
- );
- }
- private void LoadPreferences()
- {
- try
- {
- if (!App.Current.Properties.ContainsKey("ObserverPreference"))
- {
- App.Current.Properties.Add("ObserverPreference", "True");
- observerSwitch.IsToggled = true;
- }
- else
- {
- observerSwitch.IsToggled = Convert.ToBoolean(App.Current.Properties["ObserverPreference"]);
- }
- if (!App.Current.Properties.ContainsKey("PromptedOnUsage"))
- {
- App.Current.Properties.Add("PromptedOnUsage", "True");
- DisplayAlert("One-time Prompt:", "Single Tap to Open Task," + System.Environment.NewLine + "Double Tap to Complete Task", "OK");
- }
- }
- catch { }
- }
-
-
- private void DisplayList()
- {
- App.Data.Kanbans.Search((shell) =>
- {
- bool bResult = true;
- bResult = bResult && (App.Current.Properties["ObserverPreference"].Equals("True") || !shell.IsObserver);
- bResult = bResult &&
- currentCategory switch
- {
- 0 => shell.Category == "To Do",
- 1 => shell.Category == "Current",
- 2 => shell.Category == "Waiting",
- _ => false
- };
-
- bResult = bResult && (
- String.IsNullOrWhiteSpace(searchEnt.Text)
- || String.Equals(shell.Number.ToString(), searchEnt.Text)
- || shell.ManagerName.ToUpper().Contains(searchEnt.Text.ToUpper())
- || shell.Title.ToUpper().Contains(searchEnt.Text.ToUpper())
- || shell.Summary.ToUpper().Contains(searchEnt.Text.ToUpper())
- || shell.DueDate.ToString().Contains(searchEnt.Text)
- );
-
- return bResult;
- });
- searchEnt.IsEnabled = true;
- observerSwitch.IsEnabled = true;
- buttonToDo.Text = "To Do (" + App.Data.Kanbans.Items.Count(x => x.Category == "To Do") + ")";
- buttonCurrent.Text = "Current (" + App.Data.Kanbans.Items.Count(x => x.Category == "Current") + ")";
- buttonWaiting.Text = "Waiting (" + App.Data.Kanbans.Items.Count(x => x.Category == "Waiting") + ")";
- }
-
- private string ChooseCategory(string _category)
- {
- switch (_category)
- {
- case "Open":
- _category = "To Do";
- break;
- case "In Progress":
- _category = "Current";
- break;
- default:
- break;
- }
- return _category;
- }
- private void AddTask_Clicked(object sender, EventArgs e)
- {
- try
- {
- AddEditTask addEditTask = new AddEditTask();
- Navigation.PushAsync(addEditTask);
- }
- catch { }
- }
- async void KanbanList_Tapped(object sender, EventArgs e)
- {
- try
- {
- if (tapping)
- {
- doubleTap = true;
- var selectedTask = taskListView.SelectedItem as KanbanShell;
- if (selectedTask.Locked)
- {
- doubleTap = false;
- DisplayAlert("Alert", "Unable to complete locked task", "Cancel");
- return;
- }
- string chosenOption = await DisplayActionSheet("Complete Task?", "Cancel", null, "Yes", "No");
- switch (chosenOption)
- {
- case "Cancel":
- break;
- case "No":
- break;
- case "Yes":
- CompleteTask(selectedTask);
- break;
- default:
- break;
- }
- doubleTap = false;
- }
- else
- {
- tapping = true;
- Timer t = new Timer(TimerCallBack, null, 750, Timeout.Infinite);
- }
- }
- catch { }
- }
- private async void CompleteTask(KanbanShell shell)
- {
- // try
- // {
- // kanbanSubscriberShells.Remove(shell);
- // RefreshButtons(kanbanSubscriberShells);
- // DisplayList(kanbanSubscriberShells);
- // await Task.Run(() =>
- // {
- // CoreTable table = new Client<Kanban>().Query
- // (
- // new Filter<Kanban>(x => x.ID).IsEqualTo(shell.ID),
- // new Columns<Kanban>(x => x.ID, x => x.Category)
- // );
- // Kanban kanban = table.Rows.First().ToObject<Kanban>();
- // kanban.Category = "Complete";
- // new Client<Kanban>().Save(kanban, "Completed from mobile device");
- // });
- // }
- // catch { }
- }
- private async void TimerCallBack(object o) //for single tap
- {
- try
- {
- tapping = false;
- if (!doubleTap)
- {
- var selectedTask = taskListView.SelectedItem as KanbanShell;
- string loadingMessage = "Loading Task " + selectedTask.Number;
- if (selectedTask.Attachments != 0)
- {
- loadingMessage = loadingMessage + " with " + selectedTask.Attachments + " attached document(s). Please wait for photos to appear.";
- }
- Device.BeginInvokeOnMainThread(async () =>
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: loadingMessage))
- {
- Guid ID = selectedTask.ID;
- var form = new AddEditTask(ID);
- await Navigation.PushAsync(form);
- }
- });
- }
- }
- catch { }
- }
- private async void SearchEnt_Changed(object sender, EventArgs e)
- {
- DisplayList();
- }
- private void ButtonToDo_Clicked(object sender, EventArgs e)
- {
- currentCategory = 0;
- DisplayList();
- ChangeButtonColour();
- }
- private void ButtonCurrent_Clicked(object sender, EventArgs e)
- {
- currentCategory = 1;
- DisplayList();
- ChangeButtonColour();
- }
- private void ButtonWaiting_Clicked(object sender, EventArgs e)
- {
- currentCategory = 2;
- DisplayList();
- ChangeButtonColour();
- }
- private void ChangeButtonColour()
- {
- buttonToDo.BackgroundColor = currentCategory == 0 ? color : Color.Default;
- buttonCurrent.BackgroundColor = currentCategory == 1 ? color : Color.Default;
- buttonWaiting.BackgroundColor = currentCategory == 2 ? color : Color.Default;
- }
- private void ObserverSwitch_Toggled(object sender, EventArgs e)
- {
- if (firstLoad)
- return;
- if (observerSwitch.IsToggled)
- {
- if (App.Current.Properties.ContainsKey("ObserverPreference"))
- {
- App.Current.Properties["ObserverPreference"] = "True";
- }
- else
- {
- App.Current.Properties.Add("ObserverPreference", "True");
- }
- }
- else
- {
- if (App.Current.Properties.ContainsKey("ObserverPreference"))
- {
- App.Current.Properties["ObserverPreference"] = "False";
- }
- else
- {
- App.Current.Properties.Add("ObserverPreference", "False");
- }
- }
- DisplayList();
- }
- }
- }
|