public void GenerateStory_FindsWhetherStoryWasGenerated_ReturnsNotNull() { StoryEvent storyEvent = new StoryEvent { Value = DateTime.Now.ToLongTimeString() + "-" + "Picture Taken", DateTime = DateTime.Now, Finished = true }; Card card = new Card { Message = "test", StoryEventId = storyEvent.Id, Type = "1" }; Picture picture = new Picture { Path = "Test", EventId = storyEvent.Id }; List <Database.Models.VoiceRecording> voiceRecordings = new List <Database.Models.VoiceRecording> { new Database.Models.VoiceRecording { Path = "Test", EventId = storyEvent.Id } }; _db.InsertEvent(true, storyEvent, card, picture, voiceRecordings); _storyGenerator.Create(); Assert.IsNotNull(_db.GetAllStories(), "GenerateStory_FindsWhetherStoryWasGenerated_ReturnsNotNull: Did not return stories"); }
/* * Method Name: SetLastPlayed * Purpose: Used to set the currenrly played story to be the last played story */ public void SetLastPlayed(Database.Models.Story currentStory) { var stories = _db.GetAllStories(); foreach (var i in stories) { if (i.LastPlayed) { i.LastPlayed = false; } if (i.Id.Equals(currentStory.Id)) { i.LastPlayed = true; } } _db.UpdateStories(stories); }
public void C_GetAllStories_GeneratesStory_ReturnsNotNull() { StoryEvent storyEvent = new StoryEvent { Value = DateTime.Now.ToLongTimeString() + "-" + "Picture Taken", DateTime = DateTime.Now, Finished = true }; Card card = new Card { Message = "test", StoryEventId = storyEvent.Id, Type = "1" }; Picture picture = new Picture { Path = "Test", EventId = storyEvent.Id }; List <Database.Models.VoiceRecording> voiceRecordings = new List <Database.Models.VoiceRecording> { new Database.Models.VoiceRecording { Path = "Test", EventId = storyEvent.Id } }; _db.CreateConnection(); _db.Create(); _db.InsertEvent(true, storyEvent, card, picture, voiceRecordings); StoryGeneration generator = new StoryGeneration(_db, null); generator.Create(); Assert.IsNotNull(_db.GetAllStories(), "GetAllStories_GeneratesStory_ReturnsOneStory: Returned Null - No stories were made"); }
/* * Method name: OnCreate * Purpose: To set up the moving between the different stories and displaying their cover photo */ protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.TodayStoryView); Typeface buttonFont = Typeface.CreateFromAsset(Assets, "Kano.otf"); var db = new Database.Database( System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ShareMyDay.db3"); var initialStories = db.GetAllStories(); List <Database.Models.Story> stories = new List <Database.Models.Story>(); Button buttonOverlay = FindViewById <Button>(Resource.Id.storyButtonOverlay); buttonOverlay.SetTypeface(buttonFont, TypefaceStyle.Bold); foreach (var i in initialStories) { if (i.DateTime.Day.Equals(DateTime.Now.Day)) { stories.Add(i); } } bool eventsFromToday = stories.Count != 0; Button next = FindViewById <Button>(Resource.Id.changeViewButton); if (eventsFromToday) { var options = new BitmapFactory.Options { InJustDecodeBounds = true }; var sample = 4; options.InSampleSize = sample; options.InJustDecodeBounds = false; ImageView latestStory = FindViewById <ImageView>(Resource.Id.storyButton); TextView titleBox = FindViewById <TextView>(Resource.Id.storyTitle); int storyIndex = 0; if (Intent.GetStringExtra("StoryIndex") != null) { storyIndex = (int)Convert.ToInt64(Intent.GetStringExtra("StoryIndex")); } int limit = stories.Count; //this is the number of stories for a day if (stories[storyIndex].DefaultPicture != null) { int image = (int)typeof(Resource.Drawable).GetField(stories[storyIndex].DefaultPicture) .GetValue(null); latestStory.SetImageResource(image); } else { using (var image = GetImage(options, stories[storyIndex].CoverPhoto)) { latestStory.SetImageBitmap(image); } } titleBox.Text = "Story: " + stories[storyIndex].TitleValue; buttonOverlay.Click += delegate { Intent storyIntent = new Intent(this, typeof(StoryActivity)); storyIntent.PutExtra("Story", stories[storyIndex].Id.ToString()); storyIntent.PutExtra("StoryIndex", storyIndex.ToString()); StartActivity(storyIntent); }; if (limit.Equals(1) || storyIndex.Equals(limit - 1)) { next.SetBackgroundResource(Resource.Drawable.SmallClose); next.ContentDescription = "Close"; } else { next.SetBackgroundResource(Resource.Drawable.Next); } next.Click += async delegate { if (next.ContentDescription.Equals("Close")) { next.SetBackgroundResource(Resource.Drawable.SmallCloseClicked); Intent exitIntent = new Intent(this, typeof(MainActivity)); StartActivity(exitIntent); } else { next.SetBackgroundResource(Resource.Drawable.NextClicked); await Task.Delay(1); next.SetBackgroundResource(Resource.Drawable.Next); } storyIndex++; if (storyIndex < limit - 1) { if (stories[storyIndex].DefaultPicture != null) { int image = (int)typeof(Resource.Drawable).GetField(stories[storyIndex].DefaultPicture) .GetValue(null); latestStory.SetImageResource(image); } else { using (var image = GetImage(options, stories[storyIndex].CoverPhoto)) { latestStory.SetImageBitmap(image); } } titleBox.Text = "Story: " + stories[storyIndex].TitleValue; } if (storyIndex == limit - 1) { _closeClicked = true; next.SetBackgroundResource(Resource.Drawable.SmallClose); next.ContentDescription = "Close"; if (stories[storyIndex].DefaultPicture != null) { int image = (int)typeof(Resource.Drawable).GetField(stories[storyIndex].DefaultPicture) .GetValue(null); latestStory.SetImageResource(image); } else { using (var image = GetImage(options, stories[storyIndex].CoverPhoto)) { latestStory.SetImageBitmap(image); } } titleBox.Text = "Story: " + stories[storyIndex].TitleValue; } }; } else { Intent noFavouriteStories = new Intent(this, typeof(NoStoriesActivity)); noFavouriteStories.PutExtra("StoryType", "Story"); StartActivity(noFavouriteStories); } }
/* * Method name: OnCreate * Purpose: To dynamically create the layout, depending if te user has selected the todays story and favourite stories button */ protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var type = Intent.GetStringExtra("StoryType"); Typeface buttonFont = Typeface.CreateFromAsset(Assets, "Kano.otf"); var db = new Database.Database(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ShareMyDay.db3"); if (type == "Favourite") { SetContentView(Resource.Layout.NoStoriesViewFavourite); Button closeButton = FindViewById <Button>(Resource.Id.closeButton); closeButton.SetTypeface(buttonFont, TypefaceStyle.Bold); closeButton.Click += delegate { Intent exitIntent = new Intent(this, typeof(MainActivity)); StartActivity(exitIntent); }; TextView textBox = FindViewById <TextView>(Resource.Id.storyMessage); textBox.Text = "No stories are your favourite yet! Click on the favourite button at the end of a story or one of the buttons below!"; Button mostPlayed = FindViewById <Button>(Resource.Id.mostPlayedButton); mostPlayed.SetTypeface(buttonFont, TypefaceStyle.Bold); var mostPlayedStory = db.GetMostPlayed(); if (mostPlayedStory.TimesPlayed.Equals(0)) { mostPlayed.Text = "You have not played any stories yet!"; mostPlayed.SetBackgroundResource(Resource.Drawable.ButtonDimmedGenerator); mostPlayed.Enabled = false; } else { mostPlayed.Text = "Set " + mostPlayedStory.TitleValue + " as favourite"; } mostPlayed.Click += async delegate { AlertDialog.Builder favouriteCheckBox = new AlertDialog.Builder(this); favouriteCheckBox.SetTitle("New Favourite"); favouriteCheckBox.SetMessage( "If you make this story your new favourite, the current favourite story will be lost. Do you want to continue?"); favouriteCheckBox.SetPositiveButton("Yes", (senderAlert, args) => { if (db.UpdateFavourite(mostPlayedStory.Id)) { AlertDialog.Builder favouriteChanged = new AlertDialog.Builder(this); favouriteChanged.SetTitle("Favourite Story Saved"); favouriteChanged.SetMessage("This story is now your favourite story. This page will refresh automatically in 5 seconds."); favouriteChanged.SetNeutralButton("Ok", (senderAlerts, argss) => { Intent storyIntent = new Intent(this, typeof(StoryActivity)); storyIntent.PutExtra("Story", "Favourite"); StartActivity(storyIntent); }); favouriteChanged.Create(); favouriteChanged.Show(); } }); favouriteCheckBox.SetNegativeButton("No", (senderAlert, args) => {}); favouriteCheckBox.Create(); favouriteCheckBox.Show(); await Task.Delay(5000); Intent refresh = new Intent(this, typeof(StoryActivity)); refresh.PutExtra("Story", "Favourite"); StartActivity(refresh); }; Button lastPlayed = FindViewById <Button>(Resource.Id.lastPlayedButton); lastPlayed.SetTypeface(buttonFont, TypefaceStyle.Bold); var stories = db.GetAllStories(); int storyIndex = 0; bool hasPlayed = false; for (var index = 0; index < stories.Count; index++) { var i = stories[index]; if (i.LastPlayed) { lastPlayed.Text = "Set " + i.TitleValue + " as favourite"; storyIndex = index; hasPlayed = true; break; } } if (!hasPlayed) { lastPlayed.Text = "You have not played a story!"; lastPlayed.SetBackgroundResource(Resource.Drawable.ButtonDimmedGenerator); lastPlayed.Enabled = false; } lastPlayed.Click += async delegate { AlertDialog.Builder favouriteCheckBox = new AlertDialog.Builder(this); favouriteCheckBox.SetTitle("New Favourite"); favouriteCheckBox.SetMessage( "If you make this story your new favourite, the current favourite story will be lost. Do you want to continue?"); favouriteCheckBox.SetPositiveButton("Yes", (senderAlert, args) => { if (db.UpdateFavourite(stories[storyIndex].Id)) { AlertDialog.Builder favouriteChanged = new AlertDialog.Builder(this); favouriteChanged.SetTitle("Favourite Story Saved"); favouriteChanged.SetMessage("This story is now your favourite story. If you do not click ok, this page will refresh automatically in 5 seconds."); favouriteChanged.SetNeutralButton("Ok", (senderAlerts, argss) => { Intent storyIntent = new Intent(this, typeof(StoryActivity)); storyIntent.PutExtra("Story", "Favourite"); StartActivity(storyIntent); }); favouriteChanged.Create(); favouriteChanged.Show(); } }); favouriteCheckBox.SetNegativeButton("No", (senderAlert, args) => {}); favouriteCheckBox.Create(); favouriteCheckBox.Show(); await Task.Delay(5000); Intent refresh = new Intent(this, typeof(StoryActivity)); refresh.PutExtra("Story", "Favourite"); StartActivity(refresh); }; } else { SetContentView(Resource.Layout.NoStoriesViewStory); Button closeButton = FindViewById <Button>(Resource.Id.closeButton); closeButton.SetTypeface(buttonFont, TypefaceStyle.Bold); closeButton.Click += delegate { Intent exitIntent = new Intent(this, typeof(MainActivity)); StartActivity(exitIntent); }; TextView textBox = FindViewById <TextView>(Resource.Id.storyMessage); textBox.Text = "No stories have been made yet! Your teacher needs to click the generate story button or wait till home time. Come back soon!"; } }
/* * Method name: Show * Purpose: To display the quick menu */ public void Show() { Button button = _activity.FindViewById <Button>(Resource.Id.quickMenuButton); PopupMenu quickMenu = new PopupMenu(_context, button); quickMenu.Inflate(Resource.Menu.TeacherQuickMenu); quickMenu.MenuItemClick += (s1, arg1) => { Console.WriteLine("{0} selected", arg1.Item.TitleFormatted); switch (arg1.Item.TitleFormatted.ToString()) { case "Generate Stories": AlertDialog.Builder alertBox = new AlertDialog.Builder(_context); alertBox.SetTitle("Generate Stories"); alertBox.SetMessage("Do you want to generate stories? Stories cannot be edited and any new events will not be added once they have been made."); alertBox.SetPositiveButton("Yes", (senderAlert, args) => { Database.Database db = new Database.Database(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ShareMyDay.db3"); StoryGeneration storyGeneration = new StoryGeneration(db, _context); storyGeneration.Create(); if (db.GetAllStories() != null && db.GetAllStories().Count != 0) { AlertDialog.Builder alertBoxGenerated = new AlertDialog.Builder(_context); alertBoxGenerated.SetTitle("Stories Generated"); alertBoxGenerated.SetMessage("Stories have been generated! Go to the story button to see the stories."); alertBoxGenerated.SetNeutralButton("OK", (senderAlerts, argss) => { }); alertBoxGenerated.Create(); alertBoxGenerated.Show(); } else { AlertDialog.Builder noStoriesBox = new AlertDialog.Builder(_context); noStoriesBox.SetTitle("No Stories"); noStoriesBox.SetMessage( "No events have been recorded to be able to make stories yet. Please try adding events first."); noStoriesBox.SetNeutralButton("OK", (senderAlertss, argss) => { }); noStoriesBox.Create(); noStoriesBox.Show(); } }); alertBox.SetNegativeButton("No", (senderAlert, args) => { }); alertBox.Create(); alertBox.Show(); break; case "Take A Picture": var cameraIntent = new Intent(_context, typeof(CameraActivity)); cameraIntent.PutExtra("PreviousActivity", "QuickMenu"); _activity.StartActivity(cameraIntent); break; case "Make A Voice Recording": var voiceRecordingIntent = new Intent(_context, typeof(VoiceRecordingActivity)); voiceRecordingIntent.PutExtra("PreviousActivity", "QuickMenu"); _activity.StartActivity(voiceRecordingIntent); break; case "Go To Main Menu": var mainMenuIntent = new Intent(_context, typeof(TeacherMainMenuActivity)); _activity.StartActivity(mainMenuIntent); break; } }; quickMenu.DismissEvent += (s2, arg2) => { Console.WriteLine("menu dismissed"); }; quickMenu.Show(); }