mirror of https://github.com/readrops/Readrops.git
put parseUrl logic in the viewModel
This commit is contained in:
parent
bc263a05f8
commit
5aa6496d1e
|
@ -147,19 +147,8 @@ public class AddFeedActivity extends AppCompatActivity implements View.OnClickLi
|
|||
else
|
||||
finalUrl = url;
|
||||
|
||||
Single.create((SingleOnSubscribe<List<ParsingResult>>) emitter -> {
|
||||
RSSNetwork rssApi = new RSSNetwork();
|
||||
List<ParsingResult> results = new ArrayList<>();
|
||||
|
||||
if (rssApi.isUrlFeedLink(finalUrl)) {
|
||||
ParsingResult parsingResult = new ParsingResult(finalUrl, null);
|
||||
results.add(parsingResult);
|
||||
|
||||
} else
|
||||
results.addAll(HtmlParser.getFeedLink(finalUrl));
|
||||
|
||||
emitter.onSuccess(results);
|
||||
}).subscribeOn(Schedulers.io())
|
||||
viewModel.parseUrl(finalUrl)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SingleObserver<List<ParsingResult>>() {
|
||||
@Override
|
||||
|
|
|
@ -5,11 +5,16 @@ import android.arch.lifecycle.AndroidViewModel;
|
|||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.readrops.app.repositories.LocalFeedRepository;
|
||||
import com.readrops.app.utils.HtmlParser;
|
||||
import com.readrops.app.utils.ParsingResult;
|
||||
import com.readrops.readropslibrary.localfeed.RSSNetwork;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
|
||||
public class AddFeedsViewModel extends AndroidViewModel {
|
||||
|
||||
|
@ -24,4 +29,20 @@ public class AddFeedsViewModel extends AndroidViewModel {
|
|||
public Completable addFeeds(List<ParsingResult> results) {
|
||||
return repository.addFeeds(results);
|
||||
}
|
||||
|
||||
public Single<List<ParsingResult>> parseUrl(String url) {
|
||||
return Single.create(emitter -> {
|
||||
RSSNetwork rssApi = new RSSNetwork();
|
||||
List<ParsingResult> results = new ArrayList<>();
|
||||
|
||||
if (rssApi.isUrlFeedLink(url)) {
|
||||
ParsingResult parsingResult = new ParsingResult(url, null);
|
||||
results.add(parsingResult);
|
||||
|
||||
} else
|
||||
results.addAll(HtmlParser.getFeedLink(url));
|
||||
|
||||
emitter.onSuccess(results);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue