Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Authentication Activity is started (on app open).
            base.OnCreate(savedInstanceState);
            // The view is set to the Authentication_Layout.
            SetContentView(Resource.Layout.Authentication_Layout);

            // Get the current user.
            auth = FirebaseAuth.Instance;
            user = auth.CurrentUser;

            if (user != null)
            {
                // If user already exists, they are already signed in.
                // Start the MainActivity.
                StartActivity(new Android.Content.Intent(this, typeof(MainActivity)).SetFlags(Android.Content.ActivityFlags.NoAnimation));
                Finish();
                return;
            }

            // Otherwise, continue to obtain the ImageButton btnlogin from the resources.
            ImageButton btnLogin = FindViewById <ImageButton>(Resource.Id.btnLogin);

            btnLogin.Click += delegate
            {
                // On btnLogin click, open a WebView (with the Steam URL).
                SetContentView(Resource.Layout.WebView_Layout);
                webView = FindViewById <WebView>(Resource.Id.webView);
                string steam_url = "https://steamcommunity.com/openid/login?openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.realm=https://clanbutton&openid.return_to=https://clanbutton/signin/";
                webView.Visibility = ViewStates.Visible;
                ExtendedWebViewClient webClient = new ExtendedWebViewClient();
                webClient.steamAuthentication = this;
                webView.SetWebViewClient(webClient);
                webView.LoadUrl(steam_url);

                // Allow JavaScript to be used in the WebView.
                WebSettings webSettings = webView.Settings;
                webSettings.JavaScriptEnabled = true;
            };
        }
