本文整理汇总了Java中android.arch.lifecycle.Transformations.map方法的典型用法代码示例。如果您正苦于以下问题:Java Transformations.map方法的具体用法?Java Transformations.map怎么用?Java Transformations.map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.arch.lifecycle.Transformations
的用法示例。
在下文中一共展示了Transformations.map方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
});
}
示例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();
}
});
}
示例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();
}
});
}
示例4: 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;
});
}
示例5: 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;
});
}
示例6: liveData
import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public LiveData<Type> liveData() {
return Transformations.map(manager.paramRecordLiveData, record -> getValueOnRecord(record));
}
示例7: liveData
import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public LiveData<Type> liveData() {
return Transformations.map(this.weightRepository.weightRecordLiveData, record -> field.getRecordValue(record));
}
示例8: init
import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
public void init(ParamRepository paramRepository) {
this.paramRepository = paramRepository;
date = Transformations.map(paramRepository.param().currentViewDate().liveData(),
CalendarDate::getCalendardate);
}
示例9: cartTotalLiveData
import android.arch.lifecycle.Transformations; //导入方法依赖的package包/类
@Override public LiveData<BigDecimal> cartTotalLiveData() {
return Transformations.map(cartLiveData, cart -> cart != null ? cart.totalPrice() : BigDecimal.ZERO);
}