コード例 #1
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();
            }
        }
コード例 #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
        private void CheckCanUpload(int index)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                AppUtils.ShowSimpleDialog(this, "Unable to Upload", "An Internet connection is required.", "Got it");
                return;
            }

            // Check if on WiFi
            var currentConnections = CrossConnectivity.Current.ConnectionTypes;

            if (!currentConnections.Contains(Plugin.Connectivity.Abstractions.ConnectionType.WiFi))
            {
                AppUtils.ShowChoiceDialog(
                    this,
                    "You're not on WiFi!",
                    "Uploading over mobile data could incur additional charges. Are you sure you want to upload without a WiFi connection?",
                    "Yes, upload",
                    (resIndex) => { var suppress = UploadResults(resIndex, UploadsComplete); },
                    "Cancel",
                    null,
                    index);
            }
            else
            {
                var suppress = UploadResults(index, UploadsComplete);
            }
        }
コード例 #4
0
        private async Task GetAndOpenActivity(string code)
        {
            LoadingOverlay loadPop = new LoadingOverlay(UIScreen.MainScreen.Bounds);

            View.Add(loadPop);

            Common.ServerResponse <LearningActivity> result =
                await Common.ServerUtils.Get <LearningActivity>("/api/LearningActivities/GetWithCode?code=" + code);

            loadPop.Hide();

            if (result == null)
            {
                var suppress = AppUtils.SignOut(this);
            }

            if (result.Success)
            {
                var suppress = AppUtils.OpenActivity(result.Data, Storyboard, NavigationController);
            }
            else
            {
                if (result.Message.StartsWith("404"))
                {
                    AppUtils.ShowSimpleDialog(this, "Not found", "No activity was found with that share code.", "Got it");
                }
                else
                {
                    AppUtils.ShowSimpleDialog(this, "Connection Error", "Something went wrong! Please try again later.", "Got it");
                }
            }
        }
コード例 #5
0
        private async void GetScan(object s, object e)
        {
            ZXing.Mobile.MobileBarcodeScanner scanner = new ZXing.Mobile.MobileBarcodeScanner();
            ZXing.Result result = await scanner.Scan();

            if (result == null)
            {
                return;
            }

            Console.WriteLine("Scanned Barcode: " + result.Text);

            NSUrlComponents comps = NSUrlComponents.FromString(result.Text);

            if (comps != null && comps.QueryItems != null)
            {
                foreach (NSUrlQueryItem queryItem in comps.QueryItems)
                {
                    if (queryItem.Name == "code")
                    {
                        var suppress = GetAndOpenActivity(queryItem.Value);
                        return;
                    }
                }
            }

            AppUtils.ShowSimpleDialog(this, "Not found", "Are you sure that was a valid OurPlace QR code?", "Got it");
        }