Пример #2
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set the view to UserProfile.
            SetContentView(Resource.Layout.UserProfile_Layout);

            // Add references to layout variables.
            Profile_Username          = FindViewById <TextView>(Resource.Id.profile_username);
            Profile_Followers         = FindViewById <TextView>(Resource.Id.profile_followers);
            Profile_EditButton        = FindViewById <ImageView>(Resource.Id.profile_edit_button);
            Profile_LogoutButton      = FindViewById <ImageView>(Resource.Id.profile_logout_button);
            Profile_VisitSteamProfile = FindViewById <ImageView>(Resource.Id.profile_visit_steam_button);
            Profile_SaveChanges       = FindViewById <ImageView>(Resource.Id.edit_profile_savechanges);
            Profile_Follow            = FindViewById <ImageView>(Resource.Id.profile_follow_button);
            Profile_Unfollow          = FindViewById <ImageView>(Resource.Id.profile_unfollow_button);
            Profile_Avatar            = FindViewById <ImageView>(Resource.Id.profile_image);
            Profile_EditOrigin        = FindViewById <EditText>(Resource.Id.origin_edit);
            Profile_EditTwitch        = FindViewById <EditText>(Resource.Id.uplay_edit);
            Profile_EditDiscord       = FindViewById <EditText>(Resource.Id.discord_edit);
            Profile_Discord           = FindViewById <TextView>(Resource.Id.profile_discord);
            Profile_Twitch            = FindViewById <TextView>(Resource.Id.profile_uplay);
            Profile_Origin            = FindViewById <TextView>(Resource.Id.profile_origin);
            Logo_Discord = FindViewById <ImageView>(Resource.Id.Discord);
            Logo_Uplay   = FindViewById <ImageView>(Resource.Id.Uplay);
            Logo_Origin  = FindViewById <ImageView>(Resource.Id.Origin);
            Current_Game = FindViewById <TextView>(Resource.Id.current_game);


            firebase_database = new DatabaseHandler();
            // Get the account of the current user (not the profile user)
            uaccount = await firebase_database.GetAccountAsync(FirebaseAuth.Instance.CurrentUser.Uid);

            //SET PROFILE DATA

            // Download profile picture.
            ExtensionMethods extensionMethods = new ExtensionMethods();

            extensionMethods.DownloadPicture(account.Avatar, Profile_Avatar);

            var followers = await firebase_database.GetUserFollowers(account);

            Profile_Username.Text  = account.Username;
            Profile_Followers.Text = $"Followers: {followers.Count}";

            Profile_VisitSteamProfile.Visibility = ViewStates.Visible;
            Profile_Follow.Visibility            = ViewStates.Visible;

            if (account.Discord?.Length > 0)
            {
                Profile_Discord.Text       = account.Discord;
                Profile_Discord.Visibility = ViewStates.Visible;
                Logo_Discord.Visibility    = ViewStates.Visible;
            }
            if (account.Twitch?.Length > 0)
            {
                Profile_Twitch.Text       = account.Twitch;
                Profile_Twitch.Visibility = ViewStates.Visible;
                Logo_Uplay.Visibility     = ViewStates.Visible;
            }
            if (account.Origin?.Length > 0)
            {
                Profile_Origin.Text       = account.Origin;
                Profile_Origin.Visibility = ViewStates.Visible;
                Logo_Origin.Visibility    = ViewStates.Visible;
            }
            Current_Game.Visibility = ViewStates.Gone;
            if (account.PlayingGameName != null && account.PlayingGameName != "")
            {
                // Check if player is currently playing a game and add it as a search option.
                Current_Game.Visibility = ViewStates.Visible;
                Current_Game.Text       = $"Currently Playing '{account.PlayingGameName}'";
            }

            if (uaccount.IsFollowing(account))
            {
                Profile_Follow.Visibility   = ViewStates.Gone;
                Profile_Unfollow.Visibility = ViewStates.Visible;
            }

            if (account.UserId == FirebaseAuth.Instance.CurrentUser.Uid)
            {
                // If the profile is owned by the user, show the edit and logout buttons.
                Profile_EditButton.Visibility   = ViewStates.Visible;
                Profile_LogoutButton.Visibility = ViewStates.Visible;
                Profile_Follow.Visibility       = ViewStates.Gone;
                Profile_Unfollow.Visibility     = ViewStates.Gone;
            }

            Profile_EditButton.Click += delegate
            {
                // Show the edit bar and save changes button.
                Profile_Follow.Visibility      = ViewStates.Gone;
                Profile_Unfollow.Visibility    = ViewStates.Gone;
                Profile_Origin.Visibility      = ViewStates.Gone;
                Profile_Twitch.Visibility      = ViewStates.Gone;
                Profile_Discord.Visibility     = ViewStates.Gone;
                Logo_Origin.Visibility         = ViewStates.Visible;
                Logo_Uplay.Visibility          = ViewStates.Visible;
                Logo_Discord.Visibility        = ViewStates.Visible;
                Profile_EditOrigin.Visibility  = ViewStates.Visible;
                Profile_EditTwitch.Visibility  = ViewStates.Visible;
                Profile_EditDiscord.Visibility = ViewStates.Visible;
                Profile_SaveChanges.Visibility = ViewStates.Visible;
                Profile_EditButton.Visibility  = ViewStates.Gone;
                Profile_EditDiscord.Text       = account.Discord;
                Profile_EditOrigin.Text        = account.Origin;
                Profile_EditTwitch.Text        = account.Twitch;
            };

            Profile_SaveChanges.Click += delegate
            {
                // Save the profile changes.
                // Remove edit bar and save changes button.
                SaveProfileChanges();
                ExtensionMethods.OpenUserProfile(account, this);
                Finish();
            };

            Profile_Follow.Click += delegate
            {
                // Add the uid to the followers of the current account.
                uaccount.Following.Add(account.UserId);
                Profile_Follow.Visibility   = ViewStates.Gone;
                Profile_Unfollow.Visibility = ViewStates.Visible;
                uaccount.Update();
                Profile_Followers.Text = $"Followers: {uaccount.Following.Count}";
            };

            Profile_Unfollow.Click += delegate
            {
                // Remove the uid from the followers of the current account.
                uaccount.Following.Remove(account.UserId);
                Profile_Unfollow.Visibility = ViewStates.Gone;
                Profile_Follow.Visibility   = ViewStates.Visible;
                uaccount.Update();
                Profile_Followers.Text = $"Followers: {followers.Count - 1}";
            };

            Profile_LogoutButton.Click += delegate
            {
                FirebaseAuth.Instance.SignOut();
                StartActivity(new Android.Content.Intent(this, typeof(AuthenticationActivity)));
            };

            Profile_VisitSteamProfile.Click += delegate
            {
                // Open WebView with Steam profile.
                SetContentView(Resource.Layout.WebView_Layout);
                webView            = FindViewById <WebView>(Resource.Id.webViewProfile);
                webView.Visibility = ViewStates.Visible;
                ExtendedWebViewClient webClient = new ExtendedWebViewClient();
                webView.SetWebViewClient(webClient);
                webView.LoadUrl("https://steamcommunity.com/profiles/" + account.SteamId);

                WebSettings webSettings = webView.Settings;
                webSettings.JavaScriptEnabled = true;
            };
        }