-
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.
Refactor home to follow clean architecture
- Loading branch information
1 parent
ab05695
commit 08032fa
Showing
20 changed files
with
138 additions
and
125 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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/modarb/android/ui/home/ui/home/data/HomeRepositoryImpl.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,26 @@ | ||
package com.modarb.android.ui.home.ui.home.data | ||
|
||
import com.modarb.android.network.ApiService | ||
import com.modarb.android.network.Result | ||
import com.modarb.android.ui.home.ui.home.domain.HomeRepository | ||
import com.modarb.android.ui.home.ui.home.domain.models.HomePageResponse | ||
|
||
class HomeRepositoryImpl(private val apiService: ApiService) : HomeRepository { | ||
override suspend fun getHomePage(token: String): Result<HomePageResponse> { | ||
|
||
return try { | ||
val response = apiService.getHomePage(token) | ||
if (response.isSuccessful) { | ||
response.body()?.let { | ||
Result.Success(it) | ||
} ?: Result.Failure(Throwable("Response body is null")) | ||
} else { | ||
Result.Failure(Throwable(response.errorBody()?.string() ?: "Unknown error")) | ||
} | ||
} catch (E: Exception) { | ||
Result.Failure(E) | ||
} | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/modarb/android/ui/home/ui/home/domain/HomeRepository.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.modarb.android.ui.home.ui.home.domain | ||
|
||
import com.modarb.android.network.Result | ||
import com.modarb.android.ui.home.ui.home.domain.models.HomePageResponse | ||
|
||
interface HomeRepository { | ||
|
||
suspend fun getHomePage(token: String): Result<HomePageResponse> | ||
} |
2 changes: 1 addition & 1 deletion
2
...rb/android/ui/home/ui/home/models/Data.kt → ...oid/ui/home/ui/home/domain/models/Data.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
2 changes: 1 addition & 1 deletion
2
...i/home/ui/home/models/HomePageResponse.kt → ...ui/home/domain/models/HomePageResponse.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
app/src/main/java/com/modarb/android/ui/home/ui/home/domain/models/MyMealPlan.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.modarb.android.ui.home.ui.home.domain.models | ||
|
||
class MyMealPlan |
4 changes: 3 additions & 1 deletion
4
...droid/ui/home/ui/home/models/MyWorkout.kt → ...i/home/ui/home/domain/models/MyWorkout.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
2 changes: 1 addition & 1 deletion
2
...oid/ui/home/ui/home/models/Preferences.kt → ...home/ui/home/domain/models/Preferences.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
2 changes: 1 addition & 1 deletion
2
...rb/android/ui/home/ui/home/models/User.kt → ...oid/ui/home/ui/home/domain/models/User.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
2 changes: 1 addition & 1 deletion
2
...android/ui/home/ui/home/models/Workout.kt → .../ui/home/ui/home/domain/models/Workout.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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/modarb/android/ui/home/ui/home/domain/usecase/HomePageUseCase.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,11 @@ | ||
package com.modarb.android.ui.home.ui.home.domain.usecase | ||
|
||
import com.modarb.android.network.Result | ||
import com.modarb.android.ui.home.ui.home.domain.HomeRepository | ||
import com.modarb.android.ui.home.ui.home.domain.models.HomePageResponse | ||
|
||
class HomePageUseCase(private val homeRepository: HomeRepository) { | ||
suspend operator fun invoke(token: String): Result<HomePageResponse> { | ||
return homeRepository.getHomePage(token) | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/modarb/android/ui/home/ui/home/logic/HomeRepository.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
app/src/main/java/com/modarb/android/ui/home/ui/home/logic/HomeViewModel.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
app/src/main/java/com/modarb/android/ui/home/ui/home/logic/HomeViewModelFactory.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
app/src/main/java/com/modarb/android/ui/home/ui/home/models/Day.kt
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
app/src/main/java/com/modarb/android/ui/home/ui/home/models/MyMealPlan.kt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app/src/main/java/com/modarb/android/ui/home/ui/home/models/Week.kt
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/modarb/android/ui/home/ui/home/presentation/HomeViewModel.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,32 @@ | ||
package com.modarb.android.ui.home.ui.home.presentation | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.modarb.android.network.Result | ||
import com.modarb.android.network.RetrofitService | ||
import com.modarb.android.network.models.BaseResponse | ||
import com.modarb.android.ui.home.ui.home.data.HomeRepositoryImpl | ||
import com.modarb.android.ui.home.ui.home.domain.models.HomePageResponse | ||
import com.modarb.android.ui.home.ui.home.domain.usecase.HomePageUseCase | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class HomeViewModel : ViewModel() { | ||
|
||
private var apiService = RetrofitService.createService() | ||
private var homeRepository = HomeRepositoryImpl(apiService) | ||
private var homeUseCase = HomePageUseCase(homeRepository) | ||
|
||
private val _homeResponse = MutableStateFlow<Result<HomePageResponse>?>(null) | ||
val homeResponse: StateFlow<Result<BaseResponse>?> get() = _homeResponse | ||
|
||
|
||
fun getUserHomePage(token: String) { | ||
viewModelScope.launch { | ||
val result = homeUseCase.invoke(token) | ||
_homeResponse.value = result | ||
} | ||
|
||
} | ||
} |