This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use type safe nav arguments
- Loading branch information
1 parent
906d1f5
commit 9c5dc26
Showing
25 changed files
with
588 additions
and
230 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
11 changes: 9 additions & 2 deletions
11
app/src/main/java/app/suhasdissa/vibeyou/domain/models/primary/Album.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,17 +1,24 @@ | ||
package app.suhasdissa.vibeyou.domain.models.primary | ||
|
||
import android.net.Uri | ||
import android.os.Parcelable | ||
import app.suhasdissa.vibeyou.utils.UriSerializer | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@Parcelize | ||
data class Album( | ||
val id: String, | ||
val title: String, | ||
@Serializable(with = UriSerializer::class) | ||
val thumbnailUri: Uri? = null, | ||
val artistsText: String, | ||
val numberOfSongs: Int? = null, | ||
val isLocal: Boolean = false, | ||
val type: Type = Type.ALBUM | ||
) { | ||
) : Parcelable { | ||
enum class Type { | ||
PLAYLIST, ALBUM | ||
} | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
app/src/main/java/app/suhasdissa/vibeyou/domain/models/primary/Artist.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,12 +1,19 @@ | ||
package app.suhasdissa.vibeyou.domain.models.primary | ||
|
||
import android.net.Uri | ||
import android.os.Parcelable | ||
import app.suhasdissa.vibeyou.utils.UriSerializer | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.serialization.Serializable | ||
|
||
@Parcelize | ||
@Serializable | ||
data class Artist( | ||
val id: String, | ||
val artistsText: String, | ||
@Serializable(with = UriSerializer::class) | ||
val thumbnailUri: Uri? = null, | ||
val description: String? = null, | ||
val numberOfTracks: Int? = null, | ||
val numberOfAlbums: Int? = null | ||
) | ||
) : Parcelable |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/app/suhasdissa/vibeyou/navigation/CustomNavTypes.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,50 @@ | ||
package app.suhasdissa.vibeyou.navigation | ||
|
||
import android.os.Bundle | ||
import androidx.navigation.NavType | ||
import app.suhasdissa.vibeyou.domain.models.primary.Album | ||
import app.suhasdissa.vibeyou.domain.models.primary.Artist | ||
import kotlinx.serialization.json.Json | ||
import java.net.URLDecoder | ||
import java.net.URLEncoder | ||
|
||
val AlbumType = object : NavType<Album>( | ||
isNullableAllowed = false | ||
) { | ||
override fun put(bundle: Bundle, key: String, value: Album) { | ||
bundle.putParcelable(key, value) | ||
} | ||
|
||
override fun get(bundle: Bundle, key: String): Album? { | ||
return bundle.getParcelable(key) | ||
} | ||
|
||
override fun parseValue(value: String): Album { | ||
return Json.decodeFromString<Album>(URLDecoder.decode(value, "UTF-8")) | ||
} | ||
|
||
override fun serializeAsValue(value: Album): String { | ||
return URLEncoder.encode(Json.encodeToString(Album.serializer(), value), "UTF-8") | ||
} | ||
} | ||
|
||
val ArtistType = object : NavType<Artist>( | ||
isNullableAllowed = false | ||
) { | ||
override fun put(bundle: Bundle, key: String, value: Artist) { | ||
bundle.putParcelable(key, value) | ||
} | ||
|
||
override fun get(bundle: Bundle, key: String): Artist? { | ||
return bundle.getParcelable(key) | ||
} | ||
|
||
override fun parseValue(value: String): Artist { | ||
return Json.decodeFromString<Artist>(URLDecoder.decode(value, "UTF-8")) | ||
} | ||
|
||
override fun serializeAsValue(value: Artist): String { | ||
return URLEncoder.encode(Json.encodeToString(Artist.serializer(), value), "UTF-8") | ||
} | ||
|
||
} |
62 changes: 47 additions & 15 deletions
62
app/src/main/java/app/suhasdissa/vibeyou/navigation/Destination.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,18 +1,50 @@ | ||
package app.suhasdissa.vibeyou.navigation | ||
|
||
sealed class Destination(val route: String) { | ||
object PipedMusic : Destination("piped_music") | ||
object LocalMusic : Destination("local_music") | ||
object OnlineSearch : Destination("online_search") | ||
object LocalSearch : Destination("local_search") | ||
object Settings : Destination("settings") | ||
object About : Destination("about") | ||
object NetworkSettings : Destination("net_settings") | ||
object DatabaseSettings : Destination("database_settings") | ||
object AppearanceSettings : Destination("appearance_settings") | ||
object Playlists : Destination("playlist_screen") | ||
object LocalPlaylists : Destination("local_playlist_screen") | ||
object SavedPlaylists : Destination("saved_playlist_screen") | ||
object Artist : Destination("artist") | ||
object LocalArtist : Destination("local_artist") | ||
import app.suhasdissa.vibeyou.domain.models.primary.Album | ||
import app.suhasdissa.vibeyou.domain.models.primary.Artist | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
sealed class Destination { | ||
@Serializable | ||
object PipedMusic : Destination() | ||
|
||
@Serializable | ||
object LocalMusic : Destination() | ||
|
||
@Serializable | ||
object OnlineSearch : Destination() | ||
|
||
@Serializable | ||
object LocalSearch : Destination() | ||
|
||
@Serializable | ||
object Settings : Destination() | ||
|
||
@Serializable | ||
object About : Destination() | ||
|
||
@Serializable | ||
object NetworkSettings : Destination() | ||
|
||
@Serializable | ||
object DatabaseSettings : Destination() | ||
|
||
@Serializable | ||
object AppearanceSettings : Destination() | ||
|
||
@Serializable | ||
data class Playlists(val album: Album) : Destination() | ||
|
||
@Serializable | ||
data class LocalPlaylists(val album: Album) : Destination() | ||
|
||
@Serializable | ||
data class SavedPlaylists(val album: Album) : Destination() | ||
|
||
@Serializable | ||
data class OnlineArtist(val artist: Artist) : Destination() | ||
|
||
@Serializable | ||
data class LocalArtist(val artist: Artist) : Destination() | ||
} |
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
Oops, something went wrong.