-
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.
feat: Refactor states, move Song model
This commit includes several key changes:- Refactored `ScreenState` to be a sealed interface instead of a sealed class. - Refactored `ResourceState` to use data classes and include loading/error messages instead of generic messages. - Moved `Song` model to `com.bobbyesp.utilities.mediastore.model` package. - Updated usages of `Song`, `ResourceState`, and `ScreenState` across the codebase to reflect the above changes. - Added documentation to the states sealed classes/interfaces - Added `toString` to `ResourceState` for easier debugging - Improved `NavType` creation functions with more documentation.
- Loading branch information
Showing
16 changed files
with
158 additions
and
25 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
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
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
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
2 changes: 1 addition & 1 deletion
2
...java/com/bobbyesp/utilities/model/Song.kt → ...bbyesp/utilities/mediastore/model/Song.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
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
55 changes: 51 additions & 4 deletions
55
app/utilities/src/main/java/com/bobbyesp/utilities/states/ResourceState.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 |
---|---|---|
@@ -1,7 +1,54 @@ | ||
package com.bobbyesp.utilities.states | ||
|
||
sealed class ResourceState<T>(val data: T? = null, val message: String? = null) { | ||
class Loading<T>(data: T? = null) : ResourceState<T>(data) | ||
class Success<T>(data: T?) : ResourceState<T>(data) | ||
class Error<T>(message: String, data: T? = null) : ResourceState<T>(data, message) | ||
/** | ||
* A sealed class representing the state of a resource. | ||
* | ||
* @param T The type of data held by this state. | ||
* @property data The data associated with the state, if any. | ||
* @property message The message associated with the state, if any. | ||
*/ | ||
sealed class ResourceState<T>( | ||
val data: T? = null, | ||
val message: String? = null | ||
) { | ||
/** | ||
* Represents a loading state with optional partial data. | ||
* | ||
* @param T The type of data held by this state. | ||
* @property partialData The partial data associated with the loading state, if any. | ||
*/ | ||
data class Loading<T>(val partialData: T? = null) : ResourceState<T>(partialData) | ||
|
||
/** | ||
* Represents a successful state with required data. | ||
* | ||
* @param T The type of data held by this state. | ||
* @property result The result data associated with the successful state. | ||
*/ | ||
data class Success<T>(val result: T) : ResourceState<T>(result) | ||
|
||
/** | ||
* Represents an error state with a message and optional data. | ||
* | ||
* @param T The type of data held by this state. | ||
* @property errorMessage The error message associated with the error state. | ||
* @property errorData The data associated with the error state, if any. | ||
*/ | ||
data class Error<T>( | ||
val errorMessage: String, | ||
val errorData: T? = null | ||
) : ResourceState<T>(errorData, errorMessage) | ||
|
||
/** | ||
* Returns a string representation of the resource state. | ||
* | ||
* @return A string describing the current state. | ||
*/ | ||
override fun toString(): String { | ||
return when (this) { | ||
is Loading -> "Loading(data=$data)" | ||
is Success -> "Success(data=$data)" | ||
is Error -> "Error(message=$message, data=$data)" | ||
} | ||
} | ||
} |
29 changes: 25 additions & 4 deletions
29
app/utilities/src/main/java/com/bobbyesp/utilities/states/ScreenState.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 |
---|---|---|
@@ -1,7 +1,28 @@ | ||
package com.bobbyesp.utilities.states | ||
|
||
sealed class ScreenState<out T> { | ||
data object Loading : ScreenState<Nothing>() | ||
data class Success<T>(val data: T?) : ScreenState<T>() | ||
data class Error(val exception: Throwable) : ScreenState<Nothing>() | ||
/** | ||
* A sealed interface representing the state of a screen. | ||
* | ||
* @param T The type of data held by this state. | ||
*/ | ||
sealed interface ScreenState<out T> { | ||
/** | ||
* Represents a loading state. | ||
*/ | ||
object Loading : ScreenState<Nothing> | ||
|
||
/** | ||
* Represents a successful state with data. | ||
* | ||
* @param T The type of data held by this state. | ||
* @property data The data associated with the successful state. | ||
*/ | ||
data class Success<T>(val data: T?) : ScreenState<T> | ||
|
||
/** | ||
* Represents an error state with an exception. | ||
* | ||
* @property exception The exception associated with the error state. | ||
*/ | ||
data class Error(val exception: Throwable) : ScreenState<Nothing> | ||
} |