-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: unify importers #3436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mostafaNazari702
wants to merge
21
commits into
ReVanced:dev
Choose a base branch
from
mostafaNazari702:feat/unify-importers
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: unify importers #3436
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bb8d014
introduce protocol handlers for opening source streams
mostafaNazari702 81bef8b
redesign stream access around callbacks and complete the file protoco…
mostafaNazari702 a9e8048
move UI requests into a generic communication layer
mostafaNazari702 3c664f3
specialize the request layer to file picking
mostafaNazari702 783c703
parse sources as URIs and route remote transport through protocol han…
mostafaNazari702 caa7808
turn the default source into a plain URL
mostafaNazari702 844dce7
route local imports through the protocol handlers
mostafaNazari702 85ef81b
merge local and remote sources into one
mostafaNazari702 9ea6088
provide the content resolver through the koin graph
mostafaNazari702 9d5de81
remove the local and remote distinction outside the handlers
mostafaNazari702 602a23c
store sources as plain URLs and migrate old rows on boot
mostafaNazari702 1168d70
remove the remaining remote references outside the handlers
mostafaNazari702 ece3dbc
enable auto update for the default source
mostafaNazari702 fdfa64c
rebuild the import dialog around a method dropdown
mostafaNazari702 f521703
offer the file picker from the auto method
mostafaNazari702 7238979
check for updates through the version resource
mostafaNazari702 2d81ce2
fill the input with the picked file
mostafaNazari702 5b2e425
stored sources as urls and renamed the column
mostafaNazari702 9019fc3
name the patches and downloader url errors
mostafaNazari702 897ff3f
fix the add button never enabling for http
mostafaNazari702 c4d27a5
read the changelog from the source url
mostafaNazari702 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,21 @@ | ||
| package app.revanced.manager.di | ||
|
|
||
| import app.revanced.manager.domain.protocol.ContentProtocolHandler | ||
| import app.revanced.manager.domain.protocol.FileProtocolHandler | ||
| import app.revanced.manager.domain.protocol.HttpProtocolHandler | ||
| import app.revanced.manager.network.service.HttpService | ||
| import app.revanced.manager.util.FilePicker | ||
| import app.revanced.manager.util.UiFilePicker | ||
| import org.koin.android.ext.koin.androidContext | ||
| import org.koin.core.module.dsl.bind | ||
| import org.koin.core.module.dsl.singleOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val serviceModule = module { | ||
| singleOf(::HttpService) | ||
| } | ||
| singleOf(::UiFilePicker) { bind<FilePicker>() } | ||
|
mostafaNazari702 marked this conversation as resolved.
|
||
| single { androidContext().contentResolver } | ||
| singleOf(::HttpProtocolHandler) | ||
| singleOf(::ContentProtocolHandler) | ||
| singleOf(::FileProtocolHandler) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/app/revanced/manager/domain/protocol/ProtocolHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package app.revanced.manager.domain.protocol | ||
|
|
||
| import android.content.ContentResolver | ||
| import android.net.Uri | ||
| import app.revanced.manager.network.service.HttpService | ||
| import app.revanced.manager.util.FilePicker | ||
| import io.ktor.client.request.url | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
| import java.io.IOException | ||
| import java.io.InputStream | ||
|
|
||
| // Opens streams for the URI scheme it is registered for. | ||
| interface ProtocolHandler { | ||
| // Opens a stream to the resource behind [uri] and passes it to [block]. | ||
| // The stream is only valid inside [block] and is closed automatically afterwards. | ||
| suspend fun <T> getStream(uri: Uri, block: suspend (InputStream) -> T): T | ||
| } | ||
|
|
||
| class HttpProtocolHandler(private val http: HttpService) : ProtocolHandler { | ||
| override suspend fun <T> getStream(uri: Uri, block: suspend (InputStream) -> T) = | ||
| http.getStream(block) { url(uri.toString()) } | ||
| } | ||
|
|
||
| // Opens content:// URIs, which the platform grants the app access to. | ||
| class ContentProtocolHandler(private val contentResolver: ContentResolver) : ProtocolHandler { | ||
| override suspend fun <T> getStream(uri: Uri, block: suspend (InputStream) -> T): T { | ||
| val stream = withContext(Dispatchers.IO) { | ||
| contentResolver.openInputStream(uri) ?: throw IOException("Cannot open $uri") | ||
| } | ||
|
|
||
| return stream.use { block(it) } | ||
| } | ||
| } | ||
|
|
||
| // Reading file:// URIs directly requires storage permissions, which the app avoids. | ||
| // The user instead picks the file through the system file picker, which yields | ||
| // a content:// URI the app is allowed to open. | ||
| class FileProtocolHandler( | ||
| private val filePicker: FilePicker, | ||
| private val contentProtocolHandler: ContentProtocolHandler | ||
| ) : ProtocolHandler { | ||
| override suspend fun <T> getStream(uri: Uri, block: suspend (InputStream) -> T): T { | ||
| val picked = filePicker.pickFile() ?: throw IOException("No file was selected") | ||
| return contentProtocolHandler.getStream(picked, block) | ||
| } | ||
| } | ||
|
|
||
| // Opens a stream to [uri] with the handler registered for its scheme. | ||
| suspend fun <T> Map<String, ProtocolHandler>.getStream( | ||
| uri: Uri, | ||
| block: suspend (InputStream) -> T | ||
| ): T { | ||
| val handler = this[uri.scheme] ?: throw IOException("No handler for $uri") | ||
| return handler.getStream(uri, block) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.