Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.documentsui.model; |
| 18 | |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 19 | import static com.android.documentsui.Shared.compareToIgnoreCaseNullable; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 20 | import static com.android.documentsui.model.DocumentInfo.getCursorInt; |
| 21 | import static com.android.documentsui.model.DocumentInfo.getCursorLong; |
| 22 | import static com.android.documentsui.model.DocumentInfo.getCursorString; |
| 23 | |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 24 | import android.annotation.IntDef; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 26 | import android.database.Cursor; |
| 27 | import android.graphics.drawable.Drawable; |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 28 | import android.net.Uri; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 29 | import android.os.Parcel; |
| 30 | import android.os.Parcelable; |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 31 | import android.provider.DocumentsContract; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 32 | import android.provider.DocumentsContract.Root; |
Jeff Sharkey | 4ec9739 | 2013-09-10 12:04:26 -0700 | [diff] [blame] | 33 | import android.text.TextUtils; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 34 | |
Jeff Sharkey | 0b14db3 | 2013-09-04 18:03:18 -0700 | [diff] [blame] | 35 | import com.android.documentsui.IconUtils; |
Jeff Sharkey | 6d97d3c | 2013-09-06 10:43:45 -0700 | [diff] [blame] | 36 | import com.android.documentsui.R; |
Jeff Sharkey | 0b14db3 | 2013-09-04 18:03:18 -0700 | [diff] [blame] | 37 | |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 38 | import java.io.DataInputStream; |
| 39 | import java.io.DataOutputStream; |
| 40 | import java.io.IOException; |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 41 | import java.lang.annotation.Retention; |
| 42 | import java.lang.annotation.RetentionPolicy; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 43 | import java.net.ProtocolException; |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 44 | import java.util.Objects; |
| 45 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Representation of a {@link Root}. |
| 48 | */ |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 49 | public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> { |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 50 | private static final int VERSION_INIT = 1; |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 51 | private static final int VERSION_DROP_TYPE = 2; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 52 | |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 53 | // The values of these constants determine the sort order of various roots in the RootsFragment. |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 54 | @IntDef(flag = true, value = { |
| 55 | TYPE_IMAGES, |
| 56 | TYPE_VIDEO, |
| 57 | TYPE_AUDIO, |
| 58 | TYPE_RECENTS, |
| 59 | TYPE_DOWNLOADS, |
| 60 | TYPE_LOCAL, |
| 61 | TYPE_MTP, |
| 62 | TYPE_OTHER |
| 63 | }) |
| 64 | @Retention(RetentionPolicy.SOURCE) |
| 65 | public @interface RootType {} |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 66 | public static final int TYPE_IMAGES = 1; |
| 67 | public static final int TYPE_VIDEO = 2; |
| 68 | public static final int TYPE_AUDIO = 3; |
| 69 | public static final int TYPE_RECENTS = 4; |
| 70 | public static final int TYPE_DOWNLOADS = 5; |
| 71 | public static final int TYPE_LOCAL = 6; |
Daichi Hirono | abf3974 | 2015-10-23 08:36:10 +0900 | [diff] [blame] | 72 | public static final int TYPE_MTP = 7; |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 73 | public static final int TYPE_OTHER = 8; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 74 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 75 | public String authority; |
| 76 | public String rootId; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 77 | public int flags; |
| 78 | public int icon; |
| 79 | public String title; |
| 80 | public String summary; |
| 81 | public String documentId; |
| 82 | public long availableBytes; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 83 | public String mimeTypes; |
| 84 | |
| 85 | /** Derived fields that aren't persisted */ |
| 86 | public String[] derivedMimeTypes; |
| 87 | public int derivedIcon; |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 88 | public @RootType int derivedType; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 89 | |
| 90 | public RootInfo() { |
| 91 | reset(); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void reset() { |
| 96 | authority = null; |
| 97 | rootId = null; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 98 | flags = 0; |
| 99 | icon = 0; |
| 100 | title = null; |
| 101 | summary = null; |
| 102 | documentId = null; |
| 103 | availableBytes = -1; |
| 104 | mimeTypes = null; |
| 105 | |
| 106 | derivedMimeTypes = null; |
| 107 | derivedIcon = 0; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 108 | derivedType = 0; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void read(DataInputStream in) throws IOException { |
| 113 | final int version = in.readInt(); |
| 114 | switch (version) { |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 115 | case VERSION_DROP_TYPE: |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 116 | authority = DurableUtils.readNullableString(in); |
| 117 | rootId = DurableUtils.readNullableString(in); |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 118 | flags = in.readInt(); |
| 119 | icon = in.readInt(); |
| 120 | title = DurableUtils.readNullableString(in); |
| 121 | summary = DurableUtils.readNullableString(in); |
| 122 | documentId = DurableUtils.readNullableString(in); |
| 123 | availableBytes = in.readLong(); |
| 124 | mimeTypes = DurableUtils.readNullableString(in); |
| 125 | deriveFields(); |
| 126 | break; |
| 127 | default: |
| 128 | throw new ProtocolException("Unknown version " + version); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void write(DataOutputStream out) throws IOException { |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 134 | out.writeInt(VERSION_DROP_TYPE); |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 135 | DurableUtils.writeNullableString(out, authority); |
| 136 | DurableUtils.writeNullableString(out, rootId); |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 137 | out.writeInt(flags); |
| 138 | out.writeInt(icon); |
| 139 | DurableUtils.writeNullableString(out, title); |
| 140 | DurableUtils.writeNullableString(out, summary); |
| 141 | DurableUtils.writeNullableString(out, documentId); |
| 142 | out.writeLong(availableBytes); |
| 143 | DurableUtils.writeNullableString(out, mimeTypes); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public int describeContents() { |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public void writeToParcel(Parcel dest, int flags) { |
| 153 | DurableUtils.writeToParcel(dest, this); |
| 154 | } |
| 155 | |
| 156 | public static final Creator<RootInfo> CREATOR = new Creator<RootInfo>() { |
| 157 | @Override |
| 158 | public RootInfo createFromParcel(Parcel in) { |
| 159 | final RootInfo root = new RootInfo(); |
| 160 | DurableUtils.readFromParcel(in, root); |
| 161 | return root; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public RootInfo[] newArray(int size) { |
| 166 | return new RootInfo[size]; |
| 167 | } |
| 168 | }; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 169 | |
| 170 | public static RootInfo fromRootsCursor(String authority, Cursor cursor) { |
| 171 | final RootInfo root = new RootInfo(); |
| 172 | root.authority = authority; |
| 173 | root.rootId = getCursorString(cursor, Root.COLUMN_ROOT_ID); |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 174 | root.flags = getCursorInt(cursor, Root.COLUMN_FLAGS); |
| 175 | root.icon = getCursorInt(cursor, Root.COLUMN_ICON); |
| 176 | root.title = getCursorString(cursor, Root.COLUMN_TITLE); |
| 177 | root.summary = getCursorString(cursor, Root.COLUMN_SUMMARY); |
| 178 | root.documentId = getCursorString(cursor, Root.COLUMN_DOCUMENT_ID); |
| 179 | root.availableBytes = getCursorLong(cursor, Root.COLUMN_AVAILABLE_BYTES); |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 180 | root.mimeTypes = getCursorString(cursor, Root.COLUMN_MIME_TYPES); |
| 181 | root.deriveFields(); |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 182 | return root; |
| 183 | } |
| 184 | |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 185 | private void deriveFields() { |
| 186 | derivedMimeTypes = (mimeTypes != null) ? mimeTypes.split("\n") : null; |
| 187 | |
| 188 | // TODO: remove these special case icons |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 189 | if (isHome()) { |
Steve McKay | ab3b893 | 2016-02-16 11:37:03 -0800 | [diff] [blame] | 190 | derivedIcon = R.drawable.ic_root_documents; |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 191 | derivedType = TYPE_LOCAL; |
| 192 | } else if (isExternalStorage()) { |
Aga Wronska | 7587fd0 | 2016-01-04 12:53:18 -0800 | [diff] [blame] | 193 | derivedIcon = R.drawable.ic_root_smartphone; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 194 | derivedType = TYPE_LOCAL; |
Steve McKay | efa1761 | 2016-01-29 18:15:39 -0800 | [diff] [blame] | 195 | // TODO: Apply SD card icon to SD devices. |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 196 | } else if (isDownloads()) { |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 197 | derivedIcon = R.drawable.ic_root_download; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 198 | derivedType = TYPE_DOWNLOADS; |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 199 | } else if (isImages()) { |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 200 | derivedIcon = R.drawable.ic_doc_image; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 201 | derivedType = TYPE_IMAGES; |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 202 | } else if (isVideos()) { |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 203 | derivedIcon = R.drawable.ic_doc_video; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 204 | derivedType = TYPE_VIDEO; |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 205 | } else if (isAudio()) { |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 206 | derivedIcon = R.drawable.ic_doc_audio; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 207 | derivedType = TYPE_AUDIO; |
| 208 | } else if (isRecents()) { |
| 209 | derivedType = TYPE_RECENTS; |
Daichi Hirono | abf3974 | 2015-10-23 08:36:10 +0900 | [diff] [blame] | 210 | } else if (isMtp()) { |
| 211 | derivedType = TYPE_MTP; |
Ben Kwa | 0c64308 | 2015-10-09 07:48:00 -0700 | [diff] [blame] | 212 | } else { |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 213 | derivedType = TYPE_OTHER; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 214 | } |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 217 | public Uri getUri() { |
| 218 | return DocumentsContract.buildRootUri(authority, rootId); |
| 219 | } |
| 220 | |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 221 | public boolean isRecents() { |
| 222 | return authority == null && rootId == null; |
| 223 | } |
| 224 | |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 225 | public boolean isHome() { |
| 226 | // Note that "home" is the expected root id for the auto-created |
| 227 | // user home directory on external storage. The "home" value should |
| 228 | // match ExternalStorageProvider.ROOT_ID_HOME. |
| 229 | return isExternalStorage() && "home".equals(rootId); |
| 230 | } |
| 231 | |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 232 | public boolean isExternalStorage() { |
| 233 | return "com.android.externalstorage.documents".equals(authority); |
| 234 | } |
| 235 | |
| 236 | public boolean isDownloads() { |
| 237 | return "com.android.providers.downloads.documents".equals(authority); |
| 238 | } |
| 239 | |
| 240 | public boolean isImages() { |
| 241 | return "com.android.providers.media.documents".equals(authority) |
| 242 | && "images_root".equals(rootId); |
| 243 | } |
| 244 | |
| 245 | public boolean isVideos() { |
| 246 | return "com.android.providers.media.documents".equals(authority) |
| 247 | && "videos_root".equals(rootId); |
| 248 | } |
| 249 | |
| 250 | public boolean isAudio() { |
| 251 | return "com.android.providers.media.documents".equals(authority) |
| 252 | && "audio_root".equals(rootId); |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Daichi Hirono | abf3974 | 2015-10-23 08:36:10 +0900 | [diff] [blame] | 255 | public boolean isMtp() { |
| 256 | return "com.android.mtp.documents".equals(authority); |
| 257 | } |
| 258 | |
| 259 | public boolean isLibrary() { |
Steve McKay | e2af078 | 2016-02-18 09:48:39 -0800 | [diff] [blame] | 260 | return derivedType == TYPE_IMAGES |
| 261 | || derivedType == TYPE_VIDEO |
| 262 | || derivedType == TYPE_AUDIO |
| 263 | || derivedType == TYPE_RECENTS; |
Daichi Hirono | abf3974 | 2015-10-23 08:36:10 +0900 | [diff] [blame] | 264 | } |
| 265 | |
Steve McKay | efa1761 | 2016-01-29 18:15:39 -0800 | [diff] [blame] | 266 | public boolean hasSettings() { |
| 267 | return (flags & Root.FLAG_HAS_SETTINGS) != 0; |
| 268 | } |
| 269 | |
Steve McKay | 4a1ca86 | 2016-02-17 18:25:47 -0800 | [diff] [blame] | 270 | public boolean supportsChildren() { |
| 271 | return (flags & Root.FLAG_SUPPORTS_IS_CHILD) != 0; |
| 272 | } |
| 273 | |
| 274 | public boolean supportsCreate() { |
| 275 | return (flags & Root.FLAG_SUPPORTS_CREATE) != 0; |
| 276 | } |
| 277 | |
Steve McKay | e2af078 | 2016-02-18 09:48:39 -0800 | [diff] [blame] | 278 | public boolean supportsRecents() { |
| 279 | return (flags & Root.FLAG_SUPPORTS_RECENTS) != 0; |
| 280 | } |
| 281 | |
| 282 | public boolean supportsSearch() { |
| 283 | return (flags & Root.FLAG_SUPPORTS_SEARCH) != 0; |
| 284 | } |
| 285 | |
Steve McKay | 4a1ca86 | 2016-02-17 18:25:47 -0800 | [diff] [blame] | 286 | public boolean isAdvanced() { |
| 287 | return (flags & Root.FLAG_ADVANCED) != 0; |
| 288 | } |
| 289 | |
| 290 | public boolean isLocalOnly() { |
| 291 | return (flags & Root.FLAG_LOCAL_ONLY) != 0; |
| 292 | } |
| 293 | |
| 294 | public boolean isEmpty() { |
| 295 | return (flags & Root.FLAG_EMPTY) != 0; |
| 296 | } |
| 297 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 298 | public Drawable loadIcon(Context context) { |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 299 | if (derivedIcon != 0) { |
Alan Viverette | 03d30a5 | 2014-08-14 12:59:10 -0700 | [diff] [blame] | 300 | return context.getDrawable(derivedIcon); |
Jeff Sharkey | 6d97d3c | 2013-09-06 10:43:45 -0700 | [diff] [blame] | 301 | } else { |
| 302 | return IconUtils.loadPackageIcon(context, authority, icon); |
| 303 | } |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 304 | } |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 305 | |
Jeff Sharkey | cbce470 | 2014-08-29 15:38:27 -0700 | [diff] [blame] | 306 | public Drawable loadDrawerIcon(Context context) { |
| 307 | if (derivedIcon != 0) { |
| 308 | return IconUtils.applyTintColor(context, derivedIcon, R.color.item_root_icon); |
| 309 | } else { |
| 310 | return IconUtils.loadPackageIcon(context, authority, icon); |
| 311 | } |
| 312 | } |
| 313 | |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 314 | public Drawable loadToolbarIcon(Context context) { |
| 315 | if (derivedIcon != 0) { |
Jeff Sharkey | cbce470 | 2014-08-29 15:38:27 -0700 | [diff] [blame] | 316 | return IconUtils.applyTintAttr(context, derivedIcon, |
Jeff Sharkey | c29dd61 | 2014-08-08 13:08:56 -0700 | [diff] [blame] | 317 | android.R.attr.colorControlNormal); |
| 318 | } else { |
| 319 | return IconUtils.loadPackageIcon(context, authority, icon); |
Jeff Sharkey | a847d79 | 2014-07-29 17:33:36 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 323 | @Override |
| 324 | public boolean equals(Object o) { |
Steve McKay | 30551a2 | 2016-02-16 13:08:10 -0800 | [diff] [blame] | 325 | if (o == null) { |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 326 | return false; |
| 327 | } |
Steve McKay | 30551a2 | 2016-02-16 13:08:10 -0800 | [diff] [blame] | 328 | |
| 329 | if (this == o) { |
| 330 | return true; |
| 331 | } |
| 332 | |
| 333 | if (o instanceof RootInfo) { |
| 334 | RootInfo other = (RootInfo) o; |
| 335 | return Objects.equals(authority, other.authority) |
| 336 | && Objects.equals(rootId, other.rootId); |
| 337 | } |
| 338 | |
| 339 | return false; |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public int hashCode() { |
| 344 | return Objects.hash(authority, rootId); |
| 345 | } |
| 346 | |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 347 | @Override |
Steve McKay | 008e948 | 2016-02-18 15:32:16 -0800 | [diff] [blame] | 348 | public int compareTo(RootInfo other) { |
| 349 | // Sort by root type, then title, then summary. |
| 350 | int score = derivedType - other.derivedType; |
| 351 | if (score != 0) { |
| 352 | return score; |
| 353 | } |
| 354 | |
| 355 | score = compareToIgnoreCaseNullable(title, other.title); |
| 356 | if (score != 0) { |
| 357 | return score; |
| 358 | } |
| 359 | |
| 360 | return compareToIgnoreCaseNullable(summary, other.summary); |
| 361 | } |
| 362 | |
| 363 | @Override |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 364 | public String toString() { |
| 365 | return "Root{authority=" + authority + ", rootId=" + rootId + ", title=" + title + "}"; |
| 366 | } |
| 367 | |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 368 | public String getDirectoryString() { |
Jeff Sharkey | 4ec9739 | 2013-09-10 12:04:26 -0700 | [diff] [blame] | 369 | return !TextUtils.isEmpty(summary) ? summary : title; |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 370 | } |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 371 | } |