您好,我正在使用Firebase实时数据库,并且实现了隐私设置,因此用户可以决定显示或隐藏哪些信息。
这是我的方法。我这是构造这样的数据的好方法吗?
{<br>
"friends" : {<br>
"7BDcIre74IfE34DL1T1ZfzrZLcZ2" : {<br>
"a3AiwvaXrHSHM05xBFq9X0TCBwi1" : {<br>
"a3AiwvaXrHSHM05xBFq9X0TCBwi1" : true,<br>
"rule1" : true<br>
}<br>
},<br>
"a3AiwvaXrHSHM05xBFq9X0TCBwi1" : {<br>
"7BDcIre74IfE34DL1T1ZfzrZLcZ2" : {<br>
"7BDcIre74IfE34DL1T1ZfzrZLcZ2" : true,<br>
"rule2" : true<br>
}<br>
}<br>
},<br>
"rules" : {<br>
"rule1" : {<br>
"showDate" : true,<br>
"showName" : false<br>
},<br>
"rule2" : {<br>
"showDate" : false,<br>
"showName" : true<br>
}<br>
},<br>
"users" : {<br>
"7BDcIre74IfE34DL1T1ZfzrZLcZ2" : {<br>
"Geburtsdatum" : "01.01.2000",<br>
"name" : "Alex"<br>
},<br>
"a3AiwvaXrHSHM05xBFq9X0TCBwi1" : {<br>
"Geburtsdatum" : "01.01.2000",<br>
"Name" : "Peter"<br>
},<br>
"eAnWvNGh13N31nUEHszOzjUfL9d2" : {<br>
"Geburtsdatum" : "01.01.2000",<br>
"Name" : "Oskar"<br>
}<br>
}<br>
}<br>
答案 0 :(得分:0)
不是。如果您想添加更多规则组合,可能会很快变得复杂且难以实施。您可以为设置创建模型类,并在每个朋友用户ID下创建一个privacy_settings节点,并在其下设置值。
数据结构:
"a3AiwvaXrHSHM05xBFq9X0TCBwi1" : {
"7BDcIre74IfE34DL1T1ZfzrZLcZ2" : {
"privacy_settings": {
"showDate" : false,
"showName" : true
}
}
}
Java模型类:
import android.os.Parcelable;
public class PrivacySettings implements Parcelable
{
boolean showDate,showName;
public PrivacySettings(boolean showDate, boolean showName)
{
this.showDate = showDate;
this.showName = showName;
}
public boolean isShowDate()
{
return showDate;
}
public void setShowDate(boolean showDate)
{
this.showDate = showDate;
}
public boolean isShowName()
{
return showName;
}
public void setShowName(boolean showName)
{
this.showName = showName;
}
@Override
public int describeContents()
{
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeByte(this.showDate ? (byte) 1 : (byte) 0);
dest.writeByte(this.showName ? (byte) 1 : (byte) 0);
}
protected PrivacySettings(Parcel in)
{
this.showDate = in.readByte() != 0;
this.showName = in.readByte() != 0;
}
public static final Parcelable.Creator<PrivacySettings> CREATOR = new Parcelable.Creator<PrivacySettings>()
{
@Override
public PrivacySettings createFromParcel(Parcel source)
{
return new PrivacySettings(source);
}
@Override
public PrivacySettings[] newArray(int size)
{
return new PrivacySettings[size];
}
};
}