Search in sources :

Example 1 with ContentHelper

use of me.devsaki.hentoid.util.ContentHelper in project Hentoid by avluis.

the class ImageViewerViewModel method reparseBook.

/**
 * Send the current book to the queue to be reparsed from scratch
 *
 * @param onError Consumer to call in case reparsing fails
 */
public void reparseBook(Consumer<Throwable> onError) {
    Content theContent = content.getValue();
    if (null == theContent)
        return;
    compositeDisposable.add(Observable.fromIterable(Stream.of(theContent).toList()).observeOn(Schedulers.io()).map(ContentHelper::reparseFromScratch).doOnNext(c -> {
        if (c.right.isEmpty())
            throw new EmptyResultException();
        dao.addContentToQueue(c.right.get(), StatusContent.SAVED, ContentHelper.QueuePosition.TOP, ContentQueueManager.getInstance().isQueueActive(getApplication()));
    }).observeOn(AndroidSchedulers.mainThread()).doOnComplete(() -> {
        if (Preferences.isQueueAutostart())
            ContentQueueManager.getInstance().resumeQueue(getApplication());
    }).subscribe(v -> {
    // Nothing; feedback is done through LiveData
    }, onError::accept));
}
Also used : Content(me.devsaki.hentoid.database.domains.Content) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) DownloadHelper(me.devsaki.hentoid.util.download.DownloadHelper) Completable(io.reactivex.Completable) Uri(android.net.Uri) Random(java.util.Random) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Chapter(me.devsaki.hentoid.database.domains.Chapter) ContentHelper(me.devsaki.hentoid.util.ContentHelper) ContentSearchManager(me.devsaki.hentoid.widget.ContentSearchManager) Optional(com.annimon.stream.Optional) Consts(me.devsaki.hentoid.core.Consts) Site(me.devsaki.hentoid.enums.Site) StringHelper(me.devsaki.hentoid.util.StringHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposables(io.reactivex.disposables.Disposables) Consumer(com.annimon.stream.function.Consumer) Map(java.util.Map) ImageFile(me.devsaki.hentoid.database.domains.ImageFile) UnsupportedContentException(me.devsaki.hentoid.util.exception.UnsupportedContentException) Schedulers(io.reactivex.schedulers.Schedulers) Collection(java.util.Collection) ObservableEmitter(io.reactivex.ObservableEmitter) Set(java.util.Set) ToastHelper(me.devsaki.hentoid.util.ToastHelper) HttpHelper(me.devsaki.hentoid.util.network.HttpHelper) Timber(timber.log.Timber) Objects(java.util.Objects) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ContentNotProcessedException(me.devsaki.hentoid.util.exception.ContentNotProcessedException) ProcessEvent(me.devsaki.hentoid.events.ProcessEvent) Application(android.app.Application) DocumentFile(androidx.documentfile.provider.DocumentFile) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) CollectionDAO(me.devsaki.hentoid.database.CollectionDAO) MediatorLiveData(androidx.lifecycle.MediatorLiveData) IntStream(com.annimon.stream.IntStream) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MutableLiveData(androidx.lifecycle.MutableLiveData) Context(android.content.Context) Preferences(me.devsaki.hentoid.util.Preferences) Stream(com.annimon.stream.Stream) EmptyResultException(me.devsaki.hentoid.util.exception.EmptyResultException) Pair(android.util.Pair) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Single(io.reactivex.Single) StatusContent(me.devsaki.hentoid.enums.StatusContent) ArrayList(java.util.ArrayList) ImageHelper(me.devsaki.hentoid.util.ImageHelper) HashSet(java.util.HashSet) Helper(me.devsaki.hentoid.util.Helper) AndroidViewModel(androidx.lifecycle.AndroidViewModel) EventBus(org.greenrobot.eventbus.EventBus) LimitReachedException(me.devsaki.hentoid.util.exception.LimitReachedException) Observable(io.reactivex.Observable) ContentParserFactory(me.devsaki.hentoid.parsers.ContentParserFactory) LiveData(androidx.lifecycle.LiveData) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) ContentQueueManager(me.devsaki.hentoid.util.download.ContentQueueManager) IOException(java.io.IOException) ImageListParser(me.devsaki.hentoid.parsers.images.ImageListParser) FileHelper(me.devsaki.hentoid.util.FileHelper) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) File(java.io.File) ObjectBoxDAO(me.devsaki.hentoid.database.ObjectBoxDAO) R(me.devsaki.hentoid.R) RandomSeedSingleton(me.devsaki.hentoid.util.RandomSeedSingleton) DownloadInterruptedException(me.devsaki.hentoid.util.exception.DownloadInterruptedException) Collections(java.util.Collections) ArchiveHelper(me.devsaki.hentoid.util.ArchiveHelper) EmptyResultException(me.devsaki.hentoid.util.exception.EmptyResultException) Content(me.devsaki.hentoid.database.domains.Content) StatusContent(me.devsaki.hentoid.enums.StatusContent)

Aggregations

Application (android.app.Application)1 Context (android.content.Context)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Pair (android.util.Pair)1 NonNull (androidx.annotation.NonNull)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 DocumentFile (androidx.documentfile.provider.DocumentFile)1 AndroidViewModel (androidx.lifecycle.AndroidViewModel)1 LiveData (androidx.lifecycle.LiveData)1 MediatorLiveData (androidx.lifecycle.MediatorLiveData)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 IntStream (com.annimon.stream.IntStream)1 Optional (com.annimon.stream.Optional)1 Stream (com.annimon.stream.Stream)1 Consumer (com.annimon.stream.function.Consumer)1 Completable (io.reactivex.Completable)1 Observable (io.reactivex.Observable)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 Single (io.reactivex.Single)1