-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c024579
commit e36c0de
Showing
4 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
49 changes: 49 additions & 0 deletions
49
.../duckplayer-impl/src/main/java/com/duckduckgo/duckplayer/impl/DuckPlayerLocalFilesPath.kt
This file contains 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,49 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.duckplayer.impl | ||
|
||
import android.content.res.AssetManager | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import java.io.IOException | ||
import javax.inject.Inject | ||
|
||
interface DuckPlayerLocalFilesPath { | ||
val assetsPath: List<String> | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class RealDuckPlayerLocalFilesPath @Inject constructor(private val assetManager: AssetManager) : DuckPlayerLocalFilesPath { | ||
|
||
override val assetsPath: List<String> = getAllAssetFilePaths("duckplayer") | ||
|
||
private fun getAllAssetFilePaths(directory: String): List<String> { | ||
val filePaths = mutableListOf<String>() | ||
val files = assetManager.list(directory) ?: return emptyList() | ||
|
||
files.forEach { | ||
val fullPath = "$directory/$it" | ||
try { | ||
assetManager.open(fullPath) | ||
filePaths.add(fullPath.removePrefix("duckplayer/")) | ||
} catch (e: IOException) { | ||
filePaths.addAll(getAllAssetFilePaths(fullPath)) | ||
} | ||
} | ||
return filePaths | ||
} | ||
} |
This file contains 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
42 changes: 42 additions & 0 deletions
42
...layer/duckplayer-impl/src/main/java/com/duckduckgo/duckplayer/impl/di/DuckPlayerModule.kt
This file contains 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,42 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.duckplayer.impl.di | ||
|
||
import android.content.Context | ||
import android.content.res.AssetManager | ||
import android.webkit.MimeTypeMap | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesTo | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.SingleInstanceIn | ||
|
||
@Module | ||
@ContributesTo(AppScope::class) | ||
class DuckPlayerModule { | ||
@Provides | ||
@SingleInstanceIn(AppScope::class) | ||
fun provideMimeTypeMap(): MimeTypeMap { | ||
return MimeTypeMap.getSingleton() | ||
} | ||
|
||
@Provides | ||
@SingleInstanceIn(AppScope::class) | ||
fun provideAssetManager(context: Context): AssetManager { | ||
return context.assets | ||
} | ||
} |