private void OnChangeFullName() { var view = LayoutInflater.Inflate(Resource.Layout.change_fullname_layout, null); // var dlg = new AlertDialog.Builder(this) .SetTitle("Change Name") .SetView(view) .Show(); InputHandler formHandler = new InputHandler(); formHandler.SetBindings(new InputBinding[] { new InputBinding("FirstName", Resource.Id.tb_firstname, true, InputTypes.Text), new InputBinding("LastName", Resource.Id.tb_lastname, true, InputTypes.Text) }, view as ViewGroup); formHandler.SetCustomError("FirstName", "required", "Please enter your first name"); formHandler.SetCustomError("LastName", "required", "Last name is required"); view.FindViewById <Button>(Resource.Id.btn_submit).Click += async delegate { if (formHandler.ValidateInputs(true).Count == 0) { var inputs = formHandler.GetInputs(); using (this.ShowProgress(null, "Applying changes...")) { var proxy = ProxyFactory.GetProxyInstace(); var response = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.Update(new BookingSystem.API.Models.DTO.UpdateUserInfo() { FullName = $"{inputs["FirstName"]} {inputs["LastName"]}" })); if (response.Successful) { // Update current user info await proxy.UpdateUserInfoAsync(); // dlg.Dismiss(); Toast.MakeText(this, "Name changed successfully!", ToastLength.Long).Show(); } else { Toast.MakeText(this, response.GetErrorDescription(), ToastLength.Short).Show(); } } } }; }
private void OnChangeUsername() { var view = LayoutInflater.Inflate(Resource.Layout.change_username_layout, null); var dlg = new AlertDialog.Builder(this) .SetTitle("Change Username") .SetView(view) .Show(); var formInputHandler = new InputHandler(); formInputHandler.SetBindings(new InputBinding[] { new InputBinding("Username", Resource.Id.tb_username, true, InputTypes.Username) }, view as ViewGroup); var tbUsername = view.FindViewById <TextInputLayout>(Resource.Id.tb_username); view.FindViewById <Button>(Resource.Id.btn_submit).Click += async delegate { var errors = formInputHandler.ValidateInputs(true); if (errors.Count == 0) { string username = tbUsername.EditText.TrimInput(); var proxy = ProxyFactory.GetProxyInstace(); using (this.ShowProgress(null, "Applying changes...")) { var response = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.Update(new BookingSystem.API.Models.DTO.UpdateUserInfo() { Username = username })); if (response.Successful) { // Update current user info await proxy.UpdateUserInfoAsync(); // dlg.Dismiss(); Toast.MakeText(this, "Username changed successfully!", ToastLength.Long).Show(); } else { Toast.MakeText(this, response.GetErrorDescription(), ToastLength.Short).Show(); } } } }; }
private void OnChangeEmail() { var contentView = LayoutInflater.Inflate(Resource.Layout.change_input_layout, null); var tbInput = contentView.FindViewById <TextInputLayout>(Resource.Id.tb_change_input); tbInput.Hint = "Email"; // var dlg = new AlertDialog.Builder(this) .SetTitle("Change Email") .SetView(contentView) .Show(); // contentView.FindViewById <Button>(Resource.Id.btn_submit).Click += async delegate { string email = tbInput.EditText.TrimInput(); if (tbInput.SetError(InputHandler.IsValidEmail(email) ? null : $"'{email}' isn't a valid email address")) { return; } // using (var pg = this.ShowProgress(null, "Processing, please hold...")) { var proxy = ProxyFactory.GetProxyInstace(); var response = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.BeginChangeEmail(email)); // dlg.Dismiss(); if (response.Successful) { pg.Dismiss(); EnterConfirmCodeActivity.Show(this, EnterConfirmCodeActivity.Email, email); } else { Toast.MakeText(this, response.GetErrorDescription(), ToastLength.Short).Show(); } } }; }
void downloadWhatsAppFileCompleted (object sender, AsyncCompletedEventArgs e) { RunOnUiThread (() => { progressDialog.Dismiss (); if (downloadedOK) { var installApk = new Intent(Intent.ActionView); installApk.SetDataAndType(Android.Net.Uri.Parse("file://" + fullLatestWhatsAppFilename), "application/vnd.android.package-archive"); installApk.SetFlags(ActivityFlags.NewTask); try { StartActivity(installApk); AlertDialog deleteWhatsApp = new AlertDialog.Builder (this).Create (); deleteWhatsApp.SetTitle (Resources.GetString(Resource.String.delete)); deleteWhatsApp.SetMessage (Resources.GetString(Resource.String.delete_description)); deleteWhatsApp.SetButton ((int)DialogButtonType.Positive, Resources.GetString(Resource.String.delete_button_delete), (object senderDelete, DialogClickEventArgs eDelete) => File.Delete(fullLatestWhatsAppFilename)); deleteWhatsApp.SetButton ((int)DialogButtonType.Negative, Resources.GetString(Resource.String.delete_button_cancel), (object senderCancel, DialogClickEventArgs eCancel) => deleteWhatsApp.Dismiss ()); deleteWhatsApp.SetCancelable (false); deleteWhatsApp.Show (); } catch (ActivityNotFoundException ex) { var errorInstalled = new AlertDialog.Builder (this).Create (); errorInstalled.SetTitle (Resources.GetString(Resource.String.download_error)); errorInstalled.SetMessage (string.Format(Resources.GetString(Resource.String.download_error_description), "WhatsApp " + latestWhatsAppVersion)); errorInstalled.Show (); } downloadedOK = false; } else { File.Delete(fullLatestWhatsAppFilename); } }); }
// Retrieve latest version of Beta Updater public async Task GetLatestAppVersion (string pageUrl) { var getVersion = new WebClient(); string htmlAndroid = getVersion.DownloadString (new Uri(pageUrl)); // Get WhatsApp latest version string[] split = htmlAndroid.Split (new char[] { '>' }); int i = 0; while (i < split.Length) { if (split.GetValue (i).ToString ().StartsWith ("v")) { split = split.GetValue (i).ToString ().Split (new char[] { 'v', '<' }); latestAppVersion = split.GetValue (1).ToString ().Trim (); break; } i++; } installedAppVersion = PackageManager.GetPackageInfo ("com.javiersantos.whatsappbetaupdater", 0).VersionName.Trim (); if (CompareVersionReceiver.VersionCompare (installedAppVersion, latestAppVersion) < 0) { appApk = appApk + "v" + latestAppVersion + "/com.javiersantos.whatsappbetaupdater.apk"; AlertDialog appUpdateDialog = new AlertDialog.Builder (this).Create (); appUpdateDialog.SetTitle (string.Format(Resources.GetString(Resource.String.app_update), latestAppVersion)); appUpdateDialog.SetMessage (string.Format(Resources.GetString(Resource.String.app_update_description), Resources.GetString(Resource.String.app_name))); appUpdateDialog.SetButton ((int)DialogButtonType.Positive, Resources.GetString (Resource.String.update_button), (object senderUpdateAppOK, DialogClickEventArgs eUpdateAppOK) => { SetDownloadDialog (); var webClient = new WebClient (); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadAppFileCompleted); webClient.DownloadFileAsync (new Uri (appApk), fullLatestAppFilename); progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), Resources.GetString(Resource.String.app_name) + " " + latestAppVersion + "...")); progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();}); progressDialog.Show (); }); appUpdateDialog.SetButton ((int)DialogButtonType.Negative, Resources.GetString(Resource.String.cancel_button), (object senderUpdateAppCancel, DialogClickEventArgs eUpdateAppCancel) => appUpdateDialog.Dismiss ()); appUpdateDialog.SetButton ((int)DialogButtonType.Neutral, Resources.GetString(Resource.String.never_button), (object senderUpdateAppNever, DialogClickEventArgs eUpdateAppNever) => {prefs.Edit().PutBoolean("prefShowAppUpdates", false).Commit(); appUpdateDialog.Dismiss (); }); appUpdateDialog.SetCancelable (false); appUpdateDialog.Show (); } }
// Retrieve latest version of WhatsApp public async Task GetLatestWhatsAppVersion (string pageUrl) { var getVersion = new WebClient(); string htmlAndroid = getVersion.DownloadString (new Uri(pageUrl)); // Get WhatsApp latest version string[] split = htmlAndroid.Split (new char[] { '>' }); int i = 0; while (i < split.Length) { if (split.GetValue (i).ToString ().StartsWith ("Version")) { split = split.GetValue (i).ToString ().Split (new char[] { ' ', '<' }); latestWhatsAppVersion = split.GetValue (1).ToString ().Trim (); break; } i++; } // Display WhatsApp installed and latest version TextView whatsapp_installed_version = FindViewById<TextView> (Resource.Id.whatsapp_installed_version); TextView whatsapp_latest_version = FindViewById<TextView> (Resource.Id.whatsapp_latest_version); installedWhatsAppVersion = PackageManager.GetPackageInfo ("com.whatsapp", 0).VersionName.Trim (); whatsapp_installed_version.Text = installedWhatsAppVersion; whatsapp_latest_version.Text = latestWhatsAppVersion; fullLatestWhatsAppFilename = filename + "WhatsApp_" + latestWhatsAppVersion + ".apk"; // Load Floating Button var fab = FindViewById<FloatingActionButton> (Resource.Id.fab); // Compare installed and latest WhatsApp version if (CompareVersionReceiver.VersionCompare(installedWhatsAppVersion, latestWhatsAppVersion) < 0) { // There is a new version fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_download)); // Preference: Autodownload if (prefAutoDownload) { SetDownloadDialog (); var webClient = new WebClient (); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadWhatsAppFileCompleted); webClient.DownloadFileAsync (new Uri (whatsAppApk), fullLatestWhatsAppFilename); progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "...")); progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();}); progressDialog.Show (); } else { fab.Click += delegate { SetDownloadDialog (); var webClient = new WebClient (); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler (downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler (downloadWhatsAppFileCompleted); webClient.DownloadFileAsync (new Uri (whatsAppApk), fullLatestWhatsAppFilename); progressDialog.SetTitle (string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "...")); progressDialog.SetButton (Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => {webClient.CancelAsync (); progressDialog.Dismiss ();}); progressDialog.Show (); }; } // There is not a new version } else { fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_menu_about)); fab.Click += delegate { AlertDialog errorInstalled = new AlertDialog.Builder (this).Create (); errorInstalled.SetTitle (Resources.GetString(Resource.String.latest_installed)); errorInstalled.SetMessage (string.Format(Resources.GetString(Resource.String.latest_installed_description), "WhatsApp " + installedWhatsAppVersion)); errorInstalled.SetButton ((int)DialogButtonType.Positive, Resources.GetString(Resource.String.ok), (object senderClose, DialogClickEventArgs eClose) => errorInstalled.Dismiss ()); errorInstalled.Show (); }; } }
void downloadWhatsAppFileCompleted(object sender, AsyncCompletedEventArgs e) { RunOnUiThread(() => { progressDialog.Dismiss(); if (downloadedOK) { var installApk = new Intent(Intent.ActionView); installApk.SetDataAndType(Android.Net.Uri.Parse("file://" + fullLatestWhatsAppFilename), "application/vnd.android.package-archive"); installApk.SetFlags(ActivityFlags.NewTask); try { StartActivity(installApk); AlertDialog deleteWhatsApp = new AlertDialog.Builder(this).Create(); deleteWhatsApp.SetTitle(Resources.GetString(Resource.String.delete)); deleteWhatsApp.SetMessage(Resources.GetString(Resource.String.delete_description)); deleteWhatsApp.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.delete_button_delete), (object senderDelete, DialogClickEventArgs eDelete) => File.Delete(fullLatestWhatsAppFilename)); deleteWhatsApp.SetButton((int)DialogButtonType.Negative, Resources.GetString(Resource.String.delete_button_cancel), (object senderCancel, DialogClickEventArgs eCancel) => deleteWhatsApp.Dismiss()); deleteWhatsApp.SetCancelable(false); deleteWhatsApp.Show(); } catch (ActivityNotFoundException ex) { var errorInstalled = new AlertDialog.Builder(this).Create(); errorInstalled.SetTitle(Resources.GetString(Resource.String.download_error)); errorInstalled.SetMessage(string.Format(Resources.GetString(Resource.String.download_error_description), "WhatsApp " + latestWhatsAppVersion)); errorInstalled.Show(); } downloadedOK = false; } else { File.Delete(fullLatestWhatsAppFilename); } }); }
// Retrieve latest version of Beta Updater public async Task GetLatestAppVersion(string pageUrl) { var getVersion = new WebClient(); string htmlAndroid = getVersion.DownloadString(new Uri(pageUrl)); // Get WhatsApp latest version string[] split = htmlAndroid.Split(new char[] { '>' }); int i = 0; while (i < split.Length) { if (split.GetValue(i).ToString().StartsWith("v")) { split = split.GetValue(i).ToString().Split(new char[] { 'v', '<' }); latestAppVersion = split.GetValue(1).ToString().Trim(); break; } i++; } installedAppVersion = PackageManager.GetPackageInfo("com.javiersantos.whatsappbetaupdater", 0).VersionName.Trim(); if (CompareVersionReceiver.VersionCompare(installedAppVersion, latestAppVersion) < 0) { appApk = appApk + "v" + latestAppVersion + "/com.javiersantos.whatsappbetaupdater.apk"; AlertDialog appUpdateDialog = new AlertDialog.Builder(this).Create(); appUpdateDialog.SetTitle(string.Format(Resources.GetString(Resource.String.app_update), latestAppVersion)); appUpdateDialog.SetMessage(string.Format(Resources.GetString(Resource.String.app_update_description), Resources.GetString(Resource.String.app_name))); appUpdateDialog.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.update_button), (object senderUpdateAppOK, DialogClickEventArgs eUpdateAppOK) => { SetDownloadDialog(); var webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadAppFileCompleted); webClient.DownloadFileAsync(new Uri(appApk), fullLatestAppFilename); progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), Resources.GetString(Resource.String.app_name) + " " + latestAppVersion + "...")); progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); }); progressDialog.Show(); }); appUpdateDialog.SetButton((int)DialogButtonType.Negative, Resources.GetString(Resource.String.cancel_button), (object senderUpdateAppCancel, DialogClickEventArgs eUpdateAppCancel) => appUpdateDialog.Dismiss()); appUpdateDialog.SetButton((int)DialogButtonType.Neutral, Resources.GetString(Resource.String.never_button), (object senderUpdateAppNever, DialogClickEventArgs eUpdateAppNever) => { prefs.Edit().PutBoolean("prefShowAppUpdates", false).Commit(); appUpdateDialog.Dismiss(); }); appUpdateDialog.SetCancelable(false); appUpdateDialog.Show(); } }
// Retrieve latest version of WhatsApp public async Task GetLatestWhatsAppVersion(string pageUrl) { var getVersion = new WebClient(); string htmlAndroid = getVersion.DownloadString(new Uri(pageUrl)); // Get WhatsApp latest version string[] split = htmlAndroid.Split(new char[] { '>' }); int i = 0; while (i < split.Length) { if (split.GetValue(i).ToString().StartsWith("Version")) { split = split.GetValue(i).ToString().Split(new char[] { ' ', '<' }); latestWhatsAppVersion = split.GetValue(1).ToString().Trim(); break; } i++; } // Display WhatsApp installed and latest version TextView whatsapp_installed_version = FindViewById <TextView> (Resource.Id.whatsapp_installed_version); TextView whatsapp_latest_version = FindViewById <TextView> (Resource.Id.whatsapp_latest_version); installedWhatsAppVersion = PackageManager.GetPackageInfo("com.whatsapp", 0).VersionName.Trim(); whatsapp_installed_version.Text = installedWhatsAppVersion; whatsapp_latest_version.Text = latestWhatsAppVersion; fullLatestWhatsAppFilename = filename + "WhatsApp_" + latestWhatsAppVersion + ".apk"; // Load Floating Button var fab = FindViewById <FloatingActionButton> (Resource.Id.fab); // Compare installed and latest WhatsApp version if (CompareVersionReceiver.VersionCompare(installedWhatsAppVersion, latestWhatsAppVersion) < 0) // There is a new version { fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_download)); // Preference: Autodownload if (prefAutoDownload) { SetDownloadDialog(); var webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadWhatsAppFileCompleted); webClient.DownloadFileAsync(new Uri(whatsAppApk), fullLatestWhatsAppFilename); progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "...")); progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); }); progressDialog.Show(); } else { fab.Click += delegate { SetDownloadDialog(); var webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadWhatsAppFileCompleted); webClient.DownloadFileAsync(new Uri(whatsAppApk), fullLatestWhatsAppFilename); progressDialog.SetTitle(string.Format(Resources.GetString(Resource.String.downloading), "WhatsApp " + latestWhatsAppVersion + "...")); progressDialog.SetButton(Resources.GetString(Resource.String.cancel_button), (object senderCancel, DialogClickEventArgs eCancel) => { webClient.CancelAsync(); progressDialog.Dismiss(); }); progressDialog.Show(); }; } // There is not a new version } else { fab.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.ic_menu_about)); fab.Click += delegate { AlertDialog errorInstalled = new AlertDialog.Builder(this).Create(); errorInstalled.SetTitle(Resources.GetString(Resource.String.latest_installed)); errorInstalled.SetMessage(string.Format(Resources.GetString(Resource.String.latest_installed_description), "WhatsApp " + installedWhatsAppVersion)); errorInstalled.SetButton((int)DialogButtonType.Positive, Resources.GetString(Resource.String.ok), (object senderClose, DialogClickEventArgs eClose) => errorInstalled.Dismiss()); errorInstalled.Show(); }; } }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.action_change_username: { OnChangeUsername(); } break; case Resource.Id.action_change_fullname: { OnChangeFullName(); } break; case Resource.Id.action_change_email: { OnChangeEmail(); } break; case Resource.Id.action_change_phone: { OnChangePhone(); } break; case Resource.Id.action_change_password: { StartActivity(typeof(ChangePasswordActivity)); } break; case Resource.Id.action_manage_wallets: { OnManageWallets(); } break; case Resource.Id.action_delete_account: { // var contentView = LayoutInflater.Inflate(Resource.Layout.delete_account_layout, null); var dlg = new AlertDialog.Builder(this) .SetTitle("Delete Account") .SetView(contentView) .Show(); contentView.FindViewById <Button>(Resource.Id.btn_delete_account).Click += async delegate { // Delete account here using (this.ShowProgress(null, "Working on it...")) { var proxy = ProxyFactory.GetProxyInstace(); var result = await proxy.ExecuteAsync(API.Endpoints.AccountEndpoints.DeleteAccount()); if (result.Successful) { // Reset preferences await proxy.SignOut(); } else { // dlg.Dismiss(); Toast.MakeText(this, result.GetErrorDescription(), ToastLength.Short).Show(); } } }; } break; } return(base.OnOptionsItemSelected(item)); }