Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sh text eol=lf
*.bat text eol=crlf
11 changes: 9 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
Expand Down Expand Up @@ -27,8 +30,12 @@ android {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
apiVersion = KotlinVersion.KOTLIN_2_0
languageVersion = KotlinVersion.KOTLIN_2_0
}
}
buildFeatures {
viewBinding true
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.5.2' apply false
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
id 'com.android.library' version '8.5.2' apply false
id 'com.google.devtools.ksp' version '2.0.0-1.0.23' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.10'
id 'com.android.application' version '8.13.1' apply false
id 'org.jetbrains.kotlin.android' version '2.2.21' apply false
id 'com.android.library' version '8.13.1' apply false
id 'com.google.devtools.ksp' version '2.2.21-2.0.4' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '2.2.21'
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true

ksp.useKSP2=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat May 04 16:01:34 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
178 changes: 89 additions & 89 deletions gradlew.bat

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

11 changes: 9 additions & 2 deletions ketch/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
Expand Down Expand Up @@ -26,8 +29,12 @@ android {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
apiVersion = KotlinVersion.KOTLIN_1_9
languageVersion = KotlinVersion.KOTLIN_1_9
}
}
}

Expand Down
22 changes: 13 additions & 9 deletions ketch/src/main/java/com/ketch/Ketch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import okhttp3.Call
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -89,7 +90,7 @@ class Ketch private constructor(
private var downloadConfig: DownloadConfig,
private var notificationConfig: NotificationConfig,
private var logger: Logger,
private var okHttpClient: OkHttpClient
private var callFactory: Call.Factory,
) {

private val mutex = Mutex()
Expand All @@ -107,10 +108,10 @@ class Ketch private constructor(
smallIcon = NotificationConst.DEFAULT_VALUE_NOTIFICATION_SMALL_ICON
)
private var logger: Logger = DownloadLogger(false)
private lateinit var okHttpClient: OkHttpClient
private lateinit var callFactory: Call.Factory

/**
* Set download config: It has no effect if using [setOkHttpClient] function
* Set download config: It has no effect if using [setCallFactory] function
* Pass timeout values inside okHttpClient itself
*
* @param config [DownloadConfig]
Expand All @@ -131,16 +132,19 @@ class Ketch private constructor(
this.logger = logger
}

fun setOkHttpClient(okHttpClient: OkHttpClient) = apply {
this.okHttpClient = okHttpClient
@Deprecated("Use setCallFactory instead.", replaceWith = ReplaceWith("setCallFactory(okHttpClient)"))
fun setOkHttpClient(okHttpClient: OkHttpClient) = setCallFactory(okHttpClient)

fun setCallFactory(callFactory: Call.Factory) = apply {
this.callFactory = callFactory
}

@Synchronized
fun build(context: Context): Ketch {
if (ketchInstance == null) {

if (!::okHttpClient.isInitialized) {
okHttpClient = OkHttpClient
if (!::callFactory.isInitialized) {
callFactory = OkHttpClient
.Builder()
.connectTimeout(downloadConfig.connectTimeOutInMs, TimeUnit.MILLISECONDS)
.readTimeout(downloadConfig.readTimeOutInMs, TimeUnit.MILLISECONDS)
Expand All @@ -152,7 +156,7 @@ class Ketch private constructor(
downloadConfig = downloadConfig,
notificationConfig = notificationConfig,
logger = logger,
okHttpClient = okHttpClient
callFactory = callFactory,
)
}
return ketchInstance!!
Expand All @@ -161,7 +165,7 @@ class Ketch private constructor(
}

init {
RetrofitInstance.getDownloadService(okHttpClient = okHttpClient)
RetrofitInstance.getDownloadService(callFactory = callFactory)
}

private val downloadManager = DownloadManager(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ketch.internal.network

import com.ketch.internal.utils.DownloadConst
import okhttp3.Call
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit
Expand All @@ -11,7 +12,7 @@ internal object RetrofitInstance {
private var downloadService: DownloadService? = null

fun getDownloadService(
okHttpClient: OkHttpClient =
callFactory: Call.Factory =
OkHttpClient
.Builder()
.connectTimeout(DownloadConst.DEFAULT_VALUE_CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS)
Expand All @@ -24,7 +25,7 @@ internal object RetrofitInstance {
downloadService = Retrofit
.Builder()
.baseUrl(DownloadConst.BASE_URL)
.client(okHttpClient)
.callFactory(callFactory)
.build()
.create(DownloadService::class.java)
}
Expand Down