-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from Javernaut/feature/new_protocols_support
New protocols support
- Loading branch information
Showing
28 changed files
with
446 additions
and
342 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
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
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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/javernaut/whatthecodec/di/DispatcherModule.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,37 @@ | ||
package com.javernaut.whatthecodec.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import javax.inject.Qualifier | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DispatcherModule { | ||
@DefaultDispatcher | ||
@Provides | ||
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default | ||
|
||
@IoDispatcher | ||
@Provides | ||
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO | ||
|
||
@MainDispatcher | ||
@Provides | ||
fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main | ||
} | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class DefaultDispatcher | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class IoDispatcher | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class MainDispatcher |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/javernaut/whatthecodec/home/domain/FileReadingUseCase.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,34 @@ | ||
package com.javernaut.whatthecodec.home.domain | ||
|
||
import com.javernaut.whatthecodec.di.IoDispatcher | ||
import com.javernaut.whatthecodec.home.presentation.MediaFileArgument | ||
import com.javernaut.whatthecodec.home.presentation.MediaFileProvider | ||
import io.github.javernaut.mediafile.MediaFile | ||
import io.github.javernaut.mediafile.model.MediaInfo | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.withContext | ||
import java.io.IOException | ||
import javax.inject.Inject | ||
|
||
class FileReadingUseCase @Inject constructor( | ||
private val mediaFileProvider: MediaFileProvider, | ||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher | ||
) { | ||
|
||
suspend fun readFile(arg: MediaFileArgument): Result<ReadingResult> = | ||
withContext(ioDispatcher) { | ||
val mediaFile = mediaFileProvider.obtainMediaFile(arg.uri) | ||
?: return@withContext Result.failure(IOException("Couldn't read the file")) | ||
|
||
val mediaInfo = mediaFile.readMediaInfo() | ||
?: return@withContext Result.failure(IOException("Couldn't read the file's meta data")) | ||
|
||
Result.success(ReadingResult(mediaFile, mediaInfo)) | ||
} | ||
|
||
// Reusing the data types from MediaFile library | ||
data class ReadingResult( | ||
val context: MediaFile, | ||
val metaData: MediaInfo | ||
) | ||
} |
Oops, something went wrong.