Exemple #1
0
        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 override void ViewDidLoad()
        {
            base.ViewDidLoad();

            LoginManager login = new LoginManager();

            login.LogInWithReadPermissions(readPermissions.ToArray(), this, delegate(LoginManagerLoginResult result, NSError error)
            {
                if (error != null)
                {
                    CognitoSyncUtils.UpdateCredentials(string.Empty);
                }
                else if (result.IsCancelled)
                {
                    CognitoSyncUtils.UpdateCredentials(string.Empty);
                }
                else
                {
                    var accessToken = result.Token;
                    CognitoSyncUtils.UpdateCredentials(accessToken.TokenString);
                    InvokeOnMainThread(() =>
                    {
                        ((AppDelegate)UIApplication.SharedApplication.Delegate).UpdateRootViewController(new TODOViewController());
                    });
                }
            });
        }
        //CognitoAccessTokenTracker tracker;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            callbackManager = CallbackManagerFactory.Create();

            LoginManager.Instance.RegisterCallback(callbackManager, new FacebookCallback <LoginResult>()
            {
                HandleSuccess = loginResult =>
                {
                    var accessToken = loginResult.AccessToken;
                    CognitoSyncUtils.UpdateCredentials(accessToken.Token);
                    Intent todoActivity = new Intent(this, typeof(TodoActivity));
                    StartActivity(todoActivity);
                },
                HandleCancel = () =>
                {
                    CognitoSyncUtils.UpdateCredentials(string.Empty);
                },
                HandleError = loginError =>
                {
                    CognitoSyncUtils.UpdateCredentials(string.Empty);
                }
            });
            LoginManager.Instance.LogInWithReadPermissions(this, new List <string> {
                "public_profile"
            });

            CognitoSyncUtils.Initialize();
        }
Exemple #4
0
        private void DeleteButtonOnClick(object sender, EventArgs e)
        {
            CognitoSyncUtils utils = new CognitoSyncUtils();

            todoId = Intent.GetStringExtra("todoItem");
            utils.DeleteTask(todoId);
            Finish();
        }
        public void Synchronize()
        {
            RunOnUiThread(() =>
            {
                AndHUD.Shared.Show(this, "Synchronizing dataset...");
            });

            CognitoSyncUtils.Synchronize();
        }
 public void DeleteTask()
 {
     if (currentTask != null)
     {
         context.Fetch();
         NavigationController.PopViewController(true);
         CognitoSyncUtils.DeleteTask(taskDialog.Id);
         currentTask = null;
     }
 }
Exemple #7
0
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            SettingsBaseConfiguration.LogLevel = LogLevel.Debug;

            CognitoSyncUtils.Initialize();

            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main(args, null, "AppDelegate");
        }
 public void SaveTask()
 {
     context.Fetch();
     currentTask             = new Task();
     currentTask.Id          = taskDialog.Id;
     currentTask.Title       = taskDialog.Name;
     currentTask.Description = taskDialog.Description;
     currentTask.Completed   = taskDialog.Completed;
     NavigationController.PopViewController(true);
     CognitoSyncUtils.SaveTask(currentTask);
     currentTask = null;
 }
        private void SaveButtonOnClick(object sender, EventArgs e)
        {
            var task = new Task()
            {
                Id          = todoId,
                Description = descriptionText.Text,
                Title       = titleText.Text,
                Completed   = taskCompleted.Checked
            };

            CognitoSyncUtils.SaveTask(task);
            Finish();
        }
        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 OnResume()
        {
            base.OnResume();

            todoId = Intent.GetStringExtra("todoItem");

            if (!string.IsNullOrEmpty(todoId))
            {
                todoTask = CognitoSyncUtils.GetTask(todoId);
                if (todoTask != null)
                {
                    titleText.SetText(todoTask.Title, TextView.BufferType.Editable);
                    descriptionText.SetText(todoTask.Description, TextView.BufferType.Editable);
                    saveButton.Enabled    = true;
                    deleteButton.Enabled  = true;
                    taskCompleted.Checked = todoTask.Completed;
                }
            }
        }
        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);
                    });
                }
            });
        }
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     CognitoSyncUtils.Synchronize();
 }
 private void trackerAccessTokenChangedEvent(object sender, AccessTokenChangedArgs e)
 {
     CognitoSyncUtils.UpdateCredentials(e.NewAccessToken);
 }