mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 12:19:55 +00:00
Add intent-filter to open any text based file
This commit is contained in:
parent
771546a0cb
commit
724d08507a
2 changed files with 44 additions and 8 deletions
|
@ -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" />
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue