| Name | Message | Date |
|---|---|---|
| 📄 FolderPickerActivity.cs | 4 days ago | |
| 📄 NoteListActivity.cs | 4 days ago | |
| 📄 SettingsActivity.cs | 4 days ago |
📄
src/Activities/NoteListActivity.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
102
using Android.Views; using AndroidX.RecyclerView.Widget; using NotesApp.Adapters; using NotesApp.Graph; using NotesApp.Models; using NotesApp.Storage; namespace NotesApp.Activities; [Activity(Label = "@string/app_name", Exported = false)] public class NoteListActivity : Activity { private RecyclerView _recyclerView = null!; private ProgressBar _progressBar = null!; private NoteListAdapter _adapter = null!; private GraphService _graphService = null!; private bool _hasScrolledToBottom; protected override void OnCreate(Bundle? savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_note_list); _recyclerView = FindViewById<RecyclerView>(Resource.Id.note_recycler_view)!; _recyclerView.SetLayoutManager(new LinearLayoutManager(this)); _adapter = new NoteListAdapter(); _recyclerView.SetAdapter(_adapter); _progressBar = FindViewById<ProgressBar>(Resource.Id.note_refresh_progress)!; _graphService = new GraphService(this); // Cache renders immediately, scrolled to the bottom, before any network call. BindItems(NoteCacheStore.Load()); _ = RefreshAsync(); } private async Task RefreshAsync() { var folderId = AppSettings.RootFolderId; if (folderId is null) return; _progressBar.Visibility = ViewStates.Visible; try { var cacheById = NoteCacheStore.Load().ToDictionary(e => e.Id); var remoteNotes = await _graphService.ListMarkdownFilesAsync(folderId); var changedIds = remoteNotes .Where(n => !cacheById.TryGetValue(n.Id, out var existing) || existing.ETag != n.ETag ) .Select(n => n.Id) .ToList(); var freshPreviews = await _graphService.GetPreviewsAsync(changedIds); var merged = remoteNotes .Select(n => new NoteCacheEntry( n.Id, n.Name, n.ETag, n.LastModifiedUtc, freshPreviews.TryGetValue(n.Id, out var preview) ? preview : cacheById.TryGetValue(n.Id, out var existing) ? existing.Preview : "", n.Size )) .OrderBy(e => e.Name, StringComparer.OrdinalIgnoreCase) .ToList(); NoteCacheStore.Save(merged); BindItems(merged); } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Long)?.Show(); } finally { _progressBar.Visibility = ViewStates.Gone; } } private void BindItems(List<NoteCacheEntry> entries) { _adapter.SetItems(entries); // Only force scroll-to-bottom on the initial (cache-empty) load; don't yank the // scroll position if the user is already reading older notes when a refresh lands. if (!_hasScrolledToBottom && entries.Count > 0) { _recyclerView.ScrollToPosition(entries.Count - 1); _hasScrolledToBottom = true; } } }