• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 android.health.connect.aidl;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.time.LocalDate;
24 import java.time.format.DateTimeFormatter;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Objects;
28 
29 /** @hide */
30 public class ActivityDatesResponseParcel implements Parcelable {
31     private final List<LocalDate> mLocalDates;
32 
ActivityDatesResponseParcel(@onNull List<LocalDate> localDates)33     public ActivityDatesResponseParcel(@NonNull List<LocalDate> localDates) {
34         Objects.requireNonNull(localDates);
35         mLocalDates = localDates;
36     }
37 
38     public static final Creator<ActivityDatesResponseParcel> CREATOR =
39             new Creator<ActivityDatesResponseParcel>() {
40                 @Override
41                 public ActivityDatesResponseParcel createFromParcel(Parcel in) {
42                     return new ActivityDatesResponseParcel(in);
43                 }
44 
45                 @Override
46                 public ActivityDatesResponseParcel[] newArray(int size) {
47                     return new ActivityDatesResponseParcel[size];
48                 }
49             };
50 
ActivityDatesResponseParcel(Parcel in)51     protected ActivityDatesResponseParcel(Parcel in) {
52         int size = in.readInt();
53 
54         mLocalDates = new ArrayList<>(size);
55         for (int i = 0; i < size; i++) {
56             String date = in.readString();
57             mLocalDates.add(LocalDate.parse(date));
58         }
59     }
60 
61     @NonNull
getDates()62     public List<LocalDate> getDates() {
63         return mLocalDates;
64     }
65 
66     @Override
describeContents()67     public int describeContents() {
68         return 0;
69     }
70 
71     /**
72      * Flatten this object in to a Parcel.
73      *
74      * @param dest The Parcel in which the object should be written.
75      * @param flags Additional flags about how the object should be written. May be 0 or {@link
76      *     #PARCELABLE_WRITE_RETURN_VALUE}.
77      */
78     @Override
writeToParcel(@onNull Parcel dest, int flags)79     public void writeToParcel(@NonNull Parcel dest, int flags) {
80         dest.writeInt(mLocalDates.size());
81         mLocalDates.forEach(
82                 (localDate -> {
83                     dest.writeString(localDate.format(DateTimeFormatter.ISO_LOCAL_DATE));
84                 }));
85     }
86 }
87