Skip to content

Commit

Permalink
Merge pull request #18 from vipulyaara/develop
Browse files Browse the repository at this point in the history
Release 0.20.0
  • Loading branch information
vipulyaara authored May 5, 2024
2 parents b828853 + b9f51dc commit 1936c98
Show file tree
Hide file tree
Showing 26 changed files with 289 additions and 90 deletions.
11 changes: 2 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {

defaultConfig {
applicationId = "com.kafka.user"
versionCode = 58
versionName = "0.18.0"
versionCode = 60
versionName = "0.20.0"

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())
Expand Down Expand Up @@ -113,13 +113,6 @@ android {
checkDependencies = true
warning += "AutoboxingStateCreation"
}

dependenciesInfo {
// Disables dependency metadata when building APKs.
includeInApk = false
// Disables dependency metadata when building Android App Bundles.
includeInBundle = false
}
}

dependencies {
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/kafka/user/home/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.navigation.compose.navigation
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import com.google.accompanist.navigation.material.bottomSheet
import com.kafka.data.model.SearchFilter
import com.kafka.reader.ReaderScreen
import com.kafka.reader.online.OnlineReader
import com.kafka.search.SearchScreen
Expand Down Expand Up @@ -142,6 +143,7 @@ private fun NavGraphBuilder.addLibraryRoot() {
addWebView(RootScreen.Library)
addOnlineReader(RootScreen.Library)
addLogin(RootScreen.Library)
addProfile(RootScreen.Library)
}
}

