1 /* 2 * Copyright (C) 2017 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.settings.intelligence.search.sitemap; 18 19 import android.content.ContentValues; 20 import android.text.TextUtils; 21 22 import com.android.settings.intelligence.search.indexing.IndexDatabaseHelper; 23 24 import java.util.Objects; 25 26 /** 27 * Data model for a parent-child page pair. 28 * <p/> 29 * A list of {@link SiteMapPair} can represent the breadcrumb for a search result from settings. 30 */ 31 public class SiteMapPair { 32 private final String mParentClass; 33 private final String mParentTitle; 34 private final String mChildClass; 35 private final String mChildTitle; 36 private final String mHighlightableMenuKey; 37 SiteMapPair(String parentClass, String parentTitle, String childClass, String childTitle, String highlightableMenuKey)38 public SiteMapPair(String parentClass, String parentTitle, String childClass, String childTitle, 39 String highlightableMenuKey) { 40 mParentClass = parentClass; 41 mParentTitle = parentTitle; 42 mChildClass = childClass; 43 mChildTitle = childTitle; 44 mHighlightableMenuKey = highlightableMenuKey; 45 } 46 47 @Override hashCode()48 public int hashCode() { 49 return Objects.hash(mParentClass, mChildClass); 50 } 51 52 @Override equals(Object other)53 public boolean equals(Object other) { 54 if (other == null || !(other instanceof SiteMapPair)) { 55 return false; 56 } 57 return TextUtils.equals(mParentClass, ((SiteMapPair) other).mParentClass) 58 && TextUtils.equals(mChildClass, ((SiteMapPair) other).mChildClass); 59 } 60 getParentClass()61 public String getParentClass() { 62 return mParentClass; 63 } 64 getParentTitle()65 public String getParentTitle() { 66 return mParentTitle; 67 } 68 getChildClass()69 public String getChildClass() { 70 return mChildClass; 71 } 72 getChildTitle()73 public String getChildTitle() { 74 return mChildTitle; 75 } 76 getHighlightableMenuKey()77 public String getHighlightableMenuKey() { 78 return mHighlightableMenuKey; 79 } 80 81 /** 82 * Converts this object into {@link ContentValues}. The content follows schema in 83 * {@link IndexDatabaseHelper.SiteMapColumns}. 84 */ toContentValue()85 public ContentValues toContentValue() { 86 final ContentValues values = new ContentValues(); 87 values.put(IndexDatabaseHelper.SiteMapColumns.DOCID, hashCode()); 88 values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_CLASS, mParentClass); 89 values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_TITLE, mParentTitle); 90 values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_CLASS, mChildClass); 91 values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_TITLE, mChildTitle); 92 values.put(IndexDatabaseHelper.SiteMapColumns.HIGHLIGHTABLE_MENU_KEY, 93 mHighlightableMenuKey); 94 return values; 95 } 96 } 97