mirror of https://git.sr.ht/~oppen/ariane
handle intent text extras
This commit is contained in:
parent
b64b2e6ff6
commit
782ca7e94f
|
@ -14,11 +14,17 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
<activity android:name="oppen.ariane.ui.GemActivity">
|
||||
<activity android:name="oppen.ariane.ui.GemActivity"
|
||||
android:label="Open in Ariane">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
|
|
@ -16,6 +16,5 @@ sealed class GemState {
|
|||
data class ResponseAudio(val uri: URI, val header: GeminiResponse.Header, val cacheUri: Uri) : GemState()
|
||||
data class ResponseError(val header: GeminiResponse.Header): GemState()
|
||||
|
||||
data class TabChange(val count: Int) : GemState()
|
||||
object Blank: GemState()
|
||||
}
|
|
@ -3,10 +3,9 @@ package oppen.ariane.ui
|
|||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.MATCH_ALL
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.activity.viewModels
|
||||
|
@ -220,6 +219,43 @@ class GemActivity : AppCompatActivity() {
|
|||
RuntimeCache.remove(address)
|
||||
model.request(address)
|
||||
}
|
||||
|
||||
checkIntentExtras()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Checks intent to see if Activity was opened to handle selected text
|
||||
*
|
||||
*/
|
||||
private fun checkIntentExtras() {
|
||||
|
||||
//First check if there's a uri from a web link or other
|
||||
val uri = intent.data
|
||||
if(uri != null){
|
||||
binding.addressEdit.setText(uri.toString())
|
||||
model.request(uri.toString())
|
||||
return
|
||||
}
|
||||
|
||||
//Then check if we've arrived here via some selected text
|
||||
val processText = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
||||
intent.hasExtra(Intent.EXTRA_PROCESS_TEXT) -> {
|
||||
intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT).toString()
|
||||
}
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
processText?.let { text ->
|
||||
if (text.startsWith("gemini://")) {
|
||||
binding.addressEdit.setText(text)
|
||||
model.request(text)
|
||||
} else {
|
||||
Snackbar.make(binding.root, "$text is not a valid Gemini address", Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
|
|
@ -21,7 +21,6 @@ class GemViewModel: ViewModel() {
|
|||
this.onState = onState
|
||||
|
||||
request(URI.create(Ariane.DEFAULT_HOME_CAPSULE))//todo - regression: should check prefs...
|
||||
onState(GemState.TabChange(1))
|
||||
}
|
||||
|
||||
fun request(address: String) {
|
||||
|
|
Loading…
Reference in New Issue