Search in sources :

Example 1 with GankBeauty

use of com.rengwuxian.rxjavasamples.model.GankBeauty in project RxJavaSamples by rengwuxian.

the class GankBeautyResultToItemsMapper method call.

@Override
public List<Item> call(GankBeautyResult gankBeautyResult) {
    List<GankBeauty> gankBeauties = gankBeautyResult.beauties;
    List<Item> items = new ArrayList<>(gankBeauties.size());
    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
    SimpleDateFormat outputFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
    for (GankBeauty gankBeauty : gankBeauties) {
        Item item = new Item();
        try {
            Date date = inputFormat.parse(gankBeauty.createdAt);
            item.description = outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
            item.description = "unknown date";
        }
        item.imageUrl = gankBeauty.url;
        items.add(item);
    }
    return items;
}
Also used : Item(com.rengwuxian.rxjavasamples.model.Item) GankBeauty(com.rengwuxian.rxjavasamples.model.GankBeauty) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with GankBeauty

use of com.rengwuxian.rxjavasamples.model.GankBeauty in project RxJavaSamples by rengwuxian.

the class GankBeautyResultToItemsMapper method apply.

@Override
public List<Item> apply(GankBeautyResult gankBeautyResult) {
    List<GankBeauty> gankBeauties = gankBeautyResult.beauties;
    List<Item> items = new ArrayList<>(gankBeauties.size());
    SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
    SimpleDateFormat outputFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
    for (GankBeauty gankBeauty : gankBeauties) {
        Item item = new Item();
        try {
            Date date = inputFormat.parse(gankBeauty.createdAt);
            item.description = outputFormat.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
            item.description = "unknown date";
        }
        item.imageUrl = gankBeauty.url;
        items.add(item);
    }
    return items;
}
Also used : Item(com.rengwuxian.rxjavasamples.model.Item) GankBeauty(com.rengwuxian.rxjavasamples.model.GankBeauty) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

GankBeauty (com.rengwuxian.rxjavasamples.model.GankBeauty)2 Item (com.rengwuxian.rxjavasamples.model.Item)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2