/*
         * Method name: OnCreate
         * Purpose: Used to display the events in a story - this is done dynamically through layouts
         */
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            var previousActivity = Intent.GetStringExtra("Event");
            var db = new Database.Database(
                System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ShareMyDay.db3");

            var eventInformation = db.FindEventByValue(previousActivity);

            _close = new Button(this);
            _close.SetBackgroundResource(Resource.Drawable.Back);

            _close.Click += delegate
            {
                _close.SetBackgroundResource(Resource.Drawable.BackClicked);
                Intent back = new Intent(this, typeof(EventListActivity));
                StartActivity(back);
            };

            LinearLayout outerLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            ScrollView innerLayout = new ScrollView(this);

            LinearLayout informationLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            informationLayout.SetPadding(0, 0, 0, 50);

            if (eventInformation != null)
            {
                TextView title = new TextView(this)
                {
                    Text          = previousActivity,
                    TextSize      = 30,
                    TextAlignment = TextAlignment.Center
                };

                title.SetTextColor(Color.White);
                title.SetBackgroundColor(Color.ParseColor("#213f5e"));
                informationLayout.AddView(title);

                if (eventInformation.Cards != null && eventInformation.Cards.Count != 0)
                {
                    TextView cardTitle = new TextView(this)
                    {
                        Text     = "Card Tapped: " + eventInformation.Cards[0].Message,
                        TextSize = 20
                    };
                    cardTitle.SetTextColor(Color.Black);
                    cardTitle.SetPadding(40, 50, 0, 10);
                    informationLayout.AddView(cardTitle);
                }
                else
                {
                    TextView cardTitle = new TextView(this)
                    {
                        Text     = "No cards tapped for this event",
                        TextSize = 20
                    };
                    cardTitle.SetTextColor(Color.Black);
                    cardTitle.SetPadding(40, 50, 0, 50);
                    informationLayout.AddView(cardTitle);
                }

                if (eventInformation.VoiceRecordings != null && eventInformation.VoiceRecordings.Count != 0)
                {
                    TextView recordingTitle = new TextView(this)
                    {
                        Text     = "Event Recordings: ",
                        TextSize = 20
                    };
                    recordingTitle.SetTextColor(Color.Black);
                    recordingTitle.SetPadding(40, 0, 0, 50);
                    informationLayout.AddView(recordingTitle);

                    int count = 0;
                    foreach (var i in eventInformation.VoiceRecordings)
                    {
                        count++;
                        Button voiceRecording = new Button(this)
                        {
                            Text = "Play recording " + count,
                        };
                        voiceRecording.SetTextColor(Color.White);
                        voiceRecording.SetBackgroundResource(Resource.Drawable.ButtonGenerator);

                        voiceRecording.Click += delegate
                        {
                            List <string> copy = new List <string>();

                            copy.Add(i.Path);


                            VoiceRecording.VoiceRecording audioPlayer = new VoiceRecording.VoiceRecording();

                            audioPlayer.PlayRecordings(copy);
                        };
                        voiceRecording.SetPadding(0, 30, 0, 30);
                        informationLayout.AddView(voiceRecording, ViewGroup.LayoutParams.MatchParent,
                                                  250);
                    }

                    if (eventInformation.VoiceRecordings.Count > 1)
                    {
                        Button groupedVoiceRecordings = new Button(this)
                        {
                            Text = "Play All Recordings "
                        };
                        groupedVoiceRecordings.SetTextColor(Color.White);
                        groupedVoiceRecordings.SetBackgroundResource(Resource.Drawable.ButtonGenerator);
                        groupedVoiceRecordings.Click += delegate
                        {
                            List <string> copy = new List <string>();
                            foreach (var j in eventInformation.VoiceRecordings)
                            {
                                copy.Add(j.Path);
                            }

                            VoiceRecording.VoiceRecording audioPlayer = new VoiceRecording.VoiceRecording();

                            audioPlayer.PlayRecordings(copy);
                        };
                        informationLayout.AddView(groupedVoiceRecordings, ViewGroup.LayoutParams.MatchParent,
                                                  250);
                    }
                }
                else
                {
                    TextView recordingTitle = new TextView(this)
                    {
                        Text     = "No voice recordings have been made for this event",
                        TextSize = 20
                    };
                    recordingTitle.SetTextColor(Color.Black);
                    recordingTitle.SetPadding(40, 50, 0, 50);
                    informationLayout.AddView(recordingTitle);
                }


                if (eventInformation.Pictures != null && eventInformation.Pictures.Count != 0)
                {
                    TextView imageTitle = new TextView(this)
                    {
                        Text     = "Event Pictures:",
                        TextSize = 20
                    };
                    imageTitle.SetTextColor(Color.Black);
                    imageTitle.SetPadding(40, 50, 0, 50);
                    informationLayout.AddView(imageTitle);
                    Toast.MakeText(this, "Images Loading...", ToastLength.Short).Show();
                    foreach (var i in eventInformation.Pictures)
                    {
                        ImageView imageViewer = new ImageView(this);
                        imageViewer.SetPadding(0, 10, 0, 50);
                        var options = new BitmapFactory.Options {
                            InJustDecodeBounds = true
                        };

                        var sample = 4;
                        options.InSampleSize = sample;

                        options.InJustDecodeBounds = false;
                        using (var image = await GetImage(options, i.Path))
                        {
                            if (image == null)
                            {
                                TextView noImageTitle = new TextView(this)
                                {
                                    Text     = "Sorry the image does not exist.",
                                    TextSize = 20
                                };
                                noImageTitle.SetTextColor(Color.Black);
                                noImageTitle.SetPadding(40, 50, 0, 50);
                                informationLayout.AddView(noImageTitle);
                            }
                            else
                            {
                                imageViewer.SetImageBitmap(image);
                                informationLayout.AddView(imageViewer);
                            }
                        }
                    }
                }
                else
                {
                    TextView imageTitle = new TextView(this)
                    {
                        Text     = "No pictures have been taken for this event",
                        TextSize = 20
                    };
                    imageTitle.SetTextColor(Color.Black);
                    imageTitle.SetPadding(40, 50, 0, 50);
                    informationLayout.AddView(imageTitle);
                }

                informationLayout.AddView(_close, ViewGroup.LayoutParams.MatchParent,
                                          450);
                innerLayout.AddView(informationLayout,
                                    ViewGroup.LayoutParams.MatchParent,
                                    ViewGroup.LayoutParams.WrapContent);
                outerLayout.AddView(innerLayout);

                SetContentView(outerLayout);
            }
        }
