|
@@ -3,75 +3,62 @@ |
3 |
3 |
|
|
4 |
4 |
|
import java.util.*; |
5 |
5 |
|
|
6 |
|
- |
class DetailRowModelImpl<RowType> implements DetailRowModel<RowType> |
7 |
|
- |
{ |
|
6 |
+ |
class DetailRowModelImpl<RowType> implements DetailRowModel<RowType> { |
8 |
7 |
|
private DetailRowAlignment mAlign = DetailRowAlignment.Top; |
9 |
8 |
|
private int mIndex = -1; |
10 |
9 |
|
private RowType mItem = null; |
11 |
10 |
|
private DetailRowCallback<RowType> mCallback = null; |
12 |
11 |
|
|
13 |
|
- |
public DetailRowCallback<RowType> getCallback() |
14 |
|
- |
{ |
|
12 |
+ |
public DetailRowCallback<RowType> getCallback() { |
15 |
13 |
|
return mCallback; |
16 |
14 |
|
} |
17 |
15 |
|
|
18 |
|
- |
public void setCallback( DetailRowCallback<RowType> pCallback ) |
19 |
|
- |
{ |
|
16 |
+ |
public void setCallback( DetailRowCallback<RowType> pCallback ) { |
20 |
17 |
|
mCallback = pCallback; |
21 |
18 |
|
} |
22 |
19 |
|
|
23 |
20 |
|
@Override |
24 |
|
- |
public int getDetailRow() |
25 |
|
- |
{ |
|
21 |
+ |
public int getDetailRow() { |
26 |
22 |
|
return mIndex; |
27 |
23 |
|
} |
28 |
24 |
|
|
29 |
|
- |
public RowType getDetailItem() |
30 |
|
- |
{ |
|
25 |
+ |
public RowType getDetailItem() { |
31 |
26 |
|
return mItem; |
32 |
27 |
|
} |
33 |
28 |
|
|
34 |
29 |
|
@Override |
35 |
|
- |
public DetailRowAlignment getAlign() |
36 |
|
- |
{ |
|
30 |
+ |
public DetailRowAlignment getAlign() { |
37 |
31 |
|
return mAlign; |
38 |
32 |
|
} |
39 |
33 |
|
|
40 |
34 |
|
@Override |
41 |
|
- |
public boolean isDetailRow( int pIndex ) |
42 |
|
- |
{ |
|
35 |
+ |
public boolean isDetailRow( int pIndex ) { |
43 |
36 |
|
return mIndex == pIndex; |
44 |
37 |
|
} |
45 |
38 |
|
|
46 |
|
- |
public boolean isDetailRow( RowType pItem ) |
47 |
|
- |
{ |
|
39 |
+ |
public boolean isDetailRow( RowType pItem ) { |
48 |
40 |
|
return mItem == pItem; |
49 |
41 |
|
} |
50 |
42 |
|
|
51 |
|
- |
private boolean canShowDetailFor( int index, RowType pItem ) |
52 |
|
- |
{ |
|
43 |
+ |
private boolean canShowDetailFor( int index, RowType pItem ) { |
53 |
44 |
|
return (mCallback == null) || mCallback.canShowDetailFor( index, pItem ); |
54 |
45 |
|
} |
55 |
46 |
|
|
56 |
47 |
|
/** |
57 |
48 |
|
* @return true if changed |
58 |
49 |
|
*/ |
59 |
|
- |
public boolean maybeSetDetailRow( int pIndex, RowType pItem ) |
60 |
|
- |
{ |
61 |
|
- |
if ( mIndex != pIndex && canShowDetailFor( pIndex, pItem ) ) |
62 |
|
- |
{ |
|
50 |
+ |
public boolean maybeSetDetailRow( int pIndex, RowType pItem ) { |
|
51 |
+ |
if ( mIndex != pIndex && canShowDetailFor( pIndex, pItem ) ) { |
63 |
52 |
|
setDetailRow( pIndex, pItem ); |
64 |
53 |
|
return true; |
65 |
54 |
|
} |
66 |
55 |
|
return false; |
67 |
56 |
|
} |
68 |
57 |
|
|
69 |
|
- |
private void setDetailRow( int pIndex, RowType pItem ) |
70 |
|
- |
{ |
|
58 |
+ |
private void setDetailRow( int pIndex, RowType pItem ) { |
71 |
59 |
|
assert pIndex >= 0; |
72 |
60 |
|
assert pItem != null; |
73 |
|
- |
if ( mIndex != pIndex && canShowDetailFor( pIndex, pItem ) ) |
74 |
|
- |
{ |
|
61 |
+ |
if ( mIndex != pIndex && canShowDetailFor( pIndex, pItem ) ) { |
75 |
62 |
|
int oldIndex = mIndex; |
76 |
63 |
|
mIndex = pIndex; |
77 |
64 |
|
mItem = pItem; |
|
@@ -79,8 +66,7 @@ |
79 |
66 |
|
} |
80 |
67 |
|
} |
81 |
68 |
|
|
82 |
|
- |
private void clearDetailRow() |
83 |
|
- |
{ |
|
69 |
+ |
private void clearDetailRow() { |
84 |
70 |
|
mIndex = -1; |
85 |
71 |
|
mItem = null; |
86 |
72 |
|
} |
|
@@ -88,45 +74,35 @@ |
88 |
74 |
|
/** |
89 |
75 |
|
* @return true if changed |
90 |
76 |
|
*/ |
91 |
|
- |
public boolean update( List<RowType> pRowValues, int pOffset, int pCount ) |
92 |
|
- |
{ |
|
77 |
+ |
public boolean update( List<RowType> pRowValues, int pOffset, int pCount ) { |
93 |
78 |
|
assert pOffset + pCount <= pRowValues.size() : "size=" + pRowValues.size() + ",offset=" + pOffset + ",count=" + pCount; |
94 |
79 |
|
|
95 |
|
- |
if ( mIndex >= 0 && mIndex < pCount && canShowDetailFor( mIndex, mItem ) ) |
96 |
|
- |
{ |
|
80 |
+ |
if ( mIndex >= 0 && mIndex < pCount && canShowDetailFor( mIndex, mItem ) ) { |
97 |
81 |
|
return false; |
98 |
82 |
|
} |
99 |
83 |
|
|
100 |
84 |
|
int candidateIndex = mIndex; |
101 |
|
- |
if ( candidateIndex > pCount ) |
102 |
|
- |
{ |
|
85 |
+ |
if ( candidateIndex > pCount ) { |
103 |
86 |
|
candidateIndex = pCount; |
104 |
87 |
|
} |
105 |
|
- |
for ( int i = candidateIndex + 1; i < pCount; i++ ) |
106 |
|
- |
{ |
|
88 |
+ |
for ( int i = candidateIndex + 1; i < pCount; i++ ) { |
107 |
89 |
|
RowType candidate = pRowValues.get( i + pOffset ); |
108 |
|
- |
if ( canShowDetailFor( i, candidate ) ) |
109 |
|
- |
{ |
|
90 |
+ |
if ( canShowDetailFor( i, candidate ) ) { |
110 |
91 |
|
setDetailRow( i, candidate ); |
111 |
92 |
|
return true; |
112 |
93 |
|
} |
113 |
94 |
|
} |
114 |
|
- |
for ( int i = candidateIndex - 1; i >= 0; i-- ) |
115 |
|
- |
{ |
|
95 |
+ |
for ( int i = candidateIndex - 1; i >= 0; i-- ) { |
116 |
96 |
|
RowType candidate = pRowValues.get( i + pOffset ); |
117 |
|
- |
if ( canShowDetailFor( i, candidate ) ) |
118 |
|
- |
{ |
|
97 |
+ |
if ( canShowDetailFor( i, candidate ) ) { |
119 |
98 |
|
setDetailRow( i, candidate ); |
120 |
99 |
|
return true; |
121 |
100 |
|
} |
122 |
101 |
|
} |
123 |
|
- |
if ( mIndex != -1 ) |
124 |
|
- |
{ |
|
102 |
+ |
if ( mIndex != -1 ) { |
125 |
103 |
|
clearDetailRow(); |
126 |
104 |
|
return true; |
127 |
|
- |
} |
128 |
|
- |
else |
129 |
|
- |
{ |
|
105 |
+ |
} else { |
130 |
106 |
|
return false; |
131 |
107 |
|
} |
132 |
108 |
|
} |