1 /*
2  * Copyright 2018 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.pump.db;
18 
19 import android.net.Uri;
20 
21 import androidx.annotation.AnyThread;
22 import androidx.annotation.NonNull;
23 import androidx.annotation.Nullable;
24 
25 @AnyThread
26 public class Movie extends Video {
27     private final String mTitle;
28     private final int mYear;
29 
30     // TODO(b/123706949) Lock mutable fields to ensure consistent updates
31     private Uri mThumbnailUri;
32     private Uri mPosterUri;
33     private String mSynopsis;
34     private String mDescription;
35     private boolean mLoaded;
36 
Movie(long id, @NonNull String mimeType, @NonNull String title)37     Movie(long id, @NonNull String mimeType, @NonNull String title) {
38         super(id, mimeType);
39 
40         mTitle = title;
41         mYear = Integer.MIN_VALUE;
42     }
43 
Movie(long id, @NonNull String mimeType, @NonNull String title, int year)44     Movie(long id, @NonNull String mimeType, @NonNull String title, int year) {
45         super(id, mimeType);
46 
47         mTitle = title;
48         if (year <= 0) {
49             throw new IllegalArgumentException();
50         }
51         mYear = year;
52     }
53 
getTitle()54     public @NonNull String getTitle() {
55         return mTitle;
56     }
57 
hasYear()58     public boolean hasYear() {
59         return mYear > 0;
60     }
61 
getYear()62     public int getYear() {
63         if (!hasYear()) {
64             throw new IllegalStateException();
65         }
66         return mYear;
67     }
68 
getThumbnailUri()69     public @Nullable Uri getThumbnailUri() {
70         return mThumbnailUri;
71     }
72 
setThumbnailUri(@onNull Uri thumbnailUri)73     public boolean setThumbnailUri(@NonNull Uri thumbnailUri) {
74         if (thumbnailUri.equals(mThumbnailUri)) {
75             return false;
76         }
77         mThumbnailUri = thumbnailUri;
78         return true;
79     }
80 
getPosterUri()81     public @Nullable Uri getPosterUri() {
82         return mPosterUri;
83     }
84 
setPosterUri(@onNull Uri posterUri)85     public boolean setPosterUri(@NonNull Uri posterUri) {
86         if (posterUri.equals(mPosterUri)) {
87             return false;
88         }
89         mPosterUri = posterUri;
90         return true;
91     }
92 
getSynopsis()93     public @Nullable String getSynopsis() {
94         return mSynopsis;
95     }
96 
setSynopsis(@onNull String synopsis)97     public boolean setSynopsis(@NonNull String synopsis) {
98         if (synopsis.equals(mSynopsis)) {
99             return false;
100         }
101         mSynopsis = synopsis;
102         return true;
103     }
104 
getDescription()105     public @Nullable String getDescription() {
106         return mDescription;
107     }
108 
setDescription(@onNull String description)109     public boolean setDescription(@NonNull String description) {
110         if (description.equals(mDescription)) {
111             return false;
112         }
113         mDescription = description;
114         return true;
115     }
116 
isLoaded()117     boolean isLoaded() {
118         return mLoaded;
119     }
120 
setLoaded()121     void setLoaded() {
122         mLoaded = true;
123     }
124 }
125