Skip to content

Commit

Permalink
Search screen
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Dec 2, 2023
1 parent 84e3bbd commit fbe8006
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@

<data
android:host="settings"
android:scheme="shortcut" />
android:scheme="movies_shortcut" />

</intent-filter>

<intent-filter
android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="search"
android:scheme="movies_shortcut" />

</intent-filter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ fun Context.installLauncherIcon() {
setIcon(IconAlias.Red)
}

internal val Context.shortcutSearchIconRes: Int
@DrawableRes get() = when {
isEnabled(IconAlias.Red) -> R.drawable.ic_shortcut_search_red_48
isEnabled(IconAlias.Purple) -> R.drawable.ic_shortcut_search_purple_48
isEnabled(IconAlias.Brown) -> R.drawable.ic_shortcut_search_brown_48
else -> 0
}

internal val Context.shortcutSettingsIconRes: Int
@DrawableRes get() = when {
isEnabled(IconAlias.Red) -> R.drawable.ic_shortcut_settings_outline_red_48
isEnabled(IconAlias.Purple) -> R.drawable.ic_shortcut_settings_outline_purple_48
isEnabled(IconAlias.Brown) -> R.drawable.ic_shortcut_settings_outline_brown_48
isEnabled(IconAlias.Red) -> R.drawable.ic_shortcut_settings_red_48
isEnabled(IconAlias.Purple) -> R.drawable.ic_shortcut_settings_purple_48
isEnabled(IconAlias.Brown) -> R.drawable.ic_shortcut_settings_brown_48
else -> 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@ import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.core.net.toUri
import org.michaelbel.movies.ui.R
import org.michaelbel.movies.ui.appicon.shortcutSearchIconRes
import org.michaelbel.movies.ui.appicon.shortcutSettingsIconRes

private const val SEARCH_SHORTCUT_ID = "searchShortcutId"
private const val SETTINGS_SHORTCUT_ID = "settingsShortcutId"

const val INTENT_ACTION_SETTINGS = "shortcut://settings"
const val INTENT_ACTION_SEARCH = "movies_shortcut://search"
const val INTENT_ACTION_SETTINGS = "movies_shortcut://settings"

/**
* See [App Shortcuts Design Guidelines](https://commondatastorage.googleapis.com/androiddevelopers/shareables/design/app-shortcuts-design-guidelines.pdf)
*/
fun Context.installShortcuts() {
val searchShortcut = ShortcutInfoCompat.Builder(this, SEARCH_SHORTCUT_ID)
.setShortLabel(getString(R.string.shortcuts_search_title))
.setLongLabel(getString(R.string.shortcuts_search_title))
.setRank(1)
.setIcon(IconCompat.createWithResource(this, shortcutSearchIconRes))
.setIntent(Intent(Intent.ACTION_VIEW, INTENT_ACTION_SEARCH.toUri()))
.build()
val settingsShortcut = ShortcutInfoCompat.Builder(this, SETTINGS_SHORTCUT_ID)
.setShortLabel(getString(R.string.shortcuts_settings_title))
.setLongLabel(getString(R.string.shortcuts_settings_title))
.setRank(1)
.setIcon(IconCompat.createWithResource(this, shortcutSettingsIconRes))
.setIntent(Intent(Intent.ACTION_VIEW, INTENT_ACTION_SETTINGS.toUri()))
.build()
ShortcutManagerCompat.pushDynamicShortcut(this, settingsShortcut)
ShortcutManagerCompat.setDynamicShortcuts(this, listOf(searchShortcut, settingsShortcut))
}
14 changes: 14 additions & 0 deletions core/ui/src/main/res/drawable/ic_shortcut_search_brown_48.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#D7CCC8"
android:pathData="M24,24m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0" />
<path
android:fillColor="#000000"
android:pathData="M21.5,15C23.224,15 24.877,15.685 26.096,16.904C27.315,18.123 28,19.776 28,21.5C28,23.11 27.41,24.59 26.44,25.73L26.71,26H27.5L32.5,31L31,32.5L26,27.5V26.71L25.73,26.44C24.59,27.41 23.11,28 21.5,28C19.776,28 18.123,27.315 16.904,26.096C15.685,24.877 15,23.224 15,21.5C15,19.776 15.685,18.123 16.904,16.904C18.123,15.685 19.776,15 21.5,15ZM21.5,17C19,17 17,19 17,21.5C17,24 19,26 21.5,26C24,26 26,24 26,21.5C26,19 24,17 21.5,17Z" />
</vector>
14 changes: 14 additions & 0 deletions core/ui/src/main/res/drawable/ic_shortcut_search_purple_48.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#D1C4E9"
android:pathData="M24,24m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0"/>
<path
android:fillColor="#000000"
android:pathData="M21.5,15C23.224,15 24.877,15.685 26.096,16.904C27.315,18.123 28,19.776 28,21.5C28,23.11 27.41,24.59 26.44,25.73L26.71,26H27.5L32.5,31L31,32.5L26,27.5V26.71L25.73,26.44C24.59,27.41 23.11,28 21.5,28C19.776,28 18.123,27.315 16.904,26.096C15.685,24.877 15,23.224 15,21.5C15,19.776 15.685,18.123 16.904,16.904C18.123,15.685 19.776,15 21.5,15ZM21.5,17C19,17 17,19 17,21.5C17,24 19,26 21.5,26C24,26 26,24 26,21.5C26,19 24,17 21.5,17Z"/>
</vector>
14 changes: 14 additions & 0 deletions core/ui/src/main/res/drawable/ic_shortcut_search_red_48.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FFCDD2"
android:pathData="M24,24m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0" />
<path
android:fillColor="#000000"
android:pathData="M21.5,15C23.224,15 24.877,15.685 26.096,16.904C27.315,18.123 28,19.776 28,21.5C28,23.11 27.41,24.59 26.44,25.73L26.71,26H27.5L32.5,31L31,32.5L26,27.5V26.71L25.73,26.44C24.59,27.41 23.11,28 21.5,28C19.776,28 18.123,27.315 16.904,26.096C15.685,24.877 15,23.224 15,21.5C15,19.776 15.685,18.123 16.904,16.904C18.123,15.685 19.776,15 21.5,15ZM21.5,17C19,17 17,19 17,21.5C17,24 19,26 21.5,26C24,26 26,24 26,21.5C26,19 24,17 21.5,17Z"/>
</vector>
1 change: 1 addition & 0 deletions core/ui/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="language_code">ru</string>
<string name="shortcuts_search_title">Поиск</string>
<string name="shortcuts_settings_title">Настройки</string>
<string name="notification_enable_title">Включите Уведомления\nдля Movies</string>
<string name="notification_enable_subtitle">Пожалуйста позвольте Movies отправлять вам уведомления</string>
Expand Down
1 change: 1 addition & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="language_code">en</string>
<string name="shortcuts_search_title">Search</string>
<string name="shortcuts_settings_title">Settings</string>
<string name="notification_enable_title">Turn on Notifications\nFor Movies</string>
<string name="notification_enable_subtitle">Please allow Movies to send you notifications</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package org.michaelbel.movies.search

import androidx.navigation.NavController
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import org.michaelbel.movies.search.ui.SearchRoute
import org.michaelbel.movies.ui.shortcuts.INTENT_ACTION_SEARCH

private val SEARCH_SHORTCUT_NAV_DEEP_LINK: NavDeepLink = navDeepLink {
uriPattern = INTENT_ACTION_SEARCH
}

fun NavController.navigateToSearch() {
navigate(SearchDestination.route)
Expand All @@ -14,7 +21,8 @@ fun NavGraphBuilder.searchGraph(
navigateToDetails: (Int) -> Unit,
) {
composable(
route = SearchDestination.route
route = SearchDestination.route,
deepLinks = listOf(SEARCH_SHORTCUT_NAV_DEEP_LINK)
) {
SearchRoute(
onBackClick = navigateBack,
Expand Down

0 comments on commit fbe8006

Please sign in to comment.