Example #1
0
        void Save_Click(object sender, EventArgs e)
        {
            PictureInfo info = CurrentPicture;

            String file = info.User.Username + info.ID + ".jpg";

            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream myFileStream = myStore.CreateFile(file);

            WriteableBitmap bitmap = new WriteableBitmap((BitmapSource)this.imgPicture.Source);

            bitmap.SaveJpeg(myFileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
            myFileStream.Close();

            myFileStream = myStore.OpenFile(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            var lib = new MediaLibrary();

            lib.SavePicture(file, myFileStream);

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been saved to your media library.");

            toastDisplay.Show();
        }
Example #2
0
        void Save_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MenuItem    item = sender as MenuItem;
            PictureInfo info = item.DataContext as PictureInfo;

            String file = info.User.Username + info.ID + ".jpg";

            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream myFileStream = myStore.CreateFile(file);

            BitmapImage b = new BitmapImage(new Uri(info.MediumURL, UriKind.Absolute));

            b.CreateOptions = BitmapCreateOptions.None;

            Image i = new Image();

            i.Source = b;

            WriteableBitmap bitmap = new WriteableBitmap((BitmapSource)i.Source);

            bitmap.SaveJpeg(myFileStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
            myFileStream.Close();

            myFileStream = myStore.OpenFile(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            var lib = new MediaLibrary();

            lib.SavePicture(file, myFileStream);

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been saved to your media library.");

            toastDisplay.Show();
        }
Example #3
0
        private void Login_Click(object sender, EventArgs e)
        {
            if (!InputValidator.isNotEmpty(this.usernameInput.Text) ||
                !InputValidator.isNotEmpty(this.passwordInput.Password))
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Oops!",
                    "Please check that you have entered all required fields.",
                    3000);
                toastDisplay.Show();
                return;
            }


            App.MetrocamService.AuthenticateCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_AuthenticateCompleted_Login);
            GlobalLoading.Instance.IsLoading           = true;

            // Atach timer event handler for tick
            this.timer.Tick += new EventHandler(timer_Tick);
            // Set one second as each tick
            this.timer.Interval = new TimeSpan(0, 0, 1);
            // Start timer
            this.timer.Start();

            App.MetrocamService.Authenticate(this.usernameInput.Text, this.passwordInput.Password);
        }
        private void MetrocamService_CreateUserCompleted(object sender, RequestCompletedEventArgs e)
        {
            // Unsubscribe
            App.MetrocamService.CreateUserCompleted -= new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_CreateUserCompleted);

            UnauthorizedAccessException err = e.Data as UnauthorizedAccessException;

            if (err != null)
            {
                if (GlobalLoading.Instance.IsLoading)
                {
                    GlobalLoading.Instance.IsLoading = false;
                }
                // There was an error with CreateUser in the webservice
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Signup Failure",
                    "This Username and/or Email is already being registered to another account.",
                    3000);
                toastDisplay.Show();
                return;
            }

            // Now we authenticate using the username and password
            App.MetrocamService.AuthenticateCompleted += new RequestCompletedEventHandler(MetrocamService_AuthenticateCompleted);

            // Calls Authenticate to obtain UserInfo object
            App.MetrocamService.Authenticate(this.UsernameInput.Text, this.PasswordInput.Password);
        }
Example #5
0
        private void Flag_Click(object sender, EventArgs e)
        {
            if (doingWork)
            {
                return;
            }

            if (CurrentPicture.IsFlagged || App.ChangedFlaggedStatus.ContainsKey(CurrentPicture.ID))
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Oops!",
                    "You have already flagged this picture.");

                toastDisplay.Show();
                return;
            }

            FlaggedPicture data = new FlaggedPicture();

            data.UserID    = App.MetrocamService.CurrentUser.ID;
            data.PictureID = CurrentPicture.ID;

            App.MetrocamService.CreateFlaggedPictureCompleted += new RequestCompletedEventHandler(MetrocamService_CreateFlaggedPictureCompleted);
            if (GlobalLoading.Instance.IsLoading == false)
            {
                GlobalLoading.Instance.IsLoading = true;
            }
            doingWork = true;
            App.MetrocamService.CreateFlaggedPicture(data);
        }
