Browse Source

parse tag starts

pull/61/merge
Thodoris1999 6 years ago
parent
commit
c9c3e03123
  1. 35
      app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java
  2. 10
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  3. 33
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java

35
app/src/main/java/gr/thmmy/mthmmy/model/BBTag.java

@ -0,0 +1,35 @@
package gr.thmmy.mthmmy.model;
public class BBTag {
private int start, end;
private String name;
public BBTag(int start, String name) {
this.start = start;
this.name = name;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

10
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -123,16 +123,12 @@ public class SessionManager {
editor.putString(USERNAME, extractUserName(document)); editor.putString(USERNAME, extractUserName(document));
editor.putInt(USER_ID, extractUserId(document)); editor.putInt(USER_ID, extractUserId(document));
String avatar = extractAvatarLink(document); String avatar = extractAvatarLink(document);
if (avatar != null) { if (avatar != null)
editor.putBoolean(HAS_AVATAR, true);
editor.putString(AVATAR_LINK, avatar); editor.putString(AVATAR_LINK, avatar);
} else editor.putBoolean(HAS_AVATAR, avatar != null);
editor.putBoolean(HAS_AVATAR, false); editor.putString(LOGOUT_LINK, extractLogoutLink(document));
editor.apply(); editor.apply();
sharedPrefs.edit().putString(LOGOUT_LINK, extractLogoutLink(document)).apply();
return SUCCESS; return SUCCESS;
} else { } else {
Timber.i("Login failed."); Timber.i("Login failed.");

33
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/BBParser.java

@ -2,11 +2,44 @@ package gr.thmmy.mthmmy.utils.parsing;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.SpannedString; import android.text.SpannedString;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.model.BBTag;
import timber.log.Timber;
public class BBParser { public class BBParser {
public static final String[] supportedTags = {"b"}; public static final String[] supportedTags = {"b"};
public SpannedString bb2span(String bb) { public SpannedString bb2span(String bb) {
SpannableStringBuilder builder = new SpannableStringBuilder(bb); SpannableStringBuilder builder = new SpannableStringBuilder(bb);
BBTag[] tags = getTags(bb);
}
public BBTag[] getTags(String bb) {
Pattern bbtagPattern = Pattern.compile("[*+]");
LinkedList<BBTag> tags = new LinkedList<>();
String searcingString = bb;
Matcher bbMatcher = bbtagPattern.matcher(searcingString);
while (bbMatcher.find()) {
String name = bbMatcher.group(0);
if (!isSupported(name)) continue;
tags.add(new BBTag(bbMatcher.start(), name));
searcingString = searcingString.substring(bbMatcher.start() + name.length());
bbMatcher = bbtagPattern.matcher(searcingString);
}
return tags.toArray(new BBTag[0]);
}
public boolean isSupported(String tagName) {
for (String tag : supportedTags)
if (TextUtils.equals(tag, tagName)) return true;
return false;
} }
} }

Loading…
Cancel
Save