Fix batoto chapter dates. Remove subjects subscribe schedulers

This commit is contained in:
inorichi 2015-12-05 15:43:33 +01:00
parent d859947c7c
commit eaab0f33ce
4 changed files with 37 additions and 11 deletions

View File

@ -18,9 +18,14 @@ import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import eu.kanade.mangafeed.data.database.models.Chapter;
import eu.kanade.mangafeed.data.database.models.Manga;
@ -41,8 +46,22 @@ public class Batoto extends Source {
public static final String MANGA_URL = "/comic_pop?id=%s";
public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global&section=login";
private Pattern datePattern;
private Map<String, Integer> dateFields;
public Batoto(Context context) {
super(context);
datePattern = Pattern.compile("(\\d+|A)\\s+(.*?)s? ago.*");
dateFields = new HashMap<String, Integer>() {{
put("second", Calendar.SECOND);
put("minute", Calendar.MINUTE);
put("hour", Calendar.HOUR);
put("day", Calendar.DATE);
put("week", Calendar.WEEK_OF_YEAR);
put("month", Calendar.MONTH);
put("year", Calendar.YEAR);
}};
}
@Override
@ -325,16 +344,27 @@ public class Batoto extends Source {
private long parseDateFromElement(Element dateElement) {
String dateAsString = dateElement.text();
Date date;
try {
Date specificDate = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(dateAsString);
return specificDate.getTime();
date = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(dateAsString);
} catch (ParseException e) {
// Do Nothing.
}
Matcher m = datePattern.matcher(dateAsString);
if (m.matches()) {
String number = m.group(1);
int amount = number.equals("A") ? 1 : Integer.parseInt(m.group(1));
String unit = m.group(2);
Calendar cal = Calendar.getInstance();
// Not an error
cal.add(dateFields.get(unit), -amount);
date = cal.getTime();
} else {
return 0;
}
}
return date.getTime();
}
@Override
protected List<String> parseHtmlToPageUrls(String unparsedHtml) {

View File

@ -31,7 +31,6 @@ import icepick.State;
import nucleus.factory.RequiresPresenter;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
@RequiresPresenter(CataloguePresenter.class)
@ -139,7 +138,6 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
queryDebouncerSubject = PublishSubject.create();
queryDebouncerSubscription = queryDebouncerSubject
.debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::restartRequest);
}

View File

@ -66,7 +66,6 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
restartableLatestCache(GET_MANGA_DETAIL,
() -> mangaDetailSubject
.subscribeOn(Schedulers.io())
.flatMap(Observable::from)
.filter(manga -> !manga.initialized)
.window(3)

View File

@ -165,8 +165,7 @@ public class ViewPagerReaderFragment extends BaseFragment {
final AtomicInteger currentValue = new AtomicInteger(-1);
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS, Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(tick -> {
// Refresh UI only if progress change