57 lines
2.3 KiB
C#
57 lines
2.3 KiB
C#
using Android.Views;
|
|
using AndroidX.AppCompat.App;
|
|
using Google.Android.Material.Color;
|
|
using Google.Android.Material.FloatingActionButton;
|
|
using Google.Android.Material.Snackbar;
|
|
using Google.Android.Material.TextField;
|
|
|
|
namespace SimpleNotes;
|
|
|
|
[Activity(Label = "@string/settings_page", MainLauncher = false,Theme ="@style/Theme.SimpleNotes")]
|
|
public class SettingActivity : AppCompatActivity
|
|
{
|
|
|
|
|
|
protected override void OnCreate(Bundle? savedInstanceState)
|
|
{
|
|
base.OnCreate(savedInstanceState);
|
|
DynamicColors.ApplyToActivityIfAvailable(this);
|
|
// Set our view from the "main" layout resource
|
|
SetContentView(Resource.Layout.activity_settings);
|
|
SetSupportActionBar(FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar));
|
|
TextInputEditText? settings_endpoint = FindViewById<TextInputEditText>(Resource.Id.settings_endpoint);
|
|
TextInputEditText? settings_username = FindViewById<TextInputEditText>(Resource.Id.settings_username);
|
|
TextInputEditText? settings_password = FindViewById<TextInputEditText>(Resource.Id.settings_password);
|
|
Button? settings_save = FindViewById<Button>(Resource.Id.settings_save);
|
|
|
|
if(settings_endpoint == null || settings_username == null || settings_password == null || settings_save==null) return;
|
|
|
|
var config=this.GetSharedPreferences("config",Android.Content.FileCreationMode.Private);
|
|
if(config != null)
|
|
{
|
|
var endpoint = config.GetString("endpoint","");
|
|
var username = config.GetString("username","");
|
|
var password = config.GetString("password","");
|
|
|
|
if(!string.IsNullOrWhiteSpace(endpoint))
|
|
{
|
|
settings_endpoint.Text = endpoint;
|
|
}
|
|
|
|
if(!string.IsNullOrWhiteSpace(username))
|
|
{
|
|
settings_username.Text = username;
|
|
}
|
|
if(!string.IsNullOrWhiteSpace(password))
|
|
{
|
|
settings_password.Text = password;
|
|
}
|
|
|
|
settings_save.Click += (sender,e)=>{
|
|
config.Edit()?.PutString("endpoint",settings_endpoint.Text)?.PutString("username",settings_username.Text)?.PutString("password",settings_password.Text)?.Commit();
|
|
this.FinishActivity(0);
|
|
};
|
|
}
|
|
}
|
|
|
|
} |