Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 795d133e authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "[Spa Search] Add highlight for search result" into main

parents 4e5a274e 684226cc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2025 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.settingslib.spa.search">

    <uses-sdk android:minSdkVersion="31" />
</manifest>
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
syntax = "proto2";

package com.android.settingslib.spa.search;
option java_package = "com.android.settingslib.spa.search";

message SpaSearchLandingKey {
  oneof page {
@@ -26,6 +27,8 @@ message SpaSearchLandingKey {
message SpaSearchLandingSpaPage {
  /** The destination of SPA page. */
  optional string destination = 1;
  /** The key to highlight the item. */
  optional string highlight_item_key = 2;
}

message SpaSearchLandingFragment {
+13 −1
Original line number Diff line number Diff line
@@ -17,9 +17,21 @@
package com.android.settingslib.spa.search

import android.content.Context
import com.android.settingslib.spa.framework.compose.HighlightBox

interface SearchablePage {
    data class SearchItem(val itemTitle: String, val keywords: String? = null)
    data class SearchItem(
        /**
         * The key to highlight the item in the page.
         *
         * The corresponding item in the page should be wrapped with [HighlightBox] and pass this
         * key to [HighlightBox]'s `highlightItemKey` parameter. When search result item is clicked,
         * the item with this key will be highlighted.
         */
        val highlightItemKey: String,
        val itemTitle: String,
        val keywords: String? = null,
    )

    /** Gets the title of the page. */
    fun getPageTitleForSearch(context: Context): String
+8 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ abstract class SpaSearchLandingActivity : Activity() {
            val destination = key.spaPage.destination
            if (destination.isNotEmpty()) {
                Log.d(TAG, "Launch SPA search result: ${key.spaPage}")
                startSpaPage(destination)
                startSpaPage(destination, key.spaPage.highlightItemKey)
            }
        }
        if (key.hasFragment()) {
@@ -55,7 +55,13 @@ abstract class SpaSearchLandingActivity : Activity() {

    abstract fun isValidCall(): Boolean

    open fun startSpaPage(destination: String) {
    /**
     * Starts the Spa page.
     *
     * @param destination The destination of SPA page.
     * @param highlightItemKey The key to highlight the item.
     */
    open fun startSpaPage(destination: String, highlightItemKey: String) {
        throw UnsupportedOperationException()
    }

+12 −8
Original line number Diff line number Diff line
@@ -46,22 +46,26 @@ class SpaSearchRepository() {
        private fun SettingsPageProvider.createSpaSearchIndexablePage(
            getPageTitleForSearch: (context: Context) -> String,
            getSearchItems: (context: Context) -> List<SearchItem>,
        ): SpaSearchIndexablePage {
            val searchLandingKey =
                SpaSearchLandingKey.newBuilder()
                    .setSpaPage(SpaSearchLandingSpaPage.newBuilder().setDestination(name))
                    .build()
            return SpaSearchIndexablePage(targetClass = this::class.java) { context ->
        ) =
            SpaSearchIndexablePage(targetClass = this::class.java) { context ->
                val pageTitle = getPageTitleForSearch(context)
                getSearchItems(context).map { searchItem ->
                    SpaSearchIndexableItem(
                        searchLandingKey = searchLandingKey,
                        searchLandingKey = spaPageLandingKey(name, searchItem.highlightItemKey),
                        pageTitle = pageTitle,
                        itemTitle = searchItem.itemTitle,
                        keywords = searchItem.keywords,
                    )
                }
            }
        }

        private fun spaPageLandingKey(name: String, highlightItemKey: String) =
            SpaSearchLandingKey.newBuilder()
                .setSpaPage(
                    SpaSearchLandingSpaPage.newBuilder()
                        .setDestination(name)
                        .setHighlightItemKey(highlightItemKey)
                )
                .build()
    }
}
Loading