summaryrefslogtreecommitdiffstats
path: root/src/de/animux/android/andmal/api/MalList.java
blob: 79a37b6f948efa31ffab2025659fe9deb2907ba6 (plain) (blame)
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
package de.animux.android.andmal.api;

import java.util.Collection;
import java.util.Map;

public abstract class MalList {

	private String username;

	private String password;

	protected boolean needsRefresh;

	private static MalList cache;

	public MalList(String username, String password) {
		this.username = username;
		this.password = password;
		cache = this;
		setNeedsRefresh(true);
	}

	public MalList() {
		if (cache != null) {
			this.username = cache.getUsername();
			this.password = cache.getPassword();
			setNeedsRefresh(false);
		}
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		if (this.username != null && this.username.equals(username))
			return;
		
		this.username = username;
		this.needsRefresh = true;
		
		if (cache != this
				&& (cache.getUsername() == null || !cache.getUsername().equals(
						username))) {
			cache.setUsername(username);
		}
	}

	protected String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		if (this.password != null && this.password.equals(password))
			return;
		
		this.password = password;
		this.needsRefresh = true;
		
		if (cache != this
				&& (cache.getPassword() == null || !cache.getPassword().equals(
						password))) {
			cache.setPassword(password);
		}
	}

	public void setNeedsRefresh(boolean needsRefresh) {
		this.needsRefresh = needsRefresh;
	}

	public boolean needsRefresh() {
		return needsRefresh;
	}

	abstract public void refresh();

	abstract public Map<MalState, Collection<MalObject>> getObjects();

}