-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
10 changed files
with
96 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,12 @@ | ||
plugins { | ||
id("paypal.android.library") | ||
id("paypal.android.hilt") | ||
} | ||
|
||
android { | ||
namespace = "com.saeed.paypal.core.common" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.coroutines.android) | ||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
5 changes: 5 additions & 0 deletions
5
core/common/src/main/java/com/saeed/paypal/core/decoder/StringDecoder.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,5 @@ | ||
package com.saeed.paypal.core.decoder | ||
|
||
interface StringDecoder { | ||
fun decodeString(encodedString: String): String | ||
} |
8 changes: 8 additions & 0 deletions
8
core/common/src/main/java/com/saeed/paypal/core/decoder/UriDecoder.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,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) | ||
} |
15 changes: 15 additions & 0 deletions
15
core/common/src/main/java/com/saeed/paypal/core/decoder/di/StringDecoderModule.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,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 | ||
} |
12 changes: 12 additions & 0 deletions
12
core/common/src/main/java/com/saeed/paypal/core/network/PayPalDispatchers.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,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 | ||
} |
19 changes: 19 additions & 0 deletions
19
core/common/src/main/java/com/saeed/paypal/core/network/di/DispatchersModule.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,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
21
core/common/src/main/java/com/saeed/paypal/core/result/Result.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,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)) } | ||
} |
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