package com.foxx.androidcast;

/*********************************************************************
 * CastActivityTracker.java
 * Created at: Sun 17 May 2026 18:17:14 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastActivityTracker
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 35 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	e7007416d4f7ce75f65c74e0bb2ccf13b30a468a01a47827487a68fe980a93ce
**********************************************************************/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

/** Remembers the last foreground activity for tray / notification resume. */
public final class CastActivityTracker {
    private static volatile Class<? extends Activity> lastActivityClass;

    private CastActivityTracker() {}

    public static void onResume(Activity activity) {
        if (activity != null) {
            lastActivityClass = activity.getClass();
            CastTrayNotifier.syncWhenForeground(activity);
        }
    }

    public static Intent resumeIntent(Context context) {
        Class<? extends Activity> cls = lastActivityClass;
        if (cls != null) {
            Intent intent = new Intent(context, cls);
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            return intent;
        }
        return new Intent(context, MainActivity.class);
    }
}
