Search in sources :

Example 6 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project RxCache by VictorAlbertos.

the class ProcessorProvidersTest method getSubscriberCompleted.

private TestObserver getSubscriberCompleted(boolean hasCache, final boolean evictCache, boolean detailResponse, Loader loader, boolean useExpiredDataIfLoaderNotAvailable) {
    Observable observable;
    switch(loader) {
        case VALID:
            observable = Observable.just(new Mock("message"));
            break;
        case NULL:
            observable = Observable.error(new RuntimeException("No data"));
            break;
        default:
            observable = Observable.create(new ObservableOnSubscribe<Object>() {

                @Override
                public void subscribe(ObservableEmitter<Object> e) throws Exception {
                    throw new RuntimeException("error");
                }
            });
            break;
    }
    ConfigProvider configProvider = new ConfigProvider("mockKey", null, null, detailResponse, true, false, "", "", observable, new EvictProvider(evictCache));
    if (hasCache)
        twoLayersCacheMock.save("mockKey", "", "", new Mock("message"), configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
    processorProvidersUT = new ProcessorProvidersBehaviour(twoLayersCacheMock, useExpiredDataIfLoaderNotAvailable, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
    TestObserver observerMock = processorProvidersUT.getData(configProvider).test();
    observerMock.awaitTerminalEvent();
    return observerMock;
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ConfigProvider(io.rx_cache2.ConfigProvider) EvictProvider(io.rx_cache2.EvictProvider) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter) TestObserver(io.reactivex.observers.TestObserver)

Example 7 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project okhttp-OkGo by jeasonlzy.

the class RxFormUploadActivity method formUpload2.

@OnClick(R.id.formUpload2)
public void formUpload2(View view) {
    final ArrayList<File> files = new ArrayList<>();
    if (imageItems != null && imageItems.size() > 0) {
        for (int i = 0; i < imageItems.size(); i++) {
            files.add(new File(imageItems.get(i).path));
        }
    }
    Observable.create(new ObservableOnSubscribe<Progress>() {

        @Override
        public void subscribe(@NonNull final ObservableEmitter<Progress> e) throws Exception {
            // 
            OkGo.<String>post(Urls.URL_FORM_UPLOAD).tag(// 
            this).headers("header1", // 
            "headerValue1").headers("header2", // 
            "headerValue2").params("param1", // 
            "paramValue1").params("param2", // 
            "paramValue2").addFileParams("file", // 
            files).execute(new StringCallback() {

                @Override
                public void onSuccess(Response<String> response) {
                    e.onComplete();
                }

                @Override
                public void onError(Response<String> response) {
                    e.onError(response.getException());
                }

                @Override
                public void uploadProgress(Progress progress) {
                    e.onNext(progress);
                }
            });
        }
    }).doOnSubscribe(new Consumer<Disposable>() {

        @Override
        public void accept(@NonNull Disposable disposable) throws Exception {
            btnFormUpload2.setText("正在上传中...");
        }
    }).observeOn(// 
    AndroidSchedulers.mainThread()).subscribe(new Observer<Progress>() {

        @Override
        public void onSubscribe(@NonNull Disposable d) {
            addDisposable(d);
        }

        @Override
        public void onNext(@NonNull Progress progress) {
            System.out.println("uploadProgress: " + progress);
            String downloadLength = Formatter.formatFileSize(getApplicationContext(), progress.currentSize);
            String totalLength = Formatter.formatFileSize(getApplicationContext(), progress.totalSize);
            tvDownloadSize.setText(downloadLength + "/" + totalLength);
            String speed = Formatter.formatFileSize(getApplicationContext(), progress.speed);
            tvNetSpeed.setText(String.format("%s/s", speed));
            tvProgress.setText(numberFormat.format(progress.fraction));
            pbProgress.setMax(10000);
            pbProgress.setProgress((int) (progress.fraction * 10000));
        }

        @Override
        public void onError(@NonNull Throwable e) {
            e.printStackTrace();
            btnFormUpload2.setText("上传出错");
            showToast(e.getMessage());
        }

        @Override
        public void onComplete() {
            btnFormUpload2.setText("上传完成");
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) Progress(com.lzy.okgo.model.Progress) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ArrayList(java.util.ArrayList) StringCallback(com.lzy.okgo.callback.StringCallback) NonNull(io.reactivex.annotations.NonNull) File(java.io.File) ObservableEmitter(io.reactivex.ObservableEmitter) OnClick(butterknife.OnClick)

Example 8 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project J2ME-Loader by nikita36078.

the class AppsListFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchViewDisposable = Observable.create((ObservableOnSubscribe<String>) emitter -> searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            emitter.onNext(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            emitter.onNext(newText);
            return true;
        }
    })).debounce(300, TimeUnit.MILLISECONDS).map(String::toLowerCase).distinctUntilChanged().observeOn(AndroidSchedulers.mainThread()).subscribe(charSequence -> adapter.getFilter().filter(charSequence));
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) AppUtils(ru.playsoftware.j2meloader.util.AppUtils) Bundle(android.os.Bundle) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Constants(ru.playsoftware.j2meloader.util.Constants) NonNull(androidx.annotation.NonNull) AboutDialogFragment(ru.playsoftware.j2meloader.info.AboutDialogFragment) Uri(android.net.Uri) AppRepository(ru.playsoftware.j2meloader.appsdb.AppRepository) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) ConfigActivity(ru.playsoftware.j2meloader.config.ConfigActivity) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Canvas(android.graphics.Canvas) PREF_APP_SORT(ru.playsoftware.j2meloader.util.Constants.PREF_APP_SORT) AdapterView(android.widget.AdapterView) Log(android.util.Log) RectF(android.graphics.RectF) HelpDialogFragment(ru.playsoftware.j2meloader.info.HelpDialogFragment) ProfilesActivity(ru.playsoftware.j2meloader.config.ProfilesActivity) KEY_APP_URI(ru.playsoftware.j2meloader.util.Constants.KEY_APP_URI) SearchView(androidx.appcompat.widget.SearchView) ViewGroup(android.view.ViewGroup) Config(ru.playsoftware.j2meloader.config.Config) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ListFragment(androidx.fragment.app.ListFragment) ListView(android.widget.ListView) ActivityManager(android.app.ActivityManager) Context(android.content.Context) ContextMenu(android.view.ContextMenu) AlertDialog(androidx.appcompat.app.AlertDialog) R(ru.playsoftware.j2meloader.R) PREF_LAST_PATH(ru.playsoftware.j2meloader.util.Constants.PREF_LAST_PATH) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) Environment(android.os.Environment) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) SettingsActivity(ru.playsoftware.j2meloader.settings.SettingsActivity) Intent(android.content.Intent) MenuItem(android.view.MenuItem) FragmentActivity(androidx.fragment.app.FragmentActivity) FilteredFilePickerFragment(ru.playsoftware.j2meloader.filepicker.FilteredFilePickerFragment) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) Observable(io.reactivex.Observable) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) FileUtils(ru.playsoftware.j2meloader.util.FileUtils) InstallerDialog(ru.woesss.j2me.installer.InstallerDialog) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) DonationsActivity(ru.playsoftware.j2meloader.donations.DonationsActivity) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) LogUtils(ru.playsoftware.j2meloader.util.LogUtils) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) KEY_MIDLET_NAME(ru.playsoftware.j2meloader.util.Constants.KEY_MIDLET_NAME) Bitmap(android.graphics.Bitmap) PreferenceManager(androidx.preference.PreferenceManager) Activity(android.app.Activity) EditText(android.widget.EditText) SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem)

