示例#1
0
        protected override void FinishButton_TouchUpInside(object sender, EventArgs e)
        {
            if (UpdateBasicTask())
            {
                if (string.IsNullOrWhiteSpace(currentImagePath))
                {
                    currentImagePath = previousImage;
                }
                else if (!string.IsNullOrWhiteSpace(previousImage) && !previousImage.StartsWith("upload"))
                {
                    // new image replaces old one, delete the previous image
                    File.Delete(AppUtils.GetPathForLocalFile(previousImage));
                }

                string imgUrl = (string.IsNullOrWhiteSpace(currentImagePath)) ? "" :
                                currentImagePath.StartsWith("upload") ? currentImagePath :
                                Path.Combine(Directory.GetParent(currentImagePath).Name, Path.GetFileName(currentImagePath));

                AdditionalInfoData data = new AdditionalInfoData
                {
                    ImageUrl    = imgUrl,
                    ExternalUrl = chosenLink
                };

                thisTask.JsonData = JsonConvert.SerializeObject(data);

                UpdateActivity();
                Unwind();
            }
        }
示例#2
0
        private async void ListenButton_TouchUpInside(object sender, EventArgs e)
        {
            string fullPath = currentFile.StartsWith("upload") ?
                              await DownloadExisting() : AppUtils.GetPathForLocalFile(currentFile);

            if (!File.Exists(fullPath))
            {
                AppUtils.ShowSimpleDialog(this,
                                          "File Error",
                                          "There was an error reading the file. Please record a new one.",
                                          "Got it");
                return;
            }

            var tempTask = new AppTask
            {
                TaskType    = thisTaskType,
                Description = thisTaskType.Description
            };

            ResultMediaViewerController listenAudioController = Storyboard.InstantiateViewController("MediaViewerController") as ResultMediaViewerController;

            listenAudioController.FilePath     = fullPath;
            listenAudioController.Task         = tempTask;
            listenAudioController.DeleteResult = null;
            NavigationController.PushViewController(listenAudioController, true);
        }
示例#3
0
        protected override void FinishButton_TouchUpInside(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(previousFile) && string.IsNullOrWhiteSpace(currentFile))
            {
                AppUtils.ShowSimpleDialog(this, "Choose an Audio Recording", "Please select or record some audio for the user to listen to.", "Got it");
                return;
            }

            if (UpdateBasicTask())
            {
                if (string.IsNullOrWhiteSpace(currentFile))
                {
                    thisTask.JsonData = previousFile;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(previousFile) &&
                        currentFile != previousFile &&
                        !previousFile.StartsWith("upload"))
                    {
                        // new file replaces old one, delete the previous file
                        File.Delete(AppUtils.GetPathForLocalFile(previousFile));
                    }
                    thisTask.JsonData = currentFile;
                }

                UpdateActivity();
                saved = true;
                Unwind();
            }
        }
示例#4
0
        public void UpdateContent(AppDataUpload data)
        {
            string url = (!string.IsNullOrWhiteSpace(data.ImageUrl)) ? AppUtils.GetPathForLocalFile(data.ImageUrl) : "";

            if (!File.Exists(url))
            {
                url = (string.IsNullOrWhiteSpace(data.ImageUrl)) ?
                      "" :
                      Common.ServerUtils.GetUploadUrl(data.ImageUrl);
            }

            if (string.IsNullOrWhiteSpace(url))
            {
                ImageService.Instance.LoadCompiledResource("AppLogo").Into(ActivityIcon);
            }
            else
            {
                // check if it's a local file
                if (File.Exists(url))
                {
                    ImageService.Instance.LoadFile(url).
                    Transform(new CircleTransformation()).Into(ActivityIcon);
                }
                else
                {
                    //string imgUrl = Common.ServerUtils.GetUploadUrl(url);
                    ImageService.Instance.LoadUrl(url).
                    Transform(new CircleTransformation()).Into(ActivityIcon);
                }
            }

            List <FileUpload> files = JsonConvert.DeserializeObject <List <FileUpload> >(data.FilesJson);

            float totalFileSizeMb = 0;

            string folderPath = (data.UploadType == UploadType.NewActivity) ?
                                Storage.GetCacheFolder() : Storage.GetUploadsFolder();

            foreach (FileUpload up in files)
            {
                if (!string.IsNullOrWhiteSpace(up.RemoteFilePath))
                {
                    continue;
                }

                string absPath = Path.Combine(folderPath, up.LocalFilePath);

                FileInfo fInfo = new FileInfo(absPath);
                if (fInfo.Exists)
                {
                    totalFileSizeMb += fInfo.Length / 1000000f;
                }
            }

            TitleLabel.Text    = data.Name;
            DateLabel.Text     = string.Format("Created: {0:g}", data.CreatedAt.ToLocalTime());
            FileSizeLabel.Text = string.Format("Total size: {0:0.0}MB", totalFileSizeMb);
        }
        private void UseParent()
        {
            if (currentImagePath != null &&
                currentImagePath != previousImage &&
                !currentImagePath.StartsWith("upload"))
            {
                File.Delete(AppUtils.GetPathForLocalFile(currentImagePath));
            }

            currentImagePath = "TASK::" + parentTask.Id.ToString();
            ImageService.Instance.LoadUrl(parentTask.TaskType.IconUrl).Into(ChosenImage);
        }