示例#2
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);
                        }
                    }
                };
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.VoiceRecView);
            Typeface buttonFont       = Typeface.CreateFromAsset(Assets, "Kano.otf");
            string   previousActivity = Intent.GetStringExtra("PreviousActivity");

            SpinnerComponent spinner = new SpinnerComponent(this, Resource.Id.eventSelector, this);

            spinner.Setup();

            Button startRecordingButton = FindViewById <Button> (Resource.Id.startRecordingButton);

            startRecordingButton.SetTypeface(buttonFont, TypefaceStyle.Bold);
            startRecordingButton.SetBackgroundColor(Color.ParseColor("#213f5e"));
            startRecordingButton.SetTextColor(Color.White);
            startRecordingButton.SetTextSize(ComplexUnitType.Dip, 15);

            Button playRecordingButton = FindViewById <Button> (Resource.Id.playButton);

            playRecordingButton.SetTypeface(buttonFont, TypefaceStyle.Bold);
            playRecordingButton.SetBackgroundResource(Resource.Drawable.ButtonGenerator);
            playRecordingButton.SetTextColor(Color.White);
            playRecordingButton.SetTextSize(ComplexUnitType.Dip, 15);

            Button submitButton = FindViewById <Button>(Resource.Id.submitButton);

            submitButton.SetTypeface(buttonFont, TypefaceStyle.Bold);
            submitButton.SetBackgroundResource(Resource.Drawable.ButtonGenerator);
            submitButton.SetTextColor(Color.White);
            submitButton.SetTextSize(ComplexUnitType.Dip, 15);
            playRecordingButton.Enabled = false;
            playRecordingButton.SetBackgroundResource(Resource.Drawable.ButtonDimmedGenerator);
            playRecordingButton.SetTextColor(Color.ParseColor("#969a90"));
            VoiceRecording.VoiceRecording voiceRecorder = new VoiceRecording.VoiceRecording();

            CancelButtonComponent cancelButton = new CancelButtonComponent(this);

            cancelButton.Get().SetTypeface(buttonFont, TypefaceStyle.Bold);
            cancelButton.Get().SetBackgroundResource(Resource.Drawable.ButtonGenerator);
            cancelButton.Get().SetTextColor(Color.White);
            cancelButton.Get().SetTextSize(ComplexUnitType.Dip, 15);
            cancelButton.Get().Click += (o, e) => { cancelButton.Functionality(previousActivity, this); };

            startRecordingButton.Click += delegate {
                startRecordingButton.SetTextColor(Color.Black);

                if (startRecordingButton.Text.Equals("Redo voice recording"))
                {
                    voiceRecorder.Begin(startRecordingButton, submitButton, playRecordingButton, true);
                }
                else
                {
                    voiceRecorder.Begin(startRecordingButton, submitButton, playRecordingButton, false);
                }
            };
            playRecordingButton.Click += delegate {
                voiceRecorder.Play();
                startRecordingButton.Text = "Redo voice recording";
            };

            CheckBox eventComplete = FindViewById <CheckBox>(Resource.Id.eventComplete);
            bool     ticked        = false;

            eventComplete.Click += delegate
            {
                if (eventComplete.Checked)
                {
                    ticked = true;
                }
                else
                {
                    ticked = false;
                }
            };

            submitButton.Enabled = false;
            submitButton.SetBackgroundResource(Resource.Drawable.ButtonDimmedGenerator);
            submitButton.SetTextColor(Color.ParseColor("#969a90"));
            bool anotherRecording = false;

            submitButton.Click += (o, e) => {
                if (anotherRecording == false)
                {
                    //submit to database stuff goes here

                    bool uploadedSuccessful;
                    if (spinner.GetSelected().Equals("New Event"))
                    {
                        uploadedSuccessful = voiceRecorder.SaveNewEvent(ticked);
                    }
                    else
                    {
                        uploadedSuccessful = voiceRecorder.SaveExistingEvent(spinner, ticked);
                    }
                    if (uploadedSuccessful)
                    {
                        spinner.Disable();
                        eventComplete.Enabled = false;
                        submitButton.Text     = "Take Another Voice Recording";
                        cancelButton.Get().Text = "Close";
                        startRecordingButton.Enabled = false;
                        startRecordingButton.SetBackgroundColor(Color.ParseColor("#142635"));
                        startRecordingButton.SetTextColor(Color.ParseColor("#969a90"));
                        playRecordingButton.Enabled = false;
                        playRecordingButton.SetBackgroundResource(Resource.Drawable.ButtonDimmedGenerator);
                        playRecordingButton.SetTextColor(Color.ParseColor("#969a90"));
                        AlertBoxComponent voiceRecording = new AlertBoxComponent(this);
                        voiceRecording.RepeateFunctionSetup <CameraActivity>("Take Picture",
                                                                             "Do you want to take a picture?", this, this, previousActivity);
                        voiceRecording.Show();
                        anotherRecording = true;
                    }
                    else
                    {
                        AlertBoxComponent errorUplaodingAlertBox = new AlertBoxComponent(this);
                        errorUplaodingAlertBox.Setup("Cannot Add To Event",
                                                     "This event has already been made into a story and cannot be updated. Select a different event or make a new event.");
                        errorUplaodingAlertBox.Show();
                    }
                }
                else
                {
                    Intent repeatedActivity = new Intent(this, typeof(VoiceRecordingActivity));
                    repeatedActivity.PutExtra("PreviousActivity", previousActivity);
                    StartActivity(repeatedActivity);
                }
            };
        }