当前位置: 首页>>代码示例>>Java>>正文


Java AndroidLifecycleScopeProvider类代码示例

本文整理汇总了Java中com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider的典型用法代码示例。如果您正苦于以下问题:Java AndroidLifecycleScopeProvider类的具体用法?Java AndroidLifecycleScopeProvider怎么用?Java AndroidLifecycleScopeProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AndroidLifecycleScopeProvider类属于com.uber.autodispose.android.lifecycle包,在下文中一共展示了AndroidLifecycleScopeProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadHubs

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void loadHubs() {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.loading));
    progressDialog.setCancelable(false);
    progressDialog.show();

    mHubManager.getAllInstalled()
            .subscribeOn(Schedulers.io())
            .flatMap(hubs -> mPreferenceManager.getOrderedVisibleHubs(hubs))
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(hubs -> {
                progressDialog.dismiss();
                mHubs.clear();
                mHubs.addAll(hubs);
                mPagerAdapter.notifyDataSetChanged();

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(HomeActivity.this, R.string.toast_load_hubs_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:23,代码来源:HomeActivity.java

示例2: showReinstallDialog

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void showReinstallDialog(File hubPackageFile, Hub hub, final ProgressDialog progressDialog) {
    mHubManager.readConfig(hub.getId())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(installedHub -> {
                progressDialog.dismiss();
                new AlertDialog.Builder(HomeActivity.this)
                        .setMessage(getString(R.string.dialog_ensure_reinstall_hub,
                                installedHub.getName(), installedHub.getVersion(), hub.getVersion()))
                        .setPositiveButton(R.string.yes, (dialog, which) -> {
                            installHub(hubPackageFile, progressDialog);
                        })
                        .setNegativeButton(R.string.cancel, null)
                        .show();

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(HomeActivity.this, R.string.toast_install_hub_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:22,代码来源:HomeActivity.java

示例3: installHub

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void installHub(File hubPackageFile, final ProgressDialog progressDialog) {
    progressDialog.setMessage(getString(R.string.dialog_installing_hub));
    progressDialog.setCancelable(false);
    progressDialog.show();

    mHubManager.install(this, hubPackageFile)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(hub -> {
                progressDialog.dismiss();
                Toast.makeText(HomeActivity.this, R.string.toast_install_hub_success, Toast.LENGTH_SHORT).show();

                // Send local broadcast
                BroadcastRouter.IMPL.tellHubInstalled(this, hub);

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(HomeActivity.this, R.string.toast_install_hub_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:22,代码来源:HomeActivity.java

示例4: loadHubPreferences

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void loadHubPreferences() {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.loading));
    progressDialog.setCancelable(false);
    progressDialog.show();

    mHubManager.getAllInstalled()
            .subscribeOn(Schedulers.io())
            .flatMap(hubs -> mPreferenceManager.loadHubPreferences(hubs))
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(preferences -> {
                progressDialog.dismiss();
                mPreferences.clear();
                mPreferences.addAll(preferences);
                mAdapter.notifyDataSetChanged();

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(this, R.string.toast_load_hubs_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:23,代码来源:HubManagerActivity.java

示例5: onCreate

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Log.d(TAG, "onCreate()");

  setContentView(R.layout.activity_main);

  // Using automatic disposal, this should determine that the correct time to
  // dispose is onDestroy (the opposite of onCreate).
  Observable.interval(1, TimeUnit.SECONDS)
      .doOnDispose(new Action() {
        @Override public void run() throws Exception {
          Log.i(TAG, "Disposing subscription from onCreate()");
        }
      })
      .as(AutoDispose.<Long>autoDisposable(AndroidLifecycleScopeProvider.from(this)))
      .subscribe(new Consumer<Long>() {
        @Override public void accept(Long num) throws Exception {
          Log.i(TAG, "Started in onCreate(), running until onDestroy(): " + num);
        }
      });
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:23,代码来源:MainActivity.java

示例6: onStart

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override protected void onStart() {
  super.onStart();

  Log.d(TAG, "onStart()");

  // Using automatic disposal, this should determine that the correct time to
  // dispose is onStop (the opposite of onStart).
  Observable.interval(1, TimeUnit.SECONDS)
      .doOnDispose(new Action() {
        @Override public void run() throws Exception {
          Log.i(TAG, "Disposing subscription from onStart()");
        }
      })
      .as(AutoDispose.<Long>autoDisposable(AndroidLifecycleScopeProvider.from(this)))
      .subscribe(new Consumer<Long>() {
        @Override public void accept(Long num) throws Exception {
          Log.i(TAG, "Started in onStart(), running until in onStop(): " + num);
        }
      });
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:21,代码来源:MainActivity.java

示例7: doFirstLoad

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
protected final void doFirstLoad(Runnable load) {
    Single.<Runnable>create(emitter -> {
        emitter.onSuccess(load);
    })
            .zipWith(
                    mCanFirstLoad.filter(bool -> bool).firstOrError(),
                    (runnable, bool) -> runnable)
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this, Lifecycle.Event.ON_DESTROY)).forSingle())
            .subscribe(runnable -> {
                runnable.run();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:13,代码来源:BaseLazyLoadFragment.java

示例8: onRefresh

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override
public void onRefresh() {
    mPage = 0;

    mLuaBridge.getArticles(0)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(articles -> {
                mBottomItem = null;
                mArticleList.clear();

                if (articles.size() > 0) {
                    // Add article items
                    mArticleList.addAll(articles);

                    // Add loadmore item
                    mBottomItem = new BottomItem(BottomItem.STATE_LOADMORE);
                    mArticleList.add(mBottomItem);
                }
                mAdapter.notifyDataSetChanged();

                mBinding.refreshLayout.setRefreshing(false);

            }, throwable -> {
                mArticleList.clear();

                // Add reload item
                mBottomItem = new BottomItem(BottomItem.STATE_RELOAD);
                mArticleList.add(mBottomItem);
                mAdapter.notifyDataSetChanged();

                mBinding.refreshLayout.setRefreshing(false);

                showMessageIfInDebug(throwable.getMessage());
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:38,代码来源:ArticleHubFragment.java

示例9: onLoadMore

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void onLoadMore(final int page) {
    mPage = page;

    mBottomItem.setLoading(true);
    mAdapter.notifyItemChanged(mArticleList.size() - 1);

    mLuaBridge.getArticles(page)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(articles -> {
                final int oldSize = mArticleList.size();
                if (articles.size() > 0) {
                    mBottomItem = (BottomItem) mArticleList.remove(oldSize - 1);
                    mBottomItem.setLoading(false);
                    mBottomItem.setState(BottomItem.STATE_LOADMORE);
                    mArticleList.addAll(articles);
                    mArticleList.add(mBottomItem);
                    mAdapter.notifyDataSetChanged();

                } else {
                    mBottomItem = null;
                    mArticleList.remove(oldSize - 1);
                    mAdapter.notifyItemRemoved(oldSize - 1);
                }

            }, throwable -> {
                mBottomItem.setState(BottomItem.STATE_RELOAD);
                mBottomItem.setLoading(false);
                mAdapter.notifyItemChanged(mArticleList.size() - 1);

                showMessageIfInDebug(throwable.getMessage());
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:35,代码来源:ArticleHubFragment.java

示例10: uninstallHub

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void uninstallHub(final Hub hub, final Runnable successCallback) {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.dialog_uninstalling_hub));
    progressDialog.setCancelable(false);
    progressDialog.show();

    mHubManager.uninstall(hub.getId())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
            .subscribe(isSuccess -> {
                if (!isSuccess) {
                    progressDialog.dismiss();
                    Toast.makeText(this, R.string.toast_uninstall_hub_failed, Toast.LENGTH_SHORT).show();
                    return;
                }

                successCallback.run();
                progressDialog.dismiss();
                Toast.makeText(this, R.string.toast_uninstall_hub_success, Toast.LENGTH_SHORT).show();

                // Send local broadcast
                BroadcastRouter.IMPL.tellHubUninstalled(this, CommonUtil.toArrayList(hub));

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(this, R.string.toast_uninstall_hub_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:30,代码来源:HubManagerActivity.java

示例11: onReceive

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    if (action == null) return;

    String hubId;
    int index;
    switch (action) {
        case Constants.ACTION_NOTIFY_HUB_INSTALLED:
            hubId = intent.getStringExtra(Constants.ARG_HUB_ID);
            if (hubId == null) return;

            index = HubUtil.indexOfHubPreference(mPreferences, hubId);
            if (index < 0) {
                loadHubPreferences();

            } else {
                mHubManager.readConfig(hubId)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(HubManagerActivity.this)).forSingle())
                        .subscribe(hub2 -> {
                            mPreferences.get(index).setHub(hub2);
                            mAdapter.notifyItemChanged(index);

                        }, throwable -> {});
            }
            break;
    }
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:31,代码来源:HubManagerActivity.java

示例12: saveAndFinish

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
/**
 * Save config and finish
 */
private void saveAndFinish() {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(getString(R.string.saving));
    progressDialog.setCancelable(false);
    progressDialog.show();

    Single.<Hub>create(emitter -> {
        // Process the rest of edited values
        for (PropertyVO vo : mPropertyVOs) {
            if (vo.isFoucused()) {
                onValueEdited(vo);
            }
        }

        emitter.onSuccess(mHub);
    })
            .subscribeOn(Schedulers.io())
            .flatMapCompletable(hub ->
                    mHubManager.writeUserConfig(hub.getId(), hub.getUserConfig())
                            .subscribeOn(Schedulers.io())
            )
            .observeOn(AndroidSchedulers.mainThread())
            .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forCompletable())
            .subscribe(() -> {
                // Send local broadcast
                BroadcastRouter.IMPL.tellHubInstalled(this, mHub.getId());
                progressDialog.dismiss();
                finish();

            }, throwable -> {
                progressDialog.dismiss();
                Toast.makeText(this, R.string.toast_save_config_failed, Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:38,代码来源:HubConfigActivity.java

示例13: loadRates

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
private void loadRates(Country... countries) {
    for (Country country : countries) {
        ApiClient.loadRate(country)
                .doOnSubscribe(d -> swipeRefreshLayout.setRefreshing(true))
                .doAfterTerminate(() -> swipeRefreshLayout.setRefreshing(false))
                .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
                .subscribe(newCountry -> {
                    countryBox.put(country);
                    adapter.replace(country);
                }, Timber::e);
    }
}
 
开发者ID:jumaallan,项目名称:AndelaTrackChallenge,代码行数:13,代码来源:MainActivity.java

示例14: onCreate

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calculator);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);

    AndelaTrackChallenge cryptoConverter = (AndelaTrackChallenge) getApplicationContext();
    countryBox = cryptoConverter.getBoxStore().boxFor(Country.class);
    historyRepository = cryptoConverter.getHistoryRepo();
    country = getIntent().getParcelableExtra(COUNTRY);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("");
        flagImage.setImageResource(country.getFlagRes());
    }

    currencyText.setText(String.format(Locale.getDefault(), getString(R.string.calc_currency), country.code, country.currency));

    if (country.eth > 0f && country.btc > 0f) {
        finishSetup();
    } else {
        ApiClient.loadRate(country)
                .doOnSubscribe(d -> progressBar.setVisibility(View.VISIBLE))
                .doAfterTerminate(() -> progressBar.setVisibility(View.GONE))
                .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(this)).forSingle())
                .subscribe(newCountry -> {
                    this.country = newCountry;
                    countryBox.put(newCountry);
                    finishSetup();
                }, Timber::e);
    }
}
 
开发者ID:jumaallan,项目名称:AndelaTrackChallenge,代码行数:36,代码来源:ConverterActivity.java

示例15: onReceive

import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    if (action == null) return;

    ArrayList<Hub> hubs;
    Hub hub;
    String hubId;
    int index;
    switch (action) {
        case Constants.ACTION_NOTIFY_HUB_INSTALLED:
            hub = intent.getParcelableExtra(Constants.ARG_HUB);
            hubId = intent.getStringExtra(Constants.ARG_HUB_ID);
            if (hub == null && hubId == null) break;
            if (hubId == null) hubId = hub.getId();

            index = HubUtil.indexOfHub(mHubs, hubId);

            (hub != null ? Single.just(hub) :
                    mHubManager.readConfig(hubId).subscribeOn(Schedulers.io()))
                    .flatMap(_hub -> {
                        if (index < 0) {
                            // If not found in visible hub list
                            return mPreferenceManager.loadHubPreference(_hub)
                                    .subscribeOn(Schedulers.io())
                                    .flatMap(hubPreference -> {
                                        if (!hubPreference.isVisible()) {
                                            return Single.never();
                                        } else {
                                            return Single.just(_hub);
                                        }
                                    });

                        } else {
                            return Single.just(_hub);
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread())
                    .to(AutoDispose.with(AndroidLifecycleScopeProvider.from(HomeActivity.this)).forSingle())
                    .subscribe(_hub -> {
                        if (index < 0) {
                            // Install
                            mHubs.add(_hub);

                        } else {
                            // Reinstall
                            mHubs.set(index, _hub);
                            mPagerAdapter.hackRecreateFragment(index);
                        }
                        mPagerAdapter.notifyDataSetChanged();

                    }, throwable -> {});
            break;

        case Constants.ACTION_NOTIFY_HUB_UNINSTALLED:
            hubs = intent.getParcelableArrayListExtra(Constants.ARG_HUBS);
            if (hubs == null) break;

            mHubs.removeAll(hubs);
            mPagerAdapter.notifyDataSetChanged();
            break;

        case Constants.ACTION_NOTIFY_HUB_PREFERENCE_CHANGED:
            hubs = intent.getParcelableArrayListExtra(Constants.ARG_HUBS);
            if (hubs == null) break;

            mHubs.clear();
            mHubs.addAll(hubs);
            mPagerAdapter.notifyDataSetChanged();
            break;
    }
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:73,代码来源:HomeActivity.java


注:本文中的com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。