Skip to content

Commit dcadc34

Browse files
committed
Merge SectionDescriptor
1 parent 639cb4a commit dcadc34

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

lib/QMBForm/src/main/java/com/quemb/qmbform/descriptor/FormDescriptor.java

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44

55
import java.util.ArrayList;
66
import java.util.HashMap;
7-
import java.util.List;
87
import java.util.Map;
98

109
/**
1110
* Created by tonimoeckel on 14.07.14.
1211
*/
1312
public class FormDescriptor {
13+
1414
private String mTitle;
1515
private HashMap<String, Object> mCellConfig;
1616
private ArrayList<SectionDescriptor> mSections;
1717
private OnFormRowValueChangedListener mOnFormRowValueChangedListener;
1818
private OnFormRowChangeListener mOnFormRowChangeListener;
1919

20-
public static FormDescriptor newInstance() {
20+
public static FormDescriptor newInstance(){
2121
return FormDescriptor.newInstance(null);
2222
}
2323

24-
public static FormDescriptor newInstance(String title) {
24+
public static FormDescriptor newInstance(String title){
2525

2626
FormDescriptor descriptor = new FormDescriptor();
2727
descriptor.mTitle = title;
2828
return descriptor;
2929

3030
}
3131

32-
public FormDescriptor() {
32+
public FormDescriptor(){
3333
mSections = new ArrayList<SectionDescriptor>();
3434
}
3535

@@ -40,30 +40,37 @@ public void setCellConfig(HashMap<String, Object> cellConfig) {
4040
mCellConfig = cellConfig;
4141
}
4242

43-
public void addSection(SectionDescriptor section) {
44-
insertSectionAtIndex(section, mSections.size());
43+
44+
45+
public void addSection(SectionDescriptor sectionDescriptor){
46+
insertSectionAtIndex(sectionDescriptor, mSections.size());
4547
}
4648

47-
public void removeSection(SectionDescriptor sectionDescriptor) {
49+
public void removeSection(SectionDescriptor sectionDescriptor){
4850
int index = mSections.indexOf(sectionDescriptor);
49-
if (index >= 0) {
51+
if (index>=0){
5052
removeSectionAtIndex(index);
5153
}
5254
}
5355

54-
public int countOfSections() {
56+
public int countOfSections(){
5557
return mSections.size();
5658
}
5759

58-
public SectionDescriptor sectionAtIndex(int index) {
59-
if (mSections.size() > index) {
60+
public SectionDescriptor sectionAtIndex(int index){
61+
if (mSections.size()>index){
6062
return mSections.get(index);
6163
}
6264
return null;
6365
}
6466

65-
public List<SectionDescriptor> getSections() {
66-
return mSections;
67+
public SectionDescriptor sectionByTag(String tag) {
68+
for (SectionDescriptor sectionDescriptor : mSections) {
69+
if (sectionDescriptor.getTag().equals(tag)) {
70+
return sectionDescriptor;
71+
}
72+
}
73+
return null;
6774
}
6875

6976
public SectionDescriptor getSectionWithTitle(String title) {
@@ -75,24 +82,19 @@ public SectionDescriptor getSectionWithTitle(String title) {
7582
return null;
7683
}
7784

78-
public void insertSectionAtIndex(SectionDescriptor section, int index) {
85+
public ArrayList<SectionDescriptor> getSections(){
86+
return mSections;
87+
}
88+
89+
public void insertSectionAtIndex(SectionDescriptor section, int index){
7990
section.setFormDescriptor(this);
8091
mSections.add(index, section);
81-
82-
// Propagate the CellConfig from Form to Section
83-
84-
if (mCellConfig != null)
85-
section.setCellConfig(mCellConfig);
8692
}
8793

88-
private void removeSectionAtIndex(int index) {
94+
private void removeSectionAtIndex(int index){
8995
mSections.remove(index);
9096
}
9197

92-
public void setTitle(String title) {
93-
mTitle = title;
94-
}
95-
9698
public String getTitle() {
9799
return mTitle;
98100
}
@@ -101,10 +103,10 @@ public OnFormRowValueChangedListener getOnFormRowValueChangedListener() {
101103
return mOnFormRowValueChangedListener;
102104
}
103105

104-
public RowDescriptor findRowDescriptor(String tag) {
106+
public RowDescriptor findRowDescriptor(String tag){
105107
RowDescriptor rowDescriptor = null;
106108

107-
for (SectionDescriptor sectionDescriptor : getSections()) {
109+
for (SectionDescriptor sectionDescriptor:getSections()){
108110
rowDescriptor = sectionDescriptor.findRowDescriptor(tag);
109111
if (rowDescriptor != null) break;
110112
}
@@ -117,17 +119,22 @@ public void setOnFormRowValueChangedListener(
117119
mOnFormRowValueChangedListener = onFormRowValueChangedListener;
118120
}
119121

120-
public boolean isValid(Context context) {
122+
public boolean isValid(Context context){
123+
121124
FormValidation formValidation = getFormValidation(context);
122125

123-
return formValidation.getRowValidationErrors().isEmpty();
126+
if (formValidation.getRowValidationErrors().size()>0){
127+
return false;
128+
}
129+
return true;
124130
}
125131

126132
public FormValidation getFormValidation(Context context) {
133+
127134
FormValidation formValidation = new FormValidation(context);
128-
for (SectionDescriptor sectionDescriptor : getSections()) {
129-
for (RowDescriptor rowDescriptor : sectionDescriptor.getRows()) {
130-
if (!rowDescriptor.isValid()) {
135+
for (SectionDescriptor sectionDescriptor : getSections()){
136+
for (RowDescriptor rowDescriptor : sectionDescriptor.getRows()){
137+
if (!rowDescriptor.isValid()){
131138
formValidation.getRowValidationErrors().addAll(rowDescriptor.getValidationErrors());
132139
}
133140
}
@@ -136,14 +143,14 @@ public FormValidation getFormValidation(Context context) {
136143

137144
}
138145

139-
protected void didInsertRow(RowDescriptor rowDescriptor, SectionDescriptor sectionDescriptor) {
140-
if (mOnFormRowChangeListener != null) {
146+
protected void didInsertRow(RowDescriptor rowDescriptor, SectionDescriptor sectionDescriptor){
147+
if (mOnFormRowChangeListener != null){
141148
mOnFormRowChangeListener.onRowAdded(rowDescriptor, sectionDescriptor);
142149
}
143150
}
144151

145-
protected void didRemoveRow(RowDescriptor rowDescriptor, SectionDescriptor sectionDescriptor) {
146-
if (mOnFormRowChangeListener != null) {
152+
protected void didRemoveRow(RowDescriptor rowDescriptor, SectionDescriptor sectionDescriptor){
153+
if (mOnFormRowChangeListener != null){
147154
mOnFormRowChangeListener.onRowRemoved(rowDescriptor, sectionDescriptor);
148155
}
149156
}
@@ -166,4 +173,5 @@ public Map<String, Object> getFormValues() {
166173
}
167174
return m;
168175
}
169-
}
176+
177+
}

0 commit comments

Comments
 (0)