forked from droidconKE/droidconKeKotlin
-
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.
Feed api implementation (droidconKE#125)
* Adding Feed.kt file * Adding FeedRepo.kt Interface file * Renaming Feed.kt to FeedDTO.kt * Adding Feed ViewModel * Adds feed implementation * Changing API BaseURL Test * Adding tests in FeedScreenTest.kt file * Renamed api -> FeedApi * Changed ResourceResult<List<Feed>> -> List<Feed> * Referencing String directly from the composable * Modifying FeedScreenTest.kt file * Create droidcon_logo_dark.xml * check mode in code * Added codeAnalysis.bat for windows uers and ran it * set it for all AppBars' * use if with id * contrib-readme-action has updated readme (droidconKE#127) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update to AS Flamingo (droidconKE#126) * updates * Update AS Version * Dependencies updates * update readme * Update README.md * Update README.md * Update README.md * Update README.md * rename * update java version on CI * contrib-readme-action has updated readme (droidconKE#130) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * contrib-readme-action has updated readme (droidconKE#131) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * contrib-readme-action has updated readme (droidconKE#132) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Migrate some State and viewModel calls from their composables to their respective ViewModels * contrib-readme-action has updated readme * contrib-readme-action has updated readme (droidconKE#134) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Adds feed implementation * Handling state in the FeedScreen.kt file * Refactoring results * Fixes failing tests * Fixes String resource merge conflicts --------- Co-authored-by: brian.orwe <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Harun Wangereka <[email protected]> Co-authored-by: yveskalume <[email protected]>
- Loading branch information
1 parent
8e78fa0
commit 949d8a2
Showing
18 changed files
with
442 additions
and
77 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
data/src/main/java/com/android254/data/repos/FeedManager.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 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.data.repos | ||
|
||
import com.android254.data.network.apis.FeedApi | ||
import com.android254.data.repos.mappers.toDomain | ||
import com.android254.domain.models.DataResult | ||
import com.android254.domain.models.Feed | ||
import com.android254.domain.models.ResourceResult | ||
import com.android254.domain.repos.FeedRepo | ||
import javax.inject.Inject | ||
|
||
class FeedManager @Inject constructor( | ||
private val FeedApi: FeedApi | ||
) : FeedRepo { | ||
override suspend fun fetchFeed(): ResourceResult<List<Feed>> { | ||
return when (val result = FeedApi.fetchFeed(1, 100)) { | ||
DataResult.Empty -> ResourceResult.Empty("Empty list ") | ||
is DataResult.Error -> ResourceResult.Error(result.message) | ||
is DataResult.Loading -> ResourceResult.Loading(true) | ||
is DataResult.Success -> ResourceResult.Success(result.data.map { it.toDomain() }) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
data/src/main/java/com/android254/data/repos/mappers/FeedMappers.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,28 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.data.repos.mappers | ||
|
||
import com.android254.data.network.models.responses.FeedDTO | ||
import com.android254.domain.models.Feed | ||
|
||
fun FeedDTO.toDomain() = Feed( | ||
title = title, | ||
body = body, | ||
topic = topic, | ||
url = url, | ||
image = image, | ||
createdAt = createdAt.toString() | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.domain.models | ||
|
||
class Feed( | ||
val title: String, | ||
val body: String, | ||
val topic: String, | ||
val url: String, | ||
val image: String?, | ||
val createdAt: String | ||
) |
23 changes: 23 additions & 0 deletions
23
domain/src/main/java/com/android254/domain/repos/FeedRepo.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,23 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.domain.repos | ||
|
||
import com.android254.domain.models.Feed | ||
import com.android254.domain.models.ResourceResult | ||
|
||
interface FeedRepo { | ||
suspend fun fetchFeed(): ResourceResult<List<Feed>> | ||
} |
52 changes: 52 additions & 0 deletions
52
presentation/src/main/java/com/android254/presentation/common/bottomsheet/Strings.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,52 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.presentation.common.bottomsheet | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.ui.R | ||
import androidx.compose.ui.platform.LocalConfiguration | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
@Immutable | ||
@kotlin.jvm.JvmInline | ||
value class Strings private constructor(@Suppress("unused") private val value: Int) { | ||
companion object { | ||
val NavigationMenu = Strings(0) | ||
val CloseDrawer = Strings(1) | ||
val CloseSheet = Strings(2) | ||
val DefaultErrorMessage = Strings(3) | ||
val ExposedDropdownMenu = Strings(4) | ||
val SliderRangeStart = Strings(5) | ||
val SliderRangeEnd = Strings(6) | ||
} | ||
} | ||
|
||
@Composable | ||
fun getString(string: Strings): String { | ||
LocalConfiguration.current | ||
val resources = LocalContext.current.resources | ||
return when (string) { | ||
Strings.NavigationMenu -> resources.getString(R.string.navigation_menu) | ||
Strings.CloseDrawer -> resources.getString(R.string.close_drawer) | ||
Strings.CloseSheet -> resources.getString(R.string.close_sheet) | ||
Strings.DefaultErrorMessage -> resources.getString(R.string.default_error_message) | ||
Strings.ExposedDropdownMenu -> resources.getString(R.string.dropdown_menu) | ||
Strings.SliderRangeStart -> resources.getString(R.string.range_start) | ||
Strings.SliderRangeEnd -> resources.getString(R.string.range_end) | ||
else -> "" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
presentation/src/main/java/com/android254/presentation/feed/FeedViewModel.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,51 @@ | ||
/* | ||
* Copyright 2023 DroidconKE | ||
* | ||
* 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.android254.presentation.feed | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.android254.domain.models.ResourceResult | ||
import com.android254.domain.repos.FeedRepo | ||
import com.android254.presentation.feed.view.FeedUIState | ||
import com.android254.presentation.feed.view.toPresentation | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class FeedViewModel @Inject constructor( | ||
private val feedRepo: FeedRepo | ||
) : ViewModel() { | ||
var viewState: FeedUIState by mutableStateOf(FeedUIState.Loading) | ||
private set | ||
|
||
fun fetchFeed() { | ||
viewModelScope.launch { | ||
viewState = when (val value = feedRepo.fetchFeed()) { | ||
is ResourceResult.Empty -> FeedUIState.Empty | ||
is ResourceResult.Error -> FeedUIState.Error(value.message) | ||
is ResourceResult.Loading -> FeedUIState.Loading | ||
is ResourceResult.Success -> FeedUIState.Success( | ||
value.data?.map { it.toPresentation() } | ||
?: emptyList() | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.