示例#6
0
        public void ThisApp_DocumentLoaded(Helpers.GenericTextDocument document)
        {
            if (currentImagePath != null && currentImagePath != previousImage)
            {
                File.Delete(AppUtils.GetPathForLocalFile(currentImagePath));
            }

            string tempPath = document.FileUrl.Path;

            UIImage fullSize = UIImage.FromFile(tempPath);

            ShrinkAndSaveNewImage(fullSize);
        }
示例#7
0
        public void UnwindToCreateListenAudio(UIStoryboardSegue segue)
        {
            var sourceController = segue.SourceViewController as RecordAudioController;

            if (sourceController != null && !string.IsNullOrWhiteSpace(sourceController.innerPath))
            {
                if (!string.IsNullOrWhiteSpace(currentFile) && currentFile != previousFile)
                {
                    // the previous file was replaced without being saved, delete it
                    File.Delete(AppUtils.GetPathForLocalFile(currentFile));
                }

                currentFile = sourceController.innerPath;

                ListenButton.Enabled = true;
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ChooseImageButton.TouchUpInside += ChooseImageButton_TouchUpInside;

            if (childTaskIndex != null)
            {
                parentTask = thisActivity.LearningTasks.ToList()[parentTaskIndex];
                string[] supportedParents = { "TAKE_PHOTO", "MATCH_PHOTO", "DRAW", "DRAW_PHOTO" };

                if (supportedParents.Contains(parentTask.TaskType.IdName))
                {
                    allowParentAsSource = true;
                }
            }

            if (!string.IsNullOrWhiteSpace(thisTask?.JsonData))
            {
                previousImage = thisTask.JsonData;

                if (!IsParent(previousImage))
                {
                    if (previousImage.StartsWith("upload"))
                    {
                        ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(previousImage))
                        .Into(ChosenImage);
                    }
                    else
                    {
                        ImageService.Instance.LoadFile(
                            AppUtils.GetPathForLocalFile(previousImage))
                        .Into(ChosenImage);
                    }
                }
                else
                {
                    ImageService.Instance.LoadUrl(parentTask.TaskType.IconUrl)
                    .Into(ChosenImage);
                }
            }

            folderPath = Common.LocalData.Storage.GetCacheFolder("created");
        }
示例#9
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            if (thisActivity != null)
            {
                ActivityName.Text        = thisActivity.Name;
                ActivityDescription.Text = thisActivity.Description;
                if (!string.IsNullOrWhiteSpace(thisActivity.ImageUrl))
                {
                    if (thisActivity.ImageUrl.StartsWith("upload"))
                    {
                        ImageService.Instance.LoadUrl(
                            ServerUtils.GetUploadUrl(thisActivity.ImageUrl))
                        .Into(ActivityImage);
                    }
                    else
                    {
                        ImageService.Instance.LoadFile(
                            AppUtils.GetPathForLocalFile(thisActivity.ImageUrl))
                        .Into(ActivityImage);
                    }
                }
                else
                {
                    ImageService.Instance.LoadCompiledResource("AppLogo").Into(ActivityImage);
                }
            }

            if (thisActivity == null ||
                thisActivity.LearningTasks == null ||
                thisActivity.LearningTasks.ToList().Count == 0)
            {
                canFinish = false;
                FooterButton.SetTitle("Add tasks by tapping +!", UIControlState.Normal);
            }
            else
            {
                canFinish = true;
                FooterButton.SetTitle("Finish", UIControlState.Normal);
                TableView.Source = new CreateViewSource(thisActivity.LearningTasks.ToList(), EditTask, ManageChildren, true);
            }
        }
