protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.uploadImage); //Firebase Init //FirebaseApp.InitializeApp(this); auth = FirebaseAuth.GetInstance(MainActivity.app); storage = FirebaseStorage.Instance; storageRef = storage.GetReferenceFromUrl("gs://fir-test-1bdb3.appspot.com/"); //Init View btnChoose = FindViewById <Button>(Resource.Id.btnChoose); btnUpload = FindViewById <Button>(Resource.Id.btnUpload); imgView = FindViewById <ImageView>(Resource.Id.imgView); //Events btnChoose.Click += delegate { ChooseImage(); }; btnUpload.Click += delegate { UploadImage(); }; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ViewInbox); Button timeStamp = FindViewById <Button>(Resource.Id.timeStamp); ImageView profilePicture = FindViewById <ImageView>(Resource.Id.profilePictureInbox); Button nameAndEmail = FindViewById <Button>(Resource.Id.nameAndEmailInbox); Button messageBody = FindViewById <Button>(Resource.Id.messageBodyInbox); Button next = FindViewById <Button>(Resource.Id.nextMessage); Button previous = FindViewById <Button>(Resource.Id.previousMessage); EditText replyText = FindViewById <EditText>(Resource.Id.replyBodyInbox); Button reply = FindViewById <Button>(Resource.Id.replyButton); circular_progress = FindViewById <ProgressBar>(Resource.Id.circularProgressInbox); nameAndEmail.Enabled = false; messageBody.Enabled = false; timeStamp.Enabled = false; auth = FirebaseAuth.GetInstance(MainActivity.app); toEmail = auth.CurrentUser.Email; circular_progress.Visibility = ViewStates.Visible; // Loading messages var firebase = new FirebaseClient("https://fir-test-1bdb3.firebaseio.com/"); var items = await firebase .Child("messages") .OnceAsync <MessageViewModel>(); // Loading users' data to get profile pictures var users = await firebase.Child("users").OnceAsync <UserViewModel>(); List <MessageViewModel> query = new List <MessageViewModel>(); // Filtering foreach (var item in items) { if (item.Object.ToEmail.Equals(toEmail)) { query.Add(item.Object); } } query.Reverse(); int messageNumber = 0; // To keep track of messages timeStamp.Text = query[messageNumber].Timestamp; foreach (var item in users) { if (item.Object.Email.Equals(query[messageNumber].FromEmail)) { if (!item.Object.PhotoURL.Equals(string.Empty)) { Glide.With(this).Load(item.Object.PhotoURL).Apply(RequestOptions.CircleCropTransform()).Into(profilePicture); } nameAndEmail.Text = item.Object.FirstName + " " + item.Object.LastName ?? ""; } } messageBody.Text = query[messageNumber].FromEmail + " says: \n\n" + query[messageNumber].Body; circular_progress.Visibility = ViewStates.Invisible; next.Click += (sender, e) => { int a = query.Count(); if (query.Count() - 1 == messageNumber) { // No new messages Toast.MakeText(ApplicationContext, "No more messages", ToastLength.Short).Show(); } else { circular_progress.Visibility = ViewStates.Visible; messageNumber++; timeStamp.Text = query[messageNumber].Timestamp; foreach (var item in users) { if (item.Object.Email.Equals(query[messageNumber].FromEmail)) { if (!item.Object.PhotoURL.Equals(string.Empty)) { Glide.With(this).Load(item.Object.PhotoURL).Apply(RequestOptions.CircleCropTransform()).Into(profilePicture); } nameAndEmail.Text = item.Object.FirstName + " " + item.Object.LastName ?? ""; } } messageBody.Text = query[messageNumber].FromEmail + " says: \n\n" + query[messageNumber].Body; circular_progress.Visibility = ViewStates.Invisible; } }; previous.Click += (sender, e) => { int a = query.Count(); if (messageNumber == 0) { // No new messages Toast.MakeText(ApplicationContext, "No more messages", ToastLength.Short).Show(); } else { circular_progress.Visibility = ViewStates.Visible; messageNumber--; timeStamp.Text = query[messageNumber].Timestamp; foreach (var item in users) { if (item.Object.Email.Equals(query[messageNumber].FromEmail)) { if (!item.Object.PhotoURL.Equals(string.Empty)) { Glide.With(this).Load(item.Object.PhotoURL).Apply(RequestOptions.CircleCropTransform()).Into(profilePicture); } nameAndEmail.Text = item.Object.FirstName + " " + item.Object.LastName ?? ""; } } messageBody.Text = query[messageNumber].FromEmail + " says: \n\n" + query[messageNumber].Body; circular_progress.Visibility = ViewStates.Invisible; } }; reply.Click += (sender, e) => { circular_progress.Visibility = ViewStates.Visible; if (!replyText.Text.Equals(string.Empty)) { var item = firebase.Child("messages") .PostAsync <MessageViewModel>(new MessageViewModel { ToEmail = query[messageNumber].FromEmail, FromEmail = auth.CurrentUser.Email, Body = replyText.Text.Trim(), Timestamp = DateTime.Now.ToString() }); replyText.Text = string.Empty; Toast.MakeText(ApplicationContext, "Message Sent", ToastLength.Short).Show(); } else { Toast.MakeText(ApplicationContext, "Enter a reply first", ToastLength.Short).Show(); } circular_progress.Visibility = ViewStates.Invisible; }; /* * string[] messages = new string[query.Count()]; * * for (int i = 0; i < query.Count(); i++) * { * messages[i] = query.ToList().ElementAt(i).Timestamp + "\n" + query.ToList().ElementAt(i).Body + "\n - " + query.ToList().ElementAt(i).FromEmail; * * } * ListAdapter = new ArrayAdapter<string>(this, Resource.Layout.ViewInbox, messages); * * ListView.ItemClick += (sender, e) => * { * string recipient = string.Empty; * recipient = ((TextView)e.View).Text; * string[] temps = recipient.Split(' '); * recipient = temps[temps.Length - 1]; * Intent sendMessageActivity = new Intent(ApplicationContext, typeof(MessageSendActivity)); * sendMessageActivity.PutExtra("toEmail", recipient); * HomeActivity.fromHome = false; * StartActivity(sendMessageActivity); * }; */ }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Home); // Initating Preferences for Logout Platform.Init(this, bundle); auth = FirebaseAuth.GetInstance(MainActivity.app); Button addTournament = FindViewById <Button>(Resource.Id.addTournament); Button logout = FindViewById <Button>(Resource.Id.logout); Button editProfile = FindViewById <Button>(Resource.Id.editProfile); Button sendMessage = FindViewById <Button>(Resource.Id.sendMessage); Button viewInbox = FindViewById <Button>(Resource.Id.viewInbox); Button viewProfile = FindViewById <Button>(Resource.Id.viewProfile); Button viewTournaments = FindViewById <Button>(Resource.Id.viewTournaments); Button viewSocialFeed = FindViewById <Button>(Resource.Id.viewSocialFeed); TextView homeMessage = FindViewById <TextView>(Resource.Id.welcomeMessageHome); // Modifying HomeMessage text homeMessage.Text += "\n" + auth.CurrentUser.Email; //if (!MainActivity.decision.Equals("Login as Admin")) // A player cannot add a tournament // addTournament.Text = "Add Gamer Tag"; // Checking email verification if (auth != null) { if (!auth.CurrentUser.IsEmailVerified) { auth.CurrentUser.SendEmailVerification(); homeMessage.Text = "\nEmail not verified yet! Check your inbox"; addTournament.Enabled = false; editProfile.Enabled = false; sendMessage.Enabled = false; viewInbox.Enabled = false; viewProfile.Enabled = false; viewTournaments.Enabled = false; viewSocialFeed.Enabled = false; } } viewSocialFeed.Click += (sender, e) => { Intent viewSocialActivity = new Intent(Application.Context, typeof(SocialFeedActivity)); StartActivity(viewSocialActivity); }; viewTournaments.Click += (sender, e) => { Intent viewTournamentsActivity = new Intent(Application.Context, typeof(ViewTournamentsActivity)); StartActivity(viewTournamentsActivity); }; addTournament.Click += (sender, e) => { if (!MainActivity.decision.Equals("Login as Admin")) // Player is adding gamer tags { Intent addGamerTag = new Intent(Application.Context, typeof(AddGamerTagActivity)); StartActivity(addGamerTag); } else // Admin is adding tournaments { fromHome = true; Intent addTournamentActivity = new Intent(Application.Context, typeof(AddTournamentActivity)); StartActivity(addTournamentActivity); } }; viewInbox.Click += (sender, e) => { fromHome = true; Intent viewInboxActivity = new Intent(Application.Context, typeof(ViewInboxActivity)); StartActivity(viewInboxActivity); }; sendMessage.Click += (sender, e) => { fromHome = true; Intent sendMessageActivity = new Intent(Application.Context, typeof(MessageSendActivity)); StartActivity(sendMessageActivity); }; logout.Click += (sender, e) => { auth.SignOut(); if (auth.CurrentUser == null) { Preferences.Remove("email"); Preferences.Remove("password"); Preferences.Remove("decision"); StartActivity(new Intent(this, typeof(MainActivity))); Finish(); } }; viewProfile.Click += (sender, e) => { fromHome = true; Intent viewProfileActivity = new Intent(Application.Context, typeof(ViewProfileActivity)); StartActivity(viewProfileActivity); }; editProfile.Click += (sender, e) => { Intent editProfileActivity = new Intent(Application.Context, typeof(ProfileEditActivity)); StartActivity(editProfileActivity); }; }
protected override void OnCreate(Bundle savedInstanceState) { // Getting current location fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); Task.Run(GetLastLocationFromDevice); base.OnCreate(savedInstanceState); auth = FirebaseAuth.GetInstance(MainActivity.app); mDatabase = FirebaseDatabase.Instance.Reference; tourneyID = Intent.GetStringExtra("tourneyID") ?? "None"; SetContentView(Resource.Layout.AddLocation); // Adding location button Button currentLocationButton = FindViewById <Button>(Resource.Id.currentLocationButton); currentLocationButton.Click += (sender, e) => { CameraPosition.Builder builder = CameraPosition.InvokeBuilder(); builder.Target(coords); builder.Zoom(18); builder.Bearing(155); builder.Tilt(65); CameraPosition cameraPosition = builder.Build(); CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition); if (_map != null) { // Puttin a marker in this location for admin to move around MarkerOptions tournamentLocationMarker = new MarkerOptions(); tournamentLocationMarker.SetPosition(coords); tournamentLocationMarker.SetTitle("Tournament Location"); tournamentLocationMarker.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan)); tournamentLocationMarker.Draggable(true); _map.MarkerDragEnd += MapOnMarkerDragEnd; _map.AddMarker(tournamentLocationMarker); // Moving Camera _map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(cameraPosition)); // Setting current location as tournament location in case admin does not want to change var coordinates = coords.Latitude + "," + coords.Longitude; mDatabase.Child("tournaments").Child(tourneyID).Child("location").SetValueAsync(coordinates); // Changing button text currentLocationButton.Text = "Tournament Location"; } else { Toast.MakeText(ApplicationContext, "Wait for location to load..", ToastLength.Long); } }; // Adding Save location button Button saveLocationButton = FindViewById <Button>(Resource.Id.saveLocationButton); saveLocationButton.Click += async(sender, e) => { if (coords != null) { await mDatabase.Child("tournaments").Child(tourneyID).Child("online").SetValueAsync("false"); // Going back to Tournament Main page Intent addTournamentActivity = new Intent(Application.Context, typeof(AddTournamentActivity)); addTournamentActivity.PutExtra("tourneyID", tourneyID); StartActivity(addTournamentActivity); Finish(); } else { Toast.MakeText(ApplicationContext, "Load Current Location and move Marker First", ToastLength.Long); } }; InitMapFragment(); }
protected override async void OnCreate(Bundle savedInstanceState) { auth = FirebaseAuth.GetInstance(MainActivity.app); mDatabase = FirebaseDatabase.Instance.Reference; tourneyID = Intent.GetStringExtra("tourneyID") ?? "None"; // It will be initiated if existing tournament is being edited base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.AddTournament); // Adding Components Button addTournament = FindViewById <Button>(Resource.Id.addTournamentInfo); Button addLocation = FindViewById <Button>(Resource.Id.addLocation); CheckBox LANEvent = FindViewById <CheckBox>(Resource.Id.LANEvent); Button saveInfoButton = FindViewById <Button>(Resource.Id.saveInfo); Button cancelInfoButton = FindViewById <Button>(Resource.Id.cancelInfo); Button liveButton = FindViewById <Button>(Resource.Id.tournamentLiveButton); Button noOfParticipants = FindViewById <Button>(Resource.Id.participantsNumberTourneyPage); cancelInfoButton.Text = "Delete"; noOfParticipants.Enabled = false; if (tourneyID.Equals("None")) // New tournament creation { LANEvent.Checked = false; addLocation.Enabled = false; // tourneyID = Guid.NewGuid().ToString(); var firebase = new FirebaseClient("https://fir-test-1bdb3.firebaseio.com/"); var item = await firebase.Child("tournaments") .PostAsync <TournamentViewModel>(new TournamentViewModel { AdminID = auth.CurrentUser.Email, TournamentID = "", online = "true", Format = "Knockout", Live = "false", // shows that is is not published yet Description = "", Game = "Game not set yet", Finished = "false" }); await mDatabase.Child("tournaments").Child(item.Key).Child("TournamentID").SetValueAsync(item.Key); tourneyID = item.Key; } else { FirebaseClient firebase = new FirebaseClient("https://fir-test-1bdb3.firebaseio.com/tournaments/"); var items = await firebase .Child("") .OnceAsync <TournamentViewModel>(); foreach (var item in items) { if (item.Key.Equals(tourneyID)) { if (item.Object.online.Equals("true")) { addLocation.Enabled = false; LANEvent.Checked = false; } if (item.Object.Live.Equals("true")) { addLocation.Enabled = false; LANEvent.Enabled = false; addTournament.Enabled = false; } int number; bool result = int.TryParse(item.Object.ParticipantsLimit, out number); if (result) { if (item.Object.Participants != null) { players = item.Object.Participants.Split(','); noOfParticipants.Text = "Registered: " + (players.Count()) + "/" + number; tourneyTitle = item.Object.Title; if (players.Count() != number) { liveButton.Enabled = false; } } else { noOfParticipants.Text = "Registered: " + "0/" + number; liveButton.Enabled = false; } } else { liveButton.Enabled = false; } break; } } } liveButton.Click += async(sender, e) => { await mDatabase.Child("tournaments").Child(tourneyID).Child("Live").SetValueAsync("true"); Toast.MakeText(ApplicationContext, "Tournament is now live! You cannot change any info now.", ToastLength.Long).Show(); addLocation.Enabled = false; LANEvent.Enabled = false; addTournament.Enabled = false; // 1: GENERATE BRACKET WHEN TOURNAMENT GOES LIVE HERE!! var url = "https://api.challonge.com/v1/tournaments.json?api_key=nzFuvS0FNlSVr7KWKdTpoCqP4EXhPAlyMccTfIyy&tournament[name]=" + tourneyTitle.Trim() + "&tournament[url]=" + tourneyTitle.Trim() + "_" + tourneyTitle.Trim() + "UltimateESports" + "&tournament[open_signup]=false&tournament[description]=" + "To be added here. This space is for rules" + "&tournament[show_rounds]=true&tournament[signup_cap]=" + players.Count(); // Create an HTTP web request using the URL: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); request.ContentType = "application/json"; request.Method = "POST"; request.ContentLength = 0; request.Timeout = 300000; // For use in next function string urlFull; // Send the request to the server and wait for the response: using (WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (Stream stream = response.GetResponseStream()) { // Use this stream to build a JSON document object: JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream)); //JsonValue a = jsonDoc[0]; JsonValue tourney = jsonDoc["tournament"]; string BracketID = tourney["full_challonge_url"]; urlFull = tourney["url"]; await mDatabase.Child("tournaments").Child(tourneyID).Child("BracketID").SetValueAsync(urlFull); await mDatabase.Child("tournaments").Child(tourneyID).Child("BracketURL").SetValueAsync(BracketID); //Console.Out.WriteLine("Response: {0}", jsonDoc.ToString()); } } // Add Players to the bracket foreach (var name in players) { string addParticipant = "https://api.challonge.com/v1/tournaments/" + urlFull + "/participants.json?participant[name]=" + name + "&api_key=nzFuvS0FNlSVr7KWKdTpoCqP4EXhPAlyMccTfIyy"; request = (HttpWebRequest)HttpWebRequest.Create(new Uri(addParticipant)); request.ContentType = "application/json"; request.Method = "POST"; request.ContentLength = 0; using (WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (Stream stream = response.GetResponseStream()) { // Use this stream to build a JSON document object: JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream)); Console.Out.WriteLine("Response: {0}", jsonDoc.ToString()); } } } // Starting the tournament url = "https://api.challonge.com/v1/tournaments/" + urlFull + "/start.json?api_key=nzFuvS0FNlSVr7KWKdTpoCqP4EXhPAlyMccTfIyy"; request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); request.ContentType = "application/json"; request.Method = "POST"; request.ContentLength = 0; using (WebResponse response = await request.GetResponseAsync()) { // Get a stream representation of the HTTP web response: using (Stream stream = response.GetResponseStream()) { // Use this stream to build a JSON document object: JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream)); Console.Out.WriteLine("Response: {0}", jsonDoc.ToString()); } } // 2: SEND MESSAGE TO ALL PARTICIPANTS FOR TOURNAMENT START !! var firebase = new FirebaseClient("https://fir-test-1bdb3.firebaseio.com/"); foreach (var name in players) { string message = tourneyTitle + "has just started."; await firebase.Child("messages") .PostAsync <MessageViewModel>(new MessageViewModel { ToEmail = name, FromEmail = auth.CurrentUser.Email, Body = message, Timestamp = DateTime.Now.ToString() }); } }; cancelInfoButton.Click += async(sender, e) => { // Heading to Home Page var homeActivity = new Intent(Application.Context, typeof(HomeActivity)); await mDatabase.Child("tournaments").Child(tourneyID).RemoveValueAsync(); StartActivity(homeActivity); Finish(); }; saveInfoButton.Click += (sender, e) => { // Heading to Home Page var homeActivity = new Intent(Application.Context, typeof(HomeActivity)); StartActivity(homeActivity); Finish(); }; // Button actions addTournament.Click += (sender, e) => { Intent addTournamentInfoActivity = new Intent(Application.Context, typeof(AddTournamentInfoActivity)); addTournamentInfoActivity.PutExtra("tourneyID", tourneyID); StartActivity(addTournamentInfoActivity); }; addLocation.Click += (sender, e) => { // setting tournament as LAN Intent addLocationActivity = new Intent(Application.Context, typeof(AddLocationActivity)); addLocationActivity.PutExtra("tourneyID", tourneyID); StartActivity(addLocationActivity); }; // Checkbox action LANEvent.Click += async(sender, e) => { if (LANEvent.Checked) { addLocation.Enabled = true; await mDatabase.Child("tournaments").Child(tourneyID).Child("online").SetValueAsync("false"); } else { addLocation.Enabled = false; await mDatabase.Child("tournaments").Child(tourneyID).Child("online").SetValueAsync("true"); } }; }