Skip to content

Commit

Permalink
Update builder design pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mutkuensert committed Sep 6, 2023
1 parent 87f93db commit 3e6d3ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Downloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.github.mutkuensert'
artifactId = 'downloader'
version = 'v2.3.0'
version = 'v2.3.1'

afterEvaluate {
from components.release
Expand Down
26 changes: 6 additions & 20 deletions Downloader/src/main/java/com/mutkuensert/downloader/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,20 @@ open class Downloader private constructor(
createNotificationChannelIfActive()
}

/**
* @property context is mandatory. If not set, NullPointerException will be thrown.
*
* @property scope is mandatory. If not set, NullPointerException will be thrown
*/
class Builder {
class Builder(
private val context: Context,
private val scope: CoroutineScope
) {
private var areNotificationsActive = false
private var scope: CoroutineScope? = null
private var context: Context? = null

fun build(): Downloader {
return Downloader(
scope = scope!!,
context = context!!,
scope = scope,
context = context,
areNotificationsActive = areNotificationsActive
)
}

fun context(context: Context): Builder {
this.context = context
return this
}

fun scope(scope: CoroutineScope): Builder {
this.scope = scope
return this
}

/**
* Default is false.
*/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ maven { url 'https://jitpack.io' }

Add the dependency in build.gradle file.
```gradle
implementation 'com.github.mutkuensert:downloader:v2.3.0'
implementation 'com.github.mutkuensert:downloader:v2.3.1'
```

**You can also add the library locally. To do that:**
Expand Down

0 comments on commit 3e6d3ba

Please sign in to comment.