Example #6
0
        void Flag_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been flagged for review.");

            toastDisplay.Show();
        }
        private void Accept_Click(object sender, EventArgs e)
        {
            string inputValidationMessage = CheckAllInputs();

            if (!inputValidationMessage.Equals("Valid"))
            {
                // Input validation failed
                if (toastDisplay != null)
                {
                    toastDisplay.Hide();
                }

                // Set properties of ToastPrompt
                toastDisplay = GlobalToastPrompt.CreateToastPrompt("Oops",
                                                                   inputValidationMessage,
                                                                   5000);

                toastDisplay.Show();

                return;
            }

            // Input validation passed, proceed with registration
            currentUser              = new User();
            currentUser.Username     = this.UsernameInput.Text;
            currentUser.Name         = this.FullnameInput.Text;
            currentUser.Password     = this.PasswordInput.Password;
            currentUser.EmailAddress = this.EmailInput.Text;

            // Set default values for optional fields if empty
            if (this.LocationInput.Text.Length == 0)
            {
                currentUser.Location = DefaultLocation;
            }
            else
            {
                currentUser.Location = this.LocationInput.Text;
            }

            if (this.BiographyInput.Text.Length == 0)
            {
                currentUser.Biography = DefaultBiography;
            }
            else
            {
                currentUser.Biography = this.BiographyInput.Text;
            }

            // Subscribe event to CreateUserCompleted
            App.MetrocamService.CreateUserCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_CreateUserCompleted);

            GlobalLoading.Instance.IsLoading = true;

            // Calls CreateUser to WebService
            App.MetrocamService.CreateUser(currentUser);
        }
Example #8
0
        void MetrocamService_CreateFavoritedPictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            App.MetrocamService.CreateFavoritedPictureCompleted -= MetrocamService_CreateFavoritedPictureCompleted;

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been added to your favorites.");

            toastDisplay.Show();
        }
Example #9
0
        void MetrocamService_UpdateUserCompleted(object sender, RequestCompletedEventArgs e)
        {
            App.MetrocamService.UpdateUserCompleted -= MetrocamService_UpdateUserCompleted;
            GlobalLoading.Instance.IsLoading         = false;

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Your profile picture has been updated.");

            toastDisplay.Show();
        }
        private void UsernameInput_GotFocus(object sender, RoutedEventArgs e)
        {
            if (toastDisplay != null)
            {
                toastDisplay.Hide();
            }

            // Set properties of ToastPrompt
            toastDisplay = GlobalToastPrompt.CreateToastPrompt("Username Rules",
                                                               "Must be between 4 and 25 characters.\nNo special characters.\nNo spaces.",
                                                               10000);

            toastDisplay.Show();
        }
        private void PasswordInput_GotFocus(object sender, RoutedEventArgs e)
        {
            if (toastDisplay != null)
            {
                toastDisplay.Hide();
            }

            // Set properties of ToastPrompt
            toastDisplay = GlobalToastPrompt.CreateToastPrompt("Password Rules",
                                                               "Must between 6 and 20 characters.\nAt least one capital letter.\nAt least one number.\nNo special characters.\nNo spaces.",
                                                               10000);

            toastDisplay.Show();
        }
Example #12
0
        void MetrocamService_CreateFlaggedPictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            App.MetrocamService.CreateFlaggedPictureCompleted -= MetrocamService_CreateFlaggedPictureCompleted;
            if (GlobalLoading.Instance.IsLoading)
            {
                GlobalLoading.Instance.IsLoading = false;
            }

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been flagged for review.");

            toastDisplay.Show();

            App.ChangedFlaggedStatus[CurrentPicture.ID] = true;
            doingWork = false;
        }
Example #13
0
        void MetrocamService_DeleteFavoritedPictureCompleted(object sender, RequestCompletedEventArgs e)
        {
            doingWork = false;
            GlobalLoading.Instance.IsLoading = false;

            toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                "Success!",
                "Picture has been removed from your favorites.");
            toastDisplay.Show();

            ApplicationBar.Buttons.RemoveAt(2);
            ApplicationBarIconButton favorite = new ApplicationBarIconButton(new Uri("Images/appbar.heart.png", UriKind.Relative));

            favorite.Text   = "favorite";
            favorite.Click += new EventHandler(Favorite_Click);
            ApplicationBar.Buttons.Add(favorite);


            App.MetrocamService.DeleteFavoritedPictureCompleted -= MetrocamService_DeleteFavoritedPictureCompleted;
        }
