diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java index b46fbf750..7acbf1afe 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java @@ -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§ion=login"; + private Pattern datePattern; + private Map dateFields; + public Batoto(Context context) { super(context); + + datePattern = Pattern.compile("(\\d+|A)\\s+(.*?)s? ago.*"); + dateFields = new HashMap() {{ + 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,15 +344,26 @@ 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); - return 0; + 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 diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java index 99f179303..dac224456 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java @@ -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 { queryDebouncerSubject = PublishSubject.create(); queryDebouncerSubscription = queryDebouncerSubject .debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS) - .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::restartRequest); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index 8d3cca58b..dc4729bbf 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -66,7 +66,6 @@ public class CataloguePresenter extends BasePresenter { restartableLatestCache(GET_MANGA_DETAIL, () -> mangaDetailSubject - .subscribeOn(Schedulers.io()) .flatMap(Observable::from) .filter(manga -> !manga.initialized) .window(3) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java index 6108f7326..b8f98c4d5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java @@ -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