Expand All @@ -155,8 +157,14 @@ private fun NavGraphBuilder.addSearch(root: RootScreen) {
composable(
Screen.Search.createRoute(root),
arguments = listOf(
navArgument("keyword") { type = NavType.StringType },
navArgument("filters") { type = NavType.StringType }
navArgument("keyword") {
type = NavType.StringType
defaultValue = ""
},
navArgument("filters") {
type = NavType.StringType
defaultValue = SearchFilter.Name.name
}
),
deepLinks = listOf(
navDeepLink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ internal fun RowScope.ResizableHomeNavigationRail(
maxWeight = maxWeight,
dragOffset = dragOffset,
setDragOffset = setDragOffset,
analyticsPrefix = "home.navigationRail",
) { resizableModifier ->
HomeNavigationRail(
selectedTab = selectedTab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.kafka.navigation.Navigator
import org.kafka.navigation.Screen
import org.kafka.navigation.Screen.Search.createRoute
import org.kafka.navigation.Screen.Search
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -46,7 +46,12 @@ class PlaybackViewModel @Inject constructor(
viewModelScope.launch {
val currentRoot = navigator.currentRoot.value
val creator = playbackConnection.nowPlaying.value.artist
navigator.navigate(createRoute(currentRoot, creator, SearchFilter.Creator.name))

navigator.navigate(Search.createRoute(
root = currentRoot,
keyword = creator,
filter = SearchFilter.Creator.name
))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class EventRepository @Inject constructor() {
"name" to name,
)

fun playItem(itemId: String, source: String? = null) = "play_item" to mapOf(
fun playItem(itemId: String, source: String? = null, index: Int = 0) = "play_item" to mapOf(
"item_id" to itemId,
"source" to source,
"index" to index.toString(),
)

fun readItem(itemId: String, type: String = "offline", source: String? = null) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package org.kafka.analytics.logger

import android.content.Context
import android.os.Bundle
import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.logEvent
import com.google.firebase.crashlytics.crashlytics
import com.google.firebase.crashlytics.setCustomKeys
import com.mixpanel.android.mpmetrics.MixpanelAPI
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
Expand All @@ -24,6 +27,7 @@ class AnalyticsImpl @Inject constructor(
private val eventRepository: EventRepository,
) : Analytics {
private val firebaseAnalytics by lazy { FirebaseAnalytics.getInstance(context) }
private val crashlytics by lazy { Firebase.crashlytics }
private val mixPanel = MixpanelAPI.getInstance(context, MIXPANEL_TOKEN, true)

init {
Expand All @@ -48,6 +52,17 @@ class AnalyticsImpl @Inject constructor(
override fun updateUserProperty(userData: UserData) {
firebaseAnalytics.setUserProperty("userId", userData.userId)
firebaseAnalytics.setUserProperty("country", userData.country)

if (userData.userId != null) {
crashlytics.setUserId(userData.userId)
mixPanel.identify(userData.userId)
}

crashlytics.setCustomKeys {
if (userData.country != null) {
key("country", userData.country)
}
}
}

override fun logScreenView(label: String, route: String?, arguments: Any?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const val VIEW_RECOMMENDATION_ENABLED = "view_recommendation_data_enabled"
const val USE_RECOMMENDATION_ENABLED = "use_recommendation_data_enabled"
const val RECOMMENDATION_ROW_ENABLED = "recommendation_row_enabled"
const val RECOMMENDATION_ROW_INDEX = "recommendation_row_index"
const val RELATED_CONTENT_ROW_ENABLED = "related_content_row_enabled"
const val ONLINE_READER_ENABLED = "online_reader_enabled"
const val EXACT_ALARM_ENABLED = "exact_alarm_enabled"

Expand All @@ -30,6 +31,8 @@ fun RemoteConfig.isRecommendationRowEnabled() = getBoolean(RECOMMENDATION_ROW_EN

fun RemoteConfig.recommendationRowIndex() = getLong(RECOMMENDATION_ROW_INDEX)

fun RemoteConfig.isRelatedContentRowEnabled() = getBoolean(RELATED_CONTENT_ROW_ENABLED)

fun RemoteConfig.isOnlineReaderEnabled() = getBoolean(ONLINE_READER_ENABLED)

fun RemoteConfig.isExactAlarmEnabled() = getBoolean(EXACT_ALARM_ENABLED)
2 changes: 1 addition & 1 deletion data/models/src/main/java/com/kafka/data/model/item/Doc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class Doc(
@Serializable(with = StringListSerializer::class)
val description: List<String>? = null,
@SerialName("downloads")
val downloads: Int,
val downloads: Int = 0,
@SerialName("format")
@Serializable(with = StringListSerializer::class)
val format: List<String>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ class RecommendationRepository @Inject constructor(
private val dispatchers: CoroutineDispatchers
) {

suspend fun getRecommendations(userId: String) = resultApiCall(dispatchers.io) {
suspend fun getRecommendedContent(userId: String) = resultApiCall(dispatchers.io) {
val requestBody = ContentRecommendationRequestBody.fromUser(userId)
recommendationService.getRecommendedContent(pipelessAppId, requestBody)
}

suspend fun getRelatedContent(contentId: String) = resultApiCall(dispatchers.io) {
val requestBody = RelatedContentRequestBody.fromContent(contentId)
recommendationService.getRelatedContent(pipelessAppId, requestBody)
}

suspend fun postEvent(
recommendationObjectFrom: RecommendationObject,
recommendationRelationship: RecommendationRelationship,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kafka.data.feature.recommendation

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RelatedContentRequestBody(
@SerialName("content_tagged_relationship_type")
val contentTaggedRelationshipType: String,
@SerialName("object")
val objectX: Object,
@SerialName("positive_rel")
val primaryPositiveRelationshipType: String
) {
@Serializable
data class Object(
@SerialName("id")
val id: String,
@SerialName("type")
val type: String
)

companion object {
fun fromContent(contentId: String) = RelatedContentRequestBody(
primaryPositiveRelationshipType = "viewed",
contentTaggedRelationshipType = "taggedWith",
objectX = Object(id = contentId, type = "content")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kafka.data.feature.recommendation.network

import com.kafka.data.feature.recommendation.ContentRecommendationRequestBody
import com.kafka.data.feature.recommendation.RecommendedContentResponse
import com.kafka.data.feature.recommendation.RelatedContentRequestBody
import com.kafka.data.model.recommendation.RecommendationRequestBody
import okhttp3.ResponseBody
import retrofit2.http.Body
Expand All @@ -20,4 +21,10 @@ interface RecommendationService {
@Path("app_id") appId: Int,
@Body body: ContentRecommendationRequestBody,
): RecommendedContentResponse

@POST("apps/{app_id}/algos/recommendations/related-content")
suspend fun getRelatedContent(
@Path("app_id") appId: Int,
@Body body: RelatedContentRequestBody,
): RecommendedContentResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.kafka.domain.interactors
import com.kafka.data.dao.RecentAudioDao
import com.sarahang.playback.core.PlaybackConnection
import com.sarahang.playback.core.apis.AudioDataSource
import org.kafka.analytics.logger.Analytics
import org.kafka.base.domain.Interactor
import javax.inject.Inject

Expand All @@ -13,7 +14,8 @@ import javax.inject.Inject
class ResumeAlbum @Inject constructor(
private val playbackConnection: PlaybackConnection,
private val recentAudioDao: RecentAudioDao,
private val audioDataSource: AudioDataSource
private val audioDataSource: AudioDataSource,
private val analytics: Analytics
) : Interactor<String>() {

override suspend fun doWork(params: String) {
Expand All @@ -25,6 +27,8 @@ class ResumeAlbum @Inject constructor(
.indexOf(audio?.fileId)
.coerceAtLeast(0)

analytics.log { playItem(itemId = params, index = index) }

playbackConnection.playAlbum(params, index)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GetRecommendedContent @Inject constructor(
override suspend fun doWork(params: Unit): List<Item> = withContext(dispatchers.io) {
if (firebaseAuth.currentUser != null) {
val response = recommendationRepository
.getRecommendations(firebaseAuth.currentUser!!.uid)
.getRecommendedContent(firebaseAuth.currentUser!!.uid)
val itemIds = response.getOrThrow().items.map { it.objectX.id }

val query = ArchiveQuery().booksByIdentifiers(itemIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.kafka.domain.interactors.recommendation

import com.google.firebase.auth.FirebaseAuth
import com.kafka.data.entities.Item
import com.kafka.data.feature.item.ItemRepository
import com.kafka.data.feature.recommendation.RecommendationRepository
import com.kafka.data.model.ArchiveQuery
import com.kafka.data.model.booksByIdentifiers
import kotlinx.coroutines.withContext
import org.kafka.base.CoroutineDispatchers
import org.kafka.base.debug
import org.kafka.base.domain.ResultInteractor
import org.kafka.domain.interactors.query.BuildRemoteQuery
import javax.inject.Inject

class GetRelatedContent @Inject constructor(
private val recommendationRepository: RecommendationRepository,
private val itemRepository: ItemRepository,
private val buildRemoteQuery: BuildRemoteQuery,
private val firebaseAuth: FirebaseAuth,
private val dispatchers: CoroutineDispatchers
) : ResultInteractor<String, List<Item>>() {

override suspend fun doWork(params: String): List<Item> = withContext(dispatchers.io) {
if (firebaseAuth.currentUser != null) {
val response = recommendationRepository.getRelatedContent(params)
val itemIds = response.getOrThrow().items.map { it.objectX.id }

val query = ArchiveQuery().booksByIdentifiers(itemIds)
val items = itemRepository.updateQuery(buildRemoteQuery(query))

debug { "Recommended items: ${itemIds.size} $items" }

items
.filterNot { it.isInappropriate } // remove inappropriate items
.distinctBy { it.itemId }
} else {
emptyList()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.compose.ui.unit.dp
fun LabelMedium(text: String, modifier: Modifier = Modifier) {
Text(
text = text,
style = MaterialTheme.typography.titleMedium,
modifier = modifier,
style = MaterialTheme.typography.titleMedium,
)
}

Expand Down
Loading

0 comments on commit 1936c98

Please sign in to comment.