Skip to content

Commit

Permalink
Merge pull request #15 from vipulyaara/develop
Browse files Browse the repository at this point in the history
Release 0.16.0
  • Loading branch information
vipulyaara committed Apr 23, 2024
2 parents 2bcedfe + 87852b9 commit 9ba7de1
Show file tree
Hide file tree
Showing 36 changed files with 907 additions and 192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ captures/
.idea/dictionaries
.idea/libraries
.idea/caches
.idea/kotlinc.xml

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ android {

defaultConfig {
applicationId = "com.kafka.user"
versionCode = 53
versionName = libs.versions.versionname.toString()
versionCode = 56
versionName = "0.16.0"

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())

buildConfigField(
"String",
"GOOGLE_SERVER_CLIENT_ID",
properties["PIPELESS_AUTH_TOKEN"]?.toString() ?: System.getenv("PIPELESS_AUTH_TOKEN")
properties["GOOGLE_SERVER_CLIENT_ID"]?.toString() ?: System.getenv("GOOGLE_SERVER_CLIENT_ID")
)
buildConfigField(
"String",
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/kafka/user/home/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ private fun NavGraphBuilder.addLibraryRoot() {
addPlayer(RootScreen.Library)
addWebView(RootScreen.Library)
addOnlineReader(RootScreen.Library)
addLogin(RootScreen.Library)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package com.kafka.user.initializer

import android.app.Application
import org.kafka.base.AppInitializer
import com.kafka.data.dao.RecentAudioDao
import com.kafka.data.entities.RecentAudioItem
import org.kafka.base.ProcessLifetime
import com.sarahang.playback.core.PlaybackConnection
import com.sarahang.playback.core.albumId
import com.sarahang.playback.core.fileId
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import org.kafka.base.AppInitializer
import org.kafka.base.CoroutineDispatchers
import org.kafka.base.ProcessLifetime
import org.kafka.base.debug
import javax.inject.Inject

/**
* An [AppInitializer] that updates the the currently playing audio.
*
* It listens to the [PlaybackConnection.nowPlaying] and updates the recent audio item
* so that it can be played from last item when the user plays the album again.
*/
class AudioProgressInitializer @Inject constructor(
private val playbackConnection: PlaybackConnection,
private val dispatchers: CoroutineDispatchers,
private val recentAudioDao: RecentAudioDao,
@ProcessLifetime private val coroutineScope: CoroutineScope,
) : AppInitializer {

override fun init(application: Application) {
coroutineScope.launch(dispatchers.io) {
playbackConnection.playbackProgress
.filter { it.position % 5L == 0L && it.position != 0L }
playbackConnection.nowPlaying
.collectLatest { timestamp ->
debug { "Updating progress for $timestamp" }
playbackConnection.nowPlaying.value.fileId?.let { fileId ->
val audioItem = recentAudioDao.get(fileId)
if (audioItem == null) {
val audio = RecentAudioItem(fileId, timestamp.position, timestamp.total)
recentAudioDao.insert(audio)
} else {
recentAudioDao.updateTimestamp(fileId, timestamp.position)

playbackConnection.nowPlaying.value.albumId?.let { albumId ->
playbackConnection.nowPlaying.value.fileId?.let { fileId ->
val audioItem = recentAudioDao.getByAlbumId(albumId)
if (audioItem == null) {
val audio = RecentAudioItem(fileId = fileId, albumId = albumId)
recentAudioDao.insert(audio)
} else {
recentAudioDao.updateNowPlaying(albumId = albumId, fileId = fileId)
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/kafka/user/injection/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.kafka.recommendations.topic.FirebaseTopicsImpl
import com.kafka.recommendations.topic.FirebaseTopicsInitializer
import com.kafka.user.BuildConfig
import com.kafka.user.deeplink.FirebaseDynamicDeepLinkHandler
import com.kafka.user.initializer.AudioProgressInitializer
import com.kafka.user.initializer.FirebaseInitializer
import com.kafka.user.initializer.LoggerInitializer
import com.kafka.user.initializer.ReaderProgressInitializer
Expand Down Expand Up @@ -110,7 +111,7 @@ class AppModule {


@Provides
fun provideGoogleClientIdProvider() = object : SecretsProvider {
fun provideSecretsProvider() = object : SecretsProvider {
override val googleServerClientId: String = BuildConfig.GOOGLE_SERVER_CLIENT_ID
override val pipelessAuthToken: String = BuildConfig.PIPELESS_AUTH_TOKEN
}
Expand Down Expand Up @@ -155,6 +156,10 @@ abstract class AppModuleBinds {
@IntoSet
abstract fun provideFirebaseTopicsInitializer(bind: FirebaseTopicsInitializer): AppInitializer

@Binds
@IntoSet
abstract fun provideAudioProgressInitializer(bind: AudioProgressInitializer): AppInitializer

@Singleton
@Binds
abstract fun provideNotificationManager(bind: NotificationManagerImpl): NotificationManager
Expand Down
133 changes: 133 additions & 0 deletions base/domain/src/main/java/org/kafka/base/Combine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
@file:Suppress("UNCHECKED_CAST")

package org.kafka.base

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine

fun <T1, T2, T3, T4, T5, T6, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
transform: suspend (T1, T2, T3, T4, T5, T6) -> R,
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
)
}

fun <T1, T2, T3, T4, T5, T6, T7, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
flow7: Flow<T7>,
transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R,
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
args[6] as T7,
)
}

fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
flow7: Flow<T7>,
flow8: Flow<T8>,
transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8) -> R,
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6, flow7, flow8) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
args[6] as T7,
args[7] as T8,
)
}

fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
flow7: Flow<T7>,
flow8: Flow<T8>,
flow9: Flow<T9>,
transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R,
): Flow<R> =
combine(flow, flow2, flow3, flow4, flow5, flow6, flow7, flow8, flow9) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
args[6] as T7,
args[7] as T8,
args[8] as T9,
)
}

fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
flow4: Flow<T4>,
flow5: Flow<T5>,
flow6: Flow<T6>,
flow7: Flow<T7>,
flow8: Flow<T8>,
flow9: Flow<T9>,
flow10: Flow<T10>,
transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R,
): Flow<R> = combine(
flow,
flow2,
flow3,
flow4,
flow5,
flow6,
flow7,
flow8,
flow9,
flow10
) { args: Array<*> ->
transform(
args[0] as T1,
args[1] as T2,
args[2] as T3,
args[3] as T4,
args[4] as T5,
args[5] as T6,
args[6] as T7,
args[7] as T8,
args[8] as T9,
args[9] as T10,
)
}
8 changes: 1 addition & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import com.android.build.gradle.BaseExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import org.jetbrains.kotlin.gradle.plugin.KaptExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

Expand Down Expand Up @@ -141,9 +141,3 @@ fun Project.configureAndroidProject() {
}
}
}

tasks.register("appVersionName") {
doLast {
println(libs.versions.versionname)
}
}
Loading

0 comments on commit 9ba7de1

Please sign in to comment.