koreader / android-luajit-launcher

Android NativeActivity based launcher for LuaJIT, implementing the main loop within Lua land via FFI
MIT License
130 stars 83 forks source link

import files #491

Closed pazos closed 1 month ago

pazos commented 2 months ago

Fix for https://github.com/koreader/koreader/issues/9787

TODO

The new behaviour is:

guess the path if the content seems a local file on a readable path. fallback to copy to dest dir

Logs:

06-27 01:06:12.490  8662  8684 I MainActivity: New intent: Intent { act=android.intent.action.VIEW dat=content://me.zhanghai.android.files.file_provider/... typ=application/epub+zip flg=0x13000003 cmp=org.koreader.launcher/.MainActivity (has extras) }.action
06-27 01:06:12.491  8662  8684 I UriHandler: Found content, trying to guess if it's a local file on a readable directory
06-27 01:06:12.500  8662  8684 I UriHandler: Guessed path -> /storage/emulated/0/La peste - Albert Camus.epub
06-27 01:06:40.266  8742  8765 I MainActivity: New intent: Intent { act=android.intent.action.VIEW dat=content://com.microsoft.skydrive.content.StorageAccessProvider/... typ=application/epub+zip flg=0x33000001 cmp=org.koreader.launcher/.MainActivity }.action
06-27 01:06:40.266  8742  8765 I UriHandler: Found content, trying to guess if it's a local file on a readable directory
06-27 01:06:40.290  8742  8765 I UriHandler: Non readable file, importing it
06-27 01:06:40.332  8742  8765 I UriHandler: Imported to /storage/emulated/0/Android/data/org.koreader.launcher/files/La peste - Albert Camus.epub

This change is Reviewable

pazos commented 2 months ago

make dest dir configurable.

I'm not sure if it is a good idea to add it now as it might be quite messy.

Maybe on the future?

pazos commented 2 months ago

Looks sane to me, the nullable type stuff also looks good, but I don't really know enough about the relevant Android stuff without diving deeply into the docs to say anything sensible about that :-)

Does sound sensible to you to hardcode /storage/emulated/0/Android/data/org.koreader.launcher/files as the path to import files when they cannot be guessed?

I'm not very fond of making it configurable, mostly because it adds a bunch of ugly code but it could also introduce PECKABs.

pazos commented 2 months ago

relevant Android stuff

Nothing new :)

We just repurpose toFile for content uris that cannot be guessed. It is already used via FM's + button -> import

Frenzie commented 2 months ago

Does sound sensible to you to hardcode /storage/emulated/0/Android/data/org.koreader.launcher/files as the path to import files when they cannot be guessed?

There isn't the path in between? Hardcoded to some system-provided constant that resolves to that path.

pazos commented 1 month ago

There isn't the path in between? Hardcoded to some system-provided constant that resolves to that path.

Yup, that's https://github.com/koreader/android-luajit-launcher/pull/491/files#diff-d220509d6d0eba10bb869a2c57a664a4b02666cf0d975c0d03ba3bd04f2750a3R68

Frenzie commented 1 month ago

Then hardcoded (if that's the word) sounds fine to me. :+1: