예제 #1
0
        /*
         * Method name: OnCreate
         * Purpose: To set up the story page depending whether the user has selected the favourite or todays story button
         */
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.StoryView);

            _storyId    = Intent.GetStringExtra("Story");
            _storyIndex = Intent.GetStringExtra("StoryIndex");

            ImageView pictureButton = FindViewById <ImageView>(Resource.Id.pictureBox);

            _db = new Database.Database(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
                                        "ShareMyDay.db3");

            var options = new BitmapFactory.Options {
                InJustDecodeBounds = true
            };

            var sample = 4;

            options.InSampleSize       = sample;
            options.InJustDecodeBounds = false;

            Database.Models.Story story;
            if (_storyId == "Favourite")
            {
                story = _db.FindFavouriteStory();

                if (story != null)
                {
                    SetupStory(story, options, pictureButton, _db, true);
                }
                else
                {
                    Intent noFavouriteStories = new Intent(this, typeof(NoStoriesActivity));
                    noFavouriteStories.PutExtra("StoryType", "Favourite");
                    StartActivity(noFavouriteStories);
                }
            }
            else
            {
                story = _db.FindStoryById(_storyId);

                SetupStory(story, options, pictureButton, _db, false);
            }
        }
예제 #2
0
        public void D_FindStoryById_FindStoryWithId1_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.FindStoryById("1"), "FindStoryById_FindStoryWithId1_ReturnsNotNull: Returned Null - No story with Id 1 not found");
        }
