Revision 2c9ab085
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/network/RubikUpdates.java | ||
---|---|---|
34 | 34 |
public final String mDescription; |
35 | 35 |
public final int mObjectMinorVersion; |
36 | 36 |
public final int mExtrasMinorVersion; |
37 |
public final int mPercent; |
|
37 | 38 |
public final boolean mUpdateObject; |
38 | 39 |
public final boolean mUpdateExtras; |
39 | 40 |
|
40 |
public UpdateInfo(String shortName, String longName, String description, int objectMinor, int extrasMinor, boolean updateO, boolean updateE) |
|
41 |
public UpdateInfo(String shortName, String longName, String description, int objectMinor, |
|
42 |
int extrasMinor, int percent, boolean updateO, boolean updateE) |
|
41 | 43 |
{ |
42 | 44 |
mObjectShortName = shortName; |
43 | 45 |
mObjectLongName = longName; |
44 | 46 |
mDescription = description; |
45 | 47 |
mObjectMinorVersion = objectMinor; |
46 | 48 |
mExtrasMinorVersion = extrasMinor; |
49 |
mPercent = percent; |
|
47 | 50 |
mUpdateObject = updateO; |
48 | 51 |
mUpdateExtras = updateE; |
49 | 52 |
} |
50 | 53 |
} |
51 | 54 |
|
52 | 55 |
private String mUrl; |
53 |
private final ArrayList<UpdateInfo> mNew, mUpd;
|
|
56 |
private final ArrayList<UpdateInfo> mCompleted, mStarted;
|
|
54 | 57 |
|
55 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 59 |
|
57 | 60 |
public RubikUpdates() |
58 | 61 |
{ |
59 |
mNew = new ArrayList<>();
|
|
60 |
mUpd = new ArrayList<>();
|
|
62 |
mCompleted = new ArrayList<>();
|
|
63 |
mStarted = new ArrayList<>();
|
|
61 | 64 |
} |
62 | 65 |
|
63 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
79 | 82 |
|
80 | 83 |
private void parseLine(String[] elements) |
81 | 84 |
{ |
82 |
String shortName = elements[0]; |
|
83 |
String objMinor = elements[1]; |
|
84 |
String extMinor = elements[2]; |
|
85 |
String longName = elements[3]; |
|
86 |
String description = elements[4]; |
|
87 |
int oMinor, eMinor; |
|
85 |
String shortName = elements[0].trim(); |
|
86 |
String objMinor = elements[1].trim(); |
|
87 |
String extMinor = elements[2].trim(); |
|
88 |
String percent = elements[3].trim(); |
|
89 |
String longName = elements[4]; |
|
90 |
String description = elements[5]; |
|
91 |
int oMinor, eMinor, oPercent; |
|
88 | 92 |
|
89 | 93 |
try { oMinor = Integer.parseInt(objMinor); } |
90 | 94 |
catch (NumberFormatException ex) { oMinor = -1; } |
91 | 95 |
try { eMinor = Integer.parseInt(extMinor); } |
92 | 96 |
catch (NumberFormatException ex) { eMinor = -1; } |
97 |
try { oPercent = Integer.parseInt(percent); } |
|
98 |
catch (NumberFormatException ex) { oPercent = -1; } |
|
93 | 99 |
|
94 |
if( oMinor>=0 && eMinor>=0 ) |
|
100 |
if( oMinor>=0 && eMinor>=0 && oPercent>=0 )
|
|
95 | 101 |
{ |
96 | 102 |
int objOrdinal = RubikObjectList.getOrdinal(shortName.toUpperCase()); |
103 |
boolean updateO=true, updateE=true; |
|
97 | 104 |
|
98 | 105 |
if( objOrdinal>=0 ) |
99 | 106 |
{ |
100 | 107 |
int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal); |
101 | 108 |
int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal); |
102 |
boolean updateO = localObjectMinor<oMinor; |
|
103 |
boolean updateE = localExtrasMinor<eMinor; |
|
104 |
|
|
105 |
if( updateO || updateE ) |
|
106 |
{ |
|
107 |
UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,updateO,updateE); |
|
108 |
mUpd.add(info); |
|
109 |
} |
|
109 |
updateO = localObjectMinor<oMinor; |
|
110 |
updateE = localExtrasMinor<eMinor; |
|
110 | 111 |
} |
111 |
else
|
|
112 |
if( updateO || updateE )
|
|
112 | 113 |
{ |
113 |
UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,true,true); |
|
114 |
mNew.add(info); |
|
114 |
UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,oPercent,updateO,updateE); |
|
115 |
if(oPercent>=100) mCompleted.add(info); |
|
116 |
else mStarted.add(info); |
|
115 | 117 |
} |
116 | 118 |
} |
117 | 119 |
} |
... | ... | |
122 | 124 |
{ |
123 | 125 |
android.util.Log.e("D", updates); |
124 | 126 |
|
125 |
mNew.clear();
|
|
126 |
mUpd.clear();
|
|
127 |
mCompleted.clear();
|
|
128 |
mStarted.clear();
|
|
127 | 129 |
|
128 | 130 |
String[] lines = updates.split("\n"); |
129 | 131 |
int numLines = lines.length; |
... | ... | |
134 | 136 |
for(int line=1; line<numLines; line++) |
135 | 137 |
{ |
136 | 138 |
String[] elements = lines[line].split(","); |
137 |
if( elements.length>=3 ) parseLine(elements);
|
|
139 |
if( elements.length>=6 ) parseLine(elements);
|
|
138 | 140 |
} |
139 | 141 |
} |
140 | 142 |
} |
... | ... | |
143 | 145 |
|
144 | 146 |
public void updateDone(String shortName) |
145 | 147 |
{ |
146 |
for( UpdateInfo info : mNew)
|
|
148 |
for( UpdateInfo info : mCompleted)
|
|
147 | 149 |
{ |
148 | 150 |
if( info.mObjectShortName.equals(shortName) ) |
149 | 151 |
{ |
150 |
mNew.remove(info); |
|
151 |
return; |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
for( UpdateInfo info : mUpd) |
|
156 |
{ |
|
157 |
if( info.mObjectShortName.equals(shortName) ) |
|
158 |
{ |
|
159 |
mUpd.remove(info); |
|
152 |
mCompleted.remove(info); |
|
160 | 153 |
return; |
161 | 154 |
} |
162 | 155 |
} |
... | ... | |
164 | 157 |
|
165 | 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
166 | 159 |
|
167 |
public UpdateInfo getNewUpdate(int ordinal)
|
|
160 |
public UpdateInfo getCompletedUpdate(int ordinal)
|
|
168 | 161 |
{ |
169 |
return mNew.get(ordinal);
|
|
162 |
return mCompleted.get(ordinal);
|
|
170 | 163 |
} |
171 | 164 |
|
172 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
173 | 166 |
|
174 |
public UpdateInfo getUpdUpdate(int ordinal)
|
|
167 |
public UpdateInfo getStartedUpdate(int ordinal)
|
|
175 | 168 |
{ |
176 |
return mUpd.get(ordinal);
|
|
169 |
return mStarted.get(ordinal);
|
|
177 | 170 |
} |
178 | 171 |
|
179 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
180 | 173 |
|
181 |
public int getNewNumber()
|
|
174 |
public int getCompletedNumber()
|
|
182 | 175 |
{ |
183 |
return mNew.size();
|
|
176 |
return mCompleted.size();
|
|
184 | 177 |
} |
185 | 178 |
|
186 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
187 | 180 |
|
188 |
public int getUpdNumber()
|
|
181 |
public int getStartedNumber()
|
|
189 | 182 |
{ |
190 |
return mUpd.size();
|
|
183 |
return mStarted.size();
|
|
191 | 184 |
} |
192 | 185 |
|
193 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
195 | 188 |
public void showDebug() |
196 | 189 |
{ |
197 | 190 |
android.util.Log.e("D", "url: "+mUrl); |
198 |
android.util.Log.e("D", "new objects: "+debug(mNew));
|
|
199 |
android.util.Log.e("D", "upd objects: "+debug(mUpd));
|
|
191 |
android.util.Log.e("D", "ready objects: "+debug(mCompleted));
|
|
192 |
android.util.Log.e("D", "next objects: "+debug(mStarted));
|
|
200 | 193 |
} |
201 | 194 |
} |
Also available in: Unified diff
Downloading updates: dialog progress.