protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.profile_edit_activity); mToolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(mToolbar); SupportActionBar.SetDisplayShowHomeEnabled(true); SupportActionBar.SetDisplayHomeAsUpEnabled(true); svProfile = FindViewById<ScrollView>(Resource.Id.svProfile); txtName = FindViewById<EditText>(Resource.Id.edit_profile_name); txtAddress = FindViewById<EditText>(Resource.Id.edit_profile_address); txtUsername = FindViewById<EditText>(Resource.Id.edit_profile_username); txtPassword = FindViewById<EditText>(Resource.Id.edit_profile_password); txtPort = FindViewById<EditText>(Resource.Id.edit_profile_port); radioEnigma1 = FindViewById<RadioButton>(Resource.Id.rbEnigma1); radioEnigma2 = FindViewById<RadioButton>(Resource.Id.rbEnigma2); switchStreaming = FindViewById<SwitchCompat>(Resource.Id.switch_streaming); txtStreamingPort = FindViewById<EditText>(Resource.Id.edit_streaming_port); switchTranscoding = FindViewById<SwitchCompat>(Resource.Id.switch_transcoding); txtTranscodingPort = FindViewById<EditText>(Resource.Id.edit_transcoding_port); cbUseSsl = FindViewById<CheckBox>(Resource.Id.cbUseSsl); layoutStreaming = FindViewById<LinearLayout>(Resource.Id.layout_Streaming); layoutTranscoding = FindViewById<LinearLayout>(Resource.Id.layout_Transcoding); //update controls content if (bundle != null && bundle.ContainsKey(profileNameKey)) { //restore state editProfileName = bundle.GetString(profileOriginalNameKey); txtName.Text = bundle.GetString(profileNameKey); txtAddress.Text = bundle.GetString(profileAddressKey); txtUsername.Text = bundle.GetString(profileUsernameKey); txtPassword.Text = bundle.GetString(profilePasswordKey); txtPort.Text = bundle.GetString(profilePortKey); radioEnigma1.Checked = bundle.GetBoolean(profileEnigma1Key); radioEnigma2.Checked = bundle.GetBoolean(profileEnigma2Key); switchStreaming.Checked = bundle.GetBoolean(profileStreamingKey); txtStreamingPort.Text = bundle.GetString(profileStreamingPortKey); switchTranscoding.Checked = bundle.GetBoolean(profileTranscodingKey); txtTranscodingPort.Text = bundle.GetString(profileTranscodingPortKey); cbUseSsl.Checked = bundle.GetBoolean(profileUseSslKey); isDirty = bundle.GetBoolean(isDirtyKey); } else if (Intent != null && Intent.HasExtra(ProfilesFragment.profileNameKey)) { //edit existing profile SignalMeterProfile profile = null; editProfileName = Intent.GetStringExtra(ProfilesFragment.profileNameKey); if (ConnectionManager.Profiles != null) { profile = ConnectionManager.Profiles.FirstOrDefault(x => x.Name == editProfileName); if (profile == null) profile = new SignalMeterProfile(); } else profile = new SignalMeterProfile(); txtName.Text = profile.Name; txtAddress.Text = profile.Address; txtUsername.Text = profile.Username; txtPassword.Text = profile.Password; txtPort.Text = profile.HttpPort.ToString(); radioEnigma1.Checked = profile.Enigma == global::Krkadoni.Enigma.Enums.EnigmaType.Enigma1; radioEnigma2.Checked = profile.Enigma == global::Krkadoni.Enigma.Enums.EnigmaType.Enigma2; switchStreaming.Checked = profile.Streaming; txtStreamingPort.Text = profile.StreamingPort == 0 ? string.Empty : profile.StreamingPort.ToString(); switchTranscoding.Checked = profile.Transcoding; txtTranscodingPort.Text = profile.TranscodingPort == 0 ? string.Empty : profile.TranscodingPort.ToString(); cbUseSsl.Checked = profile.UseSsl; } else { //create new profile } //add event handlers txtName.TextChanged += (sender, e) => isDirty = true; txtAddress.TextChanged += (sender, e) => isDirty = true; txtUsername.TextChanged += (sender, e) => isDirty = true; txtPassword.TextChanged += (sender, e) => isDirty = true; txtPort.TextChanged += (sender, e) => isDirty = true; radioEnigma1.CheckedChange += (sender, e) => isDirty = true; radioEnigma2.CheckedChange += (sender, e) => isDirty = true; txtStreamingPort.TextChanged += (sender, e) => isDirty = true; txtTranscodingPort.TextChanged += (sender, e) => isDirty = true; cbUseSsl.CheckedChange += (sender, e) => isDirty = true; switchStreaming.CheckedChange += (sender, e) => { isDirty = true; layoutStreaming.Visibility = switchStreaming.Checked ? ViewStates.Visible : ViewStates.Gone; if (switchStreaming.Checked) svProfile.Post(() => svProfile.ScrollTo(0, svProfile.Bottom)); }; switchTranscoding.CheckedChange += (sender, e) => { isDirty = true; layoutTranscoding.Visibility = switchTranscoding.Checked ? ViewStates.Visible : ViewStates.Gone; if (switchTranscoding.Checked) svProfile.Post(() => svProfile.ScrollTo(0, svProfile.Bottom)); }; SupportActionBar.Title = string.IsNullOrEmpty(editProfileName) ? GetString(Resource.String.action_add_profile) : editProfileName; layoutStreaming.Visibility = switchStreaming.Checked ? ViewStates.Visible : ViewStates.Gone; layoutTranscoding.Visibility = switchTranscoding.Checked ? ViewStates.Visible : ViewStates.Gone; }
private void SaveAndExit() { SignalMeterProfile profile = null; if (!string.IsNullOrEmpty(editProfileName)) profile = ConnectionManager.Profiles.FirstOrDefault(x => x.Name == editProfileName); if (profile == null) { profile = new SignalMeterProfile(); ConnectionManager.Profiles.Add(profile); } profile.Name = txtName.Text.Trim(); profile.Address = txtAddress.Text.Trim(); profile.Username = txtUsername.Text.Trim(); profile.HttpPort = int.Parse(txtPort.Text.Trim()); profile.Password = txtPassword.Text.Trim(); profile.Enigma = radioEnigma2.Checked ? EnigmaType.Enigma2 : EnigmaType.Enigma1; profile.Streaming = switchStreaming.Checked; profile.StreamingPort = Network.IsValidPort(txtStreamingPort.Text.Trim()) ? int.Parse(txtStreamingPort.Text.Trim()) : 0; profile.Transcoding = switchTranscoding.Checked; profile.TranscodingPort = Network.IsValidPort(txtTranscodingPort.Text.Trim()) ? int.Parse(txtTranscodingPort.Text.Trim()) : 0; profile.UseSsl = cbUseSsl.Checked; if (!string.IsNullOrEmpty(editProfileName) && editProfileName != profile.Name) ((GlobalApp)ApplicationContext).PreferenceManager.DeleteItem(this, editProfileName); ((GlobalApp)ApplicationContext).PreferenceManager.SaveItem(this, profile); Intent resultIntent = new Intent(); resultIntent.PutExtra(ProfilesFragment.profileNameKey, profile.Name); SetResult(Result.Ok, resultIntent); Finish(); }