예제 #3
0
        /*
         * Method name: SetupStory
         * Purpose: Used to set up the story page with all the story information
         */
        public void SetupStory(Database.Models.Story story, BitmapFactory.Options options, ImageView pictureButton,
                               Database.Database db, bool favourite)
        {
            TextView title = FindViewById <TextView>(Resource.Id.titleBox);

            title.Text = story.TitleValue;

            _storyIndex = Intent.GetStringExtra("StoryIndex");

            List <StoryEvent> storyEvents = db.FindEventsFromStory(story.Id.ToString());
            List <Picture>    pictures    = new List <Picture>();
            List <Database.Models.VoiceRecording> voiceRecordings = new List <Database.Models.VoiceRecording>();

            if (story.DefaultPicture == null)
            {
                using (var image = GetImage(options, story.CoverPhoto))
                {
                    pictureButton.SetImageBitmap(image);
                }

                if (story.Extra.Equals(false) && story.TextToSpeech.Equals(false))
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.Pictures != null && i.Pictures.Count != 0)
                        {
                            foreach (var picture in i.Pictures)
                            {
                                pictures.Add(picture);
                            }
                        }

                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                    }
                }

                bool done = false;
                if (story.TextToSpeech)
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.Pictures != null && i.Pictures.Count != 0)
                        {
                            foreach (var picture in i.Pictures)
                            {
                                pictures.Add(picture);
                            }
                        }

                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                        else
                        {
                            bool cardFound = false;
                            foreach (var j in storyEvents)
                            {
                                if (j.Cards != null && j.Cards.Count != 0)
                                {
                                    _text     = CreateSentence(j.Cards[0]);
                                    cardFound = true;
                                }
                            }

                            if (!cardFound)
                            {
                                _text = "Never guess what else happened in school today! Have a look at all of this!";
                            }
                        }

                        done = true;
                    }
                }

                if (story.Extra && !done)
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.Pictures != null && i.Pictures.Count != 0)
                        {
                            foreach (var picture in i.Pictures)
                            {
                                pictures.Add(picture);
                            }
                        }

                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                        else
                        {
                            bool cardFound = false;
                            foreach (var j in storyEvents)
                            {
                                if (j.Cards != null && j.Cards.Count != 0)
                                {
                                    _text     = CreateSentence(j.Cards[0]);
                                    cardFound = true;
                                }
                            }

                            if (!cardFound)
                            {
                                _text = "Never guess what else happened in school today! Have a look at all of this!";
                            }
                        }
                    }
                }

                int pictureCount   = pictures.Count;
                int recordingCount = voiceRecordings.Count;

                int totalSteps = 0;
                if (pictureCount > recordingCount)
                {
                    totalSteps = pictureCount;
                }
                else if (recordingCount > pictureCount)
                {
                    totalSteps = recordingCount;
                }
                else
                {
                    if (pictureCount != 0)
                    {
                        totalSteps = pictureCount;
                    }
                    else
                    {
                        if (recordingCount != 0)
                        {
                            totalSteps = recordingCount;
                        }
                    }
                }

                TextView stepCounter = FindViewById <TextView>(Resource.Id.CountBox);
                stepCounter.Text = "Click the picture to begin!";

                bool firstClick = false;
                int  counter    = 0;

                pictureButton.Click += delegate
                {
                    if (firstClick.Equals(false))
                    {
                        totalSteps--;
                        firstClick = true;
                        if (story.TextToSpeech)
                        {
                            if (_phoneVoice == null)
                            {
                                _phoneVoice = new TextToSpeech(this, this);
                            }
                            else
                            {
                                _phoneVoice.Speak(_text, QueueMode.Flush, null, null);
                            }
                        }
                    }
                    else
                    {
                        if (totalSteps.Equals(0))
                        {
                            totalSteps--;
                        }
                        else
                        {
                            counter++;
                            totalSteps--;
                        }
                    }

                    if (totalSteps.Equals(0))
                    {
                        stepCounter.Text     = "No Clicks Left. Click the picture to play again.";
                        stepCounter.TextSize = 20;
                        //increment most played
                        var numberPlayed = story.TimesPlayed;
                        numberPlayed     += 1;
                        story.TimesPlayed = numberPlayed;
                        _db.UpdateStory(story);
                    }
                    else if (totalSteps.Equals(1))
                    {
                        stepCounter.Text = totalSteps + " click left";
                    }
                    else if (totalSteps <= -1)
                    {
                        Intent replayStory = new Intent(this, typeof(StoryActivity));
                        replayStory.PutExtra("Story", _storyId);
                        StartActivity(replayStory);
                        stepCounter.Text = "No Clicks Left. Click the picture to play again.";
                    }
                    else
                    {
                        stepCounter.Text = totalSteps + " clicks left";
                    }

                    if (pictureCount > counter)
                    {
                        using (var image = GetImage(options, pictures[counter].Path))
                        {
                            pictureButton.SetImageBitmap(image);
                        }
                    }

                    if (recordingCount > counter && totalSteps > -1)
                    {
                        List <string> recording = new List <string>();
                        recording.Add(voiceRecordings[counter].Path);
                        VoiceRecording.VoiceRecording audioPlayer = new VoiceRecording.VoiceRecording();
                        audioPlayer.PlayRecordings(recording);
                    }
                };



                Button closeButton     = FindViewById <Button>(Resource.Id.closeButton);
                Button favouriteButton = FindViewById <Button>(Resource.Id.favouriteButton);


                if (story.Favourite)
                {
                    favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                }

                closeButton.Click += async delegate
                {
                    await Task.Delay(1);

                    SetLastPlayed(story);
                    closeButton.SetBackgroundResource(Resource.Drawable.BigCloseButtonClicked);

                    if (!favourite)
                    {
                        Intent back = new Intent(this, typeof(TodayStoryActivity));
                        back.PutExtra("StoryIndex", _storyIndex);
                        StartActivity(back);
                    }
                    else
                    {
                        Intent exitIntent = new Intent(this, typeof(MainActivity));
                        StartActivity(exitIntent);
                    }
                };

                favouriteButton.Click += async delegate
                {
                    var favouriteStory = _db.FindStoryById(story.Id.ToString());
                    if (favouriteStory.Favourite)
                    {
                        favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButtonClicked);
                        await Task.Delay(10);

                        AlertDialog.Builder alreadyFavourite = new AlertDialog.Builder(this);
                        alreadyFavourite.SetTitle("Are you sure you want to unfavourite?");
                        alreadyFavourite.SetMessage(
                            "This story is your favourite! Are you sure you want to remove it?");
                        alreadyFavourite.SetPositiveButton("Yes",
                                                           (senderAlerts, argss) =>
                        {
                            _db.RemoveFavourite(story.Id.ToString());

                            favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButton);
                        });
                        alreadyFavourite.SetNegativeButton("No",
                                                           (senderAlerts, argss) =>
                        {
                            favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                        });
                        alreadyFavourite.Create();
                        alreadyFavourite.Show();
                    }
                    else
                    {
                        await Task.Delay(10);

                        favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButtonClicked);
                        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", async(senderAlert, args) =>
                        {
                            if (db.UpdateFavourite(story.Id))
                            {
                                AlertDialog.Builder favouriteChanged = new AlertDialog.Builder(this);
                                favouriteChanged.SetTitle("Favourite Story Saved");
                                favouriteChanged.SetMessage("This story is now your favourite story.");
                                favouriteChanged.SetNeutralButton("Ok", (senderAlerts, argss) => { });
                                favouriteChanged.Create();
                                favouriteChanged.Show();


                                await Task.Delay(1);
                                favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                            }
                        });
                        favouriteCheckBox.SetNegativeButton("No",
                                                            (senderAlert, args) =>
                        {
                            favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButton);
                        });
                        favouriteCheckBox.Create();
                        favouriteCheckBox.Show();
                    }
                };

                Button cancelButton = FindViewById <Button>(Resource.Id.cancelButton);
                cancelButton.Click += delegate
                {
                    cancelButton.SetBackgroundResource(Resource.Drawable.FinishClicked);
                    SetLastPlayed(story);
                    if (totalSteps.Equals(0))
                    {
                        title.Visibility           = ViewStates.Invisible;
                        stepCounter.Visibility     = ViewStates.Invisible;
                        cancelButton.Visibility    = ViewStates.Invisible;
                        pictureButton.Visibility   = ViewStates.Invisible;
                        closeButton.Visibility     = ViewStates.Visible;
                        favouriteButton.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        if (!favourite)
                        {
                            Intent back = new Intent(this, typeof(TodayStoryActivity));
                            back.PutExtra("StoryIndex", _storyIndex);
                            StartActivity(back);
                        }
                        else
                        {
                            Intent exitIntent = new Intent(this, typeof(MainActivity));
                            StartActivity(exitIntent);
                        }
                    }
                };
            }
            else
            {
                int image = (int)typeof(Resource.Drawable).GetField(story.DefaultPicture).GetValue(null);
                pictureButton.SetImageResource(image);

                if (story.Extra.Equals(false) && story.TextToSpeech.Equals(false))
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                    }
                }

                bool done = false;
                if (story.TextToSpeech)
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                        else
                        {
                            bool cardFound = false;
                            foreach (var j in storyEvents)
                            {
                                if (j.Cards != null && j.Cards.Count != 0)
                                {
                                    _text     = CreateSentence(j.Cards[0]);
                                    cardFound = true;
                                }
                            }

                            if (!cardFound)
                            {
                                _text = "Never guess what else happened in school today! Have a look at all of this!";
                            }
                        }

                        done = true;
                    }
                }

                if (story.Extra && !done)
                {
                    foreach (var i in storyEvents)
                    {
                        if (i.VoiceRecordings != null && i.VoiceRecordings.Count != 0)
                        {
                            foreach (var recording in i.VoiceRecordings)
                            {
                                voiceRecordings.Add(recording);
                            }
                        }
                        else
                        {
                            bool cardFound = false;
                            foreach (var j in storyEvents)
                            {
                                if (j.Cards != null && j.Cards.Count != 0)
                                {
                                    _text     = CreateSentence(j.Cards[0]);
                                    cardFound = true;
                                }
                            }

                            if (!cardFound)
                            {
                                _text = "Never guess what else happened in school today! Have a look at all of this!";
                            }
                        }
                    }
                }

                int recordingCount = voiceRecordings.Count;

                int totalSteps = 0;
                if (recordingCount != 0)
                {
                    totalSteps = recordingCount;
                }
                else
                {
                    totalSteps = 1;
                }

                TextView stepCounter = FindViewById <TextView>(Resource.Id.CountBox);
                stepCounter.Text = "Click the picture to begin!";

                bool firstClick = false;
                int  counter    = 0;

                pictureButton.Click += delegate
                {
                    if (firstClick.Equals(false))
                    {
                        totalSteps--;
                        firstClick = true;
                        if (story.TextToSpeech)
                        {
                            if (_phoneVoice == null)
                            {
                                _phoneVoice = new TextToSpeech(this, this);
                            }
                            else
                            {
                                _phoneVoice.Speak(_text, QueueMode.Flush, null, null);
                            }
                        }
                    }
                    else
                    {
                        if (totalSteps.Equals(0))
                        {
                            totalSteps--;
                        }
                        else
                        {
                            counter++;
                            totalSteps--;
                        }
                    }

                    if (totalSteps.Equals(0))
                    {
                        stepCounter.Text     = "No Clicks Left. Click the picture to play again.";
                        stepCounter.TextSize = 20;
                        var numberPlayed = story.TimesPlayed;
                        numberPlayed     += 1;
                        story.TimesPlayed = numberPlayed;
                        _db.UpdateStory(story);
                    }
                    else if (totalSteps.Equals(1))
                    {
                        stepCounter.Text = totalSteps + " click left";
                    }
                    else if (totalSteps <= -1)
                    {
                        Intent replayStory = new Intent(this, typeof(StoryActivity));
                        replayStory.PutExtra("Story", _storyId);
                        StartActivity(replayStory);
                        stepCounter.Text = "No Clicks Left. Click the picture to play again.";
                    }
                    else
                    {
                        stepCounter.Text = totalSteps + " clicks left";
                    }

                    if (recordingCount > counter && totalSteps > -1)
                    {
                        List <string> recording = new List <string>();
                        recording.Add(voiceRecordings[counter].Path);
                        VoiceRecording.VoiceRecording audioPlayer = new VoiceRecording.VoiceRecording();
                        audioPlayer.PlayRecordings(recording);
                    }
                };

                Button closeButton     = FindViewById <Button>(Resource.Id.closeButton);
                Button favouriteButton = FindViewById <Button>(Resource.Id.favouriteButton);


                if (story.Favourite)
                {
                    favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                }

                closeButton.Click += async delegate
                {
                    await Task.Delay(1);

                    closeButton.SetBackgroundResource(Resource.Drawable.BigCloseButtonClicked);
                    SetLastPlayed(story);
                    if (!favourite)
                    {
                        Intent back = new Intent(this, typeof(TodayStoryActivity));
                        back.PutExtra("StoryIndex", _storyIndex);
                        StartActivity(back);
                    }
                    else
                    {
                        Intent exitIntent = new Intent(this, typeof(MainActivity));
                        StartActivity(exitIntent);
                    }
                };

                favouriteButton.Click += async delegate
                {
                    var favouriteStory = _db.FindStoryById(story.Id.ToString());
                    if (favouriteStory.Favourite)
                    {
                        favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButtonClicked);
                        await Task.Delay(10);

                        AlertDialog.Builder alreadyFavourite = new AlertDialog.Builder(this);
                        alreadyFavourite.SetTitle("Are you sure you want to unfavourite?");
                        alreadyFavourite.SetMessage(
                            "This story is your favourite! Are you sure you want to remove it?");
                        alreadyFavourite.SetPositiveButton("Yes",
                                                           (senderAlerts, argss) =>
                        {
                            _db.RemoveFavourite(story.Id.ToString());

                            favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButton);
                        });
                        alreadyFavourite.SetNegativeButton("No",
                                                           (senderAlerts, argss) =>
                        {
                            favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                        });
                        alreadyFavourite.Create();
                        alreadyFavourite.Show();
                    }
                    else
                    {
                        await Task.Delay(10);

                        favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButtonClicked);
                        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", async(senderAlert, args) =>
                        {
                            if (db.UpdateFavourite(story.Id))
                            {
                                AlertDialog.Builder favouriteChanged = new AlertDialog.Builder(this);
                                favouriteChanged.SetTitle("Favourite Story Saved");
                                favouriteChanged.SetMessage("This story is now your favourite story.");
                                favouriteChanged.SetNeutralButton("Ok", (senderAlerts, argss) => { });
                                favouriteChanged.Create();
                                favouriteChanged.Show();


                                await Task.Delay(1);
                                favouriteButton.SetBackgroundResource(Resource.Drawable.MakeFavouriteButton);
                            }
                        });
                        favouriteCheckBox.SetNegativeButton("No",
                                                            (senderAlert, args) =>
                        {
                            favouriteButton.SetBackgroundResource(Resource.Drawable.unFaveButton);
                        });
                        favouriteCheckBox.Create();
                        favouriteCheckBox.Show();
                    }
                };

                Button cancelButton = FindViewById <Button>(Resource.Id.cancelButton);
                cancelButton.Click += delegate
                {
                    cancelButton.SetBackgroundResource(Resource.Drawable.FinishClicked);
                    if (totalSteps.Equals(0))
                    {
                        title.Visibility           = ViewStates.Invisible;
                        stepCounter.Visibility     = ViewStates.Invisible;
                        cancelButton.Visibility    = ViewStates.Invisible;
                        pictureButton.Visibility   = ViewStates.Invisible;
                        closeButton.Visibility     = ViewStates.Visible;
                        favouriteButton.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        if (!favourite)
                        {
                            Intent back = new Intent(this, typeof(TodayStoryActivity));
                            back.PutExtra("StoryIndex", _storyIndex);
                            StartActivity(back);
                        }
                        else
                        {
                            Intent exitIntent = new Intent(this, typeof(MainActivity));
                            StartActivity(exitIntent);
                        }
                    }
                };
            }
        }