private void Refresh() { CognitoSyncUtils utils = new CognitoSyncUtils(); utils.Synchronize((exception) => { if (exception != null) { Console.WriteLine("ERROR: " + exception.Message); return; } todoLists = utils.GetTasks(); if (todoLists != null && todoLists.Count > 0) { InvokeOnMainThread(() => { Root = new RootElement("Todo List") { new Section() { from t in todoLists select(Element) new CheckboxElement((string.IsNullOrEmpty(t.Title) ? string.Empty : t.Title), t.Completed) } }; }); } }); }
public TODOViewController() : base(UITableViewStyle.Plain, null) { NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Add), false); NavigationItem.RightBarButtonItem.Clicked += (sender, e) => { taskDialog = new TaskDialog() { Id = Guid.NewGuid().ToString() }; context = new BindingContext(this, taskDialog, "New Task"); detailsScreen = new DialogViewController(context.Root, true); ActivateController(detailsScreen); }; this.RefreshRequested += delegate { NSTimer.CreateScheduledTimer(1, delegate { CognitoSyncUtils.Synchronize(); this.ReloadComplete(); }); }; CognitoSyncUtils.SetSyncAction((exception) => { if (exception != null) { Console.WriteLine("ERROR: " + exception.Message); return; } CognitoSyncUtils.LoadTasks(); todoLists = CognitoSyncUtils.GetTasks(); if (todoLists != null) { InvokeOnMainThread(() => { var e = from t in todoLists select(Element) new CheckboxElement((string.IsNullOrEmpty(t.Title) ? string.Empty : t.Title), t.Completed); var section = new Section(); foreach (var element in e) { section.Add(element); } Root = new RootElement("Todo List"); Root.Add(section); }); } }); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.todo_layout); todoListView = FindViewById <ListView>(Resource.Id.lstTasks); addTodoItenButton = FindViewById <Button>(Resource.Id.btnAddTask); todoListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { var todo = new Intent(this, typeof(TodoDetailActivity)); todo.PutExtra("todoItem", tasks[e.Position].Id); StartActivity(todo); }; addTodoItenButton.Click += (object sender, EventArgs e) => { var todo = new Intent(this, typeof(TodoDetailActivity)); todo.PutExtra("todoItem", Guid.NewGuid().ToString()); StartActivity(todo); }; CognitoSyncUtils.SetSyncAction((exception) => { if (exception != null) { Log.Error(TAG, exception.Message); AndHUD.Shared.ShowErrorWithStatus(this, "Synchronization error: " + exception.Message, MaskType.Black, TimeSpan.FromSeconds(5)); } else { CognitoSyncUtils.LoadTasks(); tasks = CognitoSyncUtils.GetTasks(); RunOnUiThread(() => { AndHUD.Shared.Dismiss(this); todoListView.Adapter = new TodoListAdapter(this, tasks); }); } }); }
public void Synchronize() { CognitoSyncUtils utils = new CognitoSyncUtils(); utils.Synchronize((exception) => { if (exception != null) { Log.Error(TAG, exception.Message); } else { tasks = utils.GetTasks(); RunOnUiThread(() => { todoListView.Adapter = new TodoListAdapter(this, tasks); }); } }); }