blob: f20d1a743c3629ce4b4fc63a370e81252279dd5e [file] [log] [blame]
Annie Chind0f87d22016-10-24 09:04:12 -07001/*
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
17package com.android.calculator2;
18
Annie Chin06fd3cf2016-11-07 16:04:33 -080019import android.text.Spannable;
Annie Chin91796232016-11-16 17:27:36 -080020import android.text.format.DateUtils;
Annie Chind0f87d22016-10-24 09:04:12 -070021
22public class HistoryItem {
23
Annie Chin91796232016-11-16 17:27:36 -080024 private long mEvaluatorIndex;
25 /** Date in millis */
26 private long mTimeInMillis;
Annie Chin06fd3cf2016-11-07 16:04:33 -080027 private Spannable mFormula;
Annie Chind0f87d22016-10-24 09:04:12 -070028
Annie Chin91796232016-11-16 17:27:36 -080029 /** This is true only for the "empty history" view. */
Annie Chinab657d42016-11-03 16:43:59 -070030 private final boolean mIsEmpty;
31
Annie Chin91796232016-11-16 17:27:36 -080032 public HistoryItem(long evaluatorIndex, long millis, Spannable formula) {
33 mEvaluatorIndex = evaluatorIndex;
34 mTimeInMillis = millis;
Annie Chind0f87d22016-10-24 09:04:12 -070035 mFormula = formula;
Annie Chinab657d42016-11-03 16:43:59 -070036 mIsEmpty = false;
37 }
38
Annie Chin91796232016-11-16 17:27:36 -080039 public long getEvaluatorIndex() {
40 return mEvaluatorIndex;
Annie Chin06fd3cf2016-11-07 16:04:33 -080041 }
42
Annie Chinab657d42016-11-03 16:43:59 -070043 public HistoryItem() {
44 mIsEmpty = true;
45 }
46
47 public boolean isEmptyView() {
48 return mIsEmpty;
Annie Chind0f87d22016-10-24 09:04:12 -070049 }
50
Annie Chin91796232016-11-16 17:27:36 -080051 /**
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 Chind0f87d22016-10-24 09:04:12 -070058 }
59
Annie Chin36147982016-12-01 15:07:34 -080060 public long getTimeInMillis() {
61 return mTimeInMillis;
62 }
63
Annie Chin06fd3cf2016-11-07 16:04:33 -080064 public Spannable getFormula() {
Annie Chind0f87d22016-10-24 09:04:12 -070065 return mFormula;
66 }
Annie Chind0f87d22016-10-24 09:04:12 -070067}