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


Java Transformations.switchMap方法代码示例

本文整理汇总了Java中android.arch.lifecycle.Transformations.switchMap方法的典型用法代码示例。如果您正苦于以下问题:Java Transformations.switchMap方法的具体用法?Java Transformations.switchMap怎么用?Java Transformations.switchMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.arch.lifecycle.Transformations的用法示例。


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

示例1: ConversationViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
public ConversationViewModel(InboxRepository repository) {
    this.conversationId = new MutableLiveData<>();

    conversation = Transformations.switchMap(conversationId, input -> {
        if (input.isEmpty()) {
            return AbsentLiveData.create();
        }
        return repository.conversation(input);
    });

    metaData = Transformations.switchMap(conversationId, input -> {
        if (input.isEmpty()) {
            return AbsentLiveData.create();
        }
        return repository.conversationMetaData(input);
    });
}
 
开发者ID:hbmartin,项目名称:firebase-chat-android-architecture-components,代码行数:19,代码来源:ConversationViewModel.java

示例2: RepoViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
public RepoViewModel(RepoRepository repository) {
    this.repoId = new MutableLiveData<>();
    repo = Transformations.switchMap(repoId, input -> {
        if (input.isEmpty()) {
            return AbsentLiveData.create();
        }
        return repository.loadRepo(input.owner, input.name);
    });
    contributors = Transformations.switchMap(repoId, input -> {
        if (input.isEmpty()) {
            return AbsentLiveData.create();
        } else {
            return repository.loadContributors(input.owner, input.name);
        }

    });
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:19,代码来源:RepoViewModel.java

示例3: UserViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Inject
public UserViewModel(UserRepository userRepository, RepoRepository repoRepository) {
    user = Transformations.switchMap(login, login -> {
        if (login == null) {
            return AbsentLiveData.create();
        } else {
            return userRepository.loadUser(login);
        }
    });
    repositories = Transformations.switchMap(login, login -> {
        if (login == null) {
            return AbsentLiveData.create();
        } else {
            return repoRepository.loadRepos(login);
        }
    });
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:19,代码来源:UserViewModel.java

示例4: DocListViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
/**
 * Default constructor.
 * @param application
 */
public DocListViewModel(Application application) {
    super(application);

    // transform database created flag to live data.
    // if it is not created, it will return ABSENT field.
    // if it is created, it will return room live data.
    final DatabaseManager databaseManager = DatabaseManager.getInstance(application);
    LiveData<Boolean> databaseCreated = databaseManager.isDatabaseCreated();
    mObservableDocuments = Transformations.switchMap(databaseCreated,
            new Function<Boolean, LiveData<List<DocumentMetadata>>>() {
                @Override
                public LiveData<List<DocumentMetadata>> apply(Boolean isDbCreated) {
                    if (!Boolean.TRUE.equals(isDbCreated)) {
                        return ABSENT;
                    } else {
                        return databaseManager.getDatabase().documentDao().loadAllDocumentsMetadata();
                    }
                }
            });

    databaseManager.initDbAsync(this.getApplication());
}
 
开发者ID:nfdz,项目名称:foco,代码行数:27,代码来源:DocListViewModel.java

示例5: PostsListViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
PostsListViewModel(@NonNull Application application, String slug, int postCount, Retrofit retrofit) {
    super(application);
    mSlug = slug;
    mPostCount = postCount;
    mRetrofit = retrofit;

    mIsLoading.setValue(true);
    mOffset.setValue(0);

    // 当 mOffset 的值发生改变,就会执行 apply
    mListLiveData = Transformations.switchMap(mOffset, new Function<Integer, LiveData<List<PostsListBean>>>() {
        @Override
        public LiveData<List<PostsListBean>> apply(Integer input) {
            return handleData(input);
        }
    });
}
 
开发者ID:iMeiji,项目名称:Daily,代码行数:18,代码来源:PostsListViewModel.java

示例6: FlexibleViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public FlexibleViewModel() {
    identifier = new MutableLiveData<>();
    liveItems = Transformations.switchMap(identifier, new Function<Identifier, LiveData<List<AdapterItem>>>() {
        @Override
        public LiveData<List<AdapterItem>> apply(Identifier input) {
            return Transformations.map(getSource(input), new Function<Source, List<AdapterItem>>() {
                @Override
                public List<AdapterItem> apply(Source source) {
                    if (isSourceValid(source)) {
                        return map(source);
                    } else {
                        return liveItems.getValue();
                    }
                }
            });
        }
    });
}
 
开发者ID:davideas,项目名称:FlexibleAdapter,代码行数:19,代码来源:FlexibleViewModel.java

示例7: HeroViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public HeroViewModel() {
    this.heroRepository = HeroRepository.getInstance();
    this.heroResult = Transformations.switchMap(forceFetchHero, forceFetch -> {
        if (forceFetch == null) {
            return AbsentLiveData.create();
        }

        return heroRepository.getHero(forceFetch);
    });
}
 
开发者ID:akexorcist,项目名称:Repository-ArchComponents,代码行数:11,代码来源:HeroViewModel.java

示例8: MainViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
MainViewModel(MainRepository repository) {
    this.repository = repository;
    filters.setValue(Filters.getDefault());
    isSignedIn = new LiveData<Boolean>() {
        @Override
        protected void onActive() {
            super.onActive();
            setValue(FirebaseAuth.getInstance().getCurrentUser() != null);
        }
    };

    restaurants = Transformations.switchMap(filters, repository::restaurants);
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:15,代码来源:MainViewModel.java

示例9: SearchViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
SearchViewModel(RepoRepository repoRepository) {
    nextPageHandler = new NextPageHandler(repoRepository);
    results = Transformations.switchMap(query, search -> {
        if (search == null || search.trim().length() == 0) {
            return AbsentLiveData.create();
        } else {
            return repoRepository.search(search);
        }
    });
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:12,代码来源:SearchViewModel.java

示例10: UserViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
public UserViewModel(UserRepository userRepository) {
    this.repository = userRepository;
    if (user == null) {
        Timber.d("Init UserViewModel");
        userIdentifier = new MutableLiveData<>();
        user = Transformations.switchMap(userIdentifier, input -> {
            if (input == null) {
                return AbsentLiveData.create();
            }
            return repository.login(new LoginRequest(input.username, input.password));
        });
    }
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:15,代码来源:UserViewModel.java

示例11: VideosViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
public VideosViewModel(Application application, VideosRepository repository) {
    super(application);

    mRepository = repository;

    mAllCategories = mRepository.getAllCategories();

    mSearchResults = Transformations.switchMap(
            mQuery, new Function<String, LiveData<List<VideoEntity>>>() {
                @Override
                public LiveData<List<VideoEntity>> apply(final String queryMessage) {
                    return mRepository.getSearchResult(queryMessage);
                }
            });


    mVideoById = Transformations.switchMap(
            mVideoId, new Function<Long, LiveData<VideoEntity>>() {
                @Override
                public LiveData<VideoEntity> apply(final Long videoId) {
                    return mRepository.getVideoById(videoId);
                }
            });

    /**
     * Using switch map function to react to the change of observed variable, the benefits of
     * this mapping method is we don't have to re-create the live data every time.
     */
    mAllVideosByCategory = Transformations.switchMap(mVideoCategory, new Function<String, LiveData<List<VideoEntity>>>() {
        @Override
        public LiveData<List<VideoEntity>> apply(String category) {
            return mRepository.getVideosInSameCategoryLiveData(category);
        }
    });
}
 
开发者ID:googlesamples,项目名称:leanback-showcase,代码行数:37,代码来源:VideosViewModel.java

示例12: LogcatContentViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public LogcatContentViewModel(@NonNull Application application, LogcatContentRepository repository) {
    super(application);
    this.repository = repository;
    contentLiveData = Transformations.switchMap(isStartFirstLoad, isStart -> repository.getLogcatContent());
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:6,代码来源:LogcatContentViewModel.java

示例13: creat

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public LiveData<String> creat(String grep) {
    return Transformations.switchMap(transData, boo -> {
        return data;
    });
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:6,代码来源:ExampleUnitTest.java

示例14: MainActivityViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
public MainActivityViewModel() {
    App.getComponent().inject(this);
    this.weatherInfoLiveData = Transformations.switchMap(cityNameLiveData, weatherRepository::getWeather);
}
 
开发者ID:SergeyVinyar,项目名称:AndroidNewArchitectureExample,代码行数:6,代码来源:MainActivityViewModel.java

示例15: RatingViewModel

import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Inject
RatingViewModel(RestaurantRepository repository) {
    this.repository = repository;
    restaurant = Transformations.switchMap(id, repository::restaurant);
    ratings = Transformations.switchMap(id, repository::ratings);
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:7,代码来源:RatingViewModel.java


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