Example #14
0
        private void MetrocamService_AuthenticateCompleted_Login(object sender, RequestCompletedEventArgs e)
        {
            this.timer.Stop();
            App.MetrocamService.AuthenticateCompleted -= MetrocamService_AuthenticateCompleted_Login;
            if (GlobalLoading.Instance.IsLoading)
            {
                GlobalLoading.Instance.IsLoading = false;
            }

            UnauthorizedAccessException err = e.Data as UnauthorizedAccessException;

            if (err != null)
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Oops!",
                    "The credentials you provided are invalid.",
                    3000);
                toastDisplay.Show();
                return;
            }

            //FetchRecentPictures();

            // Obtain UserInfo object from web service
            UserInfo currentUser = App.MetrocamService.CurrentUser;

            // Load user specific settings
            Settings.getUserSpecificSettings(currentUser.Username);

            // Store into isolated storage
            Settings.isLoggedIn.Value = true;
            Settings.username.Value   = currentUser.Username;
            Settings.password.Value   = this.passwordInput.Password;    // As of now, currentUser.Password returns a hashed password.

            App.isFromLandingPage = true;
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
Example #15
0
        // This is catched when authenticate takes too long [temporary fix to authenticate not responding atm]
        void timer_Tick(object sender, EventArgs e)
        {
            timeCount++;

            // Has authenticate taken at least 5 seconds?
            if (timeCount >= 5)
            {
                this.timer.Stop();

                // Detach event handlers
                App.MetrocamService.AuthenticateCompleted -= MetrocamService_AuthenticateCompleted_Login;
                this.timer.Tick -= timer_Tick;

                if (GlobalLoading.Instance.IsLoading)
                {
                    GlobalLoading.Instance.IsLoading = false;
                }
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Oops!",
                    "The credentials you provided are invalid.",
                    3000);
                toastDisplay.Show();
            }
        }
Example #16
0
        // When this page becomes the active page in the app
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (App.FavoritedUserPictures.Count == 0)
            {
                FavoritesLoadingMessage.Visibility = Visibility.Visible;
            }
            else
            {
                FavoritesLoadingMessage.Visibility = Visibility.Collapsed;
            }

            if (GlobalLoading.Instance.IsLoading)
            {
                GlobalLoading.Instance.IsLoading = false;
            }

            GlobalLoading.Instance.Text = "";

            startPop = DateTime.Now;

            if (App.isFromUploadPage)
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Success!",
                    "Your picture has been uploaded.");

                toastDisplay.Show();

                /**
                 * One to remove the Share page, one to remove the MainPage it came from. If you don't
                 * have the second one and hit Back, you'll load the same page and it looks weird.
                 */
                NavigationService.RemoveBackEntry();
                NavigationService.RemoveBackEntry();

                App.isFromUploadPage = false;
                return;
            }
            else if (App.isFromEditProfile)
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Success!",
                    "Your profile has been updated.");

                toastDisplay.Show();

                App.isFromEditProfile = false;
                return;
            }

            // Checks if user is already logged in previously
            if (!Settings.isLoggedIn.Value || Settings.isLoggedIn == null)
            {
                // Not logged in, navigate to landing page
                NavigationService.RemoveBackEntry();
                NavigationService.Navigate(new Uri("/LandingPage.xaml", UriKind.Relative));
                return;
            }

            if (App.isFromLandingPage)
            {
                // Clears back stack so user cannot go back to LandingPage(s)
                NavigationService.RemoveBackEntry();
                NavigationService.RemoveBackEntry();
                NavigationService.RemoveBackEntry();

                App.MetrocamService.AuthenticateCompleted += new RequestCompletedEventHandler(MetrocamService_AuthenticateCompleted);
                App.MetrocamService.Authenticate(Settings.username.Value, Settings.password.Value);
            }

            // User is logged in previously, check how this app got to main page
            if (App.isFromAppLaunch || App.isFromAppActivate)
            {
                // App is launched from start. We need to authenticate, then populate Popular, then populate Recent
                App.MetrocamService.AuthenticateCompleted += new RequestCompletedEventHandler(MetrocamService_AuthenticateCompleted);
                App.MetrocamService.Authenticate(Settings.username.Value, Settings.password.Value);
            }
            else if (App.isFromUploadPage)
            {
                // Reset back to false
                App.isFromUploadPage = false;

                // Clears back stack so user cannot go back to LandingPage(s)
                NavigationService.RemoveBackEntry();

                // Flag to refresh Recent
                isRefreshingRecent = true;

                // We need to authenticate, then populate Recent
                App.MetrocamService.AuthenticateCompleted += new RequestCompletedEventHandler(MetrocamService_AuthenticateCompleted);
                App.MetrocamService.Authenticate(Settings.username.Value, Settings.password.Value);
            }
            else if (App.pictureIsDeleted)
            {
                // User is navigated here after deleting a page
                if (MainContent.SelectedIndex == 0)
                {
                    // Refresh popular
                    isRefreshingPopular = true;
                    isRefreshingRecent  = true;
                    FetchPopularPictures();
                    FetchRecentPictures();
                    App.pictureIsDeleted = false;
                }
                else if (MainContent.SelectedIndex == 1)
                {
                    // Refresh recent
                    FetchRecentPictures();
                    App.pictureIsDeleted = false;
                }
                else
                {
                    // Refresh favourites
                    FetchFavoritedPictures();
                }
            }
            else
            {
                // User is navigated here from a page in the forward stack, so do nothing
                return;
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            GlobalLoading.Instance.Text = "";

            if (App.isFromEditProfile)
            {
                toastDisplay = GlobalToastPrompt.CreateToastPrompt(
                    "Success!",
                    "Your profile has been updated.");

                toastDisplay.Show();

                App.isFromEditProfile = false;
            }

            if (NavigationContext.QueryString["userid"].Equals(App.MetrocamService.CurrentUser.ID))
            {
                // User navigates to his own profile
                SetCurrentUserProfile();

                if (this.UserPictures.ItemsSource == null)
                {
                    App.MetrocamService.FetchUserPicturesCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_FetchUserPicturesCompleted);
                    GlobalLoading.Instance.IsLoading = true;
                    App.MetrocamService.FetchUserPictures(App.MetrocamService.CurrentUser.ID);
                }
                else if (App.pictureIsDeleted == true)
                {
                    // User has deleted a picture and is navigated back to this page
                    App.pictureIsDeleted = false;
                    App.MetrocamService.FetchUserPicturesCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_FetchUserPicturesCompleted);
                    GlobalLoading.Instance.IsLoading = true;
                    App.MetrocamService.FetchUserPictures(App.MetrocamService.CurrentUser.ID);
                }

                return;
            }
            else if (this.UserPictures.ItemsSource != null)
            {
                return;
            }

            if (NavigationContext.QueryString["type"].Equals("popular"))
            {
                // User navigated here from Popular Pivot
                SelectedPicture = (from pic in App.PopularPictures where pic.ID.Equals(NavigationContext.QueryString["id"]) select pic).First <PictureInfo>();
            }
            else if (NavigationContext.QueryString["type"].Equals("recent"))
            {
                // User navigated here from Recent Pivot
                SelectedPicture = (from pic in App.RecentPictures where pic.ID.Equals(NavigationContext.QueryString["id"]) select pic).First <PictureInfo>();
            }
            else if (NavigationContext.QueryString["type"].Equals("search"))
            {
                // User navigated here from Search Menu
                App.MetrocamService.FetchUserCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_FetchUserCompleted);
                App.MetrocamService.FetchUser(NavigationContext.QueryString["id"]);
                return;
            }

            // Save into userInfo object
            this.userInfo = SelectedPicture.User;

            // pivot name
            this.PivotRoot.Title = SelectedPicture.User.Username;

            // profile pic
            profilePicture.Source = (new BitmapImage(new Uri(SelectedPicture.User.ProfilePicture.MediumURL, UriKind.RelativeOrAbsolute)));

            // name
            fullName.Text = SelectedPicture.User.Name;

            // location
            if (SelectedPicture.User.Location == null)
            {
                hometown.Text = "Earth";
            }
            else
            {
                hometown.Text = SelectedPicture.User.Location;
            }

            // username
            usernameTextBlock.Text = SelectedPicture.User.Username;

            // bio
            if (SelectedPicture.User.Biography == null)
            {
                biographyTextBlock.Text = "Just another Metrocammer!";
            }
            else
            {
                biographyTextBlock.Text = SelectedPicture.User.Biography;
            }

            PictureLabel.Text   = SelectedPicture.User.Pictures.ToString();
            FollowingLabel.Text = SelectedPicture.User.Following.ToString();
            FollowerLabel.Text  = SelectedPicture.User.Followers.ToString();

            App.MetrocamService.FetchUserPicturesCompleted += new MobileClientLibrary.RequestCompletedEventHandler(MetrocamService_FetchUserPicturesCompleted);
            GlobalLoading.Instance.IsLoading = true;
            App.MetrocamService.FetchUserPictures(userInfo.ID);

            userInfo.ID = SelectedPicture.User.ID;

            if (App.ChangedFollowerStatus.ContainsKey(userInfo.ID))
            {
                if (App.ChangedFollowerStatus[userInfo.ID] == true)
                {
                    FollowingStatus.Text = "You are following " + userInfo.Username + ".";
                    ConstructAppBar(false, true);
                }
                else
                {
                    FollowingStatus.Text = "You are not following " + userInfo.Username + ".";
                    ConstructAppBar(false, false);
                }
            }
            else
            {
                if (SelectedPicture.User.IsFollowing == false)
                {
                    FollowingStatus.Text = "You are not following " + userInfo.Username + ".";
                    ConstructAppBar(false, false);
                }
                else
                {
                    FollowingStatus.Text = "You are following " + userInfo.Username + ".";
                    ConstructAppBar(false, true);
                }
            }
        }