Exemple #1
0
        private void InsertTaskAfterActivityResult(string identifier, string title)
        {
            var content = GetTasksContent(_accessToken);
            var index   = content.IndexOf("Tasks\r\n");

            content = content.Insert(index + 7, "\t" + identifier + "::" + title + "\r\n");
            var task = Task.Run(() => {
                var dbx = new DropboxClient(_accessToken);
                var mem = new MemoryStream(Encoding.UTF8.GetBytes(content));
                dbx.Files.UploadAsync("/Development/Tasks.txt", Dropbox.Api.Files.WriteMode.Overwrite.Instance, false, null, false, mem).ContinueWith(m => {
                    if (m.IsCompleted && m.Status == TaskStatus.RanToCompletion)
                    {
                        var genericTask = new GenericTask()
                        {
                            Category    = "B",
                            Identifier  = identifier,
                            IsCompleted = false,
                            IsOutside   = false,
                            Title       = title
                        };
                        //_data.Add(genericTask);
                        _dbHandler.InsertGenericTask(genericTask);

                        RunOnUiThread(() => Toast.MakeText(this, "Tasks updated", ToastLength.Short).Show());

                        _adapterList.Add(new JavaDictionary <string, object> {
                            { "identifier", genericTask.Identifier },
                            { "title", genericTask.Title }
                        });
                        RunOnUiThread(() => {
                            RepopulateTasksFromContent(content);
                            _listView.DeferNotifyDataSetChanged();
                        });
                    }
                    else
                    {
                        RunOnUiThread(() => Toast.MakeText(this, "Error: Unable to insert task", ToastLength.Short).Show());
                    }
                    dbx.Dispose();
                }
                                                                                                                                                      );
            });
        }