/* * Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com> * All Rights Reserved. */ package me.zhanghai.android.douya.ui; import android.content.Context; import android.util.AttributeSet; import org.threeten.bp.format.DateTimeParseException; import me.zhanghai.android.douya.R; import me.zhanghai.android.douya.network.api.info.apiv2.Broadcast; import me.zhanghai.android.douya.util.LogUtils; import me.zhanghai.android.douya.util.TimeUtils; public class TimeActionTextView extends TimeTextView { private String mAction; public TimeActionTextView(Context context) { super(context); } public TimeActionTextView(Context context, AttributeSet attrs) { super(context, attrs); } public TimeActionTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void setDoubanTime(String doubanTime) { throw new UnsupportedOperationException("Use setDoubanTimeAndAction() instead."); } /** * Should behave the same as {@link Broadcast#getActionWithTime(Context)}. */ public void setDoubanTimeAndAction(String doubanTime, String action) { mAction = action; try { setTime(TimeUtils.parseDoubanDateTime(doubanTime)); } catch (DateTimeParseException e) { LogUtils.e("Unable to parse date time: " + doubanTime); e.printStackTrace(); setTimeText(doubanTime); } } @Override protected void setTimeText(String timeText) { setText(getContext().getString(R.string.broadcast_time_action_format, timeText, mAction)); } }