mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 12:19:55 +00:00
Merge pull request #575 from PhilKes/feat/view-intent
Add intent-filter to open any text based file
This commit is contained in:
commit
e553e78efb
2 changed files with 44 additions and 8 deletions
|
@ -77,6 +77,21 @@
|
||||||
<data android:mimeType="*/*" />
|
<data android:mimeType="*/*" />
|
||||||
</intent-filter>
|
</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>
|
||||||
|
|
||||||
<activity android:name=".presentation.activity.note.ViewImageActivity" />
|
<activity android:name=".presentation.activity.note.ViewImageActivity" />
|
||||||
|
|
|
@ -188,14 +188,15 @@ abstract class EditActivity(private val type: Type) :
|
||||||
if (persistedId == null || notallyModel.originalNote == null) {
|
if (persistedId == null || notallyModel.originalNote == null) {
|
||||||
notallyModel.setState(id)
|
notallyModel.setState(id)
|
||||||
}
|
}
|
||||||
if (
|
if (notallyModel.isNewNote) {
|
||||||
notallyModel.isNewNote &&
|
when (intent.action) {
|
||||||
intent.action in setOf(Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE)
|
Intent.ACTION_SEND,
|
||||||
) {
|
Intent.ACTION_SEND_MULTIPLE -> handleSharedNote()
|
||||||
handleSharedNote()
|
Intent.ACTION_VIEW -> handleViewNote()
|
||||||
} else if (notallyModel.isNewNote) {
|
else ->
|
||||||
intent.getStringExtra(EXTRA_DISPLAYED_LABEL)?.let {
|
intent.getStringExtra(EXTRA_DISPLAYED_LABEL)?.let {
|
||||||
notallyModel.setLabels(listOf(it))
|
notallyModel.setLabels(listOf(it))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
@RequiresApi(24)
|
||||||
override fun recordAudio() {
|
override fun recordAudio() {
|
||||||
val permission = Manifest.permission.RECORD_AUDIO
|
val permission = Manifest.permission.RECORD_AUDIO
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue