private async void GetCheckLogin() { if (!await Storage.InitializeLogin()) { // Login invalid Analytics.TrackEvent("MainActivity_InvalidLogin"); var suppress = AndroidUtils.ReturnToSignIn(this); return; } Analytics.TrackEvent("MainActivity_ValidLogin"); UpdateTaskTypes(); MapsInitializer.Initialize(this); MobileBarcodeScanner.Initialize(Application); global::Android.Net.Uri dataUri = base.Intent.Data; if (dataUri == null) { return; } string activityRef = dataUri.GetQueryParameter("code"); if (!string.IsNullOrWhiteSpace(activityRef)) { GetAndOpenActivity(activityRef); } }
private async void DeleteActivity() { ProgressDialog progress = new ProgressDialog(this); progress.SetMessage(Resources.GetString(Resource.String.PleaseWait)); progress.Show(); ServerResponse <string> resp = await ServerUtils.Delete <string>("/api/learningactivities?id=" + learningActivity.Id); progress.Dismiss(); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (resp.Success) { Toast.MakeText(this, Resource.String.uploadsUploadSuccessTitle, ToastLength.Long).Show(); } else { Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show(); } MainLandingFragment.ForceRefresh = true; dbManager.DeleteProgress(learningActivity.Id); Finish(); }
public async Task <ApplicationUser> GetCurrentUser() { DatabaseManager manager = await AndroidUtils.GetDbManager().ConfigureAwait(false); if (manager.CurrentUser == null) { // Something bad has happened, log out var suppress = AndroidUtils.ReturnToSignIn(this); } return(manager.CurrentUser); }
private async void Initialise() { if (await Common.LocalData.Storage.InitializeLogin()) { Intent intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); Finish(); } else { var suppressWarning = AndroidUtils.ReturnToSignIn(this); } }
private async void GetTaskTypes() { taskTypes = (await GetDatabaseManager()).GetTaskTypes().ToList(); // If the database is no good try to pull TaskTypes from the server if (taskTypes == null || !taskTypes.Any()) { ProgressDialog progDialog = new ProgressDialog(this); progDialog.SetMessage(Resources.GetString(Resource.String.Connecting)); progDialog.Show(); DatabaseManager dbManager = await GetDatabaseManager(); List <TaskType> loadedTypes = await ServerUtils.RefreshTaskTypes(dbManager); progDialog.Dismiss(); if (loadedTypes == null) { // can't get a valid token, return to sign in to re-authorise var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (!loadedTypes.Any()) { new global::Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle(Resource.String.ErrorTitle) .SetMessage(Resource.String.ConnectionError) .SetCancelable(false) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { base.Finish(); }) .Show(); return; } dbManager.AddTaskTypes(loadedTypes); taskTypes = loadedTypes; SetupAdaptors(); } SetupAdaptors(); }
private async void GetAndOpenActivity(string code) { ProgressDialog dialog = new ProgressDialog(this); dialog.SetMessage(Resources.GetString(Resource.String.PleaseWait)); dialog.Show(); ServerResponse <LearningActivity> result = await ServerUtils.Get <LearningActivity>("/api/LearningActivities/GetWithCode?code=" + code).ConfigureAwait(false); RunOnUiThread(() => { dialog.Dismiss(); dialog.Dispose(); }); if (result == null) { var suppress = AndroidUtils.ReturnToSignIn(this); RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show()); return; } if (result.Success) { await AndroidUtils.LaunchActivity(result.Data, this).ConfigureAwait(false); } else { // if token invalid, return to signin if (ServerUtils.CheckNeedsLogin(result.StatusCode)) { var suppress = AndroidUtils.ReturnToSignIn(this); return; } if (result.Message.StartsWith("404")) { RunOnUiThread(() => Toast.MakeText(this, Resource.String.searchFail, ToastLength.Long).Show()); } else { RunOnUiThread(() => Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show()); } } }
private async void LoadData() { ServerResponse <GMapsResultColl> resp = await ServerUtils.Get <GMapsResultColl>( string.Format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?key={0}&location={1},{2}&radius=4000&type=park", Resources.GetString(Resource.String.MapsApiKey), targetLoc.Lat, targetLoc.Long)); dialog.Dismiss(); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (!resp.Success) { Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show(); return; } // Don't list places that have already been added List <GooglePlaceResult> final = new List <GooglePlaceResult>(); foreach (GooglePlaceResult res in resp.Data.results) { if (previouslyChosen.All(p => p.GooglePlaceId != res.place_id)) { final.Add(res); } } adapter = new PlacesAdapter(this, final); adapter.ItemClick += Adapter_ItemClick;; recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView); recyclerView.SetAdapter(adapter); LinearLayoutManager layoutManager = new LinearLayoutManager(this); recyclerView.SetLayoutManager(layoutManager); }
private async void GetAndReturnWithActivity(string code) { ProgressDialog dialog = new ProgressDialog(this); dialog.SetMessage(Resources.GetString(Resource.String.PleaseWait)); dialog.Show(); ServerResponse <LearningActivity> result = await ServerUtils.Get <LearningActivity>("/api/LearningActivities/GetWithCode?code=" + code).ConfigureAwait(false); dialog.Dismiss(); if (result == null) { _ = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (result.Success) { ActivityChosen(result.Data); } else { // if token invalid, return to signin if (ServerUtils.CheckNeedsLogin(result.StatusCode)) { _ = AndroidUtils.ReturnToSignIn(this); return; } if (result.StatusCode == System.Net.HttpStatusCode.NotFound) { Toast.MakeText(this, Resource.String.searchFail, ToastLength.Long).Show(); } else { Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show(); } } }
// Update the TaskTypes available in the background public async Task UpdateTaskTypes() { DatabaseManager db = await AndroidUtils.GetDbManager().ConfigureAwait(false); List <TaskType> taskTypes = await ServerUtils.RefreshTaskTypes(db).ConfigureAwait(false); if (taskTypes == null) { var suppress = AndroidUtils.ReturnToSignIn(this); RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show()); return; } if (!taskTypes.Any()) { return; } db.AddTaskTypes(taskTypes); }
private async void ApproveActivity() { ProgressDialog progress = new ProgressDialog(this); progress.SetMessage(Resources.GetString(Resource.String.PleaseWait)); progress.Show(); ServerResponse <string> resp = await ServerUtils.Post <string>("/api/learningactivities/approve?id=" + learningActivity.Id, null); progress.Dismiss(); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (resp.Success) { Toast.MakeText(this, Resource.String.uploadsUploadSuccessTitle, ToastLength.Long).Show(); } else { Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show(); return; } MainLandingFragment.ForceRefresh = true; adapter.Items.RemoveAt(0); adapter.Curator = false; learningActivity.Approved = true; dbManager.SaveActivityProgress(learningActivity, adapter.Items, enteredName); adapter.NotifyDataSetChanged(); }
private void LogOut() { _ = AndroidUtils.ReturnToSignIn(Activity); }
public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == global::Android.Resource.Id.Home) { OnBackPressed(); return(true); } if (item.ItemId != Resource.Id.menudelete) { return(base.OnOptionsItemSelected(item)); } using (var builder = new global::Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetTitle(Resource.String.deleteTitle) .SetMessage(Resource.String.deleteMessage) .SetNegativeButton(Resource.String.dialog_cancel, (a, e) => { }) .SetPositiveButton(Resource.String.DeleteBtn, async(a, e) => { if (editingSubmitted) { using (ProgressDialog prog = new ProgressDialog(this)) { prog.SetMessage(Resources.GetString(Resource.String.PleaseWait)); prog.Show(); ServerResponse <string> resp = await ServerUtils.Delete <string>("/api/learningactivities?id=" + newActivity.Id).ConfigureAwait(false); RunOnUiThread(() => prog.Dismiss()); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show()); } else if (resp.Success) { RunOnUiThread(() => Toast.MakeText(this, Resource.String.uploadsUploadSuccessTitle, ToastLength.Long).Show()); MainMyCreationsFragment.ForceRefresh = true; Finish(); } else { RunOnUiThread(() => Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show()); } } } else { DatabaseManager db = await AndroidUtils.GetDbManager().ConfigureAwait(false); var localActivities = JsonConvert.DeserializeObject <List <LearningActivity> >(db.CurrentUser.LocalCreatedActivitiesJson); localActivities.Remove(localActivities.FirstOrDefault(act => act.Id == newActivity.Id)); db.CurrentUser.LocalCreatedActivitiesJson = JsonConvert.SerializeObject(localActivities); db.AddUser(db.CurrentUser); MainMyCreationsFragment.ForceRefresh = true; Finish(); } }) .Show(); } return(true); }
private async void GetAccountDetails() { ProgressDialog dialog = new ProgressDialog(this); dialog.SetTitle(Resources.GetString(Resource.String.Connecting)); dialog.SetMessage(Resources.GetString(Resource.String.PleaseWait)); dialog.Show(); ApplicationUser tempUser = new ApplicationUser() { AccessToken = accessToken, AccessExpiresAt = accessTokenExpiresAt, RefreshToken = refreshToken, RefreshExpiresAt = refreshTokenExpiresAt }; (await GetDatabaseManager()).AddUser(tempUser); Common.ServerResponse <ApplicationUser> res = await Common.ServerUtils.Get <ApplicationUser>("api/account/"); dialog.Dismiss(); if (res == null) { var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (res.Success) { // kill the login activity Intent message = new Intent("com.park.learn.CALLBACK"); SendBroadcast(message); ApplicationUser updatedUser = res.Data; updatedUser.AccessToken = tempUser.AccessToken; updatedUser.AccessExpiresAt = tempUser.AccessExpiresAt; updatedUser.RefreshToken = tempUser.RefreshToken; updatedUser.RefreshExpiresAt = tempUser.RefreshExpiresAt; (await GetDatabaseManager()).AddUser(updatedUser); Intent intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); StartActivity(intent); Finish(); } else { // show error message, return to login screen new AlertDialog.Builder(this) .SetTitle(Resource.String.ErrorTitle) .SetMessage(Resource.String.ErrorLogin) .SetCancelable(false) .SetOnDismissListener(new OnDismissListener(() => { Intent intent = new Intent(this, typeof(LoginActivity)); StartActivity(intent); Finish(); })) .Show(); } }
private async void StartUploads(int position) { uploadProgress = new ProgressDialog(this); uploadProgress.SetTitle("Uploading"); uploadProgress.Indeterminate = false; uploadProgress.SetCancelable(false); uploadProgress.Max = 100; uploadProgress.Progress = 0; uploadProgress.SetTitle(Resource.String.uploadsUploadingFiles); uploadProgress.Show(); try { bool success = await Storage.UploadFiles( JsonConvert.DeserializeObject <List <FileUpload> >( uploads[position].FilesJson), position, (percentage) => { uploadProgress.Progress = percentage; }, (listPos, jsonData) => { uploads[listPos].FilesJson = jsonData; dbManager.UpdateUpload(uploads[listPos]); }, Storage.GetUploadsFolder()).ConfigureAwait(false); if (!success) { uploadProgress.Dismiss(); using (var builder = new global::Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetTitle(Resource.String.ErrorTitle) .SetMessage(Resource.String.ConnectionError) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { }) .Show(); } return; } } catch (Exception e) { // Refresh token not valid Console.WriteLine(e.Message); var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } ServerResponse <string> resp = new ServerResponse <string>(); UploadType type = uploads[position].UploadType; if (type == UploadType.NewActivity || type == UploadType.UpdatedActivity) { resp = await ServerUtils.UploadActivity(uploads[position], type == UploadType.UpdatedActivity).ConfigureAwait(false); } else if (type == UploadType.NewCollection || type == UploadType.UpdatedCollection) { resp = await ServerUtils.UploadCollection(uploads[position], type == UploadType.UpdatedCollection).ConfigureAwait(false); } else { // Uploading activity results AppTask[] results = JsonConvert.DeserializeObject <AppTask[]>(uploads[position].JsonData) ?? new AppTask[0]; files = JsonConvert.DeserializeObject <List <FileUpload> >(uploads[position].FilesJson); resp = await ServerUtils.UpdateAndPostResults(results, files, uploads[position].UploadRoute).ConfigureAwait(false); } RunOnUiThread(() => uploadProgress.Dismiss()); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show()); return; } if (!resp.Success) { RunOnUiThread(() => { using (var builder = new global::Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetTitle(Resource.String.ErrorTitle) .SetMessage(resp.Message) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { }) .Show(); } }); return; } dbManager.DeleteUpload(uploads[position]); RunOnUiThread(() => { adapter.Data.RemoveAt(position); adapter.NotifyDataSetChanged(); using (var builder = new global::Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetTitle(Resource.String.uploadsUploadSuccessTitle) .SetMessage(Resource.String.uploadsUploadSuccessMessage) .SetCancelable(false) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { if (!adapter.Data.Any()) { OnBackPressed(); } }).Show(); } }); }