private async void LoadData(Bundle bundle) { ProgressDialog dialog = null; currentStage = AssessmentStage.Preparing; RunOnUiThread(() => { dialog = new ProgressDialog(this); dialog.SetTitle("Downloading..."); dialog.SetMessage("Please wait while we prepare your assessment."); dialog.SetCancelable(false); dialog.Show(); }); int id = Intent.GetIntExtra("ActivityId", -1); if (id >= 0) { assessment = (Assessment)await AppData.Session.FetchActivityWithId(id); } else { assessment = await ServerData.FetchAssessment(); } if (assessment == null) { RunOnUiThread(() => { dialog.Hide(); SelfDestruct("It looks like you're offline...", "Oops! We couldn't download your assessment - check your internet connection and try again later!"); }); return; } helpers = await assessment.PrepareTasks(); FindViewById<TextView>(Resource.Id.assessment_preamble).Text = assessment.Description; tasks = assessment.AssessmentTasks; zipPath = Path.Combine(AppData.Exports.Path, assessment.Id + "_assessmentRes.zip"); results = new ScenarioResult(assessment.Id, zipPath) { IsAssessment = true }; if (bundle != null) { var previous = bundle.GetInt("ASSESSMENT_PROGRESS", -1); if (previous >= 0 && previous < tasks.Length) { taskIndex = previous; StartAssessment(bundle.GetInt("TASK_PROGRESS", -1)); } else { currentStage = AssessmentStage.Preamble; preambleContainer.Visibility = ViewStates.Visible; recButton.Visibility = ViewStates.Visible; helpButton.Visibility = ViewStates.Visible; } } else { currentStage = AssessmentStage.Preamble; preambleContainer.Visibility = ViewStates.Visible; recButton.Visibility = ViewStates.Visible; helpButton.Visibility = ViewStates.Gone; } RunOnUiThread(() => { dialog.Hide(); }); }
private async void InitialiseData(Bundle savedInstanceState) { // Load the scenario with the id that was given inside the current intent scenario = (Scenario) await AppData.Session.FetchActivityWithId(Intent.GetIntExtra("ActivityId", 0)); SupportActionBar.SetDisplayHomeAsUpEnabled(true); string scenarioFormatted = scenario.Title.Replace(" ", string.Empty).Replace("/", string.Empty); localResourcesDirectory = AppData.Cache.Path + scenarioFormatted; localTempDirectory = localResourcesDirectory + "/temp"; // If the scenario folder doesn't exist we need to download the additional files if (!GetPrefs().GetBoolean("DOWNLOADED", false) || !Directory.Exists(localResourcesDirectory)) { if (!Directory.Exists(localResourcesDirectory)) { Directory.CreateDirectory(localResourcesDirectory); Directory.CreateDirectory(localTempDirectory); } localZipPath = System.IO.Path.Combine(AppData.Exports.Path, scenarioFormatted + ".zip"); try { PrepareData(); } catch (Exception except) { Console.Write(except); Directory.Delete(localResourcesDirectory, true); } } else { // We need to populate the resources dictionary with the existing files string[] files = Directory.GetFiles(localResourcesDirectory); resources = new Dictionary<string, string>(); for (int i = 0; i < files.Length; i++) { resources.Add(System.IO.Path.GetFileName(files[i]), files[i]); } //Remove existing data from the upload queue AppData.Session.DeleteAllPendingForScenario(scenario.Id); } scenarioTitle.Text = scenario.Title; if (scenario.Creator != null) authorName.Text = scenario.Creator.Name; resultsZipPath = System.IO.Path.Combine(AppData.Exports.Path, scenario.Id + "_final.zip"); results = new ScenarioResult(scenario.Id, resultsZipPath); if (savedInstanceState != null) { currIndex = savedInstanceState.GetInt("progress", -1); } if (currIndex < 0) { titleLayout.Visibility = ViewStates.Visible; eventLayout.Visibility = ViewStates.Gone; Title = scenario.Title; } else { titleLayout.Visibility = ViewStates.Gone; eventLayout.Visibility = ViewStates.Visible; // Resume from where we left off currIndex--; ShowNextEvent(); } }