コード例 #6
0
        private async void RefreshFeed()
        {
            ShowLoading();

            if (dbManager == null)
            {
                dbManager = await Storage.GetDatabaseManager();
            }

            recentActivities = LoadRecent();
            if (recentActivities != null)
            {
                source.Rows = new List <ActivityFeedSection> {
                    recentActivities
                };
                collectionView.ReloadData();
            }

            // If we don't have internet, don't bother getting the location or
            // polling the server
            if (!AppDelegate.Online)
            {
                Console.WriteLine("No Internet access, loading cached feed");
                Toast.ShowToast("Couldn't reach the server - please check your connection!");
                AppDelegate.WhenOnline = RefreshFeed; // Reload if connection returns
                return;
            }

            ShowLoading();

            // check is location is enabled
            if (CLLocationManager.LocationServicesEnabled)
            {
                // check location permission
                if (CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
                {
                    AppUtils.ShowSimpleDialog(
                        this,
                        "Show nearby activities?",
                        "Please allow OurPlace location authorization if you would like to see nearby activities.",
                        "Got it",
                        (UIAlertAction action) =>
                    {
                        RequestLocation();
                    });
                }
                else if (CLLocationManager.Status == CLAuthorizationStatus.Denied)
                {
                    var suppress = GetFromServer();
                }
                else
                {
                    RequestLocation();
                }
            }
            else
            {
                var suppress = GetFromServer();
            }
        }
コード例 #7
0
        private void CoordinateTapped(object sender, GMSCoordEventArgs e)
        {
            if (taskData.UserLocationOnly)
            {
                AppUtils.ShowSimpleDialog(this,
                                          "Can't place custom markers during this task",
                                          "For this task, please use the 'Mark Current Location' button to place markers.",
                                          "Got it");
                return;
            }

            if (CanPlaceNewMarker())
            {
                PlaceMarkerAtCoord(e.Coordinate);
            }
        }
コード例 #8
0
        protected override void FinishButton_TouchUpInside(object sender, EventArgs e)
        {
            if (thisLocation == null)
            {
                AppUtils.ShowSimpleDialog(this, "Choose a Location", "Please choose a location for the user to navigate to.", "Got it");
                return;
            }

            if (UpdateBasicTask())
            {
                LocationHuntLocation data = new LocationHuntLocation(thisLocation.Lat, thisLocation.Long, 15f, allowMap.On);

                thisTask.JsonData = JsonConvert.SerializeObject(data);

                UpdateActivity();
                Unwind();
            }
        }
コード例 #9
0
        private async Task LoadData()
        {
            DatabaseManager dbManager = await Storage.GetDatabaseManager();

            taskTypes = dbManager.GetTaskTypes()?.OrderBy((arg) => arg.Order).ToList();

            if (taskTypes == null || taskTypes.Count == 0)
            {
                var bounds = UIScreen.MainScreen.Bounds;

                // show the loading overlay on the UI thread using the correct orientation sizing
                loadPop = new LoadingOverlay(bounds);

                View.Add(loadPop);
                taskTypes = await ServerUtils.RefreshTaskTypes(dbManager);

                loadPop.Hide();

                if (taskTypes != null || taskTypes.Count > 0)
                {
                    taskTypes = taskTypes.OrderBy((arg) => arg.Order).ToList();
                    dbManager.AddTaskTypes(taskTypes);
                    ShowTaskTypes();
                }
                else
                {
                    AppUtils.ShowSimpleDialog(this, "Error",
                                              "There was an issue communicating with the server. " +
                                              "Please check your Internet connection and try again later.",
                                              "Got it",
                                              (a) => { NavigationController.PopViewController(true); });
                }
            }
            else
            {
                ShowTaskTypes();
            }
        }
コード例 #10
0
        private async Task <bool> UploadResults(int index, Action OnFinish)
        {
            ShowLoading();

            AppDataUpload upload = viewSource.Rows[index];

            DatabaseManager dbManager = await Storage.GetDatabaseManager();

            // Upload relevent files
            bool success = await Storage.UploadFiles(
                JsonConvert.DeserializeObject <List <FileUpload> >(upload.FilesJson),
                index,
                (percentage) =>
            {
                Console.WriteLine("Upload percentage: " + percentage);
                loadPop.loadingLabel.Text = string.Format("Uploading: {0}%", percentage);
            },
                (listPos, jsonData) =>
            {
                viewSource.Rows[listPos].FilesJson = jsonData;
                dbManager.UpdateUpload(viewSource.Rows[listPos]);
                viewSource.UpdateData(dbManager.GetUploadQueue().ToList());
                upload = viewSource.Rows[index];
            },
                (upload.UploadType == UploadType.NewActivity ||
                 upload.UploadType == UploadType.UpdatedActivity)?Storage.GetCacheFolder() : Storage.GetUploadsFolder()
                );

            if (!success)
            {
                HideLoading();
                AppUtils.ShowSimpleDialog(this, "Unable to Upload", "Something went wrong, please try again later.", "Got it");
                return(false);
            }

            ServerResponse <string> resp = new ServerResponse <string>();

            if (upload.UploadType == UploadType.NewActivity ||
                upload.UploadType == UploadType.UpdatedActivity)
            {
                resp = await ServerUtils.UploadActivity(upload, upload.UploadType == UploadType.UpdatedActivity);
            }
            else
            {
                // Uploading activity results
                List <FileUpload> files = JsonConvert.DeserializeObject <List <FileUpload> >(upload.FilesJson);

                AppTask[] results = JsonConvert.DeserializeObject <AppTask[]>(upload.JsonData) ?? new AppTask[0];
                resp = await ServerUtils.UpdateAndPostResults(results, files, upload.UploadRoute);
            }

            HideLoading();

            if (resp == null)
            {
                // do this but for iOS, fool
                var suppress = AppUtils.SignOut(this);
                return(false);
            }

            if (!resp.Success)
            {
                AppUtils.ShowSimpleDialog(this, "Unable to Upload", "Something went wrong, please try again later.", "Got it");
                return(false);
            }

            dbManager.DeleteUpload(upload);

            var newList = dbManager.GetUploadQueue().ToList();

            viewSource.UpdateData(newList);
            TableView.ReloadData();

            await(ParentViewController as MainTabBarController).UpdateUploadsBadge(newList.Count);
            ManageNavItems();

            OnFinish?.Invoke();

            return(true);
        }
コード例 #11
0
 private void UploadsComplete()
 {
     AppUtils.ShowSimpleDialog(this, "Uploaded!", "Successfully uploaded. Go to ourplace.app to view your submissions!", "Got it");
 }