aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/mygram/droid/App.java
blob: a6fb9c86cc7e5c629328bcbf0232ee21ddc0de62 (plain)
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
/*
 * mygram-droid: Android TV client for Foldergram.
 * Copyright (C) 2026 Danilo M. <danix@danix.xyz>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 */

package mygram.droid;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;

public final class App extends Application implements Application.ActivityLifecycleCallbacks {
	/** Until the splash lets the user in; set again whenever the app leaves the screen. */
	static boolean locked = true;
	private int started;

	@Override
	public void onCreate() {
		super.onCreate();
		Prefs.init(this);
		registerActivityLifecycleCallbacks(this);
		// One cookie jar for the Foldergram session: Api, Glide and ExoPlayer
		// all use HttpURLConnection, which consults the default handler.
		CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
	}

	/** Before any screen draws, cover it with the splash (PIN, indexing wait) until it lets the user in. */
	@Override
	public void onActivityStarted(Activity a) {
		started++;
		if (locked && !(a instanceof SplashActivity))
			a.startActivity(new Intent(a, SplashActivity.class));
	}

	@Override
	public void onActivityStopped(Activity a) {
		if (--started == 0)
			locked = true;
	}

	@Override
	public void onActivityCreated(Activity a, Bundle state) {
	}

	@Override
	public void onActivityResumed(Activity a) {
	}

	@Override
	public void onActivityPaused(Activity a) {
	}

	@Override
	public void onActivitySaveInstanceState(Activity a, Bundle state) {
	}

	@Override
	public void onActivityDestroyed(Activity a) {
	}
}