mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-12 10:40:25 +09:00
Editor | Open a file by default app on device instead of downloading it when clicked (#1904)
This commit is contained in:
parent
1469b7d998
commit
e09cb4dc90
4 changed files with 34 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
### New features & enhancements 🚀
|
||||
|
||||
* Editor | Opening a file by default app on device instead of downloading it when clicked (#1904)
|
||||
* Editor | Latex block in experimental mode. Based on WebView. (#1814)
|
||||
* Objects | Menu | Select a layout, which best suits your object: Note, Basic, Profile, or Task (#1894)
|
||||
* Sets | Delete a relation from your set (#1890)
|
||||
|
|
|
@ -29,6 +29,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.animation.doOnStart
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
|
@ -1055,9 +1056,23 @@ open class EditorFragment : NavigationFragment(R.layout.fragment_editor),
|
|||
R.id.action_pageScreen_to_linkToObjectOrWebPagesFragment
|
||||
)
|
||||
}
|
||||
Command.ShowKeyboard -> {
|
||||
is Command.ShowKeyboard -> {
|
||||
recycler.findFocus()?.focusAndShowKeyboard()
|
||||
}
|
||||
is Command.OpenFileByDefaultApp -> {
|
||||
try {
|
||||
val uri = Uri.parse(command.uri)
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
setDataAndType(uri, command.mime)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
toast("Could not open file: ${e.message}")
|
||||
Timber.e(e, "Error while opening file")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3617,7 +3617,17 @@ class EditorViewModel(
|
|||
}
|
||||
|
||||
private fun onFileClicked(id: String) {
|
||||
dispatch(Command.RequestDownloadPermission(id))
|
||||
val file = blocks.find { it.id == id }
|
||||
if (file != null && file.content is Content.File) {
|
||||
val cnt = (file.content as Content.File)
|
||||
dispatch(
|
||||
Command.OpenFileByDefaultApp(
|
||||
id = id,
|
||||
mime = cnt.mime.orEmpty(),
|
||||
uri = urlBuilder.file(cnt.hash)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun startDownloadingFile(id: String) {
|
||||
|
|
|
@ -48,6 +48,12 @@ sealed class Command {
|
|||
val id: String
|
||||
) : Command()
|
||||
|
||||
data class OpenFileByDefaultApp(
|
||||
val id: String,
|
||||
val mime: String,
|
||||
val uri: String
|
||||
) : Command()
|
||||
|
||||
object PopBackStack : Command()
|
||||
|
||||
object ShowKeyboard : Command()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue