Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
msmoradi committed Dec 8, 2022
2 parents b4ea80d + 9c803b3 commit 2d7d5b7
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
12 changes: 12 additions & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("paypal.android.library")
id("paypal.android.hilt")
}

android {
namespace = "com.saeed.paypal.core.common"
}

dependencies {
implementation(libs.kotlinx.coroutines.android)
}
2 changes: 2 additions & 0 deletions core/common/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.saeed.paypal.core.decoder

interface StringDecoder {
fun decodeString(encodedString: String): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.saeed.paypal.core.decoder

import android.net.Uri
import javax.inject.Inject

class UriDecoder @Inject constructor() : StringDecoder {
override fun decodeString(encodedString: String): String = Uri.decode(encodedString)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.saeed.paypal.core.decoder.di

import com.saeed.paypal.core.decoder.StringDecoder
import com.saeed.paypal.core.decoder.UriDecoder
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
abstract class StringDecoderModule {
@Binds
abstract fun bindStringDecoder(uriDecoder: UriDecoder): StringDecoder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.saeed.paypal.core.network

import javax.inject.Qualifier
import kotlin.annotation.AnnotationRetention.RUNTIME

@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val dispatcher: PayPalDispatchers)

enum class PayPalDispatchers {
IO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.saeed.paypal.core.network.di

import com.saeed.paypal.core.network.Dispatcher
import com.saeed.paypal.core.network.PayPalDispatchers.IO
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

@Module
@InstallIn(SingletonComponent::class)
object DispatchersModule {

@Provides
@Dispatcher(IO)
fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO
}
21 changes: 21 additions & 0 deletions core/common/src/main/java/com/saeed/paypal/core/result/Result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.saeed.paypal.core.result

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart

sealed interface Result<out T> {
data class Success<T>(val data: T) : Result<T>
data class Error(val exception: Throwable? = null) : Result<Nothing>
object Loading : Result<Nothing>
}

fun <T> Flow<T>.asResult(): Flow<Result<T>> {
return this
.map<T, Result<T>> {
Result.Success(it)
}
.onStart { emit(Result.Loading) }
.catch { emit(Result.Error(it)) }
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ include (":feature:contacts")
include (":feature:setting")
include (":core:ui")
include (":core:designsystem")
include(":core:common")

0 comments on commit 2d7d5b7

Please sign in to comment.