示例#10
0
        public void ThisApp_DocumentLoaded(Helpers.GenericTextDocument document)
        {
            if (currentFile != previousFile)
            {
                File.Delete(AppUtils.GetPathForLocalFile(currentFile));
            }

            string tempPath = document.FileUrl.Path;

            string folderPath = Common.LocalData.Storage.GetCacheFolder("created");

            currentFile = Path.Combine("created", DateTime.UtcNow.ToString("s") + Path.GetExtension(tempPath));

            string fullCurrentPath = AppUtils.GetPathForLocalFile(currentFile);

            File.Copy(tempPath, fullCurrentPath);

            ListenButton.Enabled = true;
        }
        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            Console.WriteLine("ViewWillDisappear, IsMovingFromParentViewController: " + IsMovingFromParentViewController);

            if (IsMovingFromParentViewController)
            {
                // popped - if a file isn't being referenced by the saved data, delete it
                if (!saved && currentImagePath != null &&
                    !IsParent(currentImagePath) &&
                    currentImagePath != previousImage &&
                    !currentImagePath.StartsWith("upload"))
                {
                    string path = AppUtils.GetPathForLocalFile(currentImagePath);
                    File.Delete(path);
                    Console.WriteLine("Cleaned up file at " + path);
                }
            }
        }
示例#12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddImageButton.TouchUpInside += AddImageButton_TouchUpInside;

            if (!string.IsNullOrWhiteSpace(thisTask?.JsonData))
            {
                AdditionalInfoData data =
                    JsonConvert.DeserializeObject <AdditionalInfoData>(thisTask.JsonData);

                previousImage = data.ImageUrl;

                if (!string.IsNullOrWhiteSpace(previousImage))
                {
                    if (previousImage.StartsWith("upload"))
                    {
                        ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(previousImage))
                        .Into(AccompanyingImage);
                    }
                    else
                    {
                        ImageService.Instance.LoadFile(
                            AppUtils.GetPathForLocalFile(previousImage))
                        .Into(AccompanyingImage);
                    }
                }

                if (!string.IsNullOrWhiteSpace(data.ExternalUrl))
                {
                    chosenLink     = data.ExternalUrl;
                    LinkLabel.Text = data.ExternalUrl;
                }
            }

            folderPath = Common.LocalData.Storage.GetCacheFolder("created");

            UpdateLabels();

            AddLinkButton.TouchUpInside += AddLinkButton_TouchUpInside;
        }
        protected override void FinishButton_TouchUpInside(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(previousImage) && string.IsNullOrWhiteSpace(currentImagePath))
            {
                AppUtils.ShowSimpleDialog(this, "Select an Image", "Please select or take a photo.", "Got it");
                return;
            }

            if (UpdateBasicTask())
            {
                if (string.IsNullOrWhiteSpace(currentImagePath))
                {
                    thisTask.JsonData = previousImage;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(previousImage) &&
                        !IsParent(previousImage) &&
                        !previousImage.StartsWith("upload"))
                    {
                        // new image replaces old one, delete the previous image
                        File.Delete(AppUtils.GetPathForLocalFile(previousImage));
                    }

                    if (!IsParent(currentImagePath))
                    {
                        thisTask.JsonData = Path.Combine(Directory.GetParent(currentImagePath).Name, Path.GetFileName(currentImagePath));
                    }
                    else
                    {
                        thisTask.JsonData = currentImagePath;
                    }
                }

                UpdateActivity();
                saved = true;
                Unwind();
            }
        }