Example 9 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project SmartCampus by Vegen.

the class EmploymentArticleDetailPresenter method getEmploymentList.

@Override
public void getEmploymentList(String url, int type) {
    Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
        Document document = Jsoup.connect(url).get();
        e.onNext(document);
        e.onComplete();
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
        Element body = document.body();
        if (mView != null) {
            mView.showEmploymentList(filterData(body, type));
            mView.hideLoading(false);
            if (type == Constant.FAIR)
                mView.loadMoreEnd(true);
        }
    }, throwable -> {
        if (mView != null) {
            mView.showMessage(HttpError.getErrorMessage(throwable));
            mView.hideLoading(true);
        }
    });
    mHttpLinkers.add(new DisposableHolder(disposable));
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Element(org.jsoup.nodes.Element) DisposableHolder(com.vegen.smartcampus.baseframework.network.DisposableHolder) Document(org.jsoup.nodes.Document)

Example 10 with ObservableOnSubscribe

use of io.reactivex.ObservableOnSubscribe in project SmartCampus by Vegen.

the class ArticleDetailPresenter method getNewsContent.

@Override
public void getNewsContent(String url) {
    Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
        Document document = Jsoup.connect(url).get();
        e.onNext(document);
        e.onComplete();
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
        Element body = document.body();
        // 带有href属性的a元素
        Elements links = body.select("a[href]");
        for (Element element : links) {
            element.attr("href", "");
        }
        Element author = body.select("#author").first();
        Element contentbody = body.select("#contentbody").first();
        Element showtag = body.select("#showtag").last();
        if (mView != null) {
            mView.showNewsContent("</br>" + (author.html() + contentbody.html() + showtag.html()).replace("font-size: 10.5pt", "font-size: 16.5pt").replace("FONT-SIZE: 10.5pt", "FONT-SIZE: 16.5pt").replace("src=\"/files", "src=\"" + Url.ROOT_URL + "/files").replace("href=\"\"", "").replace("【点击:", "【点击:" + SystemUtils.getRandom(5, 30)).replace("发布时间", "</br>发布时间"));
            mView.hideLoading(false);
        }
    }, throwable -> {
        if (mView != null) {
            mView.showMessage(HttpError.getErrorMessage(throwable));
            mView.hideLoading(true);
        }
    });
    mHttpLinkers.add(new DisposableHolder(disposable));
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Element(org.jsoup.nodes.Element) DisposableHolder(com.vegen.smartcampus.baseframework.network.DisposableHolder) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)64 ObservableEmitter (io.reactivex.ObservableEmitter)54 Disposable (io.reactivex.disposables.Disposable)36 Observable (io.reactivex.Observable)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 File (java.io.File)11 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)9 NonNull (io.reactivex.annotations.NonNull)8 IOException (java.io.IOException)8 Intent (android.content.Intent)7 Observer (io.reactivex.Observer)7 Consumer (io.reactivex.functions.Consumer)7 Bitmap (android.graphics.Bitmap)6 Bundle (android.os.Bundle)6 OnClick (butterknife.OnClick)6 Uri (android.net.Uri)5 View (android.view.View)5 BindView (butterknife.BindView)5 HashMap (java.util.HashMap)5