NIMSDK-AOS  10.9.70
V2NIMDndConfig.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.setting;
2 
3 // 免打扰配置
4 public class V2NIMDndConfig {
5 
6  private static final int HOURS_IN_DAY = 24;
7  private static final int MINUTES_IN_HOUR = 60;
8  // 是否显示详情
9  // true: 显示
10  // false:不限制
11  private final boolean showDetail;
12 
13  // 免打扰是否开启
14  // true:开启
15  // fasle:关闭
16  private final boolean dndOn;
17 
18  // 如果开启免打扰,开始小时数(Integer)
19  // dndOn, 该字段必传
20  private final int fromH;
21 
22  // 如果开启免打扰,开始分钟数(Integer)
23  // dndOn, 该字段必传
24  private final int fromM;
25 
26  // 如果开启免打扰,截止小时数(Integer)
27  // dndOn, 该字段必传
28  private final int toH;
29 
30  // 如果开启免打扰,截止分钟数(Integer)
31  // dndOn, 该字段必传
32  private final int toM;
33 
34  private V2NIMDndConfig() {
35  this(false, false, 0, 0, 0, 0);
36  }
37 
38  private V2NIMDndConfig(boolean showDetail, boolean dndOn, int fromH, int fromM, int toH, int toM) {
39  this.showDetail = showDetail;
40  this.dndOn = dndOn;
41  this.fromH = fromH;
42  this.fromM = fromM;
43  this.toH = toH;
44  this.toM = toM;
45  }
46 
47  public boolean isShowDetail() {
48  return showDetail;
49  }
50 
51  public boolean isDndOn() {
52  return dndOn;
53  }
54 
55  public int getFromH() {
56  return fromH;
57  }
58 
59  public int getFromM() {
60  return fromM;
61  }
62 
63  public int getToH() {
64  return toH;
65  }
66 
67  public int getToM() {
68  return toM;
69  }
70 
71  @Override
72  public String toString() {
73  return "V2NIMDndConfig{" +
74  "showDetail=" + showDetail +
75  ", dndOn=" + dndOn +
76  ", fromH=" + fromH +
77  ", fromM=" + fromM +
78  ", toH=" + toH +
79  ", toM=" + toM +
80  '}';
81  }
82 
83  public boolean isValid(){
84  if(fromH < 0 || fromH >= HOURS_IN_DAY){
85  return false;
86  }
87  if(fromM < 0 || fromM >= MINUTES_IN_HOUR){
88  return false;
89  }
90  if(toH < 0 || toH >= HOURS_IN_DAY){
91  return false;
92  }
93  if(toM < 0 || toM >= MINUTES_IN_HOUR){
94  return false;
95  }
96  return true;
97  }
98 
99 
100  public static final class V2NIMDndConfigBuilder {
101  private boolean showDetail;
102  private boolean dndOn;
103  private final int fromH;
104  private final int fromM;
105  private final int toH;
106  private final int toM;
107 
108  private V2NIMDndConfigBuilder(int fromH, int fromM, int toH, int toM) {
109  this.fromH = fromH;
110  this.fromM = fromM;
111  this.toH = toH;
112  this.toM = toM;
113  }
114 
115  public static V2NIMDndConfigBuilder builder(int fromH, int fromM, int toH, int toM) {
116  return new V2NIMDndConfigBuilder(fromH, fromM, toH, toM);
117  }
118 
119  public V2NIMDndConfigBuilder withShowDetail(boolean showDetail) {
120  this.showDetail = showDetail;
121  return this;
122  }
123 
124  public V2NIMDndConfigBuilder withDndOn(boolean dndOn) {
125  this.dndOn = dndOn;
126  return this;
127  }
128 
129  public V2NIMDndConfig build() {
130  return new V2NIMDndConfig(showDetail, dndOn, fromH, fromM, toH, toM);
131  }
132  }
133 }