protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_login); this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); this.Window.ClearFlags(WindowManagerFlags.TranslucentStatus); this.Window.SetStatusBarColor(Color.ParseColor("#204060")); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); googlebutton = FindViewById <Button>(Resource.Id.googlebutton); googlebutton.Click += Googlebutton_Click; facebookbutton = FindViewById <Button>(Resource.Id.facebookbutton); facebookbutton.Click += Facebookbutton_Click; fb_dummybuttton = FindViewById <LoginButton>(Resource.Id.fb_dummybuttton); fb_dummybuttton.SetReadPermissions(new List <string> { "public_profile", "email" }); callbackManager = CallbackManagerFactory.Create(); fb_dummybuttton.RegisterCallback(callbackManager, this); gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn).RequestIdToken("787402240794-prndui4ntngl1je2lglu46lev1esogsi.apps.googleusercontent.com") .RequestEmail().Build(); googleApiClient = new GoogleApiClient.Builder(this).AddApi(Auth.GOOGLE_SIGN_IN_API, gso).Build(); googleApiClient.Connect(); firebaseAuth = AppDataHelper.GetFirebaseAuth(); prefs = PreferenceManager.GetDefaultSharedPreferences(this); AppDataHelper.editor = prefs.Edit(); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment View view = inflater.Inflate(Resource.Layout.Account, container, false); mTxtEmail = (TextView)view.FindViewById(Resource.Id.profileEmail); mTxtName = (TextView)view.FindViewById(Resource.Id.profileName); mTxtPhone = (TextView)view.FindViewById(Resource.Id.profileNumber); mBtnSignOut = (Button)view.FindViewById(Resource.Id.dashboardLogout); if (AppDataHelper.GetCurrentUser() != null) { var user = AppDataHelper.GetCurrentUser(); mTxtEmail.Text = user.Email; } ; database = AppDataHelper.GetDatabase(); mAuth = AppDataHelper.GetFirebaseAuth(); currentUser = AppDataHelper.GetCurrentUser(); string driverID = AppDataHelper.GetCurrentUser().Uid; FirebaseDatabase.Instance.Reference.Child("drivers/" + driverID) .AddListenerForSingleValueEvent(new DataValueEventListener()); mBtnSignOut.Click += MBtnSignOut_Click; return(view); }
public void FetchUser() { //This will retrieve a document snapshot that is going to contain information about this particular user AppDataHelper.GetFirestore().Collection("users").Document(AppDataHelper.GetFirebaseAuth() .CurrentUser.Uid).Get() .AddOnSuccessListener(this); }
private void LoginButton_Click(object sender, EventArgs e) { mAuth = AppDataHelper.GetFirebaseAuth(); string email, password; email = emailText.EditText.Text; password = passwordText.EditText.Text; if (!email.Contains("@")) { Snackbar.Make(rootView, "Please Provide a valid Email", Snackbar.LengthShort).Show(); return; } else if (password.Length < 3) { Snackbar.Make(rootView, "Please Provide a valid Password", Snackbar.LengthShort).Show(); return; } TaskCompletionListener taskCompletionListener = new TaskCompletionListener(); taskCompletionListener.Success += TaskCompletionListener_Success; taskCompletionListener.Failure += TaskCompletionListener_Failure; mAuth.SignInWithEmailAndPassword(email, password) .AddOnSuccessListener(taskCompletionListener) .AddOnFailureListener(taskCompletionListener); }
private void PostAdapter_ItemLongClick(object sender, PostAdapterClickEventArgs e) { string postID = ListOfPost[e.Position].ID; string ownerID = ListOfPost[e.Position].OwnerId; if (AppDataHelper.GetFirebaseAuth().CurrentUser.Uid == ownerID) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetTitle("Edit or Delete Post"); alert.SetMessage("Are you sure"); alert.SetNegativeButton("Edit Post", (o, args) => { EditPostFragment editPostFragment = new EditPostFragment(ListOfPost[e.Position]); var trans = SupportFragmentManager.BeginTransaction(); editPostFragment.Show(trans, "edit"); }); alert.SetPositiveButton("Delete", (o, args) => { AppDataHelper.GetFirestore().Collection("posts").Document(postID).Delete(); StorageReference storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postID); storageReference.Delete(); }); alert.Show(); } }
void OrganizedData(Java.Lang.Object value) { var snapshot = (QuerySnapshot)value; if (!snapshot.IsEmpty) { if (ListOfPost.Count > 0) { ListOfPost.Clear(); } foreach (DocumentSnapshot item in snapshot.Documents) { Post post = new Post(); post.ID = item.Id; post.PostBody = item.Get("post_body") != null?item.Get("post_body").ToString() : ""; post.Author = item.Get("author") != null?item.Get("author").ToString() : ""; post.ImageId = item.Get("image_id") != null?item.Get("image_id").ToString() : ""; post.OwnerId = item.Get("owner_id") != null?item.Get("owner_id").ToString() : ""; post.DownloadUrl = item.Get("download_url") != null?item.Get("download_url").ToString() : ""; string datestring = item.Get("post_date") != null?item.Get("post_date").ToString() : ""; post.PostDate = DateTime.ParseExact(datestring, @"dd/MM/yyyy HH:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture); var data = item.Get("likes") != null?item.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); //retrieve our own id string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; //check the number of users liked the post post.LikeCount = dictionaryFromHashMap.Count; //verifies if we liked the post or not. if (dictionaryFromHashMap.Contains(uid)) { post.Liked = true; } } ListOfPost.Add(post); } OnPostRetrieved?.Invoke(this, new PostEventArgs { Posts = ListOfPost }); } }
private void SubmitButton_Click(object sender, EventArgs e) { HashMap postMap = new HashMap(); postMap.Put("author", AppDataHelper.GetFullName()); postMap.Put("owner_id", AppDataHelper.GetFirebaseAuth().CurrentUser.Uid); postMap.Put("post_date", DateTime.Now.ToString()); postMap.Put("post_body", postEditText.Text); DocumentReference newPostRef = AppDataHelper.GetFirestore().Collection("posts").Document(); string postKey = newPostRef.Id; postMap.Put("image_id", postKey); ShowProgressDialogue("Saving Information ..."); // Save Post Image to Firebase Storaage StorageReference storageReference = null; if (fileBytes != null) { storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postKey); storageReference.PutBytes(fileBytes) .AddOnSuccessListener(taskCompletionListeners) .AddOnFailureListener(taskCompletionListeners); } // Image Upload Success Callback taskCompletionListeners.Sucess += (obj, args) => { if (storageReference != null) { storageReference.DownloadUrl.AddOnSuccessListener(downloadUrlListener); } }; // Image Download URL Callback downloadUrlListener.Sucess += (obj, args) => { string downloadUrl = args.Result.ToString(); postMap.Put("download_url", downloadUrl); // Save post to Firebase Firestore newPostRef.Set(postMap); CloseProgressDialogue(); Finish(); }; // Image Upload Failure Callback taskCompletionListeners.Failure += (obj, args) => { Toast.MakeText(this, "Upload was not completed", ToastLength.Short).Show(); }; }
void InitializeFirebase() { //Firebase Init database = AppDataHelper.GetDatabase(); mAuth = AppDataHelper.GetFirebaseAuth(); currentUser = AppDataHelper.GetCurrentUser(); FirebaseApp.InitializeApp(this); //storage = FirebaseStorage.Instance; }
void OrganizeData(Java.Lang.Object Value) { var snapshot = (QuerySnapshot)Value; if (!snapshot.IsEmpty) { if (ListOfPost.Count > 0) { ListOfPost.Clear(); } foreach (DocumentSnapshot item in snapshot.Documents) { Post post = new Post(); post.ID = item.Id; post.PostBody = item.Get("post_body") != null?item.Get("post_body").ToString() : ""; post.Author = item.Get("author") != null?item.Get("author").ToString() : ""; post.ImageId = item.Get("image_id") != null?item.Get("image_id").ToString() : ""; post.OwnerId = item.Get("owner_id") != null?item.Get("owner_id").ToString() : ""; post.DownloadUrl = item.Get("download_url") != null?item.Get("download_url").ToString() : ""; string datestring = item.Get("post_date") != null?item.Get("post_date").ToString() : ""; post.PostDate = DateTime.Parse(datestring); var data = item.Get("likes") != null?item.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; post.LikeCount = dictionaryFromHashMap.Count; if (dictionaryFromHashMap.Contains(uid)) { post.Liked = true; } } ListOfPost.Add(post); } OnPostRetrieved?.Invoke(this, new PostEventArgs { Posts = ListOfPost }); } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_Splash); firebaseAuth = AppDataHelper.GetFirebaseAuth(); } catch (Exception ex) { } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AddSlide(SampleSlide.NewInstance(Resource.Layout.Intro1)); AddSlide(SampleSlide.NewInstance(Resource.Layout.Intro2)); AddSlide(SampleSlide.NewInstance(Resource.Layout.Intro3)); SetFlowAnimation(); SetColorSkipButton(Color.ParseColor("#ffffff")); SetColorDoneText(Color.ParseColor("#ffffff")); SetNextArrowColor(Color.ParseColor("#204060")); SetIndicatorColor(Color.ParseColor("#204060"), Color.ParseColor("#bdd3e9")); firebaseAuth = AppDataHelper.GetFirebaseAuth(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.login); emailText = (TextInputLayout)FindViewById(Resource.Id.emailLoginText); passwordText = (TextInputLayout)FindViewById(Resource.Id.passwordLoginText); loginButton = (Button)FindViewById(Resource.Id.loginButton); clickToRegister = (TextView)FindViewById(Resource.Id.clickToRegister); clickToRegister.Click += ClickToRegister_Click; loginButton.Click += LoginButton_Click; mAuth = AppDataHelper.GetFirebaseAuth(); }
protected override void OnResume() { base.OnResume(); FirebaseUser currentUser = AppDataHelper.GetFirebaseAuth().CurrentUser; if (currentUser != null) { StartActivity(typeof(MainActivity)); Finish(); } else { StartActivity(typeof(LoginActivity)); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.register); fullnameText = (TextInputLayout)FindViewById(Resource.Id.fullNameRegText); emailText = (TextInputLayout)FindViewById(Resource.Id.emailRegText); passwordText = (TextInputLayout)FindViewById(Resource.Id.passwordRegText); confirmPasswordText = (TextInputLayout)FindViewById(Resource.Id.confirmPasswordRegText); clickHereToLogin = (TextView)FindViewById(Resource.Id.clickToLogin); clickHereToLogin.Click += ClickHereToLogin_Click; registerButton = (Button)FindViewById(Resource.Id.registerButton); registerButton.Click += RegisterButton_Click; database = AppDataHelper.GetFirestore(); mAuth = AppDataHelper.GetFirebaseAuth(); }
protected override void OnResume() { base.OnResume(); //this will return an instance of firebase user FirebaseUser currentUser = AppDataHelper.GetFirebaseAuth().CurrentUser; //If current user is not null, the user is already logged in if (currentUser != null) { StartActivity(typeof(MainActivity)); Finish(); } else if (currentUser == null) { StartActivity(typeof(LoginActivity)); } }
public void OnSuccess(Java.Lang.Object result) { DocumentSnapshot snapshot = (DocumentSnapshot)result; if (!snapshot.Exists()) { return; } DocumentReference likeReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID); if (like) { likeReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true); } else { //check for null if (snapshot.Get("likes") == null) { return; } var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); //retrieve our own id string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; //check if our user ID is contained inside the dictionary if (dictionaryFromHashMap.Contains(uid)) { //remove our user ID to unlike the post dictionaryFromHashMap.Remove(uid); //update the hashmap withour our userid included likeReference.Update("likes", dictionaryFromHashMap); } } } }
//Whenever the user clicks the menu, this item will be called public override bool OnOptionsItemSelected(IMenuItem item) { int id = item.ItemId; if (id == Resource.Id.action_logout) { postEventListener.RemoveListener(); AppDataHelper.GetFirebaseAuth().SignOut(); StartActivity(typeof(LoginActivity)); Finish(); } if (id == Resource.Id.action_refresh) { Toast.MakeText(this, "Refresh was clicked", ToastLength.Short).Show(); } return(base.OnOptionsItemSelected(item)); }
public void ShowDialog() { sweetAlert = new SweetAlertDialog(Context, SweetAlertDialog.WarningType); sweetAlert.SetContentText("Your session will be dismissed and all unsaved data lost. Continue?"); sweetAlert.SetTitleText("Log out?"); sweetAlert.SetConfirmText("Yes"); sweetAlert.SetCancelText("No"); sweetAlert.SetConfirmClickListener(new SweetConfirmClick(alert => { editor = preferences.Edit(); editor.PutString("firstRun", "reg"); editor.Commit(); AppDataHelper.GetFirebaseAuth().SignOut(); var intent = new Intent(Context, typeof(SplashActivity)); StartActivity(intent); alert.DismissWithAnimation(); })); sweetAlert.Show(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.register); fullnameText = (TextInputLayout)FindViewById(Resource.Id.fullNameRegText); emailText = (TextInputLayout)FindViewById(Resource.Id.emailRegText); passwordText = (TextInputLayout)FindViewById(Resource.Id.passwordRegText); confirmPasswordText = (TextInputLayout)FindViewById(Resource.Id.confirmPasswordRegText); clickHereToLogin = (TextView)FindViewById(Resource.Id.clickToLogin); clickHereToLogin.Click += ClickHereToLogin_Click; registerButton = (Button)FindViewById(Resource.Id.registerButton); registerButton.Click += RegisterButton_Click; //whenver we call the GetFirestore() method, it will return an instance of our firebase firestore. database = AppDataHelper.GetFirestore(); //Instantiate firebase authentication mAuth = AppDataHelper.GetFirebaseAuth(); }
public void OnSuccess(Java.Lang.Object result) { DocumentSnapshot snapshot = (DocumentSnapshot)result; if (!snapshot.Exists()) { return; } DocumentReference likesReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID); if (Like) { likesReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true); } else { if (snapshot.Get("likes") == null) { return; } var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; if (dictionaryFromHashMap.Contains(uid)) { dictionaryFromHashMap.Remove(uid); likesReference.Update("likes", dictionaryFromHashMap); } } } }
void InitializeFirebase() { mAuth = AppDataHelper.GetFirebaseAuth(); currentUser = AppDataHelper.GetCurrentUser(); database = AppDataHelper.GetDatabase(); }
private void InitializeFirebase() { _mAuth = AppDataHelper.GetFirebaseAuth(); AppDataHelper.GetCurrentUser(); AppDataHelper.GetDatabase(); }
public void FetchUser() { AppDataHelper.GetFirestore().Collection("users").Document(AppDataHelper.GetFirebaseAuth().CurrentUser.Uid).Get() .AddOnSuccessListener(this); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); CurrentUserUid = Intent.GetStringExtra("CurrentUserUid"); CurrentUserDisplayName = Intent.GetStringExtra("CurrentUserDisplayName"); //CurrentUserEmail = Intent.GetStringExtra("CurrentUserEmail"); CurrentUserPhoto = Intent.GetStringExtra("CurrentUserPhoto"); // var ButtonClickStatus = Intent.GetStringExtra("ButtonClickStatus"); database = AppDataHelper.GetDatabase(); firebaseAuth = AppDataHelper.GetFirebaseAuth(); this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); this.Window.ClearFlags(WindowManagerFlags.TranslucentStatus); this.Window.SetStatusBarColor(Color.ParseColor("#204060")); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); toolbar.SetNavigationOnClickListener(this); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetDisplayShowTitleEnabled(true); // SupportActionBar.SetHomeButtonEnabled(true); SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.baseline_notes_24); nodataicon = FindViewById <ImageView>(Resource.Id.nodataicon); homeText = FindViewById <TextView>(Resource.Id.homeText); statsText = FindViewById <TextView>(Resource.Id.statsText); calendarpickericon = FindViewById <ImageView>(Resource.Id.calendarpickericon); calendarpickericon.SetColorFilter(Color.ParseColor("#04040C")); drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); drawerLayout.AddDrawerListener(this); navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetNavigationItemSelectedListener(this); View headerView = navigationView.GetHeaderView(0); navheader_username = headerView.FindViewById <TextView>(Resource.Id.navheader_username); navheader_username.Text = CurrentUserDisplayName; ProfilePic = headerView.FindViewById <ImageView>(Resource.Id.ProfilePic); versionno = FindViewById <TextView>(Resource.Id.versionno); versionno.Text = "v " + Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName; //Android.Net.Uri myUri = Android.Net.Uri.Parse(CurrentUserPhoto); //if (CrossConnectivity.Current.IsConnected) //{ // var imageBitmap = GetImageBitmapFromUrl(CurrentUserPhoto); // ProfilePic.SetImageBitmap(imageBitmap); //} Picasso.Get().Load(CurrentUserPhoto).Placeholder(Resource.Drawable.icon).Into(ProfilePic); // ProfilePic.SetImageURI(myUri); //ProfilePic.SetImageURI(CurrentUserPhoto); recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView); nestedscroolview = FindViewById <NestedScrollView>(Resource.Id.nestedscroolview); MarginItemDecoration_Hor marginItemDecoration_Hor = new MarginItemDecoration_Hor(15, true, true); recyclerView.AddItemDecoration(marginItemDecoration_Hor); prefs = PreferenceManager.GetDefaultSharedPreferences(this); AppDataHelper.editor = prefs.Edit(); var mString = prefs.GetString("CurrencySymbolSelected", ""); if (mString == "") { AppDataHelper.editor.PutString("CurrencySymbolSelected", GetString(Resource.String.Rs)); AppDataHelper.editor.PutString("CurrencyTextSelected", GetString(Resource.String.RsCurrency)); AppDataHelper.editor.Apply(); } var mStringOrderBySelected = prefs.GetString("OrderBySelected", ""); if (mStringOrderBySelected == "") { AppDataHelper.editor.PutString("OrderBySelected", "DateDay"); AppDataHelper.editor.Apply(); } //else //{ //} totalexpenseVALUE = FindViewById <TextView>(Resource.Id.totalexpenseVALUE); totalexpenseVALUE.Text = prefs.GetString("CurrencySymbolSelected", "") + "0"; Datetxt = FindViewById <TextView>(Resource.Id.Datetxt); Datetxt.Text = DateTime.Now.DayOfWeek + ", " + DateTime.Today.Day + " " + DateTime.Now.ToString("MMMM", CultureInfo.InvariantCulture) + " " + DateTime.Today.Year; YearSelected = DateTime.Today.Year.ToString(); MonthSelected = DateTime.Now.ToString("MMMM", CultureInfo.InvariantCulture); homeText.SetCompoundDrawablesWithIntrinsicBounds(null, GetDrawable(Resource.Drawable.baseline_home_24), null, null); statsText.SetCompoundDrawablesWithIntrinsicBounds(null, GetDrawable(Resource.Drawable.outline_insert_chart_24), null, null); homeText.Click += HomeText_Click; statsText.Click += StatsText_Click; fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += Fab_Click; if (VersionTracking.IsFirstLaunchEver) { currencyModal_Fragment = new CurrencyModal_Fragment(); var trans = SupportFragmentManager.BeginTransaction(); currencyModal_Fragment.Show(trans, "Currency"); } calendarpickericon.Click += Calendartxt_Click; TotalExpenseValue = new List <string>(); parentObjects = new List <IParentObject>(); SetupVerticalRecyclerView(); DisplayAndBindMonthRecyclerView(); int day = DateTime.Now.Day; int month = DateTime.Now.Month - 1; int year = DateTime.Now.Year; picker = new DatePickerDialog(this); picker.UpdateDate(year, month, day); bottomAppBar = FindViewById <BottomAppBar>(Resource.Id.bar); childListsearch = new List <ExpenseItemChild>(); //FetchAndListenExpensesTable(); recyclerView.SetOnClickListener(this); }
private void SetupFireBase() { _database = AppDataHelper.GetDatabase(); _mAuth = AppDataHelper.GetFirebaseAuth(); AppDataHelper.GetCurrentUser(); }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); var emailText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signin_email_et); var passText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signin_pass_et); var forgotPassBtn = view.FindViewById <MaterialButton>(Resource.Id.btn_forgot_pass); forgotPassBtn.Click += (s1, e1) => { ForgotPassFragment passFragment = new ForgotPassFragment(); AndroidX.Fragment.App.FragmentTransaction ft = ChildFragmentManager.BeginTransaction(); ft.Add(passFragment, "forgot_pass_fragment"); ft.CommitAllowingStateLoss(); }; var continueFab = view.FindViewById <FloatingActionButton>(Resource.Id.fab1); continueFab.Click += (s2, e2) => { bool enabled = !(!Patterns.EmailAddress.Matcher(emailText.EditText.Text).Matches() || passText.EditText.Text.Length < 8); switch (enabled) { case false: Toast.MakeText(Activity, "A valid email and password is required", ToastLength.Short).Show(); break; default: { //showProgress OnboardingActivity.ShowProgressDialog(); AppDataHelper.GetFirebaseAuth().SignInWithEmailAndPassword(emailText.EditText.Text, passText.EditText.Text) .AddOnCompleteListener(new OnCompleteListener(t => { if (t.IsSuccessful) { var dataRef = AppDataHelper.GetDatabase().GetReference("Drivers/" + AppDataHelper.GetCurrentUser().Uid); dataRef.AddValueEventListener(new SingleValueListener(d => { if (!d.Exists()) { return; } var stage = (d.Child(StringConstants.StageofRegistration) != null) ? d.Child(StringConstants.StageofRegistration).Value.ToString() : ""; if (stage != $"{RegistrationStage.RegistrationDone}") { editor = preferences.Edit(); editor.PutString("firstRun", "reg"); editor.Commit(); OnboardingActivity.CloseProgressDialog(); onRegUncompleteListener?.Invoke(this, new RegUncompleteArgs { StageReached = stage }); } else { editor = preferences.Edit(); editor.PutString("firstRun", "regd"); editor.Commit(); var intent = new Intent(Context, typeof(MainActivity)); intent.SetFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask); StartActivity(intent); } }, e => { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (DatabaseException) { OnboardingActivity.ShowErrorDialog("Database exeption"); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("Something went wrong, please retry"); } })); } else { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (FirebaseAuthInvalidCredentialsException) { OnboardingActivity.ShowErrorDialog("Your email or password is incorrect. Please try again."); } catch (FirebaseAuthInvalidUserException) { OnboardingActivity.ShowErrorDialog("We can't find an account with this email address. Please try again or create a new account."); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("We couldn't sign you in at this time. Please retry"); } } })); break; } } }; }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); SubmitBtn = view.FindViewById <MaterialButton>(Resource.Id.drv_signup_sbmtbtn); FnameText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_fname_et); LnameText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_lname_et); EmailText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_email_et); PhoneText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_phone_et); CodeText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_code_et); PassText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_pass_et); CityText = view.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.autocity_et); var regAppBar = view.FindViewById <AppBarLayout>(Resource.Id.signup_appbar); var toolbar = regAppBar.FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.main_toolbar); toolbar.Title = "Register"; toolbar.InflateMenu(Resource.Menu.help_menu); toolbar.MenuItemClick += Toolbar_MenuItemClick; FnameText.EditText.AfterTextChanged += EditText_AfterTextChanged; LnameText.EditText.AfterTextChanged += EditText_AfterTextChanged; PassText.EditText.AfterTextChanged += EditText_AfterTextChanged; EmailText.EditText.AfterTextChanged += EditText_AfterTextChanged; PhoneText.EditText.AfterTextChanged += EditText_AfterTextChanged; var adapter = ArrayAdapterClass.CreateArrayAdapter(Activity, names); CityText.Adapter = adapter; CityText.AfterTextChanged += EditText_AfterTextChanged; SubmitBtn.Click += (s1, e1) => { //open progress OnboardingActivity.ShowProgressDialog(); fname = FnameText.EditText.Text; lname = LnameText.EditText.Text; email = EmailText.EditText.Text; phone = PhoneText.EditText.Text; city = CityText.Text; code = CodeText.EditText.Text; AppDataHelper.GetFirebaseAuth().CreateUserWithEmailAndPassword(email, PassText.EditText.Text) .AddOnCompleteListener(new OnCompleteListener(t => { if (!t.IsSuccessful) { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (FirebaseAuthInvalidCredentialsException) { OnboardingActivity.ShowErrorDialog("The email or password is not correct"); } catch (FirebaseAuthUserCollisionException) { ShowEmailExistsDialog(); } catch (FirebaseAuthInvalidUserException) { OnboardingActivity.ShowErrorDialog("User invalid"); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("Your request could not be completed at this time"); } } else { SaveDriverToDb(); } })); }; }
void SetupFirebase() { database = AppDataHelper.GetDatabase(); mAuth = AppDataHelper.GetFirebaseAuth(); currentUser = AppDataHelper.GetCurrentUser(); }
private void SubmitButton_Click(object sender, EventArgs e) { HashMap postMap = new HashMap(); postMap.Put("author", AppDataHelper.GetFullname()); postMap.Put("owner_id", AppDataHelper.GetFirebaseAuth().CurrentUser.Uid); postMap.Put("post_date", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss tt")); postMap.Put("post_body", postEditText.Text); //this will return an instance of our firestore //this will also generate an id DocumentReference newPostRef = AppDataHelper.GetFirestore().Collection("posts").Document(); //retrieve the document ID created string postKey = newPostRef.Id; postMap.Put("image_id", postKey); ShowProgressDialogue("Posting.."); // Save post image to firebase storage StorageReference storageReference = null; //check if the filebytes is not null if (fileBytes != null) { //This is the location where our images will be uploaded in the Firebase Storage //"postImages/" + "photo" is the location + imagename storageReference = FirebaseStorage.Instance.GetReference("postImages/" + postKey); //this code will save our image file to firebase storage storageReference.PutBytes(fileBytes) .AddOnSuccessListener(taskCompletionListeners) .AddOnFailureListener(taskCompletionListeners); } taskCompletionListeners.Success += (obj, EventArgs args) => { //check if storageReference is null if (storageReference != null) { storageReference.DownloadUrl.AddOnSuccessListener(downloadUrlListener); } //to get hold of the URL downloadUrlListener.Success += (obj, args) => { string downloadUrl = args.Result.ToString(); postMap.Put("download_url", downloadUrl); //Save post to Firebase Firestore newPostRef.Set(postMap); CloseProgressDialogue(); Finish(); }; }; taskCompletionListeners.Failure += (obj, args) => { Toast.MakeText(this, "Upload failed!", ToastLength.Short).Show(); CloseProgressDialogue(); }; }