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


Java Transformations类代码示例

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


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

示例1: grepData

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
@MainThread
static LiveData<LogcatContent> grepData(LiveData<LogcatContent> rawData, String grep) {
    return Transformations.map(rawData, logcatData -> {
        String content = logcatData.getContent();
        if (GREP_SIGNAL.equals(content)) {
            return logcatData;
        }


        if (content != null) {
            logcatData.setContent(parseHtml2(content,grep));
        }

        return logcatData;

    });
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:18,代码来源:GrepFilter.java

示例2: subscribeToDbChanges

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
private void subscribeToDbChanges() {
    LiveData<List<LoanWithUserAndBook>> loans
            = mDb.loanModel().findLoansByNameAfter("Mike", getYesterdayDate());

    // Instead of exposing the list of Loans, we can apply a transformation and expose Strings.
    mLoansResult = Transformations.map(loans,
            new Function<List<LoanWithUserAndBook>, String>() {
        @Override
        public String apply(List<LoanWithUserAndBook> loansWithUserAndBook) {
            StringBuilder sb = new StringBuilder();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm",
                    Locale.US);

            for (LoanWithUserAndBook loan : loansWithUserAndBook) {
                sb.append(String.format("%s\n  (Returned: %s)\n",
                        loan.bookTitle,
                        simpleDateFormat.format(loan.endTime)));
            }
            return sb.toString();
        }
    });
}
 
开发者ID:googlecodelabs,项目名称:android-persistence,代码行数:23,代码来源:CustomResultViewModel.java

示例3: subscribeToDbChanges

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
private void subscribeToDbChanges() {
    // TODO: Modify this query to show only recent loans from specific user
    LiveData<List<LoanWithUserAndBook>> loans
            = mDb.loanModel().findAllWithUserAndBook();

    // Instead of exposing the list of Loans, we can apply a transformation and expose Strings.
    mLoansResult = Transformations.map(loans,
            new Function<List<LoanWithUserAndBook>, String>() {
        @Override
        public String apply(List<LoanWithUserAndBook> loansWithUserAndBook) {
            StringBuilder sb = new StringBuilder();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm",
                    Locale.US);

            for (LoanWithUserAndBook loan : loansWithUserAndBook) {
                sb.append(String.format("%s\n  (Returned: %s)\n",
                        loan.bookTitle,
                        simpleDateFormat.format(loan.endTime)));
            }
            return sb.toString();
        }
    });
}
 
开发者ID:googlecodelabs,项目名称:android-persistence,代码行数:24,代码来源:CustomResultViewModel.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: bindViewModel

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
public void bindViewModel(@NonNull final CheckoutShippingRatesViewModel viewModel) {
  if (this.viewModel != null) {
    throw new IllegalStateException("Already bound");
  }
  this.viewModel = viewModel;

  Transformations.map(viewModel.selectedShippingRateLiveData(), shippingRate ->
    shippingRate != null ? shippingRate.title : null)
    .observe(this, title -> {
      if (title != null) {
        shippingLineView.setText(title);
      } else {
        shippingLineView.setText(R.string.checkout_shipping_method_not_selected);
      }
    });

  Transformations.map(viewModel.selectedShippingRateLiveData(), shippingRate ->
    shippingRate != null ? CURRENCY_FORMAT.format(shippingRate.price)
      : getResources().getString(R.string.checkout_shipping_method_price_not_available))
    .observe(this, price -> priceView.setText(price));
}
 
开发者ID:Shopify,项目名称:mobile-buy-sdk-android,代码行数:22,代码来源:ShippingRatesView.java

示例10: 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

示例11: loadOrdered

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
public LiveData<List<Repo>> loadOrdered(List<Integer> repoIds) {
  SparseIntArray order = new SparseIntArray();
  int index = 0;
  for (Integer repoId : repoIds) {
    order.put(repoId, index++);
  }
  return Transformations.map(loadById(repoIds), repositories -> {
    Collections.sort(repositories, (r1, r2) -> {
      int pos1 = order.get(r1.id);
      int pos2 = order.get(r2.id);
      return pos1 - pos2;
    });
    return repositories;
  });
}
 
开发者ID:charlesng,项目名称:SampleAppArch,代码行数:16,代码来源:RepoDao.java

示例12: 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

示例13: 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

示例14: 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

示例15: loadOrdered

import android.arch.lifecycle.Transformations; //导入依赖的package包/类
public LiveData<List<Repo>> loadOrdered(List<Integer> repoIds) {
    SparseIntArray order = new SparseIntArray();
    int index = 0;
    for (Integer repoId : repoIds) {
        order.put(repoId, index++);
    }
    return Transformations.map(loadById(repoIds), repositories -> {
        Collections.sort(repositories, (r1, r2) -> {
            int pos1 = order.get(r1.id);
            int pos2 = order.get(r2.id);
            return pos1 - pos2;
        });
        return repositories;
    });
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:16,代码来源:RepoDao.java


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