/
UmbriaParser.java
90 lines (73 loc) · 3.12 KB
/
UmbriaParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.alberovalley.novedadesumbria.comm;
import android.util.Log;
import com.alberovalley.utils.AlberoLog;
public class UmbriaParser {
// ////////////////////////////////////////////////////////////
// Constants
// ////////////////////////////////////////////////////////////
private static final String STORYTELLER_TAG = "<h3>Nuevos mensajes en partidas como director</h3>";
private static final String PLAYER_TAG = "<h3>Nuevos mensajes en las partidas como jugador</h3>";
private static final String VIP_TAG = "<h3>Nuevos mensajes en partidas VIP</h3>";
private static final String PRIVATE_MESSAGES_TAG = "title=\"Mensajes privados\"><span>";
private static final String NO_MSG_TAG = "<p>No hay novedades</p>";
// ////////////////////////////////////////////////////////////
// Methods
// ////////////////////////////////////////////////////////////
public static int findStorytellerMessages(String html) {
AlberoLog.d("NovedadesParser.findStorytellerMessages ");
return findMessageByTag(html, STORYTELLER_TAG);
}
public static int findPlayerMessages(String html) {
AlberoLog.d("NovedadesParser.findPlayerMessages");
return findMessageByTag(html, PLAYER_TAG);
}
public static int findVIPMessages(String html) {
AlberoLog.d("NovedadesParser.findVIPMessages");
return findMessageByTag(html, VIP_TAG);
}
/*
* public static String findNumericalId(String html, String username) {
* String numericalId = "";
* String substring = html.substring(html.lastIndexOf(username));
* return numericalId;
* }
*/
public static int findPrivateMessages(String html) {
AlberoLog.d("NovedadesParser.findPrivateMessages ");
int msg = 0;
Log.w("novUmbria", "findPrivateMessages html" + html);
final String tag = PRIVATE_MESSAGES_TAG;
int indexOfTag = html.lastIndexOf(tag) + tag.length();
if (indexOfTag > 0) {
String substring = html.substring(
indexOfTag, indexOfTag + 1
);
AlberoLog.v("findPrivateMessages substring " + substring);
msg = Integer.parseInt(substring);
} else {
AlberoLog.v("findPrivateMessages indexOfTag <=0 ");
}
return msg;
}
public static int findMessageByTag(String html, String tag) {
AlberoLog.d("findMessageByTag tag: " + tag);
int msg = 0;
int indexOfTag = html.lastIndexOf(tag);
String substring = html.substring(indexOfTag + tag.length(), indexOfTag + (3 * tag.length()));
AlberoLog.d("findMessageByTag substring: " + substring);
indexOfTag = substring.lastIndexOf(NO_MSG_TAG);
AlberoLog.d("findMessageByTag indexOfTag: " + indexOfTag);
switch (indexOfTag) {
case -1:
// sí hay mensaje
AlberoLog.d("findMessageByTag hay mensaje: ");
msg = 1;
break;
default:
// no hay mensaje
msg = 0;
AlberoLog.d("findMessageByTag no hay mensaje: ");
}
return msg;
}
}