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 Other extends Video {
27     // TODO(b/123706949) Lock mutable fields to ensure consistent updates
28     private String mTitle;
29     private long mDuration;
30     private long mDateTaken;
31     private double mLatitude;
32     private double mLongitude;
33     private Uri mThumbnailUri;
34     private boolean mLoaded;
35 
Other(long id, @NonNull String mimeType, @NonNull String title)36     Other(long id, @NonNull String mimeType, @NonNull String title) {
37         super(id, mimeType);
38 
39         mTitle = title;
40         mDuration = Long.MIN_VALUE;
41         mDateTaken = Long.MIN_VALUE;
42         mLatitude = Double.NaN;
43         mLongitude = Double.NaN;
44     }
45 
getTitle()46     public @NonNull String getTitle() {
47         return mTitle;
48     }
49 
setTitle(@onNull String title)50     public boolean setTitle(@NonNull String title) {
51         if (title.equals(mTitle)) {
52             return false;
53         }
54         mTitle = title;
55         return true;
56     }
57 
hasDuration()58     public boolean hasDuration() {
59         return mDuration >= 0;
60     }
61 
getDuration()62     public long getDuration() {
63         if (!hasDuration()) {
64             throw new IllegalStateException();
65         }
66         return mDuration;
67     }
68 
setDuration(long duration)69     public boolean setDuration(long duration) {
70         if (duration == mDuration) {
71             return false;
72         }
73         mDuration = duration;
74         return true;
75     }
76 
hasDateTaken()77     public boolean hasDateTaken() {
78         return mDateTaken >= 0;
79     }
80 
getDateTaken()81     public long getDateTaken() {
82         if (!hasDateTaken()) {
83             throw new IllegalStateException();
84         }
85         return mDateTaken;
86     }
87 
setDateTaken(long dateTaken)88     public boolean setDateTaken(long dateTaken) {
89         if (dateTaken == mDateTaken) {
90             return false;
91         }
92         mDateTaken = dateTaken;
93         return true;
94     }
95 
hasLatLong()96     public boolean hasLatLong() {
97         return !Double.isNaN(mLatitude) && !Double.isNaN(mLongitude);
98     }
99 
setLatLong(double latitude, double longitude)100     public boolean setLatLong(double latitude, double longitude) {
101         if (latitude == mLatitude || longitude == mLongitude) {
102             return false;
103         }
104         mLatitude = latitude;
105         mLongitude = longitude;
106         return true;
107     }
108 
getLatitude()109     public double getLatitude() {
110         if (!hasLatLong()) {
111             throw new IllegalStateException();
112         }
113         return mLatitude;
114     }
115 
getLongitude()116     public double getLongitude() {
117         if (!hasLatLong()) {
118             throw new IllegalStateException();
119         }
120         return mLongitude;
121     }
122 
getThumbnailUri()123     public @Nullable Uri getThumbnailUri() {
124         return mThumbnailUri;
125     }
126 
setThumbnailUri(@onNull Uri thumbnailUri)127     public boolean setThumbnailUri(@NonNull Uri thumbnailUri) {
128         if (thumbnailUri.equals(mThumbnailUri)) {
129             return false;
130         }
131         mThumbnailUri = thumbnailUri;
132         return true;
133     }
134 
isLoaded()135     boolean isLoaded() {
136         return mLoaded;
137     }
138 
setLoaded()139     void setLoaded() {
140         mLoaded = true;
141     }
142 }
143