📄 src/Activities/NoteViewActivity.cs
using Android.Views;
using AndroidX.AppCompat.App;
using Google.Android.Material.ProgressIndicator;
using NotesApp.Graph;
using NotesApp.Views;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;

namespace NotesApp.Activities;

[Activity(Label = "@string/app_name", Exported = false)]
public class NoteViewActivity : AppCompatActivity
{
    public const string ExtraNoteId = "note_id";
    public const string ExtraNoteName = "note_name";
    public const string ExtraNotePreview = "note_preview";

    private TextView _contentView = null!;
    private LinearProgressIndicator _progressBar = null!;
    private GraphService _graphService = null!;

    protected override void OnCreate(Bundle? savedInstanceState)
    {
        AndroidX.Activity.EdgeToEdge.Enable(this);
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_note_view);

        EdgeToEdgeHelper.Apply(FindViewById(Resource.Id.note_view_root)!);

        var toolbar = FindViewById<Toolbar>(Resource.Id.note_view_toolbar)!;
        SetSupportActionBar(toolbar);
        SupportActionBar?.SetDisplayHomeAsUpEnabled(true);

        var noteId = Intent?.GetStringExtra(ExtraNoteId);
        toolbar.Title =
            Intent?.GetStringExtra(ExtraNoteName) ?? GetString(Resource.String.app_name);

        _contentView = FindViewById<TextView>(Resource.Id.note_view_content)!;
        _progressBar = FindViewById<LinearProgressIndicator>(Resource.Id.note_view_progress)!;
        _contentView.Text = Intent?.GetStringExtra(ExtraNotePreview) ?? "";

        _graphService = new GraphService(this);

        if (noteId != null)
            _ = LoadContentAsync(noteId);
    }

    public override bool OnSupportNavigateUp()
    {
        Finish();
        return true;
    }

    private async Task LoadContentAsync(string noteId)
    {
        _progressBar.Visibility = ViewStates.Visible;
        try
        {
            _contentView.Text = await _graphService.GetContentAsync(noteId);
        }
        catch (Exception ex)
        {
            Toast.MakeText(this, ex.Message, ToastLength.Long)?.Show();
            // Leave the preview text in place as a partial fallback rather than blanking it.
        }
        finally
        {
            _progressBar.Visibility = ViewStates.Gone;
        }
    }
}