Commit 22ce9c1c09b7ba6d613366aa52b1d6904a4c3518
1 parent
74c83a33
mejor gestion de urls invalidas y demas
Showing
4 changed files
with
109 additions
and
64 deletions
src/com/upc/pbe/upcnews/Descarrega.java
@@ -74,10 +74,10 @@ public class Descarrega extends AsyncTask<Object, Object, Object> { | @@ -74,10 +74,10 @@ public class Descarrega extends AsyncTask<Object, Object, Object> { | ||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | - protected String doInBackground(String u) { | 77 | + protected String doInBackground(String u) throws IOException { |
78 | this.url = u; | 78 | this.url = u; |
79 | html = ""; | 79 | html = ""; |
80 | - try { | 80 | + |
81 | URLConnection conn = new URL(url).openConnection(); | 81 | URLConnection conn = new URL(url).openConnection(); |
82 | BufferedReader in = new BufferedReader(new InputStreamReader( | 82 | BufferedReader in = new BufferedReader(new InputStreamReader( |
83 | conn.getInputStream())); | 83 | conn.getInputStream())); |
@@ -92,12 +92,6 @@ public class Descarrega extends AsyncTask<Object, Object, Object> { | @@ -92,12 +92,6 @@ public class Descarrega extends AsyncTask<Object, Object, Object> { | ||
92 | Log.d(TAG, "Descarrega finalitzada"); | 92 | Log.d(TAG, "Descarrega finalitzada"); |
93 | 93 | ||
94 | in.close(); | 94 | in.close(); |
95 | - } catch (MalformedURLException e) { | ||
96 | - Log.d(TAG, "excepcio 1, no sha trobat la URL"); | ||
97 | - } catch (IOException e) { | ||
98 | - Log.d(TAG, "excepcio 2"); | ||
99 | - } | ||
100 | - | ||
101 | return html; | 95 | return html; |
102 | 96 | ||
103 | } | 97 | } |
src/com/upc/pbe/upcnews/Directoris.java
1 | package com.upc.pbe.upcnews; | 1 | package com.upc.pbe.upcnews; |
2 | 2 | ||
3 | +import java.io.IOException; | ||
3 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
4 | 5 | ||
5 | import android.app.Activity; | 6 | import android.app.Activity; |
@@ -67,8 +68,16 @@ public class Directoris extends Activity implements OnItemClickListener | @@ -67,8 +68,16 @@ public class Directoris extends Activity implements OnItemClickListener | ||
67 | 68 | ||
68 | public void showResources() | 69 | public void showResources() |
69 | { | 70 | { |
70 | - ArrayList<String> entries = parser.parse(d.doInBackground(currentFolder)); | ||
71 | - this.createEntries(entries); | 71 | + ArrayList<String> entries; |
72 | + try | ||
73 | + { | ||
74 | + entries = parser.parse(d.doInBackground(currentFolder)); | ||
75 | + this.createEntries(entries); | ||
76 | + } | ||
77 | + catch (IOException e) | ||
78 | + { | ||
79 | + // Nunca llegará aquí la cosa, y si lo hace ES CULPA DEL SERVIDOR!! | ||
80 | + } | ||
72 | } | 81 | } |
73 | 82 | ||
74 | public void createEntries(ArrayList<String> directories) | 83 | public void createEntries(ArrayList<String> directories) |
@@ -86,29 +95,38 @@ public class Directoris extends Activity implements OnItemClickListener | @@ -86,29 +95,38 @@ public class Directoris extends Activity implements OnItemClickListener | ||
86 | if(path.endsWith(".m3u8")) | 95 | if(path.endsWith(".m3u8")) |
87 | { | 96 | { |
88 | path = currentFolder + path; | 97 | path = currentFolder + path; |
89 | - String playlist = d.doInBackground(path); | ||
90 | - Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); | 98 | + String playlist; |
91 | try | 99 | try |
92 | { | 100 | { |
93 | - ArrayList<ParentList> m3u8parsed = p.parseFile(playlist); | ||
94 | - Log.d(TAG, "parsing completed"); | ||
95 | - HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); | ||
96 | - h.start(); | ||
97 | - } | ||
98 | - catch (ErrorException e) | ||
99 | - { | ||
100 | - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
101 | - Log.d(TAG, e.getMessage()); | ||
102 | - } | ||
103 | - catch (WarningException e) | ||
104 | - { | ||
105 | - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
106 | - Log.d(TAG, e.getMessage()); | 101 | + playlist = d.doInBackground(path); |
102 | + | ||
103 | + Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); | ||
104 | + try | ||
105 | + { | ||
106 | + ArrayList<ParentList> m3u8parsed = p.parseFile(playlist); | ||
107 | + Log.d(TAG, "parsing completed"); | ||
108 | + HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); | ||
109 | + h.start(); | ||
110 | + } | ||
111 | + catch (ErrorException e) | ||
112 | + { | ||
113 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
114 | + Log.d(TAG, e.getMessage()); | ||
115 | + } | ||
116 | + catch (WarningException e) | ||
117 | + { | ||
118 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
119 | + Log.d(TAG, e.getMessage()); | ||
120 | + } | ||
121 | + catch (InfoException e) | ||
122 | + { | ||
123 | + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
124 | + Log.d(TAG, e.getMessage()); | ||
125 | + } | ||
107 | } | 126 | } |
108 | - catch (InfoException e) | 127 | + catch (IOException e1) |
109 | { | 128 | { |
110 | - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); | ||
111 | - Log.d(TAG, e.getMessage()); | 129 | + // Nunca llegará aquí la cosa, y si lo hace ES CULPA DEL SERVIDOR!! |
112 | } | 130 | } |
113 | 131 | ||
114 | } | 132 | } |
src/com/upc/pbe/upcnews/MainActivity.java
1 | package com.upc.pbe.upcnews; | 1 | package com.upc.pbe.upcnews; |
2 | 2 | ||
3 | import java.io.File; | 3 | import java.io.File; |
4 | +import java.io.IOException; | ||
5 | +import java.net.MalformedURLException; | ||
4 | 6 | ||
5 | import android.app.Activity; | 7 | import android.app.Activity; |
6 | import android.content.Intent; | 8 | import android.content.Intent; |
@@ -58,14 +60,28 @@ public class MainActivity extends Activity implements OnClickListener { | @@ -58,14 +60,28 @@ public class MainActivity extends Activity implements OnClickListener { | ||
58 | public void onClick(View v) { | 60 | public void onClick(View v) { |
59 | Log.d(TAG, "onClicked"); | 61 | Log.d(TAG, "onClicked"); |
60 | this.descarregar(); | 62 | this.descarregar(); |
61 | - ((UpcApp) getApplication()).setDesc(html); | ||
62 | - startActivity(new Intent(this, Directoris.class)); | 63 | + if(!html.equals("EMPTY")) |
64 | + { | ||
65 | + ((UpcApp) getApplication()).setDesc(html); | ||
66 | + startActivity(new Intent(this, Directoris.class)); | ||
67 | + } | ||
63 | } | 68 | } |
64 | 69 | ||
65 | public void descarregar() { | 70 | public void descarregar() { |
66 | Descarrega d = new Descarrega(); | 71 | Descarrega d = new Descarrega(); |
67 | - Toast.makeText(this, "Download succesfull", Toast.LENGTH_LONG).show(); | ||
68 | - html = (String) d.doInBackground(((UpcApp)getApplication()).getUrl()); | 72 | + html="EMPTY"; |
73 | + try | ||
74 | + { | ||
75 | + html = (String) d.doInBackground(((UpcApp)getApplication()).getUrl()); | ||
76 | + } | ||
77 | + catch(MalformedURLException e) | ||
78 | + { | ||
79 | + Toast.makeText(this, "Invalid URL", Toast.LENGTH_LONG).show(); | ||
80 | + } | ||
81 | + catch(IOException e) | ||
82 | + { | ||
83 | + Toast.makeText(this, "Can't find URL", Toast.LENGTH_LONG).show(); | ||
84 | + } | ||
69 | } | 85 | } |
70 | 86 | ||
71 | public boolean onOptionsItemSelected(MenuItem item) { | 87 | public boolean onOptionsItemSelected(MenuItem item) { |
src/com/upc/pbe/upcnews/Parser.java
1 | package com.upc.pbe.upcnews; | 1 | package com.upc.pbe.upcnews; |
2 | 2 | ||
3 | +import java.io.IOException; | ||
3 | import java.net.MalformedURLException; | 4 | import java.net.MalformedURLException; |
4 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
5 | 6 | ||
@@ -420,41 +421,49 @@ public class Parser | @@ -420,41 +421,49 @@ public class Parser | ||
420 | + " has missing arguments"); | 421 | + " has missing arguments"); |
421 | } | 422 | } |
422 | Parser p = new Parser(URI.substring(0, URI.lastIndexOf("/") + 1), caller); | 423 | Parser p = new Parser(URI.substring(0, URI.lastIndexOf("/") + 1), caller); |
423 | - Video newList = p.parseFile(download.doInBackground(URI)).get(0).getLists().get(0); | ||
424 | - if (!GroupID.equals(ppls.getID())) | 424 | + Video newList; |
425 | + try | ||
425 | { | 426 | { |
426 | - if (ppls.getID().equals("")) | 427 | + newList = p.parseFile(download.doInBackground(URI)).get(0).getLists().get(0); |
428 | + if (!GroupID.equals(ppls.getID())) | ||
427 | { | 429 | { |
428 | - /* | ||
429 | - * If working with the default ParentList, | ||
430 | - * then modify it, don't create a new one. | ||
431 | - */ | ||
432 | - ppls.setDefault(Default); | ||
433 | - ppls.setName(Name); | ||
434 | - ppls.setType(Type); | ||
435 | - ppls.getLists().set(0, newList); | ||
436 | - ppls.setID(GroupID); | 430 | + if (ppls.getID().equals("")) |
431 | + { | ||
432 | + /* | ||
433 | + * If working with the default ParentList, | ||
434 | + * then modify it, don't create a new one. | ||
435 | + */ | ||
436 | + ppls.setDefault(Default); | ||
437 | + ppls.setName(Name); | ||
438 | + ppls.setType(Type); | ||
439 | + ppls.getLists().set(0, newList); | ||
440 | + ppls.setID(GroupID); | ||
441 | + } | ||
442 | + else | ||
443 | + { | ||
444 | + | ||
445 | + currentList = searchID(GroupID, lists); | ||
446 | + if (currentList == -1) | ||
447 | + { | ||
448 | + ParentList pl = new ParentList(GroupID); | ||
449 | + pl.setDefault(Default); | ||
450 | + pl.setName(Name); | ||
451 | + pl.setType(Type); | ||
452 | + lists.add(pl); | ||
453 | + currentList = lists.size() - 1; | ||
454 | + } | ||
455 | + ppls = lists.get(currentList); | ||
456 | + ppls.getLists().add(newList); | ||
457 | + } | ||
437 | } | 458 | } |
438 | else | 459 | else |
439 | { | 460 | { |
440 | - | ||
441 | - currentList = searchID(GroupID, lists); | ||
442 | - if (currentList == -1) | ||
443 | - { | ||
444 | - ParentList pl = new ParentList(GroupID); | ||
445 | - pl.setDefault(Default); | ||
446 | - pl.setName(Name); | ||
447 | - pl.setType(Type); | ||
448 | - lists.add(pl); | ||
449 | - currentList = lists.size() - 1; | ||
450 | - } | ||
451 | - ppls = lists.get(currentList); | ||
452 | ppls.getLists().add(newList); | 461 | ppls.getLists().add(newList); |
453 | } | 462 | } |
454 | } | 463 | } |
455 | - else | 464 | + catch (IOException e) |
456 | { | 465 | { |
457 | - ppls.getLists().add(newList); | 466 | + // Nunca llegará aquí la cosa, y si lo hace ES CULPA DEL SERVIDOR!! |
458 | } | 467 | } |
459 | } | 468 | } |
460 | 469 | ||
@@ -513,12 +522,20 @@ public class Parser | @@ -513,12 +522,20 @@ public class Parser | ||
513 | */ | 522 | */ |
514 | expectList = false; | 523 | expectList = false; |
515 | Parser p = new Parser(line.substring(0, line.lastIndexOf("/") + 1), caller); | 524 | Parser p = new Parser(line.substring(0, line.lastIndexOf("/") + 1), caller); |
516 | - Video newList = p.parseFile(download.doInBackground(line)).get(0).getLists().get(0); | ||
517 | - pls.setMaxDuration(newList.getMaxDuration()); | ||
518 | - pls.setSequence(newList.getSequence()); | ||
519 | - for (int i = 0; i < newList.getSegments().size(); i++) | 525 | + Video newList; |
526 | + try | ||
527 | + { | ||
528 | + newList = p.parseFile(download.doInBackground(line)).get(0).getLists().get(0); | ||
529 | + pls.setMaxDuration(newList.getMaxDuration()); | ||
530 | + pls.setSequence(newList.getSequence()); | ||
531 | + for (int i = 0; i < newList.getSegments().size(); i++) | ||
532 | + { | ||
533 | + pls.getSegments().add(newList.getSegments().get(i)); | ||
534 | + } | ||
535 | + } | ||
536 | + catch (IOException e) | ||
520 | { | 537 | { |
521 | - pls.getSegments().add(newList.getSegments().get(i)); | 538 | + // Nunca llegará aquí la cosa, y si lo hace ES CULPA DEL SERVIDOR!! |
522 | } | 539 | } |
523 | } | 540 | } |
524 | else | 541 | else |