Add share search action
This commit is contained in:
parent
b5903f9812
commit
457d950006
@ -5,6 +5,7 @@ import android.content.pm.PackageManager
|
|||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.rounded.StickyNote2
|
||||||
import androidx.compose.material.icons.rounded.Alarm
|
import androidx.compose.material.icons.rounded.Alarm
|
||||||
import androidx.compose.material.icons.rounded.Call
|
import androidx.compose.material.icons.rounded.Call
|
||||||
import androidx.compose.material.icons.rounded.Email
|
import androidx.compose.material.icons.rounded.Email
|
||||||
@ -24,6 +25,7 @@ import androidx.compose.material.icons.rounded.PersonSearch
|
|||||||
import androidx.compose.material.icons.rounded.Place
|
import androidx.compose.material.icons.rounded.Place
|
||||||
import androidx.compose.material.icons.rounded.QueryStats
|
import androidx.compose.material.icons.rounded.QueryStats
|
||||||
import androidx.compose.material.icons.rounded.Search
|
import androidx.compose.material.icons.rounded.Search
|
||||||
|
import androidx.compose.material.icons.rounded.Share
|
||||||
import androidx.compose.material.icons.rounded.Sms
|
import androidx.compose.material.icons.rounded.Sms
|
||||||
import androidx.compose.material.icons.rounded.SportsEsports
|
import androidx.compose.material.icons.rounded.SportsEsports
|
||||||
import androidx.compose.material.icons.rounded.StickyNote2
|
import androidx.compose.material.icons.rounded.StickyNote2
|
||||||
@ -151,6 +153,7 @@ fun getSearchActionIconVector(icon: SearchActionIcon): ImageVector {
|
|||||||
SearchActionIcon.Movie -> Icons.Rounded.Movie
|
SearchActionIcon.Movie -> Icons.Rounded.Movie
|
||||||
SearchActionIcon.Music -> Icons.Rounded.MusicNote
|
SearchActionIcon.Music -> Icons.Rounded.MusicNote
|
||||||
SearchActionIcon.Game -> Icons.Rounded.SportsEsports
|
SearchActionIcon.Game -> Icons.Rounded.SportsEsports
|
||||||
SearchActionIcon.Note -> Icons.Rounded.StickyNote2
|
SearchActionIcon.Note -> Icons.AutoMirrored.Rounded.StickyNote2
|
||||||
|
SearchActionIcon.Share -> Icons.Rounded.Share
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,6 +766,7 @@
|
|||||||
<string name="search_action_email">Email</string>
|
<string name="search_action_email">Email</string>
|
||||||
<string name="search_action_alarm">Set alarm</string>
|
<string name="search_action_alarm">Set alarm</string>
|
||||||
<string name="search_action_timer">Start timer</string>
|
<string name="search_action_timer">Start timer</string>
|
||||||
|
<string name="search_action_share">Share</string>
|
||||||
<string name="search_action_websearch">Web search</string>
|
<string name="search_action_websearch">Web search</string>
|
||||||
<string name="search_action_contact">Add to contacts</string>
|
<string name="search_action_contact">Add to contacts</string>
|
||||||
<string name="search_action_open_url">View website</string>
|
<string name="search_action_open_url">View website</string>
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import de.mm20.launcher2.crashreporter.CrashReporter
|
|||||||
import de.mm20.launcher2.database.AppDatabase
|
import de.mm20.launcher2.database.AppDatabase
|
||||||
import de.mm20.launcher2.database.entities.SearchActionEntity
|
import de.mm20.launcher2.database.entities.SearchActionEntity
|
||||||
import de.mm20.launcher2.ktx.jsonObjectOf
|
import de.mm20.launcher2.ktx.jsonObjectOf
|
||||||
|
import de.mm20.launcher2.searchactions.actions.ShareAction
|
||||||
import de.mm20.launcher2.searchactions.builders.CallActionBuilder
|
import de.mm20.launcher2.searchactions.builders.CallActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.CreateContactActionBuilder
|
import de.mm20.launcher2.searchactions.builders.CreateContactActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.EmailActionBuilder
|
import de.mm20.launcher2.searchactions.builders.EmailActionBuilder
|
||||||
@ -14,6 +15,7 @@ import de.mm20.launcher2.searchactions.builders.OpenUrlActionBuilder
|
|||||||
import de.mm20.launcher2.searchactions.builders.ScheduleEventActionBuilder
|
import de.mm20.launcher2.searchactions.builders.ScheduleEventActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.SearchActionBuilder
|
import de.mm20.launcher2.searchactions.builders.SearchActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.SetAlarmActionBuilder
|
import de.mm20.launcher2.searchactions.builders.SetAlarmActionBuilder
|
||||||
|
import de.mm20.launcher2.searchactions.builders.ShareActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.TimerActionBuilder
|
import de.mm20.launcher2.searchactions.builders.TimerActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.WebsearchActionBuilder
|
import de.mm20.launcher2.searchactions.builders.WebsearchActionBuilder
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -58,6 +60,7 @@ internal class SearchActionRepositoryImpl(
|
|||||||
TimerActionBuilder(context),
|
TimerActionBuilder(context),
|
||||||
OpenUrlActionBuilder(context),
|
OpenUrlActionBuilder(context),
|
||||||
WebsearchActionBuilder(context),
|
WebsearchActionBuilder(context),
|
||||||
|
ShareActionBuilder(context),
|
||||||
)
|
)
|
||||||
|
|
||||||
return allActions
|
return allActions
|
||||||
|
|||||||
@ -33,13 +33,14 @@ enum class SearchActionIcon(private val value: Int) {
|
|||||||
Movie(18),
|
Movie(18),
|
||||||
Music(19),
|
Music(19),
|
||||||
Game(20),
|
Game(20),
|
||||||
Note(21);
|
Note(21),
|
||||||
|
Share(22);
|
||||||
fun toInt(): Int {
|
fun toInt(): Int {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun fromInt(value: Int?): SearchActionIcon {
|
fun fromInt(value: Int?): SearchActionIcon {
|
||||||
return values().firstOrNull { it.value == value } ?: Search
|
return entries.firstOrNull { it.value == value } ?: Search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package de.mm20.launcher2.searchactions.actions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import de.mm20.launcher2.ktx.tryStartActivity
|
||||||
|
|
||||||
|
data class ShareAction(
|
||||||
|
override val label: String,
|
||||||
|
val text: String,
|
||||||
|
) : SearchAction {
|
||||||
|
override val icon: SearchActionIcon = SearchActionIcon.Share
|
||||||
|
override val iconColor: Int = 0
|
||||||
|
override val customIcon: String? = null
|
||||||
|
|
||||||
|
override fun start(context: Context) {
|
||||||
|
val intent = Intent.createChooser(
|
||||||
|
Intent(Intent.ACTION_SEND).apply {
|
||||||
|
type = "text/plain"
|
||||||
|
putExtra(Intent.EXTRA_TEXT, text)
|
||||||
|
},
|
||||||
|
null
|
||||||
|
)
|
||||||
|
context.tryStartActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -69,6 +69,7 @@ interface SearchActionBuilder {
|
|||||||
"calendar" -> return ScheduleEventActionBuilder(context)
|
"calendar" -> return ScheduleEventActionBuilder(context)
|
||||||
"website" -> return OpenUrlActionBuilder(context)
|
"website" -> return OpenUrlActionBuilder(context)
|
||||||
"websearch" -> return WebsearchActionBuilder(context)
|
"websearch" -> return WebsearchActionBuilder(context)
|
||||||
|
"share" -> return ShareActionBuilder(context)
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
package de.mm20.launcher2.searchactions.builders
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import de.mm20.launcher2.searchactions.R
|
||||||
|
import de.mm20.launcher2.searchactions.TextClassificationResult
|
||||||
|
import de.mm20.launcher2.searchactions.actions.SearchAction
|
||||||
|
import de.mm20.launcher2.searchactions.actions.SearchActionIcon
|
||||||
|
import de.mm20.launcher2.searchactions.actions.ShareAction
|
||||||
|
|
||||||
|
class ShareActionBuilder(
|
||||||
|
override val label: String,
|
||||||
|
) : SearchActionBuilder {
|
||||||
|
|
||||||
|
constructor(context: Context) : this(context.getString(R.string.search_action_share))
|
||||||
|
|
||||||
|
override val key: String
|
||||||
|
get() = "share"
|
||||||
|
|
||||||
|
override val icon: SearchActionIcon = SearchActionIcon.Share
|
||||||
|
|
||||||
|
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction? {
|
||||||
|
return ShareAction(
|
||||||
|
context.getString(R.string.search_action_share),
|
||||||
|
classifiedQuery.text
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,7 +17,7 @@ class WebsearchActionBuilder(
|
|||||||
override val key: String
|
override val key: String
|
||||||
get() = "websearch"
|
get() = "websearch"
|
||||||
|
|
||||||
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction? {
|
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction {
|
||||||
return WebsearchAction(
|
return WebsearchAction(
|
||||||
context.getString(R.string.search_action_websearch), classifiedQuery.text
|
context.getString(R.string.search_action_websearch), classifiedQuery.text
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user