Skip to content

Commit

Permalink
Merge pull request #455 from pranavkonidena/MOBILE-203/UserPages-1.3
Browse files Browse the repository at this point in the history
Mobile 203/user pages 1.3
  • Loading branch information
akshaaatt authored Aug 10, 2024
2 parents a5c8c80 + 70ccb2f commit d1f8753
Show file tree
Hide file tree
Showing 27 changed files with 1,092 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.util.Properties
import java.io.FileInputStream
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class Artist(
val artist_mbid: String,
val artist_name: String,
val listen_count: Int
@SerializedName("artist_mbid") val artistMbid: String,
@SerializedName("artist_name") val artistName: String,
@SerializedName("listen_count") val listenCount: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class ListeningActivity(
@SerializedName("from_ts") val fromTs: Int? = null,
@SerializedName("listen_count") val listenCount: Int? = null,
@SerializedName("time_range") val timeRange: String? = null,
@SerializedName("to_ts") val toTs: Int? = null,
var componentIndex: Int? = null,
var color: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class ListeningActivityPayload(
@SerializedName("from_ts") val fromTs: Int? = null,
@SerializedName("last_updated") val lastUpdated: Int? = null,
@SerializedName("listening_activity") val listeningActivity: List<ListeningActivity?>? = null,
val range: String? = null,
@SerializedName("to_ts") val toTs: Int? = null,
@SerializedName("user_id") val userId: String? = null,
)
16 changes: 16 additions & 0 deletions app/src/main/java/org/listenbrainz/android/model/user/Recording.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class Recording(
@SerializedName("artist_mbids") val artistMbids: List<String>? = listOf(),
@SerializedName("artist_name") val artistName: String? = "",
val artists: List<TopArtistInfo>? = listOf(),
@SerializedName("caa_id") val caaId: Long? = 0,
@SerializedName("caa_release_mbid") val caaReleaseMbid: String? = "",
@SerializedName("listen_count") val listenCount: Int? = 0,
@SerializedName("recording_mbid") val recordingMbid: String? = "",
@SerializedName("release_mbid") val releaseMbid: String? = "",
@SerializedName("release_name") val releaseName: String? = "",
@SerializedName("track_name") val trackName: String? = ""
)
14 changes: 14 additions & 0 deletions app/src/main/java/org/listenbrainz/android/model/user/Release.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class Release(
@SerializedName("artist_mbids") val artistMbids: List<String>? = listOf(),
@SerializedName("artist_name") val artistName: String? = "",
val artists: List<TopArtistInfo>? = listOf(),
@SerializedName("caa_id") val caaId: Long? = 0,
@SerializedName("caa_release_mbid") val caaReleaseMbid: String? = "",
@SerializedName("listen_count") val listenCount: Int? = 0,
@SerializedName("release_mbid") val releaseMbid: String? = "",
@SerializedName("release_name") val releaseName: String? = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.listenbrainz.android.model.user

data class TopAlbums(
val payload: TopAlbumsPayload? = TopAlbumsPayload()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class TopAlbumsPayload(
val count: Int? = 0,
@SerializedName("from_ts") val fromTs: Int? = 0,
@SerializedName("last_updated") val lastUpdated: Int? = 0,
@SerializedName("offset") val offset: Int? = 0,
val range: String? = "",
val releases: List<Release>? = listOf(),
@SerializedName("to_ts") val toTs: Int? = 0,
@SerializedName("total_release_count") val totalReleaseCount: Int? = 0,
@SerializedName("user_id") val userId: String? = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class TopArtistInfo(
@SerializedName("artist_credit_name") val artistCreditName: String? = null,
@SerializedName("artist_mbid") val artistMbid: String? = null,
@SerializedName("join_phrase") val joinPhrase: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class TopArtistsPayload(
val artists: List<Artist>,
val count: Int,
val from_ts: Int,
val last_updated: Int,
val offset: Int,
val range: String,
val to_ts: Int,
val total_artist_count: Int,
val user_id: String
val artists: List<Artist>,
val count: Int,
@SerializedName("from_ts") val fromTs: Int,
@SerializedName("last_updated") val lastUpdated: Int,
val offset: Int,
val range: String,
@SerializedName("to_ts") val toTs: Int,
@SerializedName("total_artist_count") val totalArtistCount: Int,
@SerializedName("user_id") val userId: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.listenbrainz.android.model.user

import com.google.gson.annotations.SerializedName

data class TopSongPayload(
val count: Int? = 0,
@SerializedName("from_ts") val fromTs: Int? = 0,
@SerializedName("last_updated") val lastUpdated: Int? = 0,
val offset: Int? = 0,
val range: String? = "",
val recordings: List<Recording>? = listOf(),
@SerializedName("to_ts") val toTs: Int? = 0,
@SerializedName("total_recording_count") val totalRecordingCount: Int? = 0,
@SerializedName("user_id") val userId: String? = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.listenbrainz.android.model.user

data class TopSongs(
val payload: TopSongPayload? = TopSongPayload()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.listenbrainz.android.model.user

data class UserListeningActivity(
val payload: ListeningActivityPayload? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package org.listenbrainz.android.repository.user
import org.listenbrainz.android.model.Listens
import org.listenbrainz.android.model.PinnedRecording
import org.listenbrainz.android.model.user.AllPinnedRecordings
import org.listenbrainz.android.model.user.TopAlbums
import org.listenbrainz.android.model.user.TopArtists
import org.listenbrainz.android.model.user.TopSongs
import org.listenbrainz.android.model.user.UserFeedback
import org.listenbrainz.android.model.user.UserListeningActivity
import org.listenbrainz.android.model.user.UserSimilarityPayload
import org.listenbrainz.android.util.Resource

Expand All @@ -14,6 +17,10 @@ interface UserRepository {
suspend fun fetchUserCurrentPins(username: String?) : Resource<PinnedRecording?>
suspend fun fetchUserPins(username: String?) : Resource<AllPinnedRecordings?>
//TODO: Move to artists VM once implemented
suspend fun getTopArtists(username: String?): Resource<TopArtists>
suspend fun getTopArtists(username: String?, rangeString: String = "all_time", count: Int = 25): Resource<TopArtists>
suspend fun getUserFeedback(username: String?, score: Int?): Resource<UserFeedback?>
suspend fun getUserListeningActivity(username: String?, rangeString: String = "all_time"): Resource<UserListeningActivity?>
suspend fun getGlobalListeningActivity(rangeString: String = "all_time"): Resource<UserListeningActivity?>
suspend fun getTopAlbums(username: String?, rangeString: String = "all_time" ,count: Int = 25): Resource<TopAlbums>
suspend fun getTopSongs(username: String?, rangeString: String = "all_time"): Resource<TopSongs>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import org.listenbrainz.android.model.Listens
import org.listenbrainz.android.model.PinnedRecording
import org.listenbrainz.android.model.ResponseError
import org.listenbrainz.android.model.user.AllPinnedRecordings
import org.listenbrainz.android.model.user.TopAlbums
import org.listenbrainz.android.model.user.TopArtists
import org.listenbrainz.android.model.user.TopSongs
import org.listenbrainz.android.model.user.UserFeedback
import org.listenbrainz.android.model.user.UserListeningActivity
import org.listenbrainz.android.model.user.UserSimilarityPayload
import org.listenbrainz.android.service.UserService
import org.listenbrainz.android.util.Resource
Expand Down Expand Up @@ -37,16 +40,43 @@ class UserRepositoryImpl @Inject constructor(
}

override suspend fun getTopArtists(
username: String?
username: String?,
rangeString: String,
count: Int
): Resource<TopArtists> = parseResponse {
if(username.isNullOrEmpty()) return ResponseError.BAD_REQUEST.asResource()
service.getTopArtistsOfUser(username)
service.getTopArtistsOfUser(username, rangeString, count)
}

override suspend fun getUserFeedback(username: String?, score: Int?): Resource<UserFeedback?> = parseResponse {
if(username.isNullOrEmpty()) return ResponseError.BAD_REQUEST.asResource()
service.getUserFeedback(username, score)
}

override suspend fun getUserListeningActivity(
username: String?,
rangeString: String
): Resource<UserListeningActivity?> = parseResponse {
if(username.isNullOrEmpty()) return ResponseError.BAD_REQUEST.asResource()
service.getUserListeningActivity(username,rangeString)
}

override suspend fun getGlobalListeningActivity(rangeString: String): Resource<UserListeningActivity?> = parseResponse {
service.getGlobalListeningActivity(rangeString)
}

override suspend fun getTopAlbums(
username: String?,
rangeString: String,
count: Int
): Resource<TopAlbums> = parseResponse {
if(username.isNullOrEmpty()) return ResponseError.BAD_REQUEST.asResource()
service.getTopAlbumsOfUser(username, rangeString)
}

override suspend fun getTopSongs(username: String?, rangeString: String): Resource<TopSongs> = parseResponse{
if(username.isNullOrEmpty()) return ResponseError.BAD_REQUEST.asResource()
service.getTopSongsOfUser(username, rangeString)
}

}
20 changes: 18 additions & 2 deletions app/src/main/java/org/listenbrainz/android/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package org.listenbrainz.android.service
import org.listenbrainz.android.model.Listens
import org.listenbrainz.android.model.PinnedRecording
import org.listenbrainz.android.model.user.AllPinnedRecordings
import org.listenbrainz.android.model.user.TopAlbums
import org.listenbrainz.android.model.user.TopArtists
import org.listenbrainz.android.model.user.TopSongs
import org.listenbrainz.android.model.user.UserFeedback
import org.listenbrainz.android.model.user.UserListeningActivity
import org.listenbrainz.android.model.user.UserSimilarityPayload
import retrofit2.Response
import retrofit2.http.GET
Expand All @@ -24,9 +27,22 @@ interface UserService {
@GET("{user_name}/pins")
suspend fun getUserPins(@Path("user_name") username: String?) : Response<AllPinnedRecordings?>

@GET("stats/user/{user_name}/artists?count=100")
suspend fun getTopArtistsOfUser(@Path("user_name") username: String?) : Response<TopArtists>
@GET("stats/user/{user_name}/artists")
suspend fun getTopArtistsOfUser(@Path("user_name") username: String?, @Query("range") rangeString: String?, @Query("count") count: Int = 25) : Response<TopArtists>

@GET("feedback/user/{user_name}/get-feedback?metadata=true")
suspend fun getUserFeedback(@Path("user_name") username: String?, @Query("score") score: Int?) : Response<UserFeedback?>

@GET("stats/user/{user_name}/listening-activity")
suspend fun getUserListeningActivity(@Path("user_name") username: String?, @Query("range") rangeString: String?): Response<UserListeningActivity?>

@GET("stats/sitewide/listening-activity")
suspend fun getGlobalListeningActivity(@Query("range") rangeString: String?) : Response<UserListeningActivity?>

@GET("stats/user/{user_name}/releases")
suspend fun getTopAlbumsOfUser(@Path("user_name") username: String?, @Query("range") rangeString: String?): Response<TopAlbums>

@GET("stats/user/{user_name}/recordings")
suspend fun getTopSongsOfUser(@Path("user_name") username: String?, @Query("range") rangeString: String?): Response<TopSongs>

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ fun ListenCardSmall(
trailingContent: @Composable (modifier: Modifier) -> Unit = {},
enableBlurbContent: Boolean = false,
blurbContent: @Composable (ColumnScope.(modifier: Modifier) -> Unit) = {},
color: Color = ListenBrainzTheme.colorScheme.level1,
titleColor: Color = ListenBrainzTheme.colorScheme.listenText,
subtitleColor: Color = titleColor.copy(alpha = 0.7f),
onClick: () -> Unit,
) {
Surface(
Expand All @@ -67,7 +70,7 @@ fun ListenCardSmall(
.clickable(enabled = true) { onClick() },
shape = ListenBrainzTheme.shapes.listenCardSmall,
shadowElevation = 4.dp,
color = ListenBrainzTheme.colorScheme.level1
color = color
) {
Column {

Expand Down Expand Up @@ -96,7 +99,7 @@ fun ListenCardSmall(

Spacer(modifier = Modifier.width(ListenBrainzTheme.paddings.coverArtAndTextGap))

TitleAndSubtitle(modifier = Modifier.padding(end = 6.dp), title = trackName, subtitle = artistName)
TitleAndSubtitle(modifier = Modifier.padding(end = 6.dp), title = trackName, subtitle = artistName, titleColor = titleColor, subtitleColor = subtitleColor)

}

Expand Down
Loading

0 comments on commit d1f8753

Please sign in to comment.