Repository navigation
Expand file tree
/
Copy pathUser.java
More file actions
executable file
·119 lines (102 loc) · 2.71 KB
/
Copy pathUser.java
File metadata and controls
executable file
·119 lines (102 loc) · 2.71 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package apijson.demo.client.model;
import android.support.annotation.NonNull;
import apijson.demo.client.application.APIJSONApplication;
import apijson.demo.server.model.Privacy;
/**用户类
* @author Lemon
*/
public class User extends apijson.demo.server.model.User {
private static final long serialVersionUID = 1L;
private Privacy privacy;
public User() {
super();
}
public User(long id) {
super(id);
}
@NonNull
public Privacy getPrivacy() {
if (privacy == null) {
privacy = new Privacy(getId());
}
return privacy;
}
public User setPrivacy(Privacy privacy) {
this.privacy = privacy;
return this;
}
public String getPhone() {
return getPrivacy().getPhone();
}
public User setPhone(String phone) {
getPrivacy().setPhone(phone);
return this;
}
@Override
public Long getId() {
return value(super.getId());
}
@Override
public Long getDate() {
return value(super.getDate());
}
@Override
public Integer getSex() {
return value(super.getSex());
}
/**判断是否为当前用户的朋友
* @return
*/
public boolean isFriend() {
return isFriend(APIJSONApplication.getInstance().getCurrentUserId());
}
/**判断是否为朋友,双方friendIdList都必须包含对方id
* @param user
* @return
*/
public boolean isFriend(User user) {
return isFriend(this, user);
}
/**判断是否为朋友,双方friendIdList都必须包含对方id
* @param user0
* @param user1
* @return
*/
public static boolean isFriend(User user0, User user1) {
return user0 != null && user1 != null && isFriend(user0, user1.getId()) && isFriend(user1, user0.getId());
}
/**判断是否为当前用户的朋友,仅从单方的friendIdList判断
* @param id
* @return
*/
public boolean isFriend(long id) {
return isFriend(this, id);
}
/**判断是否为朋友,仅从单方的friendIdList判断
* @param user0
* @param id1
* @return
*/
public static boolean isFriend(User user0, long id1) {
//id
if (id1 <= 0) {
return false;
}
long id0 = user0 == null ? 0 : user0.getId();
if (id0 <= 0) {
return false;
}
//friendIdList
return isContain(user0.getContactIdList(), id1);
}
}