Merge pull request #575 from PhilKes/feat/view-intent

Add intent-filter to open any text based file
This commit is contained in:
Phil 2025-05-06 18:41:06 +02:00 committed by GitHub
commit e553e78efb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 8 deletions

View file

@ -77,6 +77,21 @@
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" android:mimeType="text/*" />
<data android:scheme="content" android:mimeType="text/*" />
<data android:scheme="file" android:mimeType="application/json" />
<data android:scheme="content" android:mimeType="application/json" />
<data android:scheme="file" android:mimeType="application/xml" />
<data android:scheme="content" android:mimeType="application/xml" />
</intent-filter>
</activity>
<activity android:name=".presentation.activity.note.ViewImageActivity" />

View file

@ -188,16 +188,17 @@ abstract class EditActivity(private val type: Type) :
if (persistedId == null || notallyModel.originalNote == null) {
notallyModel.setState(id)
}
if (
notallyModel.isNewNote &&
intent.action in setOf(Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE)
) {
handleSharedNote()
} else if (notallyModel.isNewNote) {
if (notallyModel.isNewNote) {
when (intent.action) {
Intent.ACTION_SEND,
Intent.ACTION_SEND_MULTIPLE -> handleSharedNote()
Intent.ACTION_VIEW -> handleViewNote()
else ->
intent.getStringExtra(EXTRA_DISPLAYED_LABEL)?.let {
notallyModel.setLabels(listOf(it))
}
}
}
setupToolbars()
setupListeners()
@ -756,6 +757,26 @@ abstract class EditActivity(private val type: Type) :
}
}
private fun handleViewNote() {
val text =
intent.data?.let { uri ->
contentResolver.openInputStream(uri)?.use { inputStream ->
inputStream.bufferedReader().readText()
}
?: run {
showToast(R.string.cant_load_file)
null
}
} ?: intent.getStringExtra(Intent.EXTRA_TEXT)
val title = intent.getStringExtra(Intent.EXTRA_SUBJECT)
if (text != null) {
notallyModel.body = Editable.Factory.getInstance().newEditable(text)
}
if (title != null) {
notallyModel.title = title
}
}
@RequiresApi(24)
override fun recordAudio() {
val permission = Manifest.permission.RECORD_AUDIO