mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Fix batoto chapter dates. Remove subjects subscribe schedulers
This commit is contained in:
parent
d859947c7c
commit
eaab0f33ce
@ -18,9 +18,14 @@ import java.net.URISyntaxException;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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.Chapter;
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
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 MANGA_URL = "/comic_pop?id=%s";
|
||||||
public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global§ion=login";
|
public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global§ion=login";
|
||||||
|
|
||||||
|
private Pattern datePattern;
|
||||||
|
private Map<String, Integer> dateFields;
|
||||||
|
|
||||||
public Batoto(Context context) {
|
public Batoto(Context context) {
|
||||||
super(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
|
@Override
|
||||||
@ -325,15 +344,26 @@ public class Batoto extends Source {
|
|||||||
private long parseDateFromElement(Element dateElement) {
|
private long parseDateFromElement(Element dateElement) {
|
||||||
String dateAsString = dateElement.text();
|
String dateAsString = dateElement.text();
|
||||||
|
|
||||||
|
Date date;
|
||||||
try {
|
try {
|
||||||
Date specificDate = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(dateAsString);
|
date = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(dateAsString);
|
||||||
|
|
||||||
return specificDate.getTime();
|
|
||||||
} catch (ParseException e) {
|
} 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
|
@Override
|
||||||
|
@ -31,7 +31,6 @@ import icepick.State;
|
|||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
import rx.Subscription;
|
import rx.Subscription;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
@RequiresPresenter(CataloguePresenter.class)
|
@RequiresPresenter(CataloguePresenter.class)
|
||||||
@ -139,7 +138,6 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> {
|
|||||||
queryDebouncerSubject = PublishSubject.create();
|
queryDebouncerSubject = PublishSubject.create();
|
||||||
queryDebouncerSubscription = queryDebouncerSubject
|
queryDebouncerSubscription = queryDebouncerSubject
|
||||||
.debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS)
|
.debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::restartRequest);
|
.subscribe(this::restartRequest);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
|
|||||||
|
|
||||||
restartableLatestCache(GET_MANGA_DETAIL,
|
restartableLatestCache(GET_MANGA_DETAIL,
|
||||||
() -> mangaDetailSubject
|
() -> mangaDetailSubject
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.flatMap(Observable::from)
|
.flatMap(Observable::from)
|
||||||
.filter(manga -> !manga.initialized)
|
.filter(manga -> !manga.initialized)
|
||||||
.window(3)
|
.window(3)
|
||||||
|
@ -165,8 +165,7 @@ public class ViewPagerReaderFragment extends BaseFragment {
|
|||||||
|
|
||||||
final AtomicInteger currentValue = new AtomicInteger(-1);
|
final AtomicInteger currentValue = new AtomicInteger(-1);
|
||||||
|
|
||||||
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS)
|
progressSubscription = Observable.interval(75, TimeUnit.MILLISECONDS, Schedulers.newThread())
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(tick -> {
|
.subscribe(tick -> {
|
||||||
// Refresh UI only if progress change
|
// Refresh UI only if progress change
|
||||||
|
Loading…
Reference in New Issue
Block a user