android: cleaned up the code a bit and removed a bug with the parsing of the xml
authorXeli
Sun, 27 Nov 2011 00:54:00 +0100
changeset 6446 a49d01b96185
parent 6445 fd151457fae6
child 6447 0bb16bc5c8b4
android: cleaned up the code a bit and removed a bug with the parsing of the xml
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java	Sun Nov 27 00:53:08 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java	Sun Nov 27 00:54:00 2011 +0100
@@ -163,8 +163,9 @@
 				try {
 					input.close();
 				} catch (IOException e) {}
-		}//end if contentType == "zip"
-
+		}else{//end if contentType == "zip"
+			return EXIT_URLFAIL;
+		}
 		if(conn != null) conn.disconnect();
 
 		if(checkMD5(digester, pack))return EXIT_SUCCESS;
@@ -195,20 +196,20 @@
 				byte[] buffer = new byte[1024];//size is large enough to hold the entire hash
 				BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
 				int bytesRead = bis.read(buffer);
+				String hash = null;
 				if(bytesRead > -1){
-					String hash = new String(buffer, 0, bytesRead);
-					StringBuffer sb = new StringBuffer();
-					Integer tmp = 0;
-					for(int i = 0; i < messageDigest.length; i++){
-						tmp = 0xFF & messageDigest[i];
-						if(tmp < 0xF) sb.append('0');
-						sb.append(Integer.toHexString(tmp));
-					}
-					sb.append('\n');//add newline to become identical with the hash file
+					hash = new String(buffer, 0, bytesRead);
+				}
+				StringBuffer sb = new StringBuffer();
+				Integer tmp = 0;
+				for(int i = 0; i < messageDigest.length; i++){
+					tmp = 0xFF & messageDigest[i];
+					if(tmp < 0xF) sb.append('0');
+					sb.append(Integer.toHexString(tmp));
+				}
+				sb.append('\n');//add newline to become identical with the hash file
 
-					return hash.equals(sb.toString());
-				}
-				return false;
+				return hash.equals(sb.toString());
 			} catch (IOException e) {
 				e.printStackTrace();
 				return true;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java	Sun Nov 27 00:53:08 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java	Sun Nov 27 00:54:00 2011 +0100
@@ -79,19 +79,27 @@
 						});
 					}
 				}
-				eventType = xmlPuller.nextTag();
+				eventType = getEventType(xmlPuller);
 			}
 			
 			
 		} catch (XmlPullParserException e) {
-			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (IOException e) {
-			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
+	}
+	
 
-
+	/**
+	 * Skips whitespaces..
+	 */
+	private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
+		int eventType = xmlPuller.next();
+		while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
+			eventType = xmlPuller.next();
+		}
+		return eventType;
 	}
 
 	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java	Sun Nov 27 00:53:08 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java	Sun Nov 27 00:54:00 2011 +0100
@@ -205,8 +205,6 @@
 			case DownloadAsyncTask.EXIT_MD5:		sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break;
 			case DownloadAsyncTask.EXIT_URLFAIL:	sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break;
 			case DownloadAsyncTask.EXIT_CANCELLED:	sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break;
-				
-				
 			}
 			
 			stopForeground(true);