Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.calculator2; |
| 18 | |
Annie Chin | 06fd3cf | 2016-11-07 16:04:33 -0800 | [diff] [blame] | 19 | import android.text.Spannable; |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 20 | import android.text.format.DateUtils; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 21 | |
| 22 | public class HistoryItem { |
| 23 | |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 24 | private long mEvaluatorIndex; |
| 25 | /** Date in millis */ |
| 26 | private long mTimeInMillis; |
Annie Chin | 06fd3cf | 2016-11-07 16:04:33 -0800 | [diff] [blame] | 27 | private Spannable mFormula; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 28 | |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 29 | /** This is true only for the "empty history" view. */ |
Annie Chin | ab657d4 | 2016-11-03 16:43:59 -0700 | [diff] [blame] | 30 | private final boolean mIsEmpty; |
| 31 | |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 32 | public HistoryItem(long evaluatorIndex, long millis, Spannable formula) { |
| 33 | mEvaluatorIndex = evaluatorIndex; |
| 34 | mTimeInMillis = millis; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 35 | mFormula = formula; |
Annie Chin | ab657d4 | 2016-11-03 16:43:59 -0700 | [diff] [blame] | 36 | mIsEmpty = false; |
| 37 | } |
| 38 | |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 39 | public long getEvaluatorIndex() { |
| 40 | return mEvaluatorIndex; |
Annie Chin | 06fd3cf | 2016-11-07 16:04:33 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Annie Chin | ab657d4 | 2016-11-03 16:43:59 -0700 | [diff] [blame] | 43 | public HistoryItem() { |
| 44 | mIsEmpty = true; |
| 45 | } |
| 46 | |
| 47 | public boolean isEmptyView() { |
| 48 | return mIsEmpty; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Annie Chin | 9179623 | 2016-11-16 17:27:36 -0800 | [diff] [blame] | 51 | /** |
| 52 | * @return String in format "n days ago" |
| 53 | * For n > 7, the date is returned. |
| 54 | */ |
| 55 | public CharSequence getDateString() { |
| 56 | return DateUtils.getRelativeTimeSpanString(mTimeInMillis, System.currentTimeMillis(), |
| 57 | DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Annie Chin | 3614798 | 2016-12-01 15:07:34 -0800 | [diff] [blame^] | 60 | public long getTimeInMillis() { |
| 61 | return mTimeInMillis; |
| 62 | } |
| 63 | |
Annie Chin | 06fd3cf | 2016-11-07 16:04:33 -0800 | [diff] [blame] | 64 | public Spannable getFormula() { |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 65 | return mFormula; |
| 66 | } |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 67 | } |