-
Notifications
You must be signed in to change notification settings - Fork 0
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 #482 from bounswe/development
Development Main Merge
- Loading branch information
Showing
143 changed files
with
9,223 additions
and
1,115 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
90 changes: 84 additions & 6 deletions
90
prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.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
3 changes: 3 additions & 0 deletions
3
...olls/android/app/src/main/java/com/bounswe/predictionpolls/common/PredictionPollsError.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,3 @@ | ||
package com.bounswe.predictionpolls.common | ||
|
||
data class PredictionPollsError(val code: String, val message: String) |
9 changes: 9 additions & 0 deletions
9
prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/common/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,9 @@ | ||
package com.bounswe.predictionpolls.common | ||
|
||
/** | ||
* A generic class that holds a value or an exception | ||
*/ | ||
sealed class Result<out R> { | ||
data class Success<out T>(val data: T) : Result<T>() | ||
data class Error(val exception: Exception) : Result<Nothing>() | ||
} |
12 changes: 12 additions & 0 deletions
12
prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/feed/FeedApi.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.bounswe.predictionpolls.data.feed | ||
|
||
import com.bounswe.predictionpolls.data.feed.model.PollResponse | ||
import retrofit2.http.GET | ||
|
||
interface FeedApi { | ||
/** | ||
* Fetches the list of polls and returns the result. | ||
*/ | ||
@GET("/polls") | ||
suspend fun getPolls(): List<PollResponse> | ||
} |
12 changes: 12 additions & 0 deletions
12
...s/android/app/src/main/java/com/bounswe/predictionpolls/data/feed/FeedRemoteDataSource.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.bounswe.predictionpolls.data.feed | ||
|
||
import com.bounswe.predictionpolls.common.Result | ||
import com.bounswe.predictionpolls.data.feed.model.PollResponse | ||
import com.bounswe.predictionpolls.domain.poll.Poll | ||
|
||
interface FeedRemoteDataSource { | ||
/** | ||
* Fetches the list of polls and returns the result. | ||
*/ | ||
suspend fun getPolls(page: Int): Result<List<PollResponse>> | ||
} |
20 changes: 20 additions & 0 deletions
20
...droid/app/src/main/java/com/bounswe/predictionpolls/data/feed/FeedRemoteDataSourceImpl.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,20 @@ | ||
package com.bounswe.predictionpolls.data.feed | ||
|
||
import com.bounswe.predictionpolls.common.Result | ||
import com.bounswe.predictionpolls.data.feed.model.PollResponse | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class FeedRemoteDataSourceImpl @Inject constructor( | ||
private val feedApi: FeedApi | ||
) : FeedRemoteDataSource { | ||
override suspend fun getPolls(page: Int): Result<List<PollResponse>> = withContext(Dispatchers.IO) { | ||
try { | ||
val response = feedApi.getPolls() | ||
Result.Success(response) | ||
} catch (e: Exception) { | ||
Result.Error(e) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...lls/android/app/src/main/java/com/bounswe/predictionpolls/data/feed/FeedRepositoryImpl.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,33 @@ | ||
package com.bounswe.predictionpolls.data.feed | ||
|
||
import android.util.Log | ||
import com.bounswe.predictionpolls.common.Result | ||
import com.bounswe.predictionpolls.domain.feed.FeedRepository | ||
import com.bounswe.predictionpolls.domain.poll.Poll | ||
import javax.inject.Inject | ||
|
||
private const val TAG = "FeedRepositoryImpl" | ||
|
||
class FeedRepositoryImpl @Inject constructor( | ||
private val feedRemoteDataSource: FeedRemoteDataSource | ||
) : FeedRepository { | ||
override suspend fun getPolls(page: Int): Result<List<Poll>> = | ||
when (val result = feedRemoteDataSource.getPolls(page)) { | ||
is Result.Success -> { | ||
val polls = result.data.mapNotNull { | ||
try { | ||
it.toPollDomainModel() | ||
} catch (e: Exception) { | ||
Log.e(TAG, "getPolls: $it cannot be converted to Poll") | ||
null | ||
} | ||
} | ||
Result.Success(polls) | ||
} | ||
|
||
is Result.Error -> { | ||
Result.Error(result.exception) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.