示例#14
0
        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            if (IsMovingFromParentViewController)
            {
                // popped - if a file isn't being referenced by the saved data, delete it
                if (!saved && currentFile != null && currentFile != previousFile)
                {
                    string path = AppUtils.GetPathForLocalFile(currentFile);
                    File.Delete(path);
                    Console.WriteLine("Cleaned up file at " + path);
                }

                // clear any downloaded files
                if (!string.IsNullOrEmpty(cachePath))
                {
                    File.Delete(cachePath);
                    Console.WriteLine("Deleted " + cachePath);
                }
            }
        }
        private void ContinuePressed(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(ActivityTitle.Text))
            {
                AppUtils.ShowSimpleDialog(this, "Missing Title", "Please enter a title for your Activity!", "Got it");
                return;
            }

            if (string.IsNullOrWhiteSpace(ActivityDescription.Text))
            {
                AppUtils.ShowSimpleDialog(this, "Missing Description", "Please enter a short description describing what your Activity is about!", "Got it");
                return;
            }

            if (thisActivity == null)
            {
                thisActivity = new LearningActivity
                {
                    Id = (new Random()).Next()
                };
            }

            thisActivity.Name        = ActivityTitle.Text;
            thisActivity.Description = ActivityDescription.Text;

            if (!string.IsNullOrWhiteSpace(currentImagePath))
            {
                thisActivity.ImageUrl = Path.Combine(Directory.GetParent(currentImagePath).Name, Path.GetFileName(currentImagePath));

                if (!string.IsNullOrWhiteSpace(previousImagePath) && !previousImagePath.StartsWith("upload"))
                {
                    // new image replaces old one, delete the previous image
                    File.Delete(AppUtils.GetPathForLocalFile(previousImagePath));
                }
            }

            PerformSegue("UnwindToOverview", this);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification, KeyboardUpNotification);

            ActivityTitle.ShouldReturn          += TextFieldShouldReturn;
            ActivityTitle.EditingDidBegin       += TextFieldEditingDidBegin;
            ActivityDescription.ShouldReturn    += TextFieldShouldReturn;
            ActivityDescription.EditingDidBegin += TextFieldEditingDidBegin;

            // Limit how long the title and description strings can be
            ActivityTitle.ShouldChangeCharacters += (textField, range, replacementString) =>
            {
                var newLength = textField.Text.Length + replacementString.Length - range.Length;
                return(newLength <= 36 || (replacementString.Length - range.Length <= 0));
            };

            ActivityDescription.ShouldChangeCharacters += (textField, range, replacementString) =>
            {
                var newLength = textField.Text.Length + replacementString.Length - range.Length;
                return(newLength <= 128 || (replacementString.Length - range.Length <= 0));
            };

            UITapGestureRecognizer tapGestureRecognizer =
                new UITapGestureRecognizer(() => View.EndEditing(true));

            View.AddGestureRecognizer(tapGestureRecognizer);

            UITapGestureRecognizer imageTapGesture = new UITapGestureRecognizer(ImageTapped)
            {
                NumberOfTapsRequired = 1
            };

            ActivityLogo.UserInteractionEnabled = true;
            ActivityLogo.AddGestureRecognizer(imageTapGesture);

            folderPath = Common.LocalData.Storage.GetCacheFolder("created");

            if (thisActivity != null)
            {
                // Load previously entered data into fields
                ActivityTitle.Text       = thisActivity.Name;
                ActivityDescription.Text = thisActivity.Description;
                if (!string.IsNullOrWhiteSpace(thisActivity.ImageUrl))
                {
                    previousImagePath = thisActivity.ImageUrl;
                    Console.WriteLine("Existing image path: " + previousImagePath);

                    if (thisActivity.ImageUrl.StartsWith("upload"))
                    {
                        ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(previousImagePath))
                        .Transform(new CircleTransformation())
                        .Into(ActivityLogo);
                    }
                    else
                    {
                        string url = AppUtils.GetPathForLocalFile(previousImagePath);

                        var suppress = ImageService.Instance.InvalidateCacheEntryAsync(url, FFImageLoading.Cache.CacheType.All, true);
                        ImageService.Instance.LoadFile(url).Transform(new CircleTransformation()).Into(ActivityLogo);
                    }
                }
            }

            ContinueButton.TouchUpInside += ContinuePressed;
            CancelButton.TouchUpInside   += CancelPressed;
        }