| Name | Message | Date |
|---|---|---|
| 📄 FolderPickerActivity.cs | 4 days ago | |
| 📄 NoteListActivity.cs | 4 days ago | |
| 📄 NoteViewActivity.cs | 4 days ago | |
| 📄 SettingsActivity.cs | 4 days ago |
📄
src/Activities/SettingsActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Android.Content; using AndroidX.AppCompat.App; using NotesApp.Auth; using NotesApp.Storage; using NotesApp.Views; using Toolbar = AndroidX.AppCompat.Widget.Toolbar; namespace NotesApp.Activities; [Activity(Label = "@string/settings_title", Exported = false)] public class SettingsActivity : AppCompatActivity { private const int ChooseFolderRequestCode = 200; private TextView _accountStatus = null!; private Button _signInButton = null!; private TextView _folderStatus = null!; protected override void OnCreate(Bundle? savedInstanceState) { AndroidX.Activity.EdgeToEdge.Enable(this); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_settings); EdgeToEdgeHelper.Apply(FindViewById(Resource.Id.settings_root)!); SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.settings_toolbar)); // Only show Up when reached via the note list's gear icon - there's nothing to // go "up" to yet during first-run setup, before a folder is configured. SupportActionBar?.SetDisplayHomeAsUpEnabled(AppSettings.HasRootFolder); _accountStatus = FindViewById<TextView>(Resource.Id.account_status)!; _signInButton = FindViewById<Button>(Resource.Id.sign_in_button)!; _folderStatus = FindViewById<TextView>(Resource.Id.folder_status)!; _signInButton.Click += async (_, _) => await SignInAsync(); FindViewById<Button>(Resource.Id.choose_folder_button)!.Click += (_, _) => OpenFolderPicker(); RefreshFolderStatus(); _ = RefreshAccountStatusAsync(); } public override bool OnSupportNavigateUp() { Finish(); return true; } protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data) { base.OnActivityResult(requestCode, resultCode, data); AuthService.HandleActivityResult(requestCode, resultCode, data); if (requestCode == ChooseFolderRequestCode && resultCode == Result.Ok && data != null) { AppSettings.RootFolderId = data.GetStringExtra(FolderPickerActivity.ExtraFolderId); AppSettings.RootFolderPath = data.GetStringExtra(FolderPickerActivity.ExtraFolderPath); RefreshFolderStatus(); } } private async Task SignInAsync() { _signInButton.Enabled = false; try { await AuthService.GetAccessTokenAsync(this); await RefreshAccountStatusAsync(); } catch (Exception ex) { var message = string.Format(GetString(Resource.String.sign_in_failed), ex.Message); Toast.MakeText(this, message, ToastLength.Long)?.Show(); } finally { _signInButton.Enabled = true; } } private async Task RefreshAccountStatusAsync() { var signedIn = await AuthService.IsSignedInAsync(); _accountStatus.Text = GetString( signedIn ? Resource.String.signed_in : Resource.String.not_signed_in ); } private void OpenFolderPicker() => StartActivityForResult( new Intent(this, typeof(FolderPickerActivity)), ChooseFolderRequestCode ); private void RefreshFolderStatus() => _folderStatus.Text = AppSettings.RootFolderPath is { } path ? string.Format(GetString(Resource.String.folder_selected_format), path) : GetString(Resource.String.no_folder_selected); }