Search in sources :

Example 21 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project CloudReader by youlookwhat.

the class CollectLinkModel method getCollectUrlList.

public MutableLiveData<CollectUrlBean> getCollectUrlList() {
    final MutableLiveData<CollectUrlBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getCollectUrlList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<CollectUrlBean>() {

        @Override
        public void accept(CollectUrlBean collectUrlBean) throws Exception {
            if (collectUrlBean != null && collectUrlBean.getData() != null && collectUrlBean.getData().size() > 0) {
                // 对集合中的数据进行倒叙排序
                Collections.reverse(collectUrlBean.getData());
                data.setValue(collectUrlBean);
            } else {
                data.setValue(collectUrlBean);
            }
        }
    }, throwable -> data.setValue(null));
    addDisposable(subscribe);
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) CollectUrlBean(com.example.jingbin.cloudreader.bean.CollectUrlBean) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 22 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project CloudReader by youlookwhat.

the class WanAndroidListViewModel method getWanAndroidBanner.

public MutableLiveData<WanAndroidBannerBean> getWanAndroidBanner() {
    final MutableLiveData<WanAndroidBannerBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getWanAndroidBanner().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<WanAndroidBannerBean>() {

        @Override
        public void accept(WanAndroidBannerBean bannerBean) throws Exception {
            if (bannerBean != null && bannerBean.getData() != null && bannerBean.getData().size() > 0) {
                data.setValue(bannerBean);
            } else {
                data.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            data.setValue(null);
        }
    });
    addDisposable(subscribe);
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) WanAndroidBannerBean(com.example.jingbin.cloudreader.bean.wanandroid.WanAndroidBannerBean) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 23 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project CloudReader by youlookwhat.

the class TreeViewModel method getTree.

public MutableLiveData<TreeBean> getTree() {
    final MutableLiveData<TreeBean> data = new MutableLiveData<>();
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getTree().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<TreeBean>() {

        @Override
        public void accept(TreeBean treeBean) throws Exception {
            data.setValue(treeBean);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            data.setValue(null);
        }
    });
    addDisposable(subscribe);
    return data;
}
Also used : Disposable(io.reactivex.disposables.Disposable) MutableLiveData(androidx.lifecycle.MutableLiveData) TreeBean(com.example.jingbin.cloudreader.bean.wanandroid.TreeBean)

Example 24 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project Signal-Android by signalapp.

the class LiveDataUtil method delay.

/**
 * After {@param delay} ms after observation, emits a single Object, {@param value}.
 */
public static <T> LiveData<T> delay(long delay, T value) {
    return new MutableLiveData<T>() {

        boolean emittedValue;

        @Override
        protected void onActive() {
            if (emittedValue)
                return;
            new Handler(Looper.getMainLooper()).postDelayed(() -> setValue(value), delay);
            emittedValue = true;
        }
    };
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) Handler(android.os.Handler)

Example 25 with MutableLiveData

use of androidx.lifecycle.MutableLiveData in project android_packages_apps_Settings by omnirom.

the class PasswordsPreferenceController method addPasswordPreferences.

private void addPasswordPreferences(Context prefContext, @UserIdInt int user, PreferenceGroup group) {
    for (int i = 0; i < mServices.size(); i++) {
        final AutofillServiceInfo service = mServices.get(i);
        final AppPreference pref = new AppPreference(prefContext);
        final ServiceInfo serviceInfo = service.getServiceInfo();
        pref.setTitle(serviceInfo.loadLabel(mPm));
        final Drawable icon = mIconFactory.getBadgedIcon(serviceInfo, serviceInfo.applicationInfo, user);
        pref.setIcon(Utils.getSafeIcon(icon));
        pref.setOnPreferenceClickListener(p -> {
            final Intent intent = new Intent(Intent.ACTION_MAIN).setClassName(serviceInfo.packageName, service.getPasswordsActivity());
            prefContext.startActivityAsUser(intent, UserHandle.of(user));
            return true;
        });
        // Set a placeholder summary to avoid a UI flicker when the value loads.
        pref.setSummary(R.string.autofill_passwords_count_placeholder);
        final MutableLiveData<Integer> passwordCount = new MutableLiveData<>();
        passwordCount.observe(mLifecycleOwner, count -> {
            // TODO(b/169455298): Validate the result.
            final CharSequence summary = mContext.getResources().getQuantityString(R.plurals.autofill_passwords_count, count, count);
            pref.setSummary(summary);
        });
        // TODO(b/169455298): Limit the number of concurrent queries.
        // TODO(b/169455298): Cache the results for some time.
        requestSavedPasswordCount(service, user, passwordCount);
        group.addPreference(pref);
    }
}
Also used : AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AppPreference(com.android.settingslib.widget.AppPreference) AutofillServiceInfo(android.service.autofill.AutofillServiceInfo) Drawable(android.graphics.drawable.Drawable) MutableLiveData(androidx.lifecycle.MutableLiveData) Intent(android.content.Intent)

Aggregations

MutableLiveData (androidx.lifecycle.MutableLiveData)25 Disposable (io.reactivex.disposables.Disposable)14 Test (org.junit.Test)6 GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)3 AudioButton (org.odk.collect.android.audio.AudioButton)3 AudioVideoImageTextLabel (org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel)3 RecordingSession (org.odk.collect.audiorecorder.recording.RecordingSession)3 Handler (android.os.Handler)2 Pair (android.util.Pair)2 CoinBean (com.example.jingbin.cloudreader.bean.CoinBean)2 BaseResultBean (com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean)2 HomeListBean (com.example.jingbin.cloudreader.bean.wanandroid.HomeListBean)2 RequestImpl (com.example.jingbin.cloudreader.http.RequestImpl)2 File (java.io.File)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 Intent (android.content.Intent)1 ServiceInfo (android.content.pm.ServiceInfo)1 Drawable (android.graphics.drawable.Drawable)1 AutofillServiceInfo (android.service.autofill.AutofillServiceInfo)1 AppPreference (com.android.settingslib.widget